Bug 851040 - Try to fix intermittent browser/components/search/test/browser_contextmenu.js. a=test-only
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 14 Mar 2013 23:59:06 -0700
changeset 124879 a6e337fb1f61b1513ddf8d209b17841322a89e68
parent 124878 9606fa13b8e30f6b611569883f349adf241dbf88
child 124880 a999914becb7746be559072b2c4c188e8be5f7c3
push id24654
push usermozilla@noorenberghe.ca
push dateFri, 15 Mar 2013 07:01:14 +0000
treeherdermozilla-inbound@a6e337fb1f61 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstest-only
bugs851040
milestone22.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 851040 - Try to fix intermittent browser/components/search/test/browser_contextmenu.js. a=test-only
browser/components/search/test/browser_contextmenu.js
browser/components/search/test/head.js
--- a/browser/components/search/test/browser_contextmenu.js
+++ b/browser/components/search/test/browser_contextmenu.js
@@ -36,18 +36,17 @@ function test() {
                Ci.nsISearchEngine.DATA_XML, "data:image/x-icon,%00",
                false);
 
   function startTest() {
     contextMenu = document.getElementById("contentAreaContextMenu");
     ok(contextMenu, "Got context menu XUL");
 
     doOnloadOnce(testContextMenu);
-    var tab = gBrowser.addTab("data:text/plain;charset=utf8,test%20search");
-    gBrowser.selectedTab = tab;
+    gBrowser.selectedTab = gBrowser.addTab("data:text/plain;charset=utf8,test%20search");
   }
 
   function testContextMenu() {
     function rightClickOnDocument() {
       info("rightClickOnDocument: " + content.window.location);
       waitForBrowserContextMenu(checkContextMenu);
       var clickTarget = content.document.body;
       var eventDetails = { type: "contextmenu", button: 2 };
@@ -79,21 +78,25 @@ function test() {
           return;
         info("notifySelectionChanged: Text selected");
         content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate).
                                       removeSelectionListener(selectionListener);
         SimpleTest.executeSoon(rightClickOnDocument);
       }
     };
 
-    // add a listener to know when the selection takes effect
-    content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate).
-                                  addSelectionListener(selectionListener);
-    // select the text on the page
-    goDoCommand('cmd_selectAll');
+    // Delay the select all to avoid intermittent selection failures.
+    setTimeout(function delaySelectAll() {
+      info("delaySelectAll: " + content.window.location.toString());
+      // add a listener to know when the selection takes effect
+      content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate).
+                                    addSelectionListener(selectionListener);
+      // select the text on the page
+      goDoCommand('cmd_selectAll');
+    }, 500);
   }
 
   function finalize() {
     while (gBrowser.tabs.length != 1) {
       gBrowser.removeTab(gBrowser.tabs[0]);
     }
     content.location.href = "about:blank";
     var engine = ss.getEngineByName(ENGINE_NAME);
--- a/browser/components/search/test/head.js
+++ b/browser/components/search/test/head.js
@@ -36,16 +36,18 @@ function waitForPopupShown(aPopupId, aCa
 function waitForBrowserContextMenu(aCallback) {
   waitForPopupShown(gBrowser.selectedBrowser.contextMenu, aCallback);
 }
 
 function doOnloadOnce(aCallback) {
   function doOnloadOnceListener(aEvent) {
     info("doOnloadOnce: " + aEvent.originalTarget.location);
     removeDoOnloadOnceListener();
-    aCallback(aEvent);
+    SimpleTest.executeSoon(function doOnloadOnceCallback() {
+      aCallback(aEvent);
+    });
   }
   function removeDoOnloadOnceListener() {
-    gBrowser.removeEventListener("DOMContentLoaded", doOnloadOnceListener);
+    gBrowser.removeEventListener("load", doOnloadOnceListener, true);
   }
-  gBrowser.addEventListener("DOMContentLoaded", doOnloadOnceListener);
+  gBrowser.addEventListener("load", doOnloadOnceListener, true);
   registerCleanupFunction(removeDoOnloadOnceListener);
 }