diff --git a/layout/tools/reftest/reftest-cmdline.js b/layout/tools/reftest/reftest-cmdline.js index c2a615c89ae..3b3b23b4724 100644 --- a/layout/tools/reftest/reftest-cmdline.js +++ b/layout/tools/reftest/reftest-cmdline.js @@ -110,8 +110,33 @@ RefTestCmdLineHandler.prototype = 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; }, diff --git a/layout/tools/reftest/reftest.js b/layout/tools/reftest/reftest.js index 41305e0ccad..2a95b58889e 100644 --- a/layout/tools/reftest/reftest.js +++ b/layout/tools/reftest/reftest.js @@ -378,8 +378,10 @@ function InitAndStartRefTests() DoneTests(); } - // Focus the content browser - gBrowser.focus(); + // Focus the content browser. + if (gFocusFilterMode != FOCUS_FILTER_NON_NEEDS_FOCUS_TESTS) { + gBrowser.focus(); + } StartTests(); } @@ -1118,6 +1120,15 @@ function Focus() 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 = []; @@ -1150,6 +1161,9 @@ function StartCurrentTest() } 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)) + "%)";