[android] Make pdfium_unittests work on Android.

This updates test.gni to match chromium as of
crrev.com/d29ecfa7dc3ed49a2a49002ab941adb57c53e923, changes how
PathService::GetSourceDir behaves on Android, and specifies the runtime
test data for test_support.

BUG=pdfium:415

Review-Url: https://codereview.chromium.org/2541503002
diff --git a/BUILD.gn b/BUILD.gn
index bf28674..a91feeb 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -197,6 +197,9 @@
     "testing/utils/path_service.cpp",
     "testing/utils/path_service.h",
   ]
+  data = [
+    "testing/resources/",
+  ]
   deps = [
     ":pdfium",
     "//testing/gmock",
@@ -1776,7 +1779,6 @@
   }
   configs += [ ":pdfium_core_config" ]
   if (is_android) {
-    ignore_all_data_deps = true
     use_raw_android_executable = true
   }
 }
diff --git a/testing/test.gni b/testing/test.gni
index 535a749..b6677d4 100644
--- a/testing/test.gni
+++ b/testing/test.gni
@@ -6,59 +6,6 @@
 # TEST SETUP
 # ==============================================================================
 
-template("_gen_isolate") {
-  testonly = true
-  _runtime_deps_file = "$target_gen_dir/$target_name.runtime_deps"
-  group("${target_name}__write_deps") {
-    forward_variables_from(invoker,
-                           [
-                             "data",
-                             "data_deps",
-                             "deps",
-                             "public_deps",
-                           ])
-    write_runtime_deps = _runtime_deps_file
-  }
-
-  action(target_name) {
-    script = "//testing/generate_isolate.py"
-    inputs = [
-      _runtime_deps_file,
-    ]
-    outputs = [
-      invoker.output,
-    ]
-    args = [
-      "--output-directory=.",
-      "--out-file",
-      rebase_path(invoker.output, root_build_dir),
-      "--runtime-deps-file",
-      rebase_path(_runtime_deps_file, root_build_dir),
-    ]
-    if (is_android) {
-      args += [ "--apply-android-filters" ]
-    }
-    if (defined(invoker.apply_device_filters) && invoker.apply_device_filters) {
-      args += [ "--apply-device-filters" ]
-    }
-    _assert_no_odd_data =
-        defined(invoker.assert_no_odd_data) && invoker.assert_no_odd_data
-    if (_assert_no_odd_data) {
-      args += [ "--assert-no-odd-data" ]
-    }
-    if (defined(invoker.command)) {
-      _isolate_dir = get_path_info(invoker.output, "dir")
-      args += [
-        "--command",
-        rebase_path(invoker.command, _isolate_dir),
-      ]
-    }
-    deps = [
-      ":${invoker.target_name}__write_deps",
-    ]
-  }
-}
-
 # Define a test as an executable (or apk on Android) with the "testonly" flag
 # set.
 # Variable:
@@ -81,36 +28,10 @@
     }
 
     _test_runner_target = "${_output_name}__test_runner_script"
-    _wrapper_script_vars = [ "shard_timeout" ]
-    _gen_isolate_vars = [
-      "allow_odd_runtime_deps",
+    _wrapper_script_vars = [
       "ignore_all_data_deps",
+      "shard_timeout",
     ]
-    _generate_device_isolate =
-        !defined(invoker.ignore_all_data_deps) || !invoker.ignore_all_data_deps
-
-    if (_generate_device_isolate) {
-      _allow_odd_runtime_deps = defined(invoker.allow_odd_runtime_deps) &&
-                                invoker.allow_odd_runtime_deps
-
-      # The device isolate is needed at runtime, so it cannot go in
-      # target_gen_dir, as builder/tester configurations do not include it.
-      _target_dir_name = get_label_info(":$target_name", "dir")
-      _device_isolate_path = "$root_out_dir/gen.runtime/$_target_dir_name/$target_name.device.isolate"
-      _gen_isolate_target_name = "${target_name}__isolate"
-      _gen_isolate(_gen_isolate_target_name) {
-        forward_variables_from(invoker,
-                               [
-                                 "data",
-                                 "data_deps",
-                                 "deps",
-                                 "public_deps",
-                               ])
-        assert_no_odd_data = !_allow_odd_runtime_deps
-        output = _device_isolate_path
-        apply_device_filters = true
-      }
-    }
 
     assert(_use_raw_android_executable || enable_java_templates)
 
@@ -124,10 +45,9 @@
         # Configs will always be defined since we set_defaults in BUILDCONFIG.gn.
         configs = []
         data_deps = []
-        forward_variables_from(
-            invoker,
-            "*",
-            _wrapper_script_vars + _gen_isolate_vars + [ "extra_dist_files" ])
+        forward_variables_from(invoker,
+                               "*",
+                               _wrapper_script_vars + [ "extra_dist_files" ])
         testonly = true
 
         # Thanks to the set_defaults() for test(), configs are initialized with
@@ -161,6 +81,7 @@
       _apk_target = "${target_name}_apk"
       _apk_specific_vars = [
         "android_manifest",
+        "android_manifest_dep",
         "enable_multidex",
         "proguard_configs",
         "proguard_enabled",
@@ -175,10 +96,10 @@
         testonly = true
 
         deps = []
-        forward_variables_from(invoker,
-                               "*",
-                               _apk_specific_vars + _wrapper_script_vars +
-                                   _gen_isolate_vars + [ "visibility" ])
+        forward_variables_from(
+            invoker,
+            "*",
+            _apk_specific_vars + _wrapper_script_vars + [ "visibility" ])
 
         if (!defined(invoker.use_default_launcher) ||
             invoker.use_default_launcher) {
@@ -187,14 +108,12 @@
       }
       unittest_apk(_apk_target) {
         forward_variables_from(invoker, _apk_specific_vars + [ "deps" ])
-        unittests_dep = ":$_library_target"
+        shared_library = ":$_library_target"
         apk_name = invoker.target_name
         if (defined(invoker.output_name)) {
           apk_name = invoker.output_name
-          unittests_binary = "lib${apk_name}.so"
           install_script_name = "install_${invoker.output_name}"
         }
-        deps += [ ":$_library_target" ]
 
         # TODO(agrieve): Remove this data_dep once bots don't build the _apk
         #     target (post-GYP).
@@ -211,13 +130,13 @@
       _incremental_test_runner_target =
           "${_output_name}_incremental__test_runner_script"
       test_runner_script(_incremental_test_runner_target) {
-        forward_variables_from(invoker, _wrapper_script_vars)
-        if (_generate_device_isolate) {
-          isolate_file = _device_isolate_path
-          deps = [
-            ":$_gen_isolate_target_name",
-          ]
-        }
+        forward_variables_from(invoker,
+                               _wrapper_script_vars + [
+                                     "data",
+                                     "data_deps",
+                                     "deps",
+                                     "public_deps",
+                                   ])
         apk_target = ":$_apk_target"
         test_name = "${_output_name}_incremental"
         test_type = "gtest"
@@ -237,13 +156,13 @@
 
     _test_runner_target = "${_output_name}__test_runner_script"
     test_runner_script(_test_runner_target) {
-      forward_variables_from(invoker, _wrapper_script_vars)
-      if (_generate_device_isolate) {
-        isolate_file = _device_isolate_path
-        deps = [
-          ":$_gen_isolate_target_name",
-        ]
-      }
+      forward_variables_from(invoker,
+                             _wrapper_script_vars + [
+                                   "data",
+                                   "data_deps",
+                                   "deps",
+                                   "public_deps",
+                                 ])
 
       if (_use_raw_android_executable) {
         executable_dist_dir = "$root_out_dir/$_dist_target"
@@ -282,10 +201,7 @@
     _resources_bundle_data = target_name + "_resources_bundle_data"
 
     bundle_data(_resources_bundle_data) {
-      visibility = [
-        ":${_test_target}",
-        ":${_test_target}_generate_executable",
-      ]
+      visibility = [ ":$_test_target" ]
       sources = [
         "//testing/gtest_ios/Default.png",
       ]
@@ -306,36 +222,30 @@
       if (!defined(info_plist) && !defined(info_plist_target)) {
         info_plist = "//testing/gtest_ios/unittest-Info.plist"
       }
-      if (!defined(entitlements_path)) {
-        entitlements_path = "//testing/gtest_ios"
-      }
-      if (!defined(code_signing_identity)) {
-        code_signing_identity = ""
-      }
 
-      # TODO(crbug.com/603102): remove this once gyp support is dropped and all
-      # application uses the target name as value for BUNDLE_ID_TEST_NAME.
-      if (defined(invoker.app_name)) {
-        app_name = invoker.app_name
-      } else {
-        app_name = target_name
+      _bundle_id_suffix = target_name
+      if (ios_automatically_manage_certs) {
+        # Use the same bundle identifier for all unit tests when managing
+        # certificates automatically as the number of free certs is limited.
+        _bundle_id_suffix = "generic-unit-test"
       }
-
       if (!defined(extra_substitutions)) {
         extra_substitutions = []
       }
-      extra_substitutions += [ "BUNDLE_ID_TEST_NAME=$app_name" ]
+      extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ]
 
       if (!defined(deps)) {
         deps = []
       }
       deps += [
-        ":$_resources_bundle_data",
-
         # All shared libraries must have the sanitizer deps to properly link in
         # asan mode (this target will be empty in other cases).
         "//build/config/sanitizers:deps",
       ]
+      if (!defined(bundle_deps)) {
+        bundle_deps = []
+      }
+      bundle_deps += [ ":$_resources_bundle_data" ]
     }
   } else {
     executable(target_name) {
diff --git a/testing/utils/path_service.cpp b/testing/utils/path_service.cpp
index a67a778..1030c2b 100644
--- a/testing/utils/path_service.cpp
+++ b/testing/utils/path_service.cpp
@@ -73,7 +73,11 @@
     path->push_back(PATH_SEPARATOR);
   path->append("..");
   path->push_back(PATH_SEPARATOR);
+#if defined(ANDROID)
+  path->append("chromium_tests_root");
+#else   // Non-Android
   path->append("..");
+#endif  // defined(ANDROID)
   return true;
 }