Bug 705967 - reftest assumes we are loaded in a window and have direct access to a document. r=dbaron
authorJoel Maher <jmaher@mozilla.com>
Thu, 15 Dec 2011 07:41:40 -0500
changeset 84275 e3d5b255e1093ac34cc4cda46bd4034454bcd2b7
parent 84274 4be841d52b5b7d6b38050ef8e8ed3fc06fd56dd1
child 84276 3433303583afea1862bf789558c5fbb1fda90dec
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs705967
milestone11.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 705967 - reftest assumes we are loaded in a window and have direct access to a document. r=dbaron
layout/tools/reftest/reftest.js
--- a/layout/tools/reftest/reftest.js
+++ b/layout/tools/reftest/reftest.js
@@ -63,16 +63,17 @@ const NS_OBSERVER_SERVICE_CONTRACTID =
           "@mozilla.org/observer-service;1";
 
 var gLoadTimeout = 0;
 var gTimeoutHook = null;
 var gRemote = false;
 var gIgnoreWindowSize = false;
 var gTotalChunks = 0;
 var gThisChunk = 0;
+var gContainingWindow = null;
 
 // "<!--CLEAR-->"
 const BLANK_URL_FOR_CLEARING = "data:text/html,%3C%21%2D%2DCLEAR%2D%2D%3E";
 
 var gBrowser;
 // Are we testing web content loaded in a separate process?
 var gBrowserIsRemote;           // bool
 var gBrowserMessageManager;
@@ -184,22 +185,20 @@ function FlushTestLog()
             gDumpLog("REFTEST INFO | Saved log: " + gTestLog[i] + "\n");
         }
     }
     gTestLog = [];
 }
 
 function AllocateCanvas()
 {
-    var windowElem = document.documentElement;
-
     if (gRecycledCanvases.length > 0)
         return gRecycledCanvases.shift();
 
-    var canvas = document.createElementNS(XHTML_NS, "canvas");
+    var canvas = gContainingWindow.document.createElementNS(XHTML_NS, "canvas");
     var r = gBrowser.getBoundingClientRect();
     canvas.setAttribute("width", Math.ceil(r.width));
     canvas.setAttribute("height", Math.ceil(r.height));
 
     return canvas;
 }
 
 function ReleaseCanvas(canvas)
@@ -231,18 +230,22 @@ function OnRefTestLoad()
 
     var prefs = Components.classes["@mozilla.org/preferences-service;1"].
                 getService(Components.interfaces.nsIPrefBranch2);
     try {
         gBrowserIsRemote = prefs.getBoolPref("browser.tabs.remote");
     } catch (e) {
         gBrowserIsRemote = false;
     }
+    
+    if (gContainingWindow == null && window != null) {
+      gContainingWindow = window;
+    }
 
-    gBrowser = document.createElementNS(XUL_NS, "xul:browser");
+    gBrowser = gContainingWindow.document.createElementNS(XUL_NS, "xul:browser");
     gBrowser.setAttribute("id", "browser");
     gBrowser.setAttribute("type", "content-primary");
     gBrowser.setAttribute("remote", gBrowserIsRemote ? "true" : "false");
     // Make sure the browser element is exactly 800x1000, no matter
     // what size our window is
     gBrowser.setAttribute("style", "min-width: 800px; min-height: 1000px; max-width: 800px; max-height: 1000px");
 
     document.getElementById("reftest-window").appendChild(gBrowser);
@@ -305,25 +308,23 @@ function InitAndStartRefTests()
       gThisChunk = prefs.getIntPref("reftest.thisChunk");
     }
     catch(e) {
       gTotalChunks = 0;
       gThisChunk = 0;
     }
 
     try {
-        gWindowUtils = window.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIDOMWindowUtils);
+        gWindowUtils = gContainingWindow.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIDOMWindowUtils);
         if (gWindowUtils && !gWindowUtils.compareCanvases)
             gWindowUtils = null;
     } catch (e) {
         gWindowUtils = null;
     }
 
-    var windowElem = document.documentElement;
-
     gIOService = CC[IO_SERVICE_CONTRACTID].getService(CI.nsIIOService);
     gDebug = CC[DEBUG_CONTRACTID].getService(CI.nsIDebug2);
 
     RegisterProcessCrashObservers();
 
     if (gRemote) {
       gServer = null;
     } else {
@@ -466,31 +467,33 @@ function BuildConditionSandbox(aURL) {
                             "product", "productSub",
                             "platform", "oscpu", "language", "misc" ]) {
         sandbox.http[prop] = hh[prop];
         sandbox.http.__exposedProps__[prop] = "r";
     }
     // see if we have the test plugin available,
     // and set a sandox prop accordingly
     sandbox.haveTestPlugin = false;
+
+    var navigator = gContainingWindow.navigator;
     for (var i = 0; i < navigator.mimeTypes.length; i++) {
         if (navigator.mimeTypes[i].type == "application/x-test" &&
             navigator.mimeTypes[i].enabledPlugin != null &&
             navigator.mimeTypes[i].enabledPlugin.name == "Test Plug-in") {
             sandbox.haveTestPlugin = true;
             break;
         }
     }
 
     // Set a flag on sandbox if the windows default theme is active
-    var box = document.createElement("box");
+    var box = gContainingWindow.document.createElement("box");
     box.setAttribute("id", "_box_windowsDefaultTheme");
-    document.documentElement.appendChild(box);
-    sandbox.windowsDefaultTheme = (getComputedStyle(box, null).display == "none");
-    document.documentElement.removeChild(box);
+    gContainingWindow.document.documentElement.appendChild(box);
+    sandbox.windowsDefaultTheme = (gContainingWindow.getComputedStyle(box, null).display == "none");
+    gContainingWindow.document.documentElement.removeChild(box);
 
     var prefs = CC["@mozilla.org/preferences-service;1"].
                 getService(CI.nsIPrefBranch2);
     try {
         sandbox.nativeThemePref = !prefs.getBoolPref("mozilla.widget.disable-native-theme");
     } catch (e) {
         sandbox.nativeThemePref = true;
     }
@@ -501,17 +504,20 @@ function BuildConditionSandbox(aURL) {
             getIntPref: 'r',
         },
         _prefs:      prefs,
         getBoolPref: function(p) { return this._prefs.getBoolPref(p); },
         getIntPref:  function(p) { return this._prefs.getIntPref(p); }
     }
 
     sandbox.testPluginIsOOP = function () {
-        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        try {
+          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        } catch (ex) {}
+
         var prefservice = Components.classes["@mozilla.org/preferences-service;1"]
                                     .getService(CI.nsIPrefBranch);
 
         var testPluginIsOOP = false;
         if (navigator.platform.indexOf("Mac") == 0) {
             var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
                                        .getService(CI.nsIXULAppInfo)
                                        .QueryInterface(CI.nsIXULRuntime);
@@ -878,17 +884,17 @@ function Focus()
 {
     // FIXME/bug 583976: focus doesn't yet work with out-of-process
     // content.
     if (gBrowserIsRemote) {
         return false;
     }
 
     var fm = CC["@mozilla.org/focus-manager;1"].getService(CI.nsIFocusManager);
-    fm.activeWindow = window;
+    fm.activeWindow = gContainingWindow;
     try {
         var dock = CC["@mozilla.org/widget/macdocksupport;1"].getService(CI.nsIMacDockSupport);
         dock.activateApplication(true);
     } catch(ex) {
     }
     return true;
 }
 
@@ -916,34 +922,34 @@ function StartCurrentTest()
         }
     }
 
     if (gURLs.length == 0) {
         DoneTests();
     }
     else {
         var currentTest = gTotalTests - gURLs.length;
-        document.title = "reftest: " + currentTest + " / " + gTotalTests +
+        gContainingWindow.document.title = "reftest: " + currentTest + " / " + gTotalTests +
             " (" + Math.floor(100 * (currentTest / gTotalTests)) + "%)";
         StartCurrentURI(1);
     }
 }
 
 function StartCurrentURI(aState)
 {
     gState = aState;
     gCurrentURL = gURLs[0]["url" + aState].spec;
 
     if (gURICanvases[gCurrentURL] &&
         (gURLs[0].type == TYPE_REFTEST_EQUAL ||
          gURLs[0].type == TYPE_REFTEST_NOTEQUAL) &&
         gURLs[0].maxAsserts == 0) {
         // Pretend the document loaded --- RecordResult will notice
         // there's already a canvas for this URL
-        setTimeout(RecordResult, 0);
+        gContainingWindow.setTimeout(RecordResult, 0);
     } else {
         var currentTest = gTotalTests - gURLs.length;
         gDumpLog("REFTEST TEST-START | " + gCurrentURL + " | " + currentTest + " / " + gTotalTests +
             " (" + Math.floor(100 * (currentTest / gTotalTests)) + "%)\n");
         LogInfo("START " + gCurrentURL);
         var type = gURLs[0].type
         if (TYPE_SCRIPT == type) {
             SendLoadScriptTest(gCurrentURL, gLoadTimeout);
@@ -1018,18 +1024,18 @@ function UpdateCanvasCache(url, canvas)
 // Fortunately this is pretty cheap.
 function DoDrawWindow(ctx, x, y, w, h)
 {
     var flags = ctx.DRAWWINDOW_DRAW_CARET | ctx.DRAWWINDOW_DRAW_VIEW;
     var testRect = gBrowser.getBoundingClientRect();
     if (gIgnoreWindowSize ||
         (0 <= testRect.left &&
          0 <= testRect.top &&
-         window.innerWidth >= testRect.right &&
-         window.innerHeight >= testRect.bottom)) {
+         gContainingWindow.innerWidth >= testRect.right &&
+         gContainingWindow.innerHeight >= testRect.bottom)) {
         // We can use the window's retained layer manager
         // because the window is big enough to display the entire
         // browser element
         flags |= ctx.DRAWWINDOW_USE_WIDGET_LAYERS;
     } else if (gBrowserIsRemote) {
         gDumpLog("REFTEST TEST-UNEXPECTED-FAIL | " + gCurrentURL + " | can't drawWindow remote content\n");
         ++gTestResults.Exception;
     }
@@ -1041,23 +1047,23 @@ function DoDrawWindow(ctx, x, y, w, h)
         if (flags & ctx.DRAWWINDOW_USE_WIDGET_LAYERS) {
             flagsStr += " | DRAWWINDOW_USE_WIDGET_LAYERS";
         } else {
             // Output a special warning because we need to be able to detect
             // this whenever it happens.
             gDumpLog("REFTEST INFO | WARNING: USE_WIDGET_LAYERS disabled\n");
         }
         gDumpLog("REFTEST INFO | drawWindow flags = " + flagsStr +
-                 "; window size = " + window.innerWidth + "," + window.innerHeight +
+                 "; window size = " + gContainingWindow.innerWidth + "," + gContainingWindow.innerHeight +
                  "; test browser size = " + testRect.width + "," + testRect.height +
                  "\n");
     }
 
     LogInfo("DoDrawWindow " + x + "," + y + "," + w + "," + h);
-    ctx.drawWindow(window, x, y, w, h, "rgb(255,255,255)",
+    ctx.drawWindow(gContainingWindow, x, y, w, h, "rgb(255,255,255)",
                    gDrawWindowFlags);
 }
 
 function InitCurrentCanvasWithSnapshot()
 {
     LogInfo("Initializing canvas snapshot");
 
     if (gURLs[0].type == TYPE_LOAD || gURLs[0].type == TYPE_SCRIPT) {