From e3f9f50b1d299a341d3d6007693ef27a9a97a964 Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Fri, 15 Apr 2016 12:33:13 -0400 Subject: [PATCH] Bug 1261152 - Keep the content process alive between tps runs. r=jmaher MozReview-Commit-ID: 77wW1Y9z62B --HG-- extra : rebase_source : d839cb03cba7786edfafcb585ee3fc7ab183485b --- .../talos/talos/tests/tabswitch/bootstrap.js | 26 +++++++++++---- .../content/tabswitch-content-process.js | 32 +++++++++++++++++++ .../talos/tests/tabswitch/content/test.html | 17 +++------- .../talos/talos/tests/tabswitch/tps.manifest | 2 +- 4 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js diff --git a/testing/talos/talos/tests/tabswitch/bootstrap.js b/testing/talos/talos/tests/tabswitch/bootstrap.js index d53eb7234bc9..0a92c59a6642 100644 --- a/testing/talos/talos/tests/tabswitch/bootstrap.js +++ b/testing/talos/talos/tests/tabswitch/bootstrap.js @@ -7,6 +7,7 @@ Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Task.jsm"); Cu.import("resource://gre/modules/Timer.jsm"); +Cu.import("resource://gre/modules/RemotePageManager.jsm"); let aboutNewTabService = Cc["@mozilla.org/browser/aboutnewtab-service;1"] .getService(Ci.nsIAboutNewTabService); @@ -430,7 +431,13 @@ function test(window) { win.gBrowser.removeAllTabsBut(resultsTab); if (pref) Services.prefs.setBoolPref("browser.tabs.warnOnCloseOtherTabs", pref); - Services.obs.notifyObservers(win, 'tabswitch-test-results', JSON.stringify({'times': times, 'urls': testURLs})); + + remotePage.sendAsyncMessage("tabswitch-test-results", { + times, + urls: testURLs, + }); + + win.close(); }); } @@ -476,7 +483,8 @@ function shutdown(aData, aReason) { unloadFromWindow(window); } Services.obs.removeObserver(observer, "tabswitch-urlfile"); - Services.obs.removeObserver(observer, "tabswitch-do-test"); + + remotePage.destroy(); } function handleFile(win, file) { @@ -510,14 +518,14 @@ function handleFile(win, file) { var observer = { observe: function(aSubject, aTopic, aData) { - if (aTopic == "tabswitch-do-test") { - test(aSubject); - } else if (aTopic == "tabswitch-urlfile") { + 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"); @@ -531,5 +539,11 @@ function startup(aData, aReason) { Services.wm.addListener(windowListener); Services.obs.addObserver(observer, "tabswitch-urlfile", false); - Services.obs.addObserver(observer, "tabswitch-do-test", false); + + 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); + }); } diff --git a/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js b/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js new file mode 100644 index 000000000000..030d51a86634 --- /dev/null +++ b/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js @@ -0,0 +1,32 @@ +const {classes: Cc, utils: Cu, interfaces: Ci} = Components; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +const CHROME_URI = "chrome://tabswitch/content/test.html"; + +class TabSwitchAboutModule { + constructor() { + this.QueryInterface = XPCOMUtils.generateQI([Ci.nsIAboutModule]); + } + + newChannel(aURI, aLoadInfo) { + let uri = Services.io.newURI(CHROME_URI, null, null); + 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); +let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); +let UUIDGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator); + +registrar.registerFactory(UUIDGenerator.generateUUID(), "", + "@mozilla.org/network/protocol/about;1?what=tabswitch", + factory); diff --git a/testing/talos/talos/tests/tabswitch/content/test.html b/testing/talos/talos/tests/tabswitch/content/test.html index ac600cbb15da..4c4eff552b2a 100644 --- a/testing/talos/talos/tests/tabswitch/content/test.html +++ b/testing/talos/talos/tests/tabswitch/content/test.html @@ -1,22 +1,13 @@ diff --git a/testing/talos/talos/tests/tabswitch/tps.manifest b/testing/talos/talos/tests/tabswitch/tps.manifest index a41677c7a363..cabe207e5d05 100644 --- a/testing/talos/talos/tests/tabswitch/tps.manifest +++ b/testing/talos/talos/tests/tabswitch/tps.manifest @@ -1 +1 @@ -% chrome://tabswitch/content/test.html#auto +% about:tabswitch#auto