Bug 1372292 - Load sessionrestore Talos test result page in a tab after the measurement is done. r?Yoric
MozReview-Commit-ID: 4cl64N6nwuN
--- a/testing/talos/talos/startup_test/sessionrestore/addon/SessionRestoreTalosTest.js
+++ b/testing/talos/talos/startup_test/sessionrestore/addon/SessionRestoreTalosTest.js
@@ -16,16 +16,17 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
"resource://gre/modules/Timer.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "StartupPerformance",
"resource:///modules/sessionstore/StartupPerformance.jsm");
// Observer Service topics.
const STARTUP_TOPIC = "profile-after-change";
+const WINDOW_READY_TOPIC = "browser-delayed-startup-finished";
// Process Message Manager topics.
const MSG_REQUEST = "session-restore-test?duration";
const MSG_PROVIDE = "session-restore-test:duration";
function nsSessionRestoreTalosTest() { }
nsSessionRestoreTalosTest.prototype = {
@@ -44,16 +45,20 @@ nsSessionRestoreTalosTest.prototype = {
observe: function DS_observe(aSubject, aTopic, aData) {
switch (aTopic) {
case STARTUP_TOPIC:
this.init();
break;
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.
*/
@@ -76,16 +81,29 @@ nsSessionRestoreTalosTest.prototype = {
/**
* Session Restore is complete, hurray.
*/
onReady: function(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.gBrowser) {
+ // 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;
@@ -102,14 +120,21 @@ nsSessionRestoreTalosTest.prototype = {
});
}, 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) {
+ win.gBrowser.addTab("chrome://session-restore-test/content/index.html");
+ }
};
////////////////////////////////////////////////////////////////////////////////
//// Module
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsSessionRestoreTalosTest]);
rename from testing/talos/talos/startup_test/sessionrestore/index.html
rename to testing/talos/talos/startup_test/sessionrestore/addon/content/index.html
--- a/testing/talos/talos/startup_test/sessionrestore/index.html
+++ b/testing/talos/talos/startup_test/sessionrestore/addon/content/index.html
@@ -1,18 +1,18 @@
<html>
<head>
<meta charset="UTF-8"/>
<title>Session Restore Regression Test</title>
-<script type="text/javascript" src="../../scripts/MozillaFileLogger.js"></script>
-<script type="text/javascript" src="../../tests/quit.js"></script>
-<script type="text/javascript" src="../../scripts/Profiler.js"></script>
-<script type="text/javascript" src="./main.js">
+<script type="text/javascript" src="chrome://pageloader/content/MozillaFileLogger.js"></script>
+<script type="text/javascript" src="chrome://pageloader/content/quit.js"></script>
+<script type="text/javascript" src="chrome://pageloader/content/Profiler.js"></script>
+<script type="text/javascript" src="chrome://session-restore-test/content/main.js">
</script>
<div>
<strong>Time between sessionRestoreInit and sessionRestored</strong>
<span id="sessionRestoreInit-to-sessionRestored">
(in progress)
</span>
</div>
rename from testing/talos/talos/startup_test/sessionrestore/main.js
rename to testing/talos/talos/startup_test/sessionrestore/addon/content/main.js
--- a/testing/talos/talos/startup_test/sessionrestore/main.js
+++ b/testing/talos/talos/startup_test/sessionrestore/addon/content/main.js
@@ -1,42 +1,40 @@
"use strict";
var Services = Components.utils.import("resource://gre/modules/Services.jsm", {}).Services;
// Process Message Manager topics.
const MSG_REQUEST = "session-restore-test?duration";
const MSG_PROVIDE = "session-restore-test:duration";
-Services.cpmm.addMessageListener(MSG_PROVIDE,
- /**
- * Display the result, send it to the harness and quit.
- */
- function finish(msg) {
- console.log(`main.js: received data on ${MSG_PROVIDE}`, msg);
- Services.cpmm.removeMessageListener(MSG_PROVIDE, finish);
- var duration = msg.data.duration;
+addEventListener("load", function() {
+ Services.cpmm.addMessageListener(MSG_PROVIDE,
+ /**
+ * Display the result, send it to the harness and quit.
+ */
+ function finish(msg) {
+ console.log(`main.js: received data on ${MSG_PROVIDE}`, msg);
+ Services.cpmm.removeMessageListener(MSG_PROVIDE, finish);
+ var duration = msg.data.duration;
+ Profiler.pause("This test measures the time between sessionRestoreInit and sessionRestored, ignore everything around that");
+ Profiler.initFromURLQueryParams(location.search);
+ Profiler.finishStartupProfiling();
- Profiler.pause("This test measures the time between sessionRestoreInit and sessionRestored, ignore everything around that");
- Profiler.initFromURLQueryParams(location.search);
- Profiler.finishStartupProfiling();
-
- setTimeout(function () {
// Show result on screen. Nice but not really necessary.
document.getElementById("sessionRestoreInit-to-sessionRestored").textContent = duration + "ms";
// Report data to Talos, if possible
dumpLog("__start_report" +
duration +
"__end_report\n\n");
// Next one is required by the test harness but not used
dumpLog("__startTimestamp" +
Date.now() +
"__endTimestamp\n\n");
+ goQuitApplication();
+ });
- goQuitApplication();
- }, 0);
+ // In case the add-on has broadcasted the message before we were loaded,
+ // request a second broadcast.
+ Services.cpmm.sendAsyncMessage(MSG_REQUEST, {});
});
-
-// In case the add-on has broadcasted the message before we were loaded,
-// request a second broadcast.
-Services.cpmm.sendAsyncMessage(MSG_REQUEST, {});
--- a/testing/talos/talos/test.py
+++ b/testing/talos/talos/test.py
@@ -159,34 +159,34 @@ class sessionrestore(TsBase):
"""
extensions = \
'${talos}/startup_test/sessionrestore/addon/sessionrestore-signed.xpi'
cycles = 10
timeout = 1000000
gecko_profile_startup = True
gecko_profile_entries = 10000000
profile_path = '${talos}/startup_test/sessionrestore/profile'
- url = 'startup_test/sessionrestore/index.html'
shutdown = False
reinstall = ['sessionstore.js', 'sessionCheckpoints.json']
- # Restore the session
+ # Restore the session. We have to provide a URL, otherwise Talos
+ # asks for a manifest URL.
+ url = 'about:home'
preferences = {'browser.startup.page': 3}
unit = 'ms'
@register_test()
class sessionrestore_no_auto_restore(sessionrestore):
"""
A start up test measuring the time it takes to load a sessionstore.js file.
1. Set up Firefox to *not* restore automatically from sessionstore.js file.
2. Launch Firefox.
3. Measure the delta between firstPaint and sessionRestored.
"""
- # Restore about:home
preferences = {'browser.startup.page': 1}
@register_test()
class tpaint(TsBase):
"""
Tests the amount of time it takes the open a new window. This test does
not include startup time. Multiple test windows are opened in succession,