Reland "a11y-common-mv3: Add to field trial config"

This is a reland of commit b3f7e1c2119d8db4db053ca2aa244d95e80d10a1

Changes:
AccessibilityExtensionAutomationTreeWalkerTest.Backward/Forward
failure on MSAN is because they have an iteration that runs more
than 30s. Long running tasks would cause the service worker to
be considered as stalled and gets killed. This is fixed by calling
an API and using `await` to yield control to service worker message
loop.

Original change's description:
> a11y-common-mv3: Add to field trial config
>
> - Add AccessibilityManifestV3AccessibilityCommon fieldtrial config
>   to prepare for a finch roll out;
> - Skip AccessibilityExtensionLocalStorageTest.Migration test in service
>   worker because localStorage is not available;
>
> AX-Relnotes: n/a.
> Bug: 388867838
> Change-Id: I90b2fb51cefbb1dedb529586e1b89ea58cf24d10
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6719634
> Reviewed-by: Akihiro Ota <akihiroota@chromium.org>
> Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1490225}

Cq-Include-Trybots: luci.chromium.try:linux_chromium_chromeos_msan_rel_ng
Bug: 388867838
Change-Id: I3936cd9a37cdba0ab0bfc374d0ff3bd30a51f220
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6781374
Reviewed-by: Kyungjun Lee <kyungjunlee@google.com>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1491691}
diff --git a/chrome/browser/resources/chromeos/accessibility/common/local_storage_test.js b/chrome/browser/resources/chromeos/accessibility/common/local_storage_test.js
index f88b60f2..ddf234e 100644
--- a/chrome/browser/resources/chromeos/accessibility/common/local_storage_test.js
+++ b/chrome/browser/resources/chromeos/accessibility/common/local_storage_test.js
@@ -17,8 +17,15 @@
   }
 };
 
+// TODO(crbug.com/260589686): Remove after localStorage migration is done.
 AX_TEST_F(
     'AccessibilityExtensionLocalStorageTest', 'Migration', async function() {
+      if (isRunningInServiceWorker()) {
+        console.log(
+            'Skip because "localStorage" is not available in service worker.');
+        return;
+      }
+
       localStorage['catSound'] = 'meow';
       localStorage['catIsShy'] = String(false);
       localStorage['catIsFluffy'] = String(true);
diff --git a/chrome/browser/resources/chromeos/accessibility/common/testing/common.js b/chrome/browser/resources/chromeos/accessibility/common/testing/common.js
index 75c412d1..f5a0d6b 100644
--- a/chrome/browser/resources/chromeos/accessibility/common/testing/common.js
+++ b/chrome/browser/resources/chromeos/accessibility/common/testing/common.js
@@ -31,6 +31,19 @@
 }
 
 /**
+ * Helper to keep the service worker alive by calling an extension API.
+ * Caller should use `await` on the returned promise to yield control to
+ * allow the service worker to respond to pings.
+ */
+function keepServiceWorkerAlive() {
+  if (!isRunningInServiceWorker()) {
+    return Promise.resovle();
+  }
+
+  return chrome.runtime.getPlatformInfo();
+}
+
+/**
  * Helper to import a module, and expose it onto window.
  * @param {string|!Array<string>} toImport Names of the module exports to
  *     expose.
diff --git a/chrome/browser/resources/chromeos/accessibility/common/tree_walker_test.js b/chrome/browser/resources/chromeos/accessibility/common/tree_walker_test.js
index 74d081ab..470a69036 100644
--- a/chrome/browser/resources/chromeos/accessibility/common/tree_walker_test.js
+++ b/chrome/browser/resources/chromeos/accessibility/common/tree_walker_test.js
@@ -60,7 +60,7 @@
 TEST_F(
     'AccessibilityExtensionAutomationTreeWalkerTest', 'MAYBE_Forward',
     function() {
-      chrome.automation.getDesktop(this.newCallback(function(d) {
+      chrome.automation.getDesktop(this.newCallback(async function(d) {
         const resultList = [];
         this.flattenTree(d, resultList);
         let it = new AutomationTreeWalker(d, 'forward');
@@ -70,6 +70,10 @@
         assertEquals(null, it.next().node);
 
         for (let j = 0; j < resultList.length; j++) {
+          // This is needed because this iteration could take more than 30s on
+          // MSAN bots.
+          await keepServiceWorkerAlive();
+
           it = new AutomationTreeWalker(resultList[j], 'forward');
           const start = it.node;
           let cur = it.next().node;
@@ -91,7 +95,7 @@
 TEST_F(
     'AccessibilityExtensionAutomationTreeWalkerTest', 'MAYBE_Backward',
     function() {
-      chrome.automation.getDesktop(this.newCallback(function(d) {
+      chrome.automation.getDesktop(this.newCallback(async function(d) {
         const resultList = [];
         this.flattenTree(d, resultList);
         let it = new AutomationTreeWalker(
@@ -101,6 +105,10 @@
         }
 
         for (let j = resultList.length - 1; j >= 0; j--) {
+          // This is needed because this iteration could take more than 30s on
+          // MSAN bots.
+          await keepServiceWorkerAlive();
+
           it = new AutomationTreeWalker(resultList[j], 'backward');
           const start = it.node;
           let cur = it.next().node;
diff --git a/testing/variations/fieldtrial_testing_config.json b/testing/variations/fieldtrial_testing_config.json
index f84f5c5a..b81772f 100644
--- a/testing/variations/fieldtrial_testing_config.json
+++ b/testing/variations/fieldtrial_testing_config.json
@@ -180,6 +180,21 @@
             ]
         }
     ],
+    "AccessibilityManifestV3AccessibilityCommon": [
+        {
+            "platforms": [
+                "chromeos"
+            ],
+            "experiments": [
+                {
+                    "name": "Enabled",
+                    "enable_features": [
+                        "AccessibilityManifestV3AccessibilityCommon"
+                    ]
+                }
+            ]
+        }
+    ],
     "AccessibilityManifestV3BrailleIme": [
         {
             "platforms": [