Bug 859339 - blur reftests that don't need focus; r=dbaron
authorNathan Froyd <froydnj@mozilla.com>
Mon, 29 Jul 2013 12:33:44 -0400
changeset 166485 06c3ed54ed62ce6e61b7728552d06037f3806807
parent 166484 39f4bb8c55d8dd95f07d53fd79cc4d35957d226e
child 166486 988382ff109cbf89c5af0028af6ca5e63cec6a13
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs859339
milestone27.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 859339 - blur reftests that don't need focus; r=dbaron This patch opens a second window during non-remote reftests. This second window is used purely as a place to place focus when tests don't need focus themselves. Unfocusing the reftests windows when tests don't require focus means that tests that ought to have needs-focus cause failures more consistently. We don't use a second window for remote reftests. Even though we theoretically could (on desktop platforms, for instance), our primary remote reftest use-cases are for Android and B2G. And those platforms do not support multiple windows.
layout/tools/reftest/reftest-cmdline.js
layout/tools/reftest/reftest.js
--- a/layout/tools/reftest/reftest-cmdline.js
+++ b/layout/tools/reftest/reftest-cmdline.js
@@ -105,17 +105,42 @@ RefTestCmdLineHandler.prototype =
     // Checking whether two files are the same is slow on Windows.
     // Setting this pref makes tests run much faster there.
     branch.setBoolPref("security.fileuri.strict_origin_policy", false);
     // Disable the thumbnailing service
     branch.setBoolPref("browser.pagethumbnails.capturing_disabled", true);
 
     var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
                            .getService(nsIWindowWatcher);
-    wwatch.openWindow(null, "chrome://reftest/content/reftest.xul", "_blank",
-                      "chrome,dialog=no,all", args);
+
+    function loadReftests() {
+      wwatch.openWindow(null, "chrome://reftest/content/reftest.xul", "_blank",
+                        "chrome,dialog=no,all", args);
+    }
+
+    var remote = false;
+    try {
+      remote = prefs.getBoolPref("reftest.remote");
+    } catch (ex) {
+    }
+
+    // If we are running on a remote machine, assume that we can't open another
+    // window for transferring focus to when tests don't require focus.
+    if (remote) {
+      loadReftests();
+    }
+    else {
+      // This dummy window exists solely for enforcing proper focus discipline.
+      var dummy = wwatch.openWindow(null, "about:blank", "dummy",
+                                    "chrome,dialog=no,left=800,height=200,width=200,all", null);
+      dummy.onload = function dummyOnload() {
+        dummy.focus();
+        loadReftests();
+      }
+    }
+
     cmdLine.preventDefault = true;
   },
 
   helpInfo : "  -reftest <file>    Run layout acceptance tests on given manifest.\n"
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RefTestCmdLineHandler]);
--- a/layout/tools/reftest/reftest.js
+++ b/layout/tools/reftest/reftest.js
@@ -401,18 +401,20 @@ function InitAndStartRefTests()
             StartHTTPServer();
     } catch (ex) {
         //gBrowser.loadURI('data:text/plain,' + ex);
         ++gTestResults.Exception;
         gDumpLog("REFTEST TEST-UNEXPECTED-FAIL | | EXCEPTION: " + ex + "\n");
         DoneTests();
     }
 
-    // Focus the content browser
-    gBrowser.focus();
+    // Focus the content browser.
+    if (gFocusFilterMode != FOCUS_FILTER_NON_NEEDS_FOCUS_TESTS) {
+        gBrowser.focus();
+    }
 
     StartTests();
 }
 
 function StartHTTPServer()
 {
     gServer.registerContentType("sjs", "sjs");
     gServer.start(-1);
@@ -1149,16 +1151,25 @@ function Focus()
         var dock = CC["@mozilla.org/widget/macdocksupport;1"].getService(CI.nsIMacDockSupport);
         dock.activateApplication(true);
     } catch(ex) {
     }
 #endif // XP_MACOSX
     return true;
 }
 
+function Blur()
+{
+    // On non-remote reftests, this will transfer focus to the dummy window
+    // we created to hold focus for non-needs-focus tests.  Buggy tests
+    // (ones which require focus but don't request needs-focus) will then
+    // fail.
+    gContainingWindow.blur();
+}
+
 function StartCurrentTest()
 {
     gTestLog = [];
 
     // make sure we don't run tests that are expected to kill the browser
     while (gURLs.length > 0) {
         var test = gURLs[0];
         if (test.expected == EXPECTED_DEATH) {
@@ -1181,16 +1192,19 @@ function StartCurrentTest()
     }
 
     if (gURLs.length == 0) {
         RestoreChangedPreferences();
         DoneTests();
     }
     else {
         gDumpLog("REFTEST TEST-START | " + gURLs[0].prettyPath + "\n");
+        if (!gURLs[0].needsFocus) {
+            Blur();
+        }
         var currentTest = gTotalTests - gURLs.length;
         gContainingWindow.document.title = "reftest: " + currentTest + " / " + gTotalTests +
             " (" + Math.floor(100 * (currentTest / gTotalTests)) + "%)";
         StartCurrentURI(1);
     }
 }
 
 function StartCurrentURI(aState)