/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- / /* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; var EXPORTED_SYMBOLS = [ "OnRefTestLoad", "OnRefTestUnload", "getTestPlugin" ]; Cu.import("resource://gre/modules/FileUtils.jsm"); Cu.import("resource://reftest/globals.jsm", this); Cu.import("resource://reftest/httpd.jsm", this); Cu.import("resource://reftest/manifest.jsm", this); Cu.import("resource://reftest/StructuredLog.jsm", this); Cu.import("resource://reftest/PerTestCoverageUtils.jsm", this); Cu.import("resource://gre/modules/Services.jsm"); Cu.import('resource://gre/modules/XPCOMUtils.jsm'); const { E10SUtils } = ChromeUtils.import( "resource://gre/modules/E10SUtils.jsm" ); XPCOMUtils.defineLazyGetter(this, "OS", function() { const { OS } = Cu.import("resource://gre/modules/osfile.jsm"); return OS; }); function HasUnexpectedResult() { return g.testResults.Exception > 0 || g.testResults.FailedLoad > 0 || g.testResults.UnexpectedFail > 0 || g.testResults.UnexpectedPass > 0 || g.testResults.AssertionUnexpected > 0 || g.testResults.AssertionUnexpectedFixed > 0; } // By default we just log to stdout var gDumpFn = function(line) { dump(line); if (g.logFile) { g.logFile.writeString(line); } } var gDumpRawLog = function(record) { // Dump JSON representation of data on a single line var line = "\n" + JSON.stringify(record) + "\n"; dump(line); if (g.logFile) { g.logFile.writeString(line); } } g.logger = new StructuredLogger('reftest', gDumpRawLog); var logger = g.logger; function TestBuffer(str) { logger.debug(str); g.testLog.push(str); } function isWebRenderOnAndroidDevice() { var xr = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime); // This is the best we can do for now; maybe in the future we'll have // more correct detection of this case. return xr.OS == "Android" && g.browserIsRemote && g.windowUtils.layerManagerType == "WebRender"; } function FlushTestBuffer() { // In debug mode, we've dumped all these messages already. if (g.logLevel !== 'debug') { for (var i = 0; i < g.testLog.length; ++i) { logger.info("Saved log: " + g.testLog[i]); } } g.testLog = []; } function LogWidgetLayersFailure() { logger.error( "Screen resolution is too low - USE_WIDGET_LAYERS was disabled. " + (g.browserIsRemote ? "Since E10s is enabled, there is no fallback rendering path!" : "The fallback rendering path is not reliably consistent with on-screen rendering.")); logger.error( "If you cannot increase your screen resolution you can try reducing " + "gecko's pixel scaling by adding something like '--setpref " + "layout.css.devPixelsPerPx=1.0' to your './mach reftest' command " + "(possibly as an alias in ~/.mozbuild/machrc). Note that this is " + "inconsistent with CI testing, and may interfere with HighDPI/" + "reftest-zoom tests."); } function AllocateCanvas() { if (g.recycledCanvases.length > 0) { return g.recycledCanvases.shift(); } var canvas = g.containingWindow.document.createElementNS(XHTML_NS, "canvas"); var r = g.browser.getBoundingClientRect(); canvas.setAttribute("width", Math.ceil(r.width)); canvas.setAttribute("height", Math.ceil(r.height)); return canvas; } function ReleaseCanvas(canvas) { // store a maximum of 2 canvases, if we're not caching if (!g.noCanvasCache || g.recycledCanvases.length < 2) { g.recycledCanvases.push(canvas); } } function IDForEventTarget(event) { try { return "'" + event.target.getAttribute('id') + "'"; } catch (ex) { return ""; } } function getTestPlugin(aName) { var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); var tags = ph.getPluginTags(); // Find the test plugin for (var i = 0; i < tags.length; i++) { if (tags[i].name == aName) return tags[i]; } logger.warning("Failed to find the test-plugin."); return null; } function OnRefTestLoad(win) { g.crashDumpDir = Cc[NS_DIRECTORY_SERVICE_CONTRACTID] .getService(Ci.nsIProperties) .get("ProfD", Ci.nsIFile); g.crashDumpDir.append("minidumps"); g.pendingCrashDumpDir = Cc[NS_DIRECTORY_SERVICE_CONTRACTID] .getService(Ci.nsIProperties) .get("UAppData", Ci.nsIFile); g.pendingCrashDumpDir.append("Crash Reports"); g.pendingCrashDumpDir.append("pending"); var env = Cc["@mozilla.org/process/environment;1"]. getService(Ci.nsIEnvironment); g.browserIsRemote = Services.appinfo.browserTabsRemoteAutostart; g.browserIsFission = Services.appinfo.fissionAutostart; var prefs = Cc["@mozilla.org/preferences-service;1"]. getService(Ci.nsIPrefBranch); g.browserIsIframe = prefs.getBoolPref("reftest.browser.iframe.enabled", false); g.logLevel = prefs.getStringPref("reftest.logLevel", "info"); if (win === undefined || win == null) { win = window; } if (g.containingWindow == null && win != null) { g.containingWindow = win; } if (g.browserIsIframe) { g.browser = g.containingWindow.document.createElementNS(XHTML_NS, "iframe"); g.browser.setAttribute("mozbrowser", ""); } else { g.browser = g.containingWindow.document.createElementNS(XUL_NS, "xul:browser"); } g.browser.setAttribute("id", "browser"); g.browser.setAttribute("type", "content"); g.browser.setAttribute("primary", "true"); g.browser.setAttribute("remote", g.browserIsRemote ? "true" : "false"); // Make sure the browser element is exactly 800x1000, no matter // what size our window is g.browser.setAttribute("style", "padding: 0px; margin: 0px; border:none; min-width: 800px; min-height: 1000px; max-width: 800px; max-height: 1000px"); if (Services.appinfo.OS == "Android") { let doc = g.containingWindow.document.getElementById('main-window'); while (doc.hasChildNodes()) { doc.firstChild.remove(); } doc.appendChild(g.browser); // TODO Bug 1156817: reftests don't have most of GeckoView infra so we // can't register this actor ChromeUtils.unregisterWindowActor("LoadURIDelegate"); ChromeUtils.unregisterWindowActor("WebBrowserChrome"); } else { document.getElementById("reftest-window").appendChild(g.browser); } // reftests should have the test plugins enabled, not click-to-play let plugin1 = getTestPlugin("Test Plug-in"); let plugin2 = getTestPlugin("Second Test Plug-in"); if (plugin1 && plugin2) { g.testPluginEnabledStates = [plugin1.enabledState, plugin2.enabledState]; plugin1.enabledState = Ci.nsIPluginTag.STATE_ENABLED; plugin2.enabledState = Ci.nsIPluginTag.STATE_ENABLED; } else { logger.warning("Could not get test plugin tags."); } g.browserMessageManager = g.browser.frameLoader.messageManager; // The content script waits for the initial onload, then notifies // us. RegisterMessageListenersAndLoadContentScript(false); } function InitAndStartRefTests() { /* These prefs are optional, so we don't need to spit an error to the log */ try { var prefs = Cc["@mozilla.org/preferences-service;1"]. getService(Ci.nsIPrefBranch); } catch(e) { logger.error("EXCEPTION: " + e); } try { prefs.setBoolPref("android.widget_paints_background", false); } catch (e) {} // If fission is enabled, then also put data: URIs in the default web process, // since most reftests run in the file process, and this will make data: //