Bug 1277344 - Opened a new private window, to remove setting docshell to private. r=ehsan
authorJames Andreou <jandreou@mozilla.com>
Tue, 07 Jun 2016 18:56:07 -0700
changeset 301003 d617b44be9a9b7adf4f3621f1168a52312db7e62
parent 301002 66f36dfa22da54abbd176f8fa164c6e7d538a4c7
child 301004 b92ba4dc0af5dcaa1732aa036e1ea75d8ec19717
push id19599
push usercbook@mozilla.com
push dateWed, 08 Jun 2016 10:16:21 +0000
treeherderfx-team@81f4cc3f6f4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1277344
milestone50.0a1
Bug 1277344 - Opened a new private window, to remove setting docshell to private. r=ehsan MozReview-Commit-ID: 9hFEKV3Wq2J
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js
@@ -9,37 +9,29 @@
 // Step 1: create new tab, load a page that sets test=value in non-private storage
 // Step 2: create a new tab, load a page that sets test2=value2 in private storage
 // Step 3: load a page in the tab from step 1 that checks the value of test2 is value2 and the total count in non-private storage is 1
 // Step 4: load a page in the tab from step 2 that checks the value of test is value and the total count in private storage is 1
 
 add_task(function test() {
   let prefix = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html';
 
-  function setUsePrivateBrowsing(browser, val) {
-    return ContentTask.spawn(browser, val, function* (val) {
-      docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = val;
-    });
-  };
-
   function getElts(browser) {
     return browser.contentTitle.split('|');
   };
 
   // Step 1
-  gBrowser.selectedTab = gBrowser.addTab(prefix + '?action=set&name=test&value=value&initial=true');
   let non_private_browser = gBrowser.selectedBrowser;
+  non_private_browser.loadURI(prefix + '?action=set&name=test&value=value&initial=true');
   yield BrowserTestUtils.browserLoaded(non_private_browser);
 
 
   // Step 2
-  gBrowser.selectedTab = gBrowser.addTab();
-  let private_browser = gBrowser.selectedBrowser;
-  yield BrowserTestUtils.browserLoaded(private_browser);
-  yield setUsePrivateBrowsing(private_browser, true);
+  let private_window = yield BrowserTestUtils.openNewBrowserWindow({ private : true });
+  let private_browser = private_window.getBrowser().selectedBrowser;
   private_browser.loadURI(prefix + '?action=set&name=test2&value=value2');
   yield BrowserTestUtils.browserLoaded(private_browser);
 
 
   // Step 3
   non_private_browser.loadURI(prefix + '?action=get&name=test2');
   yield BrowserTestUtils.browserLoaded(non_private_browser);
   let elts = yield getElts(non_private_browser);
@@ -50,35 +42,41 @@ add_task(function test() {
   // Step 4
   private_browser.loadURI(prefix + '?action=get&name=test');
   yield BrowserTestUtils.browserLoaded(private_browser);
   elts = yield getElts(private_browser);
   isnot(elts[0], 'value', "private window shouldn't see public storage");
   is(elts[1], '1', "private window should only see private items");
 
 
-  // Make the private tab public again, which should clear the
+  // Reopen the private window again, without privateBrowsing, which should clear the
   // the private storage.
-  yield setUsePrivateBrowsing(private_browser, false);
+  private_window.close();
+  private_window = yield BrowserTestUtils.openNewBrowserWindow({ private : false });
+  private_browser = null;
   yield new Promise(resolve => Cu.schedulePreciseGC(resolve));
+  private_browser = private_window.getBrowser().selectedBrowser;
 
   private_browser.loadURI(prefix + '?action=get&name=test2');
   yield BrowserTestUtils.browserLoaded(private_browser);
   elts = yield getElts(private_browser);
   isnot(elts[0], 'value2', "public window shouldn't see cleared private storage");
   is(elts[1], '1', "public window should only see public items");
 
 
   // Making it private again should clear the storage and it shouldn't
   // be able to see the old private storage as well.
-  yield setUsePrivateBrowsing(private_browser, true);
+  private_window.close();
+  private_window = yield BrowserTestUtils.openNewBrowserWindow({ private : true });
+  private_browser = null;
+  yield new Promise(resolve => Cu.schedulePreciseGC(resolve));
+  private_browser = private_window.getBrowser().selectedBrowser;
 
   private_browser.loadURI(prefix + '?action=set&name=test3&value=value3');
-  BrowserTestUtils.browserLoaded(private_browser);
+  yield BrowserTestUtils.browserLoaded(private_browser);
   elts = yield getElts(private_browser);
   is(elts[1], '1', "private window should only see new private items");
 
   // Cleanup.
   non_private_browser.loadURI(prefix + '?final=true');
   yield BrowserTestUtils.browserLoaded(non_private_browser);
-  gBrowser.removeCurrentTab();
-  gBrowser.removeCurrentTab();
+  private_window.close();
 });