Bug 1301160 - Part 4 - Test that the parent tab ID is properly restored when reopening a recently closed tab. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 07 Jan 2017 22:26:46 +0100
changeset 460766 221e44a38a3b384efcce3d0e6249642033fdf6a7
parent 460765 3a5dffafac5826467c8995cd7239c241b299b842
child 542132 3b885df29dc3bb66f65455358cc72aeb1fb3a472
push id41481
push usermozilla@buttercookie.de
push dateFri, 13 Jan 2017 19:07:33 +0000
reviewerssebastian
bugs1301160
milestone53.0a1
Bug 1301160 - Part 4 - Test that the parent tab ID is properly restored when reopening a recently closed tab. r?sebastian MozReview-Commit-ID: 6X4KYhJxagj
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_session_parentid.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -36,14 +36,15 @@ skip-if = debug
 [test_offline_page.html]
 skip-if = true # Bug 1241478
 [test_reader_view.html]
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
 [test_select_disabled.html]
 [test_selectoraddtab.html]
 [test_session_form_data.html]
+[test_session_parentid.html]
 [test_session_scroll_position.html]
 [test_session_zombification.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_parentid.html
@@ -0,0 +1,126 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1301160
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1044556</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.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">
+
+  /** Test for Bug 1301160 **/
+
+  "use strict";
+
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+  Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/Messaging.jsm");
+  Cu.import("resource://gre/modules/Task.jsm");
+
+  // The chrome window and related services
+  let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let BrowserApp = chromeWin.BrowserApp;
+  let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
+
+  // Track the tabs where the tests are happening
+  let tabParent;
+  let tabChild1;
+  let tabChild2;
+
+  function cleanupTabs() {
+    if (tabParent) {
+      BrowserApp.closeTab(tabParent);
+      tabParent = null;
+    }
+
+    if (tabChild1) {
+      BrowserApp.closeTab(tabChild1);
+      tabChild1 = null;
+    }
+
+    if (tabChild2) {
+      BrowserApp.closeTab(tabChild2);
+      tabChild2 = null;
+    }
+  }
+
+  const url = "data:text/html;charset=utf-8,It%20was%20a%20dark%20and%20stormy%20night.";
+
+  add_task(function* test_sessionStoreParentId() {
+    SimpleTest.registerCleanupFunction(function() {
+      cleanupTabs();
+    });
+
+    // First, check that passing a parent tab ID works as expected
+    tabParent = BrowserApp.addTab(url , { selected: true });
+    yield promiseBrowserEvent(tabParent.browser, "DOMContentLoaded");
+
+    // Open tabs without passing a parent tab ID
+    tabChild1 = BrowserApp.addTab(url , { selected: false });
+    tabChild2 = BrowserApp.addTab(url , { selected: true });
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabChild2, "2nd child tab is selected");
+
+    // After closing that tab, its neighbour should be selected
+    BrowserApp.closeTab(tabChild2);
+    tabChild2 = null;
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabChild1, "1st child tab is selected");
+
+    // Add a new tab and pass a parent tab ID this time
+    tabChild2 = BrowserApp.addTab(url , { selected: true, parentId: tabParent.id });
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabChild2, "2nd child tab is selected");
+
+    // After closing that tab, its parent should be selected
+    BrowserApp.closeTab(tabChild2);
+    tabChild2 = null;
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabParent, "parent tab is selected");
+
+    // Reset selection and switch to the other child tab
+    BrowserApp.selectTab(tabChild1);
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabChild1, "1st child tab is selected");
+
+    // Now check that this works even if the child tab is closed and subsequently restored
+    tabChild2 = BrowserApp.addTab(url , { selected: false, parentId: tabParent.id });
+    yield promiseTabEvent(tabChild2.browser, "SSTabDataUpdated");
+    BrowserApp.closeTab(tabChild2);
+    yield promiseTabEvent(tabChild2.browser, "SSTabCloseProcessed");
+
+    // Restore the tab
+    let closedTabData = ss.getClosedTabs(chromeWin)[0];
+    let browser = ss.undoCloseTab(chromeWin, closedTabData);
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    tabChild2 = BrowserApp.getTabForBrowser(browser);
+    is(BrowserApp.selectedTab, tabChild2, "restored 2nd child tab is selected");
+
+    // After closing that tab, its parent should be selected
+    BrowserApp.closeTab(tabChild2);
+    tabChild2 = null;
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabParent, "parent tab is selected after restoring");
+
+    cleanupTabs();
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1301160">Mozilla Bug 1301160</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>