Bug 1267720 - Add a test that ensures that proper chromeFlags and nsILoadContext properties are set for private windows. r?ehsan draft
authorMike Conley <mconley@mozilla.com>
Mon, 02 May 2016 13:59:25 -0400
changeset 370965 aedb2c13c1542e5cc52e5a623cf875e02ad31d37
parent 370964 f675f7abef22d6dc125bab6bec54189916f0ac20
child 370966 c4cc41f5a12c121710f88f7f82f77aee6274bef8
push id19190
push usermconley@mozilla.com
push dateWed, 25 May 2016 17:23:31 +0000
reviewersehsan
bugs1267720
milestone49.0a1
Bug 1267720 - Add a test that ensures that proper chromeFlags and nsILoadContext properties are set for private windows. r?ehsan MozReview-Commit-ID: Hvzfk6yDEXk
browser/components/privatebrowsing/test/browser/browser.ini
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_context_and_chromeFlags.js
--- a/browser/components/privatebrowsing/test/browser/browser.ini
+++ b/browser/components/privatebrowsing/test/browser/browser.ini
@@ -18,16 +18,17 @@ support-files =
 [browser_privatebrowsing_DownloadLastDirWithCPS.js]
 [browser_privatebrowsing_about.js]
 tags = trackingprotection
 [browser_privatebrowsing_aboutHomeButtonAfterWindowClose.js]
 [browser_privatebrowsing_aboutSessionRestore.js]
 [browser_privatebrowsing_cache.js]
 [browser_privatebrowsing_certexceptionsui.js]
 [browser_privatebrowsing_concurrent.js]
+[browser_privatebrowsing_context_and_chromeFlags.js]
 [browser_privatebrowsing_crh.js]
 [browser_privatebrowsing_downloadLastDir.js]
 [browser_privatebrowsing_downloadLastDir_c.js]
 [browser_privatebrowsing_downloadLastDir_toggle.js]
 [browser_privatebrowsing_geoprompt.js]
 [browser_privatebrowsing_lastpbcontextexited.js]
 [browser_privatebrowsing_localStorage.js]
 [browser_privatebrowsing_localStorage_before_after.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_context_and_chromeFlags.js
@@ -0,0 +1,57 @@
+"use strict";
+
+/**
+ * Given some window in the parent process, ensure that
+ * the nsIXULWindow has the CHROME_PRIVATE_WINDOW chromeFlag,
+ * and that the usePrivateBrowsing property is set to true on
+ * both the window's nsILoadContext, as well as on the initial
+ * browser's content docShell nsILoadContext.
+ *
+ * @param win (nsIDOMWindow)
+ *        An nsIDOMWindow in the parent process.
+ * @return Promise
+ */
+function assertWindowIsPrivate(win) {
+  let winDocShell = win.QueryInterface(Ci.nsIInterfaceRequestor)
+                       .getInterface(Ci.nsIDocShell);
+  let chromeFlags = winDocShell.QueryInterface(Ci.nsIDocShellTreeItem)
+                               .treeOwner
+                               .QueryInterface(Ci.nsIInterfaceRequestor)
+                               .getInterface(Ci.nsIXULWindow)
+                               .chromeFlags;
+  Assert.ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
+            "Should have the private window chrome flag");
+
+  let loadContext = winDocShell.QueryInterface(Ci.nsILoadContext);
+  Assert.ok(loadContext.usePrivateBrowsing,
+            "The parent window should be using private browsing");
+
+  return ContentTask.spawn(win.gBrowser.selectedBrowser, null, function*() {
+    let loadContext = docShell.QueryInterface(Ci.nsILoadContext);
+    Assert.ok(loadContext.usePrivateBrowsing,
+              "Content docShell should be using private browsing");
+  });
+}
+
+/**
+ * Tests that chromeFlags bits and the nsILoadContext.usePrivateBrowsing
+ * attribute are properly set when opening a new private browsing
+ * window.
+ */
+add_task(function* test_context_and_chromeFlags() {
+  let win = yield BrowserTestUtils.openNewBrowserWindow({ private: true });
+  yield assertWindowIsPrivate(win);
+
+  let browser = win.gBrowser.selectedBrowser;
+
+  let newWinPromise = BrowserTestUtils.waitForNewWindow();
+  yield ContentTask.spawn(browser, null, function*() {
+    content.open("http://example.com", "_blank", "width=100,height=100");
+  });
+
+  let win2 = yield newWinPromise;
+  yield assertWindowIsPrivate(win2);
+
+  yield BrowserTestUtils.closeWindow(win2);
+  yield BrowserTestUtils.closeWindow(win);
+});