Bug 1451460 - Stub out WebExtension bits for tps. r?rwood
MozReview-Commit-ID: 5lbluH6PPjB
rename from testing/talos/talos/tests/tabswitch/bootstrap.js
rename to testing/talos/talos/tests/tabswitch/api.js
--- a/testing/talos/talos/tests/tabswitch/bootstrap.js
+++ b/testing/talos/talos/tests/tabswitch/api.js
@@ -1,12 +1,11 @@
-
// -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
-/* globals APP_SHUTDOWN */
+/* globals APP_SHUTDOWN, ExtensionAPI */
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/Promise.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Task.jsm");
ChromeUtils.import("resource://gre/modules/Timer.jsm");
ChromeUtils.import("resource://gre/modules/RemotePageManager.jsm");
@@ -467,50 +466,25 @@ function loadIntoWindow(window) {
window.tab_switch_test = test;
item.setAttribute("oncommand", "tab_switch_test(window)");
let toolsMenu = window.document.getElementById("menu_ToolsPopup");
if (!toolsMenu)
return;
toolsMenu.appendChild(item);
}
-function install(aData, aReason) {}
-function uninstall(aData, aReason) {}
-
-function shutdown(aData, aReason) {
- // When the application is shutting down we normally don't have to clean
- // up any UI changes made
- if (aReason == APP_SHUTDOWN) {
- return;
- }
-
- Services.wm.removeListener(windowListener);
-
- // Unload from any existing windows
- let list = Services.wm.getEnumerator("navigator:browser");
- while (list.hasMoreElements()) {
- let window = list.getNext().QueryInterface(Ci.nsIDOMWindow);
- unloadFromWindow(window);
- }
- Services.obs.removeObserver(observer, "tabswitch-urlfile");
-
- remotePage.destroy();
-}
-
function handleFile(win, file) {
-
let localFile = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsIFile);
localFile.initWithPath(file);
let localURI = Services.io.newFileURI(localFile);
let req = new win.XMLHttpRequest();
req.open("get", localURI.spec, false);
req.send(null);
-
let testURLs = [];
let server = Services.prefs.getCharPref("addon.test.tabswitch.webserver");
let maxurls = Services.prefs.getIntPref("addon.test.tabswitch.maxurls");
let parent = server + "/tests/";
let lines = req.responseText.split('<a href=\"');
testURLs = [];
if (maxurls && maxurls > 0) {
lines.splice(maxurls, lines.length);
@@ -529,29 +503,49 @@ var observer = {
if (aTopic == "tabswitch-urlfile") {
handleFile(aSubject, aData);
}
}
};
var remotePage;
-function startup(aData, aReason) {
- // Load into any existing windows
- let list = Services.wm.getEnumerator("navigator:browser");
- let window;
- while (list.hasMoreElements()) {
- window = list.getNext().QueryInterface(Ci.nsIDOMWindow);
- loadIntoWindow(window);
- }
+this.tps = class extends ExtensionAPI {
+ getAPI(context) {
+ return {
+ tps: {
+ setup({ frameScriptPath }) {
+ let list = Services.wm.getEnumerator("navigator:browser");
+ let window;
+ while (list.hasMoreElements()) {
+ window = list.getNext().QueryInterface(Ci.nsIDOMWindow);
+ loadIntoWindow(window);
+ }
+ // Load into any new windows
+ Services.wm.addListener(windowListener);
+ Services.obs.addObserver(observer, "tabswitch-urlfile");
- // Load into any new windows
- Services.wm.addListener(windowListener);
+ const frameScriptURL = context.extension.baseURI.resolve(frameScriptPath);
+ Services.ppmm.loadFrameScript(frameScriptURL, true);
+ remotePage = new RemotePages("about:tabswitch");
+ remotePage.addMessageListener("tabswitch-do-test", function doTest(msg) {
+ test(msg.target.browser.ownerGlobal);
+ });
- Services.obs.addObserver(observer, "tabswitch-urlfile");
+ return () => {
+ Services.ppmm.sendAsyncMessage("TPS:Teardown");
+
+ Services.wm.removeListener(windowListener);
- Services.ppmm.loadProcessScript("chrome://tabswitch/content/tabswitch-content-process.js", true);
-
- remotePage = new RemotePages("about:tabswitch");
- remotePage.addMessageListener("tabswitch-do-test", function doTest(msg) {
- test(msg.target.browser.ownerGlobal);
- });
-}
+ // Unload from any existing windows
+ let list = Services.wm.getEnumerator("navigator:browser");
+ while (list.hasMoreElements()) {
+ let window = list.getNext().QueryInterface(Ci.nsIDOMWindow);
+ unloadFromWindow(window);
+ }
+ Services.obs.removeObserver(observer, "tabswitch-urlfile");
+ remotePage.destroy();
+ };
+ }
+ }
+ };
+ }
+};
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/tabswitch/background.js
@@ -0,0 +1,13 @@
+/* globals browser */
+
+/**
+ * The TPS test is a Pageloader test, meaning that the tps.manifest file
+ * tells Talos to load a particular page. The loading of that page signals
+ * the start of the test. It's also where results need to go, as the
+ * Talos gunk augments the loaded page with a special tpRecordTime
+ * function that is used to report results.
+ */
+
+let frameScriptPath = "content/tabswitch-content-process.js";
+
+browser.tps.setup({ frameScriptPath });
deleted file mode 100644
--- a/testing/talos/talos/tests/tabswitch/chrome.manifest
+++ /dev/null
@@ -1,1 +0,0 @@
-content tabswitch content/
\ No newline at end of file
--- a/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js
+++ b/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js
@@ -1,30 +1,64 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-const CHROME_URI = "chrome://tabswitch/content/test.html";
-
-class TabSwitchAboutModule {
- constructor() {
- this.QueryInterface = XPCOMUtils.generateQI([Ci.nsIAboutModule]);
- }
+const WEBEXTENSION_ID = "tabswitch-talos@mozilla.org";
+const ABOUT_PAGE_NAME = "tabswitch";
+const Registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+const UUID = "0f459ab4-b4ba-4741-ac89-ee47dea07adb";
+const ABOUT_PATH_PATH = "content/test.html";
- newChannel(aURI, aLoadInfo) {
- let uri = Services.io.newURI(CHROME_URI);
- let chan = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
- chan.originalURI = aURI;
- return chan;
- }
+XPCOMUtils.defineLazyGetter(
+ this, "processScript",
+ () => Cc["@mozilla.org/webextensions/extension-process-script;1"]
+ .getService().wrappedJSObject);
+
+const TPSProcessScript = {
+ init() {
+ let extensionChild = processScript.getExtensionChild(WEBEXTENSION_ID);
+ let aboutPageURI = extensionChild.baseURI.resolve(ABOUT_PATH_PATH);
- getURIFlags(aURI) {
- return Ci.nsIAboutModule.ALLOW_SCRIPT |
- Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD;
- }
-}
+ class TabSwitchAboutModule {
+ constructor() {
+ this.QueryInterface = XPCOMUtils.generateQI([Ci.nsIAboutModule]);
+ }
+ newChannel(aURI, aLoadInfo) {
+ let uri = Services.io.newURI(aboutPageURI);
+ let chan = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
+ chan.originalURI = aURI;
+ return chan;
+ }
+ getURIFlags(aURI) {
+ return Ci.nsIAboutModule.ALLOW_SCRIPT |
+ Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD;
+ }
+ }
+
+ let factory = XPCOMUtils._getFactory(TabSwitchAboutModule);
+ this._factory = factory;
-let factory = XPCOMUtils._getFactory(TabSwitchAboutModule);
-let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
-let UUIDGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
+ Registrar.registerFactory(
+ Components.ID(UUID), "",
+ `@mozilla.org/network/protocol/about;1?what=${ABOUT_PAGE_NAME}`,
+ factory);
+
+ this._hasSetup = true;
+ },
+
+ teardown() {
+ if (!this._hasSetup) {
+ return;
+ }
-registrar.registerFactory(UUIDGenerator.generateUUID(), "",
- "@mozilla.org/network/protocol/about;1?what=tabswitch",
- factory);
+ Registrar.unregisterFactory(Components.ID(UUID), this._factory);
+ this._hasSetup = false;
+ this._factory = null;
+ },
+
+ receiveMessage(msg) {
+ if (msg.name == "TPS:Teardown") {
+ this.teardown();
+ }
+ }
+};
+
+TPSProcessScript.init();
--- a/testing/talos/talos/tests/tabswitch/content/test.html
+++ b/testing/talos/talos/tests/tabswitch/content/test.html
@@ -1,18 +1,17 @@
<html>
<head>
<script>
function do_test(override) {
if (override || document.location.hash.indexOf("#auto") == 0) {
sendAsyncMessage("tabswitch-do-test");
addMessageListener("tabswitch-test-results", function onMessage(msg) {
let data = msg.data;
- content.tpRecordTime(data.times.join(","), 0, data.urls.join(","));
- sendAsyncMessage("tabswitch-test-results-reported");
+ tpRecordTime(data.times.join(","), 0, data.urls.join(","));
});
}
}
</script>
</head>
<body onload="do_test(false)">
Hello Talos!
</body>
deleted file mode 100644
--- a/testing/talos/talos/tests/tabswitch/install.rdf
+++ /dev/null
@@ -1,21 +0,0 @@
-<?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>tab-switch-test@lassey.us</em:id>
- <em:type>2</em:type>
- <em:name>Tab Switch Test</em:name>
- <em:version>1.0.7</em:version>
- <em:bootstrap>true</em:bootstrap>
- <em:description>Measures the performance of switching tabs</em:description>
- <em:creator>Brad Lassey</em:creator>
- <em:multiprocessCompatible>true</em:multiprocessCompatible>
- <!-- Desktop -->
- <em:targetApplication>
- <Description>
- <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
- <em:minVersion>38.0</em:minVersion>
- <em:maxVersion>*</em:maxVersion>
- </Description>
- </em:targetApplication>
- </Description>
-</RDF>
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/tabswitch/manifest.json
@@ -0,0 +1,24 @@
+{
+ "applications": {
+ "gecko": {
+ "id": "tabswitch-talos@mozilla.org"
+ }
+ },
+ "manifest_version": 2,
+ "name": "TPS (tabswitch) Talos Test",
+ "version": "0.1",
+ "permissions": [],
+ "background": {
+ "scripts": ["background.js"]
+ },
+ "experiment_apis": {
+ "tps": {
+ "schema": "schema.json",
+ "parent": {
+ "scopes": ["addon_parent"],
+ "script": "api.js",
+ "paths": [["tps"]]
+ }
+ }
+ }
+}
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/tabswitch/schema.json
@@ -0,0 +1,23 @@
+[
+ {
+ "namespace": "tps",
+ "description": "Special powers for the TPS Talos test",
+ "functions": [
+ {
+ "name": "setup",
+ "type": "function",
+ "description": "Prepares the TPS test to be run by the Talos framework.",
+ "parameters": [{
+ "type": "object",
+ "name": "setupArgs",
+ "properties": {
+ "frameScriptPath": {
+ "type": "string",
+ "description": "Relative path for the frame script to load for the test in the initial tab."
+ }
+ }
+ }]
+ }
+ ]
+ }
+]
\ No newline at end of file