[ios] Simplify setting CFBundleIdentifier in Info.plist

Change all Info.plist templates to use ${BUNDLE_IDENTIFIER} variable
to set the CFBundleIdentifier value. The variable is based on the gn
variable `bundle_identifier` passed to the `ios_app_bundle` template.

This variable (defaults to `$ios_app_bundle_id_prefix.$output_name`)
is also used to set PRODUCT_BUNDLE_IDENTIFIER in the generated Xcode
project. Using one variable for both ensures that the values are
identical (if they are not, running the application on a device from
Xcode will fail).

Bug: 1250788
Change-Id: I7066425eebd2d24b4b862e5244453ec7cd818d6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3205359
Reviewed-by: Dirk Pranke <[email protected]>
Reviewed-by: Ali Juma <[email protected]>
Commit-Queue: Sylvain Defresne <[email protected]>
Cr-Commit-Position: refs/heads/main@{#929082}
diff --git a/testing/test.gni b/testing/test.gni
index b8e4e29..d88d26c 100644
--- a/testing/test.gni
+++ b/testing/test.gni
@@ -445,6 +445,11 @@
     }
 
     _test_target = target_name
+    _output_name = target_name
+    if (defined(invoker.output_name)) {
+      _output_name = invoker.output_name
+    }
+
     _wrapper_output_name = "run_${target_name}"
     ios_test_runner_wrapper(_wrapper_output_name) {
       forward_variables_from(invoker,
@@ -452,6 +457,7 @@
                                "data",
                                "deps",
                                "executable_args",
+                               "output_name",
                                "retries",
                                "shards",
                              ])
@@ -509,18 +515,11 @@
       }
 
       if (ios_use_shared_bundle_id_for_test_apps) {
-        _gtest_bundle_id_suffix = "unittests"
+        bundle_identifier = "$ios_app_bundle_id_prefix.gtest.unittests"
       } else {
-        _gtest_bundle_id_suffix = "${target_name}"
+        bundle_identifier = "$ios_app_bundle_id_prefix.gtest." +
+                            string_replace(_output_name, "_", "-")
       }
-      xcode_product_bundle_id =
-          "$ios_app_bundle_id_prefix.gtest.$_gtest_bundle_id_suffix"
-
-      if (!defined(extra_substitutions)) {
-        extra_substitutions = []
-      }
-      extra_substitutions +=
-          [ "GTEST_BUNDLE_ID_SUFFIX=$_gtest_bundle_id_suffix" ]
 
       if (!defined(bundle_deps)) {
         bundle_deps = []