Bug 1446676: Part 1b - Convert talos overlay extensions to bootstrapped extensions. r?aswan
MozReview-Commit-ID: Awq8hpjKjY7
--- a/testing/mochitest/bootstrap.js
+++ b/testing/mochitest/bootstrap.js
@@ -1,15 +1,83 @@
/* 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/. */
+ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
+ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+/////// Android ///////
+
+Cu.importGlobalProperties(["TextDecoder"]);
+
+class DefaultMap extends Map {
+ constructor(defaultConstructor = undefined, init = undefined) {
+ super(init);
+ if (defaultConstructor) {
+ this.defaultConstructor = defaultConstructor;
+ }
+ }
+
+ get(key) {
+ let value = super.get(key);
+ if (value === undefined && !this.has(key)) {
+ value = this.defaultConstructor(key);
+ this.set(key, value);
+ }
+ return value;
+ }
+}
+
+const windowTracker = {
+ init() {
+ Services.obs.addObserver(this, "chrome-document-global-created");
+ },
+
+ overlays: new DefaultMap(() => new Set()),
+
+ 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;
+
+ if (this.overlays.has(documentURI)) {
+ for (let overlay of this.overlays.get(documentURI)) {
+ document.loadOverlay(overlay, null);
+ }
+ }
+ }
+ },
+};
+
+function readSync(uri) {
+ let channel = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
+ let buffer = NetUtil.readInputStream(channel.open2());
+ return new TextDecoder().decode(buffer);
+}
+
+function androidStartup(data, reason) {
+ windowTracker.init();
+
+ for (let line of readSync(data.resourceURI.resolve("chrome.manifest")).split("\n")) {
+ let [directive, ...args] = line.trim().split(/\s+/);
+ if (directive === "overlay") {
+ let [url, overlay] = args;
+ windowTracker.overlays.get(url).add(overlay);
+ }
+ }
+}
+
+/////// Desktop ///////
+
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.
setupWindow: function(win) {
win.nativeConsole = win.console;
ChromeUtils.defineModuleGetter(win, "console",
"resource://gre/modules/Console.jsm");
},
@@ -48,26 +116,33 @@ function loadMochitest(e) {
WindowListener.setupWindow(win);
Services.wm.addListener(WindowListener);
let overlay = "chrome://mochikit/content/browser-test-overlay.xul";
win.document.loadOverlay(overlay, null);
}
function startup(data, reason) {
- let win = Services.wm.getMostRecentWindow("navigator:browser");
- // wait for event fired from start_desktop.js containing the
- // suite and url to load
- win.addEventListener('mochitest-load', loadMochitest);
+ 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
+ win.addEventListener('mochitest-load', loadMochitest);
+ }
}
function shutdown(data, reason) {
- let windows = Services.wm.getEnumerator("navigator:browser");
- while (windows.hasMoreElements()) {
- let win = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
- WindowListener.tearDownWindow(win);
+ if (AppConstants.platform != "android") {
+ let windows = Services.wm.getEnumerator("navigator:browser");
+ while (windows.hasMoreElements()) {
+ let win = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
+ WindowListener.tearDownWindow(win);
+ }
+
+ Services.wm.removeListener(WindowListener);
}
-
- Services.wm.removeListener(WindowListener);
}
function install(data, reason) {}
function uninstall(data, reason) {}
+
--- a/testing/mochitest/install.rdf
+++ b/testing/mochitest/install.rdf
@@ -1,18 +1,16 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>mochikit@mozilla.org</em:id>
<em:version>1.0</em:version>
-#ifdef MOCHITEST_BOOTSTRAP
<em:bootstrap>true</em:bootstrap>
-#endif
<em:targetApplication>
<Description>
<em:id>toolkit@mozilla.org</em:id>
#expand <em:minVersion>__MOZILLA_VERSION_U__</em:minVersion>
<!-- Set to * so toolkit/mozapps/update/chrome tests pass. -->
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
--- a/testing/mochitest/moz.build
+++ b/testing/mochitest/moz.build
@@ -14,19 +14,17 @@ DIRS += [
XPI_NAME = 'mochijar'
JAR_MANIFESTS += ['jar.mn']
USE_EXTENSION_MANIFEST = True
FINAL_TARGET_PP_FILES += ['install.rdf']
-if CONFIG['OS_TARGET'] != 'Android':
- DEFINES['MOCHITEST_BOOTSTRAP'] = True
- FINAL_TARGET_FILES += ['bootstrap.js']
+FINAL_TARGET_FILES += ['bootstrap.js']
MOCHITEST_MANIFESTS += [
'tests/MochiKit-1.4.2/tests/mochitest.ini',
]
MOCHITEST_CHROME_MANIFESTS += ['chrome/chrome.ini']
GENERATED_FILES += [
'automation.py',
--- a/testing/talos/talos/generate-tart-xpi.html
+++ b/testing/talos/talos/generate-tart-xpi.html
@@ -1,24 +1,25 @@
-<html>
+<html>
<!--
* 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/.
-->
<head>
<meta charset="UTF-8"/>
<title>TART addon xpi generator</title>
<script src="scripts/jszip.min.js"></script>
<script src="scripts/xpigen.js"></script>
<script>
/* import-globals-from scripts/xpigen.js */
var base = "tests/tart/addon/";
var files = [
+ "bootstrap.js",
"chrome.manifest",
"install.rdf",
"content/framescript.js",
"content/tart.overlay.xul",
"content/tart.html",
"content/tart.ico",
"content/tart.js",
"content/blank.icon.html",
--- a/testing/talos/talos/generate-tresize-xpi.html
+++ b/testing/talos/talos/generate-tresize-xpi.html
@@ -9,16 +9,17 @@
<title>Tresize addon xpi generator</title>
<script src="scripts/jszip.min.js"></script>
<script src="scripts/xpigen.js"></script>
<script>
/* import-globals-from scripts/xpigen.js */
var base = "startup_test/tresize/addon/";
var files = [
+ "bootstrap.js",
"chrome.manifest",
"install.rdf",
"content/framescript.js",
"content/Profiler.js",
"content/tresize.overlay.xul",
"content/tresize.js",
"content/tresize-test.html"
];
copy from testing/talos/talos/bootstrap.js
copy to testing/talos/talos/startup_test/tresize/addon/bootstrap.js
--- a/testing/talos/talos/startup_test/tresize/addon/install.rdf
+++ b/testing/talos/talos/startup_test/tresize/addon/install.rdf
@@ -1,14 +1,15 @@
<?xml version="1.0"?><RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"><Description about="urn:mozilla:install-manifest">
<!-- Required Items -->
<em:id>tresize@mozilla.org</em:id>
<em:name>TResize - Firefox Window Resize Test</em:name>
<em:version>1.0.3</em:version>
+<em:bootstrap>true</em:bootstrap>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
copy from testing/talos/talos/bootstrap.js
copy to testing/talos/talos/tests/devtools/addon/bootstrap.js
--- a/testing/talos/talos/tests/devtools/addon/install.rdf
+++ b/testing/talos/talos/tests/devtools/addon/install.rdf
@@ -1,14 +1,15 @@
<?xml version="1.0"?><RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"><Description about="urn:mozilla:install-manifest">
<!-- Required Items -->
<em:id>bug1150215@mozilla.org</em:id>
<em:name>DAMP - Devtools At Maximum Performance</em:name>
<em:version>0.0.16</em:version>
+<em:bootstrap>true</em:bootstrap>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>44.0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
copy from testing/talos/talos/bootstrap.js
copy to testing/talos/talos/tests/tart/addon/bootstrap.js
--- a/testing/talos/talos/tests/tart/addon/install.rdf
+++ b/testing/talos/talos/tests/tart/addon/install.rdf
@@ -1,14 +1,15 @@
<?xml version="1.0"?><RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"><Description about="urn:mozilla:install-manifest">
<!-- Required Items -->
<em:id>bug848358@mozilla.org</em:id>
<em:name>TART - Tab Animation regression Test</em:name>
<em:version>1.6.2</em:version>
+<em:bootstrap>true</em:bootstrap>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>