Bug 1209689 - Regression test. r=Mossop draft
authorMike Conley <mconley@mozilla.com>
Wed, 28 Oct 2015 15:25:04 -0400
changeset 307992 c346cf82216cab0c5b33ac0a3928ff2ffe8ada7e
parent 307991 1897c0dd3e4f32a919b722d577bac86fd57a5752
child 307993 a1c4b1c3bfac6ccfa1d1c44a30b4ace26b845841
push id7421
push usermconley@mozilla.com
push dateWed, 11 Nov 2015 04:06:00 +0000
reviewersMossop
bugs1209689
milestone45.0a1
Bug 1209689 - Regression test. r=Mossop
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_unrestored_crashedTabs.js
browser/components/sessionstore/test/head.js
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -73,16 +73,18 @@ run-if = e10s
 [browser_attributes.js]
 [browser_backup_recovery.js]
 [browser_broadcast.js]
 [browser_capabilities.js]
 [browser_cleaner.js]
 [browser_cookies.js]
 [browser_crashedTabs.js]
 skip-if = !e10s || !crashreporter
+[browser_unrestored_crashedTabs.js]
+skip-if = !e10s || !crashreporter
 [browser_dying_cache.js]
 [browser_dynamic_frames.js]
 [browser_form_restore_events.js]
 [browser_formdata.js]
 skip-if = buildapp == 'mulet'
 [browser_formdata_cc.js]
 [browser_formdata_format.js]
 [browser_formdata_xpath.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_unrestored_crashedTabs.js
@@ -0,0 +1,73 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests that if we have tabs that are still in the "click to
+ * restore" state, that if their browsers crash, that we don't
+ * show the crashed state for those tabs (since selecting them
+ * should restore them anyway).
+ */
+
+const PREF = "browser.sessionstore.restore_on_demand";
+const PAGE = "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";
+
+add_task(function* test() {
+  yield promiseSetPrefEnv({
+    set: [
+      [PREF, true],
+    ],
+  })
+
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: PAGE,
+  }, function*(browser) {
+    yield TabStateFlusher.flush(browser);
+
+    // We'll create a second "pending" tab. This is the one we'll
+    // ensure doesn't go to about:tabcrashed. We start it non-remote
+    // since this is how SessionStore creates all browsers before
+    // they are restored.
+    let unrestoredTab = gBrowser.addTab("about:blank", {
+      skipAnimation: true,
+      forceNotRemote: true,
+    });
+
+    let state = {
+      entries: [{url: PAGE}],
+    };
+
+    ss.setTabState(unrestoredTab, JSON.stringify(state));
+
+    ok(!unrestoredTab.hasAttribute("crashed"), "tab is not crashed");
+    ok(unrestoredTab.hasAttribute("pending"), "tab is pending");
+
+    // Now crash the selected browser.
+    yield BrowserTestUtils.crashBrowser(browser);
+
+    ok(!unrestoredTab.hasAttribute("crashed"), "tab is still not crashed");
+    ok(unrestoredTab.hasAttribute("pending"), "tab is still pending");
+
+    // Selecting the tab should now restore it.
+    gBrowser.selectedTab = unrestoredTab;
+    yield promiseTabRestored(unrestoredTab);
+
+    ok(!unrestoredTab.hasAttribute("crashed"), "tab is still not crashed");
+    ok(!unrestoredTab.hasAttribute("pending"), "tab is no longer pending");
+
+    // The original tab should still be crashed
+    let originalTab = gBrowser.getTabForBrowser(browser);
+    ok(originalTab.hasAttribute("crashed"), "original tab is crashed");
+    ok(!originalTab.isRemoteBrowser, "Should not be remote");
+
+    // We'd better be able to restore it still.
+    gBrowser.selectedTab = originalTab;
+    SessionStore.reviveCrashedTab(originalTab);
+    yield promiseTabRestored(originalTab);
+
+    // Clean up.
+    yield BrowserTestUtils.removeTab(unrestoredTab);
+  });
+});
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -562,8 +562,14 @@ function modifySessionStorage(browser, d
       }, true);
 
       for (let key of keys) {
         frame.sessionStorage[key] = data[key];
       }
     });
   });
 }
+
+function promiseSetPrefEnv(inPrefs) {
+  return new Promise((resolve) => {
+    SpecialPowers.pushPrefEnv(inPrefs, resolve);
+  });
+}