Bug 1269369 - make sure DOCUMENT_LOAD_COMPLETE event is fired for loaded top level remote docs. draft
authorYura Zenevich <yzenevich@mozilla.com>
Tue, 11 Oct 2016 18:47:21 -0600
changeset 485451 1b3795ad7f6a6d76ee117b599af3f76f895f013a
parent 485450 40832b849691bf87dfb6566ec8142a5a72fce7f2
child 485452 4e6b145ed79fee8460d98d2449f00e45c4dc15f0
push id45733
push useraklotz@mozilla.com
push dateThu, 16 Feb 2017 17:45:58 +0000
bugs1269369
milestone54.0a1
Bug 1269369 - make sure DOCUMENT_LOAD_COMPLETE event is fired for loaded top level remote docs. MozReview-Commit-ID: 2aBNIxcdc11
accessible/generic/ApplicationAccessible.cpp
accessible/generic/DocAccessible.h
accessible/tests/browser/.eslintrc.js
accessible/tests/browser/e10s/head.js
accessible/tests/browser/head.js
accessible/tests/browser/shared-head.js
--- a/accessible/generic/ApplicationAccessible.cpp
+++ b/accessible/generic/ApplicationAccessible.cpp
@@ -13,16 +13,17 @@
 #include "Role.h"
 #include "States.h"
 
 #include "nsIComponentManager.h"
 #include "nsIDOMDocument.h"
 #include "nsIWindowMediator.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/Services.h"
+#include "nsGlobalWindow.h"
 #include "nsIStringBundle.h"
 
 using namespace mozilla::a11y;
 
 ApplicationAccessible::ApplicationAccessible() :
   AccessibleWrap(nullptr, nullptr)
 {
   mType = eApplicationType;
@@ -154,16 +155,37 @@ KeyBinding
 ApplicationAccessible::AccessKey() const
 {
   return KeyBinding();
 }
 
 void
 ApplicationAccessible::Init()
 {
+  if (XRE_IsContentProcess()) {
+    nsGlobalWindow::WindowByIdTable* windowsById =
+      nsGlobalWindow::GetWindowsTable();
+    if (!windowsById) {
+      return;
+    }
+    for (auto iter = windowsById->Iter(); !iter.Done(); iter.Next()) {
+      nsGlobalWindow* window = iter.Data();
+      if (!window->IsOuterWindow() || !window->IsTopLevelWindow()) {
+        continue;
+      }
+      nsCOMPtr<nsIDocument> docNode = window->GetDocument();
+      if (!docNode) {
+        continue;
+      }
+      DocAccessible* docAcc = GetAccService()->GetDocAccessible(docNode);
+      docAcc->NotifyOfLoad(nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE);
+    }
+    return;
+  }
+
   // Basically children are kept updated by Append/RemoveChild method calls.
   // However if there are open windows before accessibility was started
   // then we need to make sure root accessibles for open windows are created so
   // that all root accessibles are stored in application accessible children
   // array.
 
   nsCOMPtr<nsIWindowMediator> windowMediator =
     do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
--- a/accessible/generic/DocAccessible.h
+++ b/accessible/generic/DocAccessible.h
@@ -393,16 +393,17 @@ protected:
 
   /**
    * Marks this document as loaded or loading.
    */
   void NotifyOfLoad(uint32_t aLoadEventType);
   void NotifyOfLoading(bool aIsReloading);
 
   friend class DocManager;
+  friend class ApplicationAccessible;
 
   /**
    * Perform initial update (create accessible tree).
    * Can be overridden by wrappers to prepare initialization work.
    */
   virtual void DoInitialUpdate();
 
   /**
--- a/accessible/tests/browser/.eslintrc.js
+++ b/accessible/tests/browser/.eslintrc.js
@@ -21,24 +21,21 @@ module.exports = { // eslint-disable-lin
     "testDescr": true,
     "testStates": true,
     "testRelation": true,
     "testValue": true,
     "testAccessibleTree": true,
     "isAccessible": true,
     "getAccessibleDOMNodeID": true,
 
-    // Defined for all top level accessibility browser tests.
     "setE10sPrefs": true,
     "unsetE10sPrefs": true,
     "initPromise": true,
     "shutdownPromise": true,
     "forceGC": true,
-
-    // Defined for all e10s accessibility browser tests.
     "addAccessibleTask": true,
     "BrowserTestUtils": true,
     "ContentTask": true,
     "gBrowser": true,
     "isDefunct": true,
     "loadScripts": true,
     "loadFrameScripts": true,
     "Logger": true,
--- a/accessible/tests/browser/e10s/head.js
+++ b/accessible/tests/browser/e10s/head.js
@@ -19,16 +19,18 @@ Services.scriptloader.loadSubScript(
  * @param  {String}             doc    URL (relative to current directory) or
  *                                     data URL or markup snippet that is used
  *                                     to test content with
  * @param  {Function|Function*} task   a generator or a function with tests to
  *                                     run
  */
 function addAccessibleTask(doc, task) {
   add_task(function*() {
+    yield setE10sPrefs();
+
     let url;
     if (doc.includes('doc_')) {
       url = `${CURRENT_CONTENT_DIR}e10s/${doc}`;
     } else {
       // Assume it's a markup snippet.
       url = `data:text/html,
         <html>
           <head>
@@ -71,14 +73,16 @@ function addAccessibleTask(doc, task) {
 
       Logger.log(
         `e10s enabled: ${Services.appinfo.browserTabsRemoteAutostart}`);
       Logger.log(`Actually remote browser: ${browser.isRemoteBrowser}`);
 
       let event = yield onDocLoad;
       yield task(browser, event.accessible);
     });
+
+    yield unsetE10sPrefs();
   });
 }
 
 // Loading and common.js from accessible/tests/mochitest/ for all tests, as
 // well as events.js.
 loadScripts({ name: 'common.js', dir: MOCHITESTS_DIR }, 'e10s/events.js');
--- a/accessible/tests/browser/head.js
+++ b/accessible/tests/browser/head.js
@@ -1,41 +1,15 @@
 /* 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 initPromise, shutdownPromise, waitForEvent, setE10sPrefs,
-            unsetE10sPrefs, forceGC */
-
-/**
- * Set e10s related preferences in the test environment.
- * @return {Promise} promise that resolves when preferences are set.
- */
-function setE10sPrefs() {
-  return new Promise(resolve =>
-    SpecialPowers.pushPrefEnv({
-      set: [
-        ['browser.tabs.remote.autostart', true],
-        ['browser.tabs.remote.force-enable', true],
-        ['extensions.e10sBlocksEnabling', false]
-      ]
-    }, resolve));
-}
-
-/**
- * Unset e10s related preferences in the test environment.
- * @return {Promise} promise that resolves when preferences are unset.
- */
-function unsetE10sPrefs() {
-  return new Promise(resolve => {
-    SpecialPowers.popPrefEnv(resolve);
-  });
-}
+/* exported initPromise, shutdownPromise, forceGC */
 
 // Load the shared-head file first.
 Services.scriptloader.loadSubScript(
   'chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js',
   this);
 
 /**
  * Returns a promise that resolves when 'a11y-init-or-shutdown' event is fired.
--- a/accessible/tests/browser/shared-head.js
+++ b/accessible/tests/browser/shared-head.js
@@ -1,17 +1,18 @@
 /* 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 Logger, MOCHITESTS_DIR, isDefunct, invokeSetAttribute, invokeFocus,
             invokeSetStyle, findAccessibleChildByID, getAccessibleDOMNodeID,
-            CURRENT_CONTENT_DIR, loadScripts, loadFrameScripts, Cc, Cu */
+            CURRENT_CONTENT_DIR, loadScripts, loadFrameScripts, Cc, Cu,
+            setE10sPrefs, unsetE10sPrefs */
 
 const { interfaces: Ci, utils: Cu, classes: Cc } = Components;
 
 /**
  * Current browser test directory path used to load subscripts.
  */
 const CURRENT_DIR =
   'chrome://mochitests/content/browser/accessible/tests/browser/';
@@ -73,16 +74,41 @@ let Logger = {
   logToAppConsole(msg) {
     if (this.dumpToAppConsole) {
       Services.console.logStringMessage(`${msg}`);
     }
   }
 };
 
 /**
+ * Set e10s related preferences in the test environment.
+ * @return {Promise} promise that resolves when preferences are set.
+ */
+function setE10sPrefs() {
+  return new Promise(resolve =>
+    SpecialPowers.pushPrefEnv({
+      set: [
+        ['browser.tabs.remote.autostart', true],
+        ['browser.tabs.remote.force-enable', true],
+        ['extensions.e10sBlocksEnabling', false]
+      ]
+    }, resolve));
+}
+
+/**
+ * Unset e10s related preferences in the test environment.
+ * @return {Promise} promise that resolves when preferences are unset.
+ */
+function unsetE10sPrefs() {
+  return new Promise(resolve => {
+    SpecialPowers.popPrefEnv(resolve);
+  });
+}
+
+/**
  * Check if an accessible object has a defunct test.
  * @param  {nsIAccessible}  accessible object to test defunct state for
  * @return {Boolean}        flag indicating defunct state
  */
 function isDefunct(accessible) {
   let defunct = false;
   try {
     let extState = {};