Bug 806687 - Port browser_privatebrowsing_localStorage.js to the new per-window PB APIs; r=ehsan
authorBellindira Castillo [:bellindira] <bellindira@appcoast.com>
Mon, 12 Nov 2012 11:39:58 -0600
changeset 117725 b431265004e5f15338762b74975aad27ce8cf701
parent 117724 400d7b156d2fa2b189dafce8dae9e00c9feba484
child 117726 f934c574fd3fc3d501b879259b3ca3c8e09c0de8
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs806687
milestone19.0a1
Bug 806687 - Port browser_privatebrowsing_localStorage.js to the new per-window PB APIs; r=ehsan
browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_localStorage.js
browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_localStorage_page1.html
browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_localStorage_page2.html
--- a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
@@ -12,18 +12,21 @@ include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_BROWSER_FILES =  \
 		head.js \
 		browser_privatebrowsing_certexceptionsui.js \
 		browser_privatebrowsing_concurrent.js \
 		browser_privatebrowsing_concurrent_page.html \
 		browser_privatebrowsing_cookieacceptdialog.js \
 		browser_privatebrowsing_crh.js \
-		browser_privatebrowsing_lastpbcontextexited.js \
 		browser_privatebrowsing_downloadLastDir.js \
 		browser_privatebrowsing_downloadLastDir_c.js \
 		browser_privatebrowsing_downloadLastDir_toggle.js \
 		browser_privatebrowsing_DownloadLastDirWithCPS.js \
+		browser_privatebrowsing_lastpbcontextexited.js \
+		browser_privatebrowsing_localStorage.js \
+		browser_privatebrowsing_localStorage_page1.html \
+		browser_privatebrowsing_localStorage_page2.html \
 		browser_privatebrowsing_opendir.js \
 		browser_privatebrowsing_theming.js \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
copy from browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_localStorage.js
copy to browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_localStorage.js
--- a/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_localStorage.js
+++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_localStorage.js
@@ -1,26 +1,49 @@
 /* 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() {
-  let pb = Cc["@mozilla.org/privatebrowsing;1"].
-           getService(Ci.nsIPrivateBrowsingService);
   waitForExplicitFinish();
-  pb.privateBrowsingEnabled = true;
-  let tab = gBrowser.selectedTab = gBrowser.addTab();
-  let browser = gBrowser.selectedBrowser;
-  browser.addEventListener('load', function() {
-    browser.removeEventListener('load', arguments.callee, true);
-    let tab2 = gBrowser.selectedTab = gBrowser.addTab();
-    browser.contentWindow.location = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/global/' +
-                     'browser_privatebrowsing_localStorage_page2.html';
-    browser.addEventListener('load', function() {
-      browser.removeEventListener('load', arguments.callee, true);
-      is(browser.contentWindow.document.title, '2', "localStorage should contain 2 items");
-      pb.privateBrowsingEnabled = false;
-      finish();
-    }, true);
-  }, true);
-  browser.loadURI('http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/global/' +
-                  'browser_privatebrowsing_localStorage_page1.html');
+
+  function checkLocalStorage(aWindow, aCallback) {
+    executeSoon(function() {
+      let tab = aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab();
+      let browser = aWindow.gBrowser.selectedBrowser;
+      browser.addEventListener('load', function() {
+        browser.removeEventListener('load', arguments.callee, true);
+        let tab2 = aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab();
+        browser.contentWindow.location = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/perwindow/' +
+                         'browser_privatebrowsing_localStorage_page2.html';
+        browser.addEventListener('load', function() {
+          browser.removeEventListener('load', arguments.callee, true);
+          is(browser.contentWindow.document.title, '2', "localStorage should contain 2 items");
+          aCallback();
+        }, true);
+      }, true);
+
+      browser.loadURI('http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/perwindow/' +
+                      'browser_privatebrowsing_localStorage_page1.html');
+    });
+  }
+
+  let windowsToClose = [];
+  function testOnWindow(options, callback) {
+    let win = OpenBrowserWindow(options);
+    win.addEventListener("load", function onLoad() {
+      win.removeEventListener("load", onLoad, false);
+      windowsToClose.push(win);
+      callback(win);
+    }, false);
+  };
+
+  registerCleanupFunction(function() {
+    windowsToClose.forEach(function(win) {
+      win.close();
+    });
+  });
+
+  testOnWindow({private: true}, function(win) {
+    checkLocalStorage(win, finish);
+  });
+
 }
copy from browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_localStorage_page1.html
copy to browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_localStorage_page1.html
copy from browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_localStorage_page2.html
copy to browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_localStorage_page2.html