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
authorMike de Boer <mdeboer@mozilla.com>
Wed, 11 Apr 2018 12:06:16 +0200
changeset 468000 74478b16e546d7c5c9c77552efb5f16a49811502
parent 467999 dec31c64321f13507d858038ccd3986b89f5c43e
child 468001 04c3950aaad9164a74d514d3292c45ac235a7e91
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1034036
milestone61.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 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: 6z1zHUKDf9
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
@@ -266,8 +266,9 @@ skip-if = debug
 [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_1446343-windowsize.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,77 @@
+"use strict";
+
+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() {
+  let windows = [];
+  let count = 0;
+  for (let url of gTestURLsMap.keys()) {
+    let window = !count ? PRIMARY_WINDOW : await BrowserTestUtils.openNewBrowserWindow();
+    let browserLoaded = BrowserTestUtils.browserLoaded(window.gBrowser.selectedBrowser);
+    await BrowserTestUtils.loadURI(window.gBrowser.selectedBrowser, url);
+    await browserLoaded;
+    // 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) {
+      let activated = BrowserTestUtils.waitForEvent(windows[count - 1], "activate");
+      window.minimize();
+      await activated;
+    }
+    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();
+});