2016-01-25 17:55:57 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2018-03-17 07:31:04 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2016-01-25 17:55:57 +03:00
|
|
|
|
2018-03-14 03:33:33 +03:00
|
|
|
function loadChromeScripts(win) {
|
|
|
|
Services.scriptloader.loadSubScript("chrome://mochikit/content/chrome-harness.js", win);
|
|
|
|
Services.scriptloader.loadSubScript("chrome://mochikit/content/mochitest-e10s-utils.js", win);
|
|
|
|
Services.scriptloader.loadSubScript("chrome://mochikit/content/browser-test.js", win);
|
|
|
|
}
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
// ///// Android ///////
|
2018-03-17 07:31:04 +03:00
|
|
|
|
|
|
|
Cu.importGlobalProperties(["TextDecoder"]);
|
|
|
|
|
|
|
|
const windowTracker = {
|
|
|
|
init() {
|
|
|
|
Services.obs.addObserver(this, "chrome-document-global-created");
|
|
|
|
},
|
|
|
|
|
|
|
|
async observe(window, topic, data) {
|
|
|
|
if (topic === "chrome-document-global-created") {
|
|
|
|
await new Promise(resolve =>
|
|
|
|
window.addEventListener("DOMContentLoaded", resolve, {once: true}));
|
|
|
|
|
|
|
|
let {document} = window;
|
|
|
|
let {documentURI} = document;
|
|
|
|
|
2018-03-14 03:33:33 +03:00
|
|
|
if (documentURI !== "chrome://browser/content/browser.xul") {
|
|
|
|
return;
|
2018-03-17 07:31:04 +03:00
|
|
|
}
|
2018-03-14 03:33:33 +03:00
|
|
|
loadChromeScripts(window);
|
2018-03-17 07:31:04 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
function androidStartup(data, reason) {
|
2018-03-14 03:33:33 +03:00
|
|
|
// Only browser chrome tests need help starting.
|
|
|
|
let testRoot = Services.prefs.getStringPref("mochitest.testRoot", "");
|
|
|
|
if (testRoot.endsWith("/chrome")) {
|
|
|
|
windowTracker.init();
|
2018-03-17 07:31:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
// ///// Desktop ///////
|
2018-03-17 07:31:04 +03:00
|
|
|
|
2016-01-25 17:55:57 +03:00
|
|
|
var WindowListener = {
|
|
|
|
// browser-test.js is only loaded into the first window. Setup that
|
|
|
|
// needs to happen in all navigator:browser windows should go here.
|
2018-01-27 00:32:30 +03:00
|
|
|
setupWindow(win) {
|
2016-01-25 17:55:57 +03:00
|
|
|
win.nativeConsole = win.console;
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(win, "console",
|
2016-01-25 17:55:57 +03:00
|
|
|
"resource://gre/modules/Console.jsm");
|
|
|
|
},
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
tearDownWindow(win) {
|
2016-01-25 17:55:57 +03:00
|
|
|
if (win.nativeConsole) {
|
|
|
|
win.console = win.nativeConsole;
|
|
|
|
win.nativeConsole = undefined;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
onOpenWindow(win) {
|
2016-01-25 17:55:57 +03:00
|
|
|
win = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
|
|
|
|
|
2017-01-25 09:01:52 +03:00
|
|
|
win.addEventListener("load", function() {
|
2016-01-25 17:55:57 +03:00
|
|
|
if (win.document.documentElement.getAttribute("windowtype") == "navigator:browser") {
|
|
|
|
WindowListener.setupWindow(win);
|
|
|
|
}
|
2017-01-25 09:01:52 +03:00
|
|
|
}, {once: true});
|
2016-01-25 17:55:57 +03:00
|
|
|
}
|
2018-01-27 00:32:30 +03:00
|
|
|
};
|
2016-01-25 17:55:57 +03:00
|
|
|
|
|
|
|
function loadMochitest(e) {
|
|
|
|
let flavor = e.detail[0];
|
|
|
|
let url = e.detail[1];
|
|
|
|
|
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
2018-01-27 00:32:30 +03:00
|
|
|
win.removeEventListener("mochitest-load", loadMochitest);
|
2016-01-25 17:55:57 +03:00
|
|
|
|
|
|
|
// for mochitest-plain, navigating to the url is all we need
|
|
|
|
win.loadURI(url);
|
|
|
|
if (flavor == "mochitest") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowListener.setupWindow(win);
|
|
|
|
Services.wm.addListener(WindowListener);
|
|
|
|
|
2018-03-14 03:33:33 +03:00
|
|
|
loadChromeScripts(win);
|
2016-01-25 17:55:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function startup(data, reason) {
|
2018-03-17 07:31:04 +03:00
|
|
|
if (AppConstants.platform == "android") {
|
|
|
|
androidStartup(data, reason);
|
|
|
|
} else {
|
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
// wait for event fired from start_desktop.js containing the
|
|
|
|
// suite and url to load
|
2018-01-27 00:32:30 +03:00
|
|
|
win.addEventListener("mochitest-load", loadMochitest);
|
2018-03-17 07:31:04 +03:00
|
|
|
}
|
2016-01-25 17:55:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function shutdown(data, reason) {
|
2018-03-17 07:31:04 +03:00
|
|
|
if (AppConstants.platform != "android") {
|
|
|
|
let windows = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (windows.hasMoreElements()) {
|
|
|
|
let win = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
|
|
|
|
WindowListener.tearDownWindow(win);
|
|
|
|
}
|
2018-03-21 21:51:03 +03:00
|
|
|
|
2018-03-17 07:31:04 +03:00
|
|
|
Services.wm.removeListener(WindowListener);
|
|
|
|
}
|
2016-01-25 17:55:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function install(data, reason) {}
|
|
|
|
function uninstall(data, reason) {}
|
2018-03-17 07:31:04 +03:00
|
|
|
|