/* -*- 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", ]; const { FileUtils } = ChromeUtils.importESModule( "resource://gre/modules/FileUtils.sys.mjs" ); const { XHTML_NS, XUL_NS, IO_SERVICE_CONTRACTID, DEBUG_CONTRACTID, NS_DIRECTORY_SERVICE_CONTRACTID, NS_OBSERVER_SERVICE_CONTRACTID, TYPE_REFTEST_EQUAL, TYPE_REFTEST_NOTEQUAL, TYPE_LOAD, TYPE_SCRIPT, TYPE_PRINT, URL_TARGET_TYPE_TEST, URL_TARGET_TYPE_REFERENCE, EXPECTED_PASS, EXPECTED_FAIL, EXPECTED_RANDOM, EXPECTED_FUZZY, PREF_BOOLEAN, PREF_STRING, PREF_INTEGER, FOCUS_FILTER_NON_NEEDS_FOCUS_TESTS, g, } = ChromeUtils.import("resource://reftest/globals.jsm"); const { HttpServer } = ChromeUtils.import("resource://reftest/httpd.jsm"); const { ReadTopManifest, CreateUrls } = ChromeUtils.import( "resource://reftest/manifest.jsm" ); const { StructuredLogger } = ChromeUtils.importESModule( "resource://reftest/StructuredLog.sys.mjs" ); const { PerTestCoverageUtils } = ChromeUtils.importESModule( "resource://reftest/PerTestCoverageUtils.sys.mjs" ); const { XPCOMUtils } = ChromeUtils.importESModule( "resource://gre/modules/XPCOMUtils.sys.mjs" ); const { E10SUtils } = ChromeUtils.importESModule( "resource://gre/modules/E10SUtils.sys.mjs" ); const lazy = {}; XPCOMUtils.defineLazyServiceGetters(lazy, { proxyService: [ "@mozilla.org/network/protocol-proxy-service;1", "nsIProtocolProxyService", ], }); 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 isAndroidDevice() { 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; } 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 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"); 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.useDrawSnapshot = prefs.getBoolPref("reftest.use-draw-snapshot", 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; color-scheme: env(-moz-content-preferred-color-scheme)"); 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"); } else { document.getElementById("reftest-window").appendChild(g.browser); } 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: //