Bug 1313571 - Fix Intermittent browser/components/sessionstore/test/browser_undoCloseById.js, r?mikedeboer draft
authorBob Silverberg <bsilverberg@mozilla.com>
Fri, 28 Oct 2016 08:15:11 -0400
changeset 430967 3e0f7d04ea3e486cfd691037dcbd0d43b37da405
parent 430966 75ed5d87d53e4e851d08c59000937d5eeef85f99
child 535317 4442f4070bb79765e8374b7f02de4547103e7f5c
push id33951
push userbmo:bob.silverberg@gmail.com
push dateFri, 28 Oct 2016 12:16:35 +0000
reviewersmikedeboer
bugs1313571
milestone52.0a1
Bug 1313571 - Fix Intermittent browser/components/sessionstore/test/browser_undoCloseById.js, r?mikedeboer MozReview-Commit-ID: CHW1vqPN63f
browser/components/sessionstore/test/browser_undoCloseById.js
--- a/browser/components/sessionstore/test/browser_undoCloseById.js
+++ b/browser/components/sessionstore/test/browser_undoCloseById.js
@@ -13,20 +13,23 @@ function openAndCloseTab(window, url) {
   yield promiseRemoveTab(tab);
 }
 
 function* openWindow(url) {
   let win = yield promiseNewWindowLoaded();
   let flags = Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY;
   win.gBrowser.selectedBrowser.loadURIWithFlags(url, flags);
   yield promiseBrowserLoaded(win.gBrowser.selectedBrowser, true, url);
-  // Wait 20 ms because if we close this window immediately it sometimes
-  // is not recorded by SessionStorage.
+  return win;
+}
+
+function closeWindow(win) {
+  yield BrowserTestUtils.closeWindow(win);
+  // Wait 20 ms to allow SessionStorage a chance to register the closed window.
   yield new Promise(resolve => setTimeout(resolve, 20));
-  return win;
 }
 
 add_task(function* test_undoCloseById() {
   // Clear the lists of closed windows and tabs.
   forgetClosedWindows();
   while (SessionStore.getClosedTabCount(window)) {
     SessionStore.forgetClosedTab(window, 0);
   }
@@ -38,17 +41,17 @@ add_task(function* test_undoCloseById() 
   yield openAndCloseTab(win, "about:mozilla");
   is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab");
 
   // Record the first closedId created.
   let initialClosedId = SessionStore.getClosedTabData(win, false)[0].closedId;
 
   // Open and close another window.
   let win2 = yield openWindow("about:mozilla");
-  yield BrowserTestUtils.closeWindow(win2);  // closedId == initialClosedId + 1
+  yield closeWindow(win2);  // closedId == initialClosedId + 1
   is(SessionStore.lastClosedObjectType, "window", "The last closed object is a window");
 
   // Open and close another tab in the first window.
   yield openAndCloseTab(win, "about:robots");  // closedId == initialClosedId + 2
   is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab");
 
   // Undo closing the second tab.
   let tab = SessionStore.undoCloseById(initialClosedId + 2);
@@ -71,45 +74,45 @@ add_task(function* test_undoCloseById() 
   is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab");
   yield promiseRemoveTab(tab2); // closedId == initialClosedId + 4
   is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab");
 
   // Open another new window.
   let win3 = yield openWindow("about:mozilla");
 
   // Close both windows.
-  yield BrowserTestUtils.closeWindow(win); // closedId == initialClosedId + 5
+  yield closeWindow(win); // closedId == initialClosedId + 5
   is(SessionStore.lastClosedObjectType, "window", "The last closed object is a window");
-  yield BrowserTestUtils.closeWindow(win3); // closedId == initialClosedId + 6
+  yield closeWindow(win3); // closedId == initialClosedId + 6
   is(SessionStore.lastClosedObjectType, "window", "The last closed object is a window");
 
   // Undo closing the second window.
   win = SessionStore.undoCloseById(initialClosedId + 6);
   yield BrowserTestUtils.waitForEvent(win, "load");
 
   // Make sure we wait until this window is restored.
   yield BrowserTestUtils.waitForEvent(win.gBrowser.tabContainer,
                                       "SSTabRestored");
 
   is(win.gBrowser.selectedBrowser.currentURI.spec, "about:mozilla", "The expected window was re-opened");
 
   let notWin = SessionStore.undoCloseById(initialClosedId + 6);
   is(notWin, undefined, "Re-opened window cannot be unClosed again by closedId");
 
   // Close the window again.
-  yield BrowserTestUtils.closeWindow(win);
+  yield closeWindow(win);
   is(SessionStore.lastClosedObjectType, "window", "The last closed object is a window");
 
   // Undo closing the first window.
   win = SessionStore.undoCloseById(initialClosedId + 5);
 
   yield BrowserTestUtils.waitForEvent(win, "load");
 
   // Make sure we wait until this window is restored.
   yield BrowserTestUtils.waitForEvent(win.gBrowser.tabContainer,
                                       "SSTabRestored");
 
   is(win.gBrowser.selectedBrowser.currentURI.spec, "about:robots", "The expected window was re-opened");
 
   // Close the window again.
-  yield BrowserTestUtils.closeWindow(win);
+  yield closeWindow(win);
   is(SessionStore.lastClosedObjectType, "window", "The last closed object is a window");
 });