/* 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/. */ import { FileUtils } from "resource://gre/modules/FileUtils.sys.mjs"; import { globals } from "resource://reftest/globals.sys.mjs"; const { XHTML_NS, XUL_NS, DEBUG_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, } = globals; import { HttpServer } from "resource://reftest/httpd.sys.mjs"; import { ReadTopManifest, CreateUrls, } from "resource://reftest/manifest.sys.mjs"; import { StructuredLogger } from "resource://reftest/StructuredLog.sys.mjs"; import { PerTestCoverageUtils } from "resource://reftest/PerTestCoverageUtils.sys.mjs"; import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; import { E10SUtils } from "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() { // This is the best we can do for now; maybe in the future we'll have // more correct detection of this case. return Services.appinfo.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) { 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); } } export function OnRefTestLoad(win) { g.crashDumpDir = Services.dirsvc.get("ProfD", Ci.nsIFile); g.crashDumpDir.append("minidumps"); g.pendingCrashDumpDir = Services.dirsvc.get("UAppData", Ci.nsIFile); g.pendingCrashDumpDir.append("Crash Reports"); g.pendingCrashDumpDir.append("pending"); g.browserIsRemote = Services.appinfo.browserTabsRemoteAutostart; g.browserIsFission = Services.appinfo.fissionAutostart; g.browserIsIframe = Services.prefs.getBoolPref( "reftest.browser.iframe.enabled", false ); g.useDrawSnapshot = Services.prefs.getBoolPref( "reftest.use-draw-snapshot", false ); g.logLevel = Services.prefs.getStringPref("reftest.logLevel", "info"); 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"); // FIXME: This ideally shouldn't be needed, but on android and windows // sometimes the window is occluded / hidden, which causes some crashtests // to time out. Bug 1864255 might be able to help here. g.browser.setAttribute("manualactiveness", "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 { win.document.getElementById("reftest-window").appendChild(g.browser); } g.browserMessageManager = g.browser.frameLoader.messageManager; // See the comment above about manualactiveness. g.browser.docShellIsActive = true; // The content script waits for the initial onload, then notifies // us. RegisterMessageListenersAndLoadContentScript(false); } function InitAndStartRefTests() { try { Services.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: //