Bug 1261842 - Fix up some private browsing tests to account for initial browsers being remote now. r?jdm draft
authorMike Conley <mconley@mozilla.com>
Thu, 26 May 2016 12:24:05 -0400
changeset 392012 2be7c7e47dbc556c247974e82fc17d44a0bc9b1b
parent 392011 5f1dc2d985a19c01ec9d0fd4e9290ab27453bd1f
child 392013 d12b17a53e8bb2c6664ba1cab79d92b905bbbf6e
push id23919
push usermconley@mozilla.com
push dateFri, 22 Jul 2016 20:54:03 +0000
reviewersjdm
bugs1261842
milestone50.0a1
Bug 1261842 - Fix up some private browsing tests to account for initial browsers being remote now. r?jdm MozReview-Commit-ID: CxhKsIXnPxj
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_noSessionRestoreMenuOption.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_nonbrowser.js
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_noSessionRestoreMenuOption.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_noSessionRestoreMenuOption.js
@@ -1,34 +1,23 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-// This test checks that the Session Restore menu option is not enabled in private mode
-
-function test() {
-  waitForExplicitFinish();
+"use strict";
 
-  function testNoSessionRestoreMenuItem() { 
-    let win = OpenBrowserWindow({private: true});
-    win.addEventListener("load", function onLoad() {
-      win.removeEventListener("load", onLoad, false);
-      ok(true, "The second private window got loaded");
-      let srCommand = win.document.getElementById("Browser:RestoreLastSession");
-      ok(srCommand, "The Session Restore command should exist");
-      is(PrivateBrowsingUtils.isWindowPrivate(win), true,
-         "PrivateBrowsingUtils should report the correct per-window private browsing status");
-      is(srCommand.hasAttribute("disabled"), true,
-         "The Session Restore command should be disabled in private browsing mode");
-      win.close();
-      finish();
-    }, false);
-  }
+/**
+ * Tests that if we open a tab within a private browsing window, and then
+ * close that private browsing window, that subsequent private browsing
+ * windows do not allow the command for restoring the last session.
+ */
+add_task(function* test_no_session_restore_menu_option() {
+  let win = yield BrowserTestUtils.openNewBrowserWindow({ private: true });
+  ok(true, "The first private window got loaded");
+  win.gBrowser.addTab("about:mozilla");
+  yield BrowserTestUtils.closeWindow(win);
 
-  let win = OpenBrowserWindow({private: true});
-  win.addEventListener("load", function onload() {
-    win.removeEventListener("load", onload, false);
-    ok(true, "The first private window got loaded");
-    win.gBrowser.addTab("about:mozilla");
-    win.close();
-    testNoSessionRestoreMenuItem();
-  }, false);
-}
+  win = yield BrowserTestUtils.openNewBrowserWindow({ private: true });
+  let srCommand = win.document.getElementById("Browser:RestoreLastSession");
+  ok(srCommand, "The Session Restore command should exist");
+  is(PrivateBrowsingUtils.isWindowPrivate(win), true,
+     "PrivateBrowsingUtils should report the correct per-window private browsing status");
+  is(srCommand.hasAttribute("disabled"), true,
+     "The Session Restore command should be disabled in private browsing mode");
+
+  yield BrowserTestUtils.closeWindow(win);
+});
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_nonbrowser.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_nonbrowser.js
@@ -1,34 +1,19 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-function test() {
-  waitForExplicitFinish();
-
-  let windowsToClose = [];
-  registerCleanupFunction(function() {
-    windowsToClose.forEach(function(win) {
-      win.close();
-    });
-  });
+"use strict";
 
-  let win = OpenBrowserWindow({private: true});
-  win.addEventListener("load", function onLoad() {
-    win.removeEventListener("load", onLoad, false);
-    let chromeWin = win.open("chrome://browser/content/places/places.xul",
-      "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
-    chromeWin.addEventListener("load", function chromeWinLoad() {
-      chromeWin.removeEventListener("load", chromeWinLoad, false);
-      win.close();
-    }, false);
-    windowsToClose.push(chromeWin);
-  }, false);
+/**
+ * Tests that we fire the last-pb-context-exited observer notification
+ * when the last private browsing window closes, even if a chrome window
+ * was opened from that private browsing window.
+ */
+add_task(function* () {
+  let win = yield BrowserTestUtils.openNewBrowserWindow({private: true});
+  let chromeWin = win.open("chrome://browser/content/places/places.xul", "_blank",
+    "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
+  yield BrowserTestUtils.waitForEvent(chromeWin, "load");
+  let obsPromise = TestUtils.topicObserved("last-pb-context-exited");
+  yield BrowserTestUtils.closeWindow(win);
+  yield obsPromise;
+  Assert.ok(true, "Got the last-pb-context-exited notification");
+  chromeWin.close();
+});
 
-  let observer = function() {
-    is(true, true, "observer fired");
-    Services.obs.removeObserver(observer, "last-pb-context-exited");
-    executeSoon(finish);
-  };
-  Services.obs.addObserver(observer, "last-pb-context-exited", false);
-  windowsToClose.push(win);
-}
\ No newline at end of file