Bug 1495638 Convert talos sessionrestore extension to webextension r=mikedeboer

--HG--
rename : testing/talos/talos/startup_test/sessionrestore/addon/bootstrap.js => testing/talos/talos/startup_test/sessionrestore/addon/api.js
rename : testing/talos/talos/startup_test/sessionrestore/addon/install.rdf => testing/talos/talos/startup_test/sessionrestore/addon/manifest.json
extra : rebase_source : 93ad820d63b158ed7c71115f24375698625cfcab
extra : amend_source : ac2d88e8aa3a1b823c24fd3b879e6577bfd57294
This commit is contained in:
Andrew Swan 2018-10-08 12:59:52 -07:00
parent 53412531d1
commit febd07150a
7 changed files with 109 additions and 166 deletions

View File

@ -0,0 +1,80 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
/* 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";
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
SessionStartup: "resource:///modules/sessionstore/SessionStartup.jsm",
setTimeout: "resource://gre/modules/Timer.jsm",
StartupPerformance: "resource:///modules/sessionstore/StartupPerformance.jsm",
});
XPCOMUtils.defineLazyScriptGetter(this, "TalosParentProfiler",
"resource://talos-powers/TalosParentProfiler.js");
/* globals ExtensionAPI */
this.sessionrestore = class extends ExtensionAPI {
onStartup() {
// run() is async but we don't want to await or return it here,
// since the extension should be considered started even before
// run() has finished all its work.
this.run();
}
async run() {
try {
let didRestore = true;
if (!StartupPerformance.isRestored) {
await SessionStartup.onceInitialized;
if (SessionStartup.sessionType == SessionStartup.NO_SESSION ||
SessionStartup.sessionType == SessionStartup.DEFER_SESSION) {
// We should only hit this patch in sessionrestore_no_auto_restore
if (!Services.prefs.getBoolPref("talos.sessionrestore.norestore", false)) {
throw new Error("Session was not restored!");
}
didRestore = false;
} else {
await new Promise(resolve => {
async function observe() {
Services.obs.removeObserver(observe, StartupPerformance.RESTORED_TOPIC);
await TalosParentProfiler.pause("This test measures the time between sessionRestoreInit and sessionRestored, ignore everything around that");
await TalosParentProfiler.finishStartupProfiling();
resolve();
}
Services.obs.addObserver(observe, StartupPerformance.RESTORED_TOPIC);
});
}
}
let startup_info = Services.startup.getStartupInfo();
let restoreTime = didRestore
? StartupPerformance.latestRestoredTimeStamp
: startup_info.sessionRestored;
let duration = restoreTime - startup_info.sessionRestoreInit;
// Report data to Talos, if possible.
dump("__start_report" + duration + "__end_report\n\n");
// Next one is required by the test harness but not used.
// eslint-disable-next-line mozilla/avoid-Date-timing
dump("__startTimestamp" + Date.now() + "__endTimestamp\n\n");
} catch (ex) {
dump(`SessionRestoreTalosTest: error ${ex}\n`);
dump(ex.stack);
dump("\n");
}
Services.startup.quit(Services.startup.eForceQuit);
}
};

View File

@ -1,142 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
/* 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";
ChromeUtils.defineModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(this, "setTimeout",
"resource://gre/modules/Timer.jsm");
ChromeUtils.defineModuleGetter(this, "SessionStartup",
"resource:///modules/sessionstore/SessionStartup.jsm");
ChromeUtils.defineModuleGetter(this, "StartupPerformance",
"resource:///modules/sessionstore/StartupPerformance.jsm");
// Observer Service topics.
const WINDOW_READY_TOPIC = "browser-idle-startup-tasks-finished";
// Process Message Manager topics.
const MSG_REQUEST = "session-restore-test?duration";
const MSG_PROVIDE = "session-restore-test:duration";
const sessionRestoreTest = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver]),
// ////////////////////////////////////////////////////////////////////////////
// // nsIObserver
observe: function DS_observe(aSubject, aTopic, aData) {
switch (aTopic) {
case StartupPerformance.RESTORED_TOPIC:
this.onReady(true);
break;
case WINDOW_READY_TOPIC:
Services.obs.removeObserver(this, WINDOW_READY_TOPIC);
this.onWindow(aSubject);
break;
default:
throw new Error(`Unknown topic ${aTopic}`);
}
},
/**
* Perform initialization on profile-after-change.
*/
init() {
if (StartupPerformance.isRestored) {
this.onReady(true);
} else {
SessionStartup.onceInitialized.then(() => {
if (SessionStartup.sessionType == SessionStartup.NO_SESSION ||
SessionStartup.sessionType == SessionStartup.DEFER_SESSION) {
this.onReady(false);
} else {
Services.obs.addObserver(this, StartupPerformance.RESTORED_TOPIC);
}
});
}
},
/**
* Session Restore is complete, hurray.
*/
onReady(hasRestoredTabs) {
if (hasRestoredTabs) {
Services.obs.removeObserver(this, StartupPerformance.RESTORED_TOPIC);
}
// onReady might fire before the browser window has finished initializing
// or sometimes soon after. We handle both cases here.
let win = Services.wm.getMostRecentWindow("navigator:browser");
if (!win || !win.gBrowserInit || !win.gBrowserInit.idleTasksFinished) {
// We didn't have a window around yet, so we'll wait until one becomes
// available before opening the result tab.
Services.obs.addObserver(this, WINDOW_READY_TOPIC);
} else {
// We have a window, so we can open the result tab in it right away.
this.onWindow(win);
}
try {
setTimeout(function() {
// `StartupPerformance.latestRestoredTimeStamp` actually becomes available only on the next tick.
let startup_info = Services.startup.getStartupInfo();
let duration =
hasRestoredTabs
? StartupPerformance.latestRestoredTimeStamp - startup_info.sessionRestoreInit
: startup_info.sessionRestored - startup_info.sessionRestoreInit;
// Broadcast startup duration information immediately, in case the talos
// page is already loaded.
Services.ppmm.broadcastAsyncMessage(MSG_PROVIDE, {duration});
// Now, in case the talos page isn't loaded yet, prepare to respond if it
// requestions the duration information.
Services.ppmm.addMessageListener(MSG_REQUEST, function listener() {
Services.ppmm.removeMessageListener(MSG_REQUEST, listener);
Services.ppmm.broadcastAsyncMessage(MSG_PROVIDE, {duration});
});
}, 0);
} catch (ex) {
dump(`SessionRestoreTalosTest: error ${ex}\n`);
dump(ex.stack);
dump("\n");
}
},
/**
* A window is ready for us to open the result tab in.
*/
onWindow(win) {
let args = win.arguments[0];
let queryString = "";
if (args && args instanceof Ci.nsIArray) {
// For start-up tests Gecko Profiler arguments are passed to the first URL in
// the query string, with the presumption that the tab that is being loaded at
// start-up will want to use those arguments with the TalosContentProfiler scripts.
//
// Because we're actually loading the results (and the content that reports
// the results) in a new tab _after_ the window has opened, we need to send
// those arguments over to the new tab that we open so that the profiler scripts
// will continue to work.
Cu.importGlobalProperties(["URL"]);
let url = new URL(args.queryElementAt(0, Ci.nsISupportsString).data);
queryString = url.search;
}
win.gBrowser.addTrustedTab("chrome://session-restore-test/content/index.html" + queryString);
},
};
function startup(data, reason) {
sessionRestoreTest.init();
}
function shutdown(data, reason) {}
function install(data, reason) {}
function uninstall(data, reason) {}

View File

@ -1 +0,0 @@
content session-restore-test content/

View File

@ -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">
<!-- Required Items -->
<em:id>session-restore-test-2@mozilla.org</em:id>
<em:name>Session Restore Startup Performance Test</em:name>
<em:version>2.0.11</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>
<!-- Optional Items -->
<em:creator>David Rajchenbach-Teller</em:creator>
<em:description>Bug 936630, bug 1098357. This add-on broadcasts the duration of session restore.</em:description>
<em:homepageURL>https://bugzilla.mozilla.org/show_bug.cgi?id=1098357</em:homepageURL>
</Description></RDF>

View File

@ -0,0 +1,23 @@
{
"manifest_version": 2,
"name": "Session Restore Startup Performance Test",
"description": "Bug 936630, bug 1098357. This add-on broadcasts the duration of session restore.",
"version": "2.1",
"applications": {
"gecko": {
"id": "session-restore-test-2@mozilla.org"
}
},
"experiment_apis": {
"sessionrestore": {
"schema": "schema.json",
"parent": {
"scopes": ["addon_parent"],
"script": "api.js",
"events": ["startup"]
}
}
}
}

View File

@ -177,7 +177,7 @@ class sessionrestore(TsBase):
2. Launch Firefox.
3. Measure the delta between firstPaint and sessionRestored.
"""
extensions = ['${talos}/pageloader', '${talos}/startup_test/sessionrestore/addon']
extensions = ['${talos}/startup_test/sessionrestore/addon']
cycles = 10
timeout = 900
gecko_profile_startup = True
@ -200,7 +200,10 @@ class sessionrestore_no_auto_restore(sessionrestore):
2. Launch Firefox.
3. Measure the delta between firstPaint and sessionRestored.
"""
preferences = {'browser.startup.page': 1}
preferences = {
'browser.startup.page': 1,
'talos.sessionrestore.norestore': True,
}
@register_test()