Bug 1061671 - Wait for document and frame content load to complete before starting jsat content tests. r=yzen, a=test-only
authorEitan Isaacson <eitan@monotonous.org>
Mon, 22 Sep 2014 09:27:04 -0700
changeset 225249 2c9289c8a725a7518328a65f7b8dd21480098260
parent 225248 858a86ba0a5cb6e1c6cab4df1ee6865dc3566216
child 225250 34ced01a5a6de14154525ab08cd671778445791e
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen, test-only
bugs1061671
milestone34.0a2
Bug 1061671 - Wait for document and frame content load to complete before starting jsat content tests. r=yzen, a=test-only
accessible/jsat/content-script.js
accessible/tests/mochitest/jsat/test_content_integration.html
accessible/tests/mochitest/jsat/test_content_text.html
--- a/accessible/jsat/content-script.js
+++ b/accessible/jsat/content-script.js
@@ -15,16 +15,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, 'Utils',
   'resource://gre/modules/accessibility/Utils.jsm');
 XPCOMUtils.defineLazyModuleGetter(this, 'EventManager',
   'resource://gre/modules/accessibility/EventManager.jsm');
 XPCOMUtils.defineLazyModuleGetter(this, 'ContentControl',
   'resource://gre/modules/accessibility/ContentControl.jsm');
 XPCOMUtils.defineLazyModuleGetter(this, 'Roles',
   'resource://gre/modules/accessibility/Constants.jsm');
+XPCOMUtils.defineLazyModuleGetter(this, 'States',
+  'resource://gre/modules/accessibility/Constants.jsm');
 
 Logger.debug('content-script.js');
 
 let eventManager = null;
 let contentControl = null;
 
 function forwardToParent(aMessage) {
   // XXX: This is a silly way to make a deep copy
@@ -138,17 +140,30 @@ addMessageListener(
     contentControl.start();
 
     if (!eventManager) {
       eventManager = new EventManager(this, contentControl);
     }
     eventManager.inTest = m.json.inTest;
     eventManager.start();
 
-    sendAsyncMessage('AccessFu:ContentStarted');
+    function contentStarted() {
+      let accDoc = Utils.AccRetrieval.getAccessibleFor(content.document);
+      if (accDoc && !Utils.getState(accDoc).contains(States.BUSY)) {
+        sendAsyncMessage('AccessFu:ContentStarted');
+      } else {
+        content.setTimeout(contentStarted, 0);
+      }
+    }
+
+    if (m.json.inTest) {
+      // During a test we want to wait for the document to finish loading for
+      // consistency.
+      contentStarted();
+    }
   });
 
 addMessageListener(
   'AccessFu:Stop',
   function(m) {
     Logger.debug('AccessFu:Stop');
 
     removeMessageListener('AccessFu:ContextMenu', activateContextMenu);
--- a/accessible/tests/mochitest/jsat/test_content_integration.html
+++ b/accessible/tests/mochitest/jsat/test_content_integration.html
@@ -220,21 +220,22 @@
 
           [function hideAlertAndFocusHomeButton() {
             doc.defaultView.hideAlert();
             doc.querySelector('button#home').focus();
           }, new ExpectedCursorChange(['Home', {'string': 'pushbutton'},
             'Traversal Rule test document'])]
         ]);
 
-        contentTest.start(function () {
-          closeBrowserWindow();
-          SimpleTest.finish();
-        });
-
+        addA11yLoadEvent(function() {
+          contentTest.start(function () {
+            closeBrowserWindow();
+            SimpleTest.finish();
+          });
+        }, doc.defaultView)
       });
       iframe.src = 'data:text/html;charset=utf-8,' + doc.defaultView.frameContents;
       doc.getElementById('appframe').appendChild(iframe);
     }
 
     SimpleTest.waitForExplicitFinish();
     addLoadEvent(
       function () {
--- a/accessible/tests/mochitest/jsat/test_content_text.html
+++ b/accessible/tests/mochitest/jsat/test_content_text.html
@@ -167,20 +167,22 @@
            new ExpectedEditState({
             editing: false,
             multiline: false,
             atStart: true,
             atEnd: false
            }, { focused: 'html' })]
         ]);
 
-      textTest.start(function () {
-        closeBrowserWindow();
-        SimpleTest.finish();
-      });
+      addA11yLoadEvent(function() {
+        textTest.start(function () {
+          closeBrowserWindow();
+          SimpleTest.finish();
+        });
+      }, doc.defaultView);
     }
 
     SimpleTest.waitForExplicitFinish();
     addLoadEvent(
       function () {
         openBrowserWindow(
           doTest,
           getRootDirectory(window.location.href) + "doc_content_text.html");