Bug 1499874 - Part 1: Test that restoring a tab removes it from the session store. r=esawin
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 23 Dec 2018 21:42:30 +0100
changeset 509924 75e5aa1db2e189dcc93b0d9bd1d8e65f982d1953
parent 509923 89b21137ed17c6be7bef322354ecfed8631390de
child 509925 1b2727505f8719b19133cef094dc2526cbd1ca81
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1499874
milestone66.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 1499874 - Part 1: Test that restoring a tab removes it from the session store. r=esawin Differential Revision: https://phabricator.services.mozilla.com/D15329
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_session_undo_close_tab.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -45,14 +45,15 @@ skip-if = true # Bug 1241478
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
 [test_select_disabled.html]
 [test_selectoraddtab.html]
 [test_session_clear_history.html]
 [test_session_form_data.html]
 [test_session_parentid.html]
 [test_session_scroll_position.html]
+[test_session_undo_close_tab.html]
 [test_session_zombification.html]
 [test_settings_fontinflation.html]
 [test_shared_preferences.html]
 [test_simple_discovery.html]
 [test_video_discovery.html]
 [test_web_channel.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_session_undo_close_tab.html
@@ -0,0 +1,122 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1499874
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test mobile session store undo close tab functionality</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/AddTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript">
+
+  /** Tests for Bug 1499874 **/
+
+  "use strict";
+
+  ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+  ChromeUtils.import("resource://gre/modules/Services.jsm");
+  ChromeUtils.import("resource://gre/modules/Messaging.jsm");
+
+  const PREFS_MAX_TABS_UNDO = "browser.sessionstore.max_tabs_undo";
+
+  // The chrome window and friends.
+  const chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  const BrowserApp = chromeWin.BrowserApp;
+
+  const URL = "data:text/html;charset=utf-8,It%20was%20a%20dark%20and%20stormy%20night.";
+  const TAB_COUNT = 4;
+
+  // Track the tabs where the tests are happening.
+  let tabs = [];
+
+  function cleanupTabs() {
+    tabs.forEach(tab => BrowserApp.closeTab(tab));
+    tabs = [];
+  }
+
+  SimpleTest.registerCleanupFunction(function() {
+    cleanupTabs();
+  });
+
+  let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
+
+  add_task(async function test_removeClosedTabWhenUndoCloseTab() {
+    // Clear closed tabs that might be present from previous tests.
+    Services.prefs.setIntPref(PREFS_MAX_TABS_UNDO, 0);
+    Services.prefs.clearUserPref(PREFS_MAX_TABS_UNDO);
+    let state = ss.getClosedTabs(chromeWin);
+    is(state.length, 0, "no closed tabs at the start");
+
+    // Open a few tabs.
+    const tabEvents = [];
+    for (let i = 0; i < TAB_COUNT; i++) {
+      const tab = BrowserApp.addTab(URL);
+      tabEvents.push(promiseBrowserEvent(tab.browser, "DOMContentLoaded"));
+      tabs.push(tab);
+    }
+    await Promise.all(tabEvents);
+
+    // Close them all again.
+    for (const tab of tabs) {
+      const tabClosed = promiseTabEvent(tab.browser, "SSTabCloseProcessed");
+      BrowserApp.closeTab(tab);
+      await tabClosed;
+    }
+    tabs = [];
+
+    state = ss.getClosedTabs(chromeWin);
+    is(state.length, TAB_COUNT, "expected count of closed tabs in the session store");
+
+    // Without a tab ID in the closed tab data, the session store shouldn't be
+    // able to delete the tab from its collection of closed tabs.
+    const tabDataNoTabId = {...state[0]};
+    delete tabDataNoTabId.tabId;
+    let restoredTab =
+      BrowserApp.getTabForBrowser(ss.undoCloseTab(chromeWin, tabDataNoTabId));
+    tabs.push(restoredTab);
+    await promiseBrowserEvent(restoredTab.browser, "DOMContentLoaded");
+    state = ss.getClosedTabs(chromeWin);
+    is(state.length, TAB_COUNT, "expected count of closed tabs in the session store");
+
+    // Now restore each tab in turn and check that it gets removed from the
+    // session store's closed tab collection.
+    for (let closedTab of state) {
+      // Mimic a little more closely what happens when closing a tab from the
+      // home panels, where the tab data argument for undoCloseTab has been de-
+      // serialised and therefore checking tab data objects for (reference)
+      // equality isn't sufficient to determine which closed tab needs to be
+      // removed from the session store.
+      closedTab = {...closedTab};
+
+      const id = closedTab.tabId;
+      let closedTabs = ss.getClosedTabs(chromeWin);
+      ok(closedTabs.find(tab => tab.tabId == id), "closed tabs collection contains tab");
+
+      restoredTab = BrowserApp.getTabForBrowser(ss.undoCloseTab(chromeWin, closedTab));
+      tabs.push(restoredTab);
+      await promiseBrowserEvent(restoredTab.browser, "DOMContentLoaded");
+      closedTabs = ss.getClosedTabs(chromeWin);
+      todo(!closedTabs.find(tab => tab.tabId == id), "closed tabs collection no longer contains tab");
+    }
+    state = ss.getClosedTabs(chromeWin);
+    todo_is(state.length, 0, "no more closed tabs should be left");
+
+    cleanupTabs();
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1499874">Mozilla Bug 1499874</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>