Bug 1034036 - Part 7: Test that we stored window z-indices correctly and in order of creation. Ensure that we restore windows in reverse z-index order. r?dao draft
authorMike de Boer <mdeboer@mozilla.com>
Fri, 02 Mar 2018 14:06:19 +0100
changeset 762480 c263d4a086f25375ed4a55fa0cac133a70229362
parent 762479 bfe2aa1efd1dafd4e76a1607fb7deae610ec35fe
push id101173
push usermdeboer@mozilla.com
push dateFri, 02 Mar 2018 13:07:51 +0000
reviewersdao
bugs1034036
milestone60.0a1
Bug 1034036 - Part 7: Test that we stored window z-indices correctly and in order of creation. Ensure that we restore windows in reverse z-index order. r?dao MozReview-Commit-ID: Lq54EbYzdQO
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_restore_reversed_z_order.js
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -264,9 +264,9 @@ skip-if = debug
 [browser_duplicate_history.js]
 [browser_tabicon_after_bg_tab_crash.js]
 skip-if = !crashreporter || !e10s # Tabs can't crash without e10s
 
 [browser_cookies.js]
 [browser_cookies_legacy.js]
 [browser_cookies_privacy.js]
 [browser_speculative_connect.js]
-
+[browser_restore_reversed_z_order.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_restore_reversed_z_order.js
@@ -0,0 +1,82 @@
+"use strict";
+
+ChromeUtils.import("resource:///modules/BrowserWindowTracker.jsm");
+
+const PRIMARY_WINDOW = window;
+
+let gTestURLsMap = new Map([
+  ["about:about", null],
+  ["about:license", null],
+  ["about:robots", null],
+  ["about:mozilla", null]
+]);
+let gBrowserState;
+
+add_task(async function setup() {
+  // Make sure that we start with only primary window.
+  await promiseAllButPrimaryWindowClosed();
+
+  let windows = [];
+  let count = 0;
+  for (let url of gTestURLsMap.keys()) {
+    let window = !count ? PRIMARY_WINDOW : await BrowserTestUtils.openNewBrowserWindow();
+    let promise = BrowserTestUtils.browserLoaded(window.gBrowser.selectedBrowser);
+    await BrowserTestUtils.loadURI(window.gBrowser.selectedBrowser, url);
+    await promise;
+    // Capture the title.
+    gTestURLsMap.set(url, window.gBrowser.selectedTab.label);
+    // Minimize the before-last window, to have a different window feature added
+    // to the test.
+    if (count == gTestURLsMap.size - 1) {
+      promise = BrowserTestUtils.waitForEvent(windows[count - 1], "activate");
+      window.minimize();
+      await promise;
+    }
+    windows.push(window);
+    ++count;
+  }
+
+  // Wait until we get the lastest history from all windows.
+  await Promise.all(windows.map(window => TabStateFlusher.flushWindow(window)));
+
+  gBrowserState = ss.getBrowserState();
+
+  await promiseAllButPrimaryWindowClosed();
+});
+
+add_task(async function test_z_indices_are_saved_correctly() {
+  let state = JSON.parse(gBrowserState);
+  Assert.equal(state.windows.length, gTestURLsMap.size, "Correct number of windows saved");
+
+  // Check if we saved state in correct order of creation.
+  let idx = 0;
+  for (let url of gTestURLsMap.keys()) {
+    Assert.equal(state.windows[idx].tabs[0].entries[0].url, url,
+      `Window #${idx} is stored in correct creation order`);
+    ++idx;
+  }
+
+  // Check if we saved a valid zIndex (no null, no undefined or no 0).
+  for (let window of state.windows) {
+    Assert.ok(window.zIndex, "A valid zIndex is stored");
+  }
+
+  Assert.equal(state.windows[0].zIndex, 3, "Window #1 should have the correct z-index");
+  Assert.equal(state.windows[1].zIndex, 2, "Window #2 should have correct z-index");
+  Assert.equal(state.windows[2].zIndex, 1, "Window #3 should be the topmost window");
+  Assert.equal(state.windows[3].zIndex, 4, "Minimized window should be the last window to restore");
+});
+
+add_task(async function test_windows_are_restored_in_reversed_z_order() {
+  await promiseBrowserState(gBrowserState);
+
+  let indexedTabLabels = [...gTestURLsMap.values()];
+  let tabsRestoredLabels = [...BrowserWindowTracker.orderedWindows].map(window => window.gBrowser.selectedTab.label);
+
+  Assert.equal(tabsRestoredLabels[0], indexedTabLabels[2], "First restored tab should be last used tab");
+  Assert.equal(tabsRestoredLabels[1], indexedTabLabels[1], "Second restored tab is correct");
+  Assert.equal(tabsRestoredLabels[2], indexedTabLabels[0], "Third restored tab is correct");
+  Assert.equal(tabsRestoredLabels[3], indexedTabLabels[3], "Last restored tab should be a minimized window");
+
+  await promiseAllButPrimaryWindowClosed();
+});