[lacros] Generate a test runner wrapper for lacros

This CL generates a wrapper for each test target of format:
"bin/run_{target}", and the wrapper then invokes the lacros test
runner.

Bug: 1104318
Change-Id: I0e33e745068fe08173e077a593a3c83501bf9fb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2295925
Commit-Queue: Yuke Liao <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Reviewed-by: Erik Chen <[email protected]>
Reviewed-by: Sven Zheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#788823}
diff --git a/testing/test.gni b/testing/test.gni
index 984e2a3..ad98008 100644
--- a/testing/test.gni
+++ b/testing/test.gni
@@ -6,6 +6,8 @@
 # TEST SETUP
 # ==============================================================================
 
+import("//build/config/chromeos/ui_mode.gni")
+
 if (is_android) {
   import("//build/config/android/config.gni")
   import("//build/config/android/extract_unwind_tables.gni")
@@ -29,7 +31,8 @@
   import("//build/config/ios/rules.gni")
 }
 
-if ((is_linux && !is_chromeos) || is_mac || is_win) {
+if ((is_linux && !is_chromeos) || is_mac || is_win ||
+    chromeos_is_browser_only) {
   import("//build/config/sanitizers/sanitizers.gni")
   import("//build/util/generate_wrapper.gni")
 }
@@ -376,6 +379,48 @@
         "//build/win:default_exe_manifest",
       ]
     }
+  } else if (chromeos_is_browser_only) {
+    _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
+    _executable = target_name
+    _gen_runner_target = "${target_name}__runner"
+
+    generate_wrapper(_gen_runner_target) {
+      testonly = true
+      wrapper_script = "$root_build_dir/bin/run_" + _executable
+      executable = "//build/lacros/test_runner.py"
+      executable_args = [
+        "@WrappedPath(./${_executable})",
+        "--test-launcher-bot-mode",
+      ]
+      if (is_asan) {
+        executable_args += [ "--asan=true" ]
+      }
+      if (is_msan) {
+        executable_args += [ "--msan=true" ]
+      }
+      if (is_tsan) {
+        executable_args += [ "--tsan=true" ]
+      }
+      if (use_cfi_diag) {
+        executable_args += [ "--cfi-diag=true" ]
+      }
+
+      data = [
+        "//testing/test_env.py",
+        "//.vpython",
+      ]
+    }
+
+    executable(target_name) {
+      forward_variables_from(invoker, "*")
+      if (!defined(deps)) {
+        deps = []
+      }
+
+      testonly = true
+      write_runtime_deps = _runtime_deps_file
+      deps += [ ":$_gen_runner_target" ]
+    }
   } else {
     if ((is_linux && !is_chromeos) || is_mac || is_win) {
       _runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"