Bug 1585239 - Wait for accessibility document ready in iframe. r=surkov
authorHiroyuki Ikezoe <hikezoe.birchill@mozilla.com>
Mon, 02 Dec 2019 09:50:29 +0000
changeset 504806 120e92938637c5ef9a29ea106adcb3692a462db6
parent 504805 02fbe3085e545b3e20d585ba04cb168872b40836
child 504807 18ff693f0f960d0886b2b74a645d82ddadf55663
push id36870
push usernerli@mozilla.com
push dateMon, 02 Dec 2019 18:41:58 +0000
treeherdermozilla-central@bc2e8add2746 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs1585239
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1585239 - Wait for accessibility document ready in iframe. r=surkov Differential Revision: https://phabricator.services.mozilla.com/D55067
accessible/tests/browser/states/browser_offscreen_element_in_out_of_process_iframe.js
accessible/tests/browser/states/head.js
--- a/accessible/tests/browser/states/browser_offscreen_element_in_out_of_process_iframe.js
+++ b/accessible/tests/browser/states/browser_offscreen_element_in_out_of_process_iframe.js
@@ -52,17 +52,17 @@ add_task(async function() {
         });
       });
       await waitForIFrameUpdates();
     }
 
     // Setup an out-of-process iframe which is initially scrolled out.
     const iframe = await SpecialPowers.spawn(browser, [iframeURL], setup);
 
-    await waitForIFrameUpdates();
+    await waitForIFrameA11yReady(iframe);
     await spawnTestStates(
       iframe,
       "target",
       nsIAccessibleStates.STATE_OFFSCREEN,
       nsIAccessibleStates.STATE_INVISIBLE
     );
 
     // Scroll the iframe into view and the target element is also visible but
--- a/accessible/tests/browser/states/head.js
+++ b/accessible/tests/browser/states/head.js
@@ -1,30 +1,59 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-/* exported waitForIFrameUpdates, spawnTestStates */
+/* exported waitForIFrameA11yReady, waitForIFrameUpdates, spawnTestStates */
 
 // Load the shared-head file first.
 /* import-globals-from ../shared-head.js */
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js",
   this
 );
 
 // Loading and common.js from accessible/tests/mochitest/ for all tests, as
 // well as promisified-events.js.
 loadScripts(
   { name: "common.js", dir: MOCHITESTS_DIR },
   { name: "promisified-events.js", dir: MOCHITESTS_DIR }
 );
 
+// This is another version of addA11yLoadEvent for fission.
+async function waitForIFrameA11yReady(iFrameBrowsingContext) {
+  async function waitForReady() {
+    new Promise(resolve => {
+      function waitForDocLoad() {
+        SpecialPowers.executeSoon(() => {
+          const acc = SpecialPowers.Cc[
+            "@mozilla.org/accessibilityService;1"
+          ].getService(SpecialPowers.Ci.nsIAccessibilityService);
+
+          const accDoc = acc.getAccessibleFor(content.document);
+          let state = {};
+          accDoc.getState(state, {});
+          if (state.value & SpecialPowers.Ci.nsIAccessibleStates.STATE_BUSY) {
+            SpecialPowers.executeSoon(waitForDocLoad);
+            return;
+          }
+          resolve();
+        }, 0);
+      }
+      waitForDocLoad();
+    });
+  }
+
+  await SimpleTest.promiseFocus(window);
+
+  await SpecialPowers.spawn(iFrameBrowsingContext, [], waitForReady);
+}
+
 // A utility function to make sure the information of scroll position or visible
 // area changes reach to out-of-process iframes.
 async function waitForIFrameUpdates() {
   // Wait for two frames since the information is notified via asynchronous IPC
   // calls.
   await new Promise(resolve => requestAnimationFrame(resolve));
   await new Promise(resolve => requestAnimationFrame(resolve));
 }