Bug 1134518 - Add test to ensure we don't lose shistory entries when switching a browser's remoteness r=Mossop
authorTim Taubert <ttaubert@mozilla.com>
Thu, 23 Apr 2015 15:42:55 +0200
changeset 241131 11c4c1801cbeba671a92e20022dcc2c4122ae360
parent 240938 780cf81ab0d3ed3c6833912471c8aeb198a6e099
child 241132 4d9970eb3c804a9261070d0ee0d6008946fb2166
push id59036
push usercbook@mozilla.com
push dateMon, 27 Apr 2015 10:37:48 +0000
treeherdermozilla-inbound@ad388474898c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1134518
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1134518 - Add test to ensure we don't lose shistory entries when switching a browser's remoteness r=Mossop
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_switch_remoteness.js
testing/mochitest/BrowserTestUtils/ContentTask.jsm
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -92,16 +92,18 @@ skip-if = buildapp == 'mulet'
 [browser_restore_redirect.js]
 [browser_scrollPositions.js]
 [browser_sessionHistory.js]
 # Disabled because of bug 1077581
 skip-if = e10s
 [browser_sessionStorage.js]
 [browser_swapDocShells.js]
 skip-if = e10s # See bug 918634
+[browser_switch_remoteness.js]
+run-if = e10s
 [browser_telemetry.js]
 [browser_upgrade_backup.js]
 [browser_windowRestore_perwindowpb.js]
 [browser_248970_b_perwindowpb.js]
 # Disabled because of leaks.
 # Re-enabling and rewriting this test is tracked in bug 936919.
 skip-if = true
 [browser_339445.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_switch_remoteness.js
@@ -0,0 +1,47 @@
+"use strict";
+
+const URL = "http://example.com/browser_switch_remoteness_";
+
+function countHistoryEntries(browser) {
+  return ContentTask.spawn(browser, null, function* () {
+    let Ci = Components.interfaces;
+    let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation);
+    let history = webNavigation.sessionHistory.QueryInterface(Ci.nsISHistoryInternal);
+    return history && history.count;
+  });
+}
+
+add_task(function* () {
+  // Add a new tab.
+  let tab = gBrowser.addTab("about:blank");
+  let browser = tab.linkedBrowser;
+  yield promiseBrowserLoaded(browser);
+  ok(browser.isRemoteBrowser, "browser is remote");
+
+  // Get the maximum number of preceding entries to save.
+  const MAX_BACK = Services.prefs.getIntPref("browser.sessionstore.max_serialize_back");
+  ok(MAX_BACK > -1, "check that the default has a value that caps data");
+
+  // Load more pages than we would save to disk on a clean shutdown.
+  for (let i = 0; i < MAX_BACK + 2; i++) {
+    browser.loadURI(URL + i);
+    yield promiseBrowserLoaded(browser);
+    ok(browser.isRemoteBrowser, "browser is still remote");
+  }
+
+  // Check we have the right number of shistory entries.
+  let count = yield countHistoryEntries(browser);
+  is(count, MAX_BACK + 2, "correct number of shistory entries");
+
+  // Load a non-remote page.
+  browser.loadURI("about:robots");
+  yield promiseTabRestored(tab);
+  ok(!browser.isRemoteBrowser, "browser is not remote anymore");
+
+  // Check that we didn't lose any shistory entries.
+  count = yield countHistoryEntries(browser);
+  is(count, MAX_BACK + 3, "correct number of shistory entries");
+
+  // Cleanup.
+  gBrowser.removeTab(tab);
+});
--- a/testing/mochitest/BrowserTestUtils/ContentTask.jsm
+++ b/testing/mochitest/BrowserTestUtils/ContentTask.jsm
@@ -8,20 +8,17 @@
 
 this.EXPORTED_SYMBOLS = [
   "ContentTask"
 ];
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 Cu.import("resource://gre/modules/Promise.jsm");
 
-/**
- * Set of browsers which have loaded the content-task frame script.
- */
-let gScriptLoadedSet = new WeakSet();
+const FRAME_SCRIPT = "chrome://mochikit/content/tests/BrowserTestUtils/content-task.js";
 
 /**
  * Mapping from message id to associated promise.
  */
 let gPromises = new Map();
 
 /**
  * Incrementing integer to generate unique message id.
@@ -45,22 +42,22 @@ this.ContentTask = {
    *          sent to the remote browser.
    * @return A promise object where you can register completion callbacks to be
    *         called when the task terminates.
    * @resolves With the final returned value of the task if it executes
    *           successfully.
    * @rejects An error message if execution fails.
    */
   spawn: function ContentTask_spawn(browser, arg, task) {
-    if(!gScriptLoadedSet.has(browser.permanentKey)) {
-      let mm = browser.messageManager;
-      mm.loadFrameScript(
-        "chrome://mochikit/content/tests/BrowserTestUtils/content-task.js", true);
+    let mm = browser.ownerDocument.defaultView.messageManager;
+    let scripts = mm.getDelayedFrameScripts();
 
-      gScriptLoadedSet.add(browser.permanentKey);
+    // Load the frame script if needed.
+    if (!scripts.find(script => script[0] == FRAME_SCRIPT)) {
+      mm.loadFrameScript(FRAME_SCRIPT, true);
     }
 
     let deferred = {};
     deferred.promise = new Promise((resolve, reject) => {
       deferred.resolve = resolve;
       deferred.reject = reject;
     });