Bug 722857 - Basic sanity test for before/after private browsing DOM storage implementation. r=honzab
☠☠ backed out by f023c835794e ☠ ☠
authorJosh Matthews <josh@joshmatthews.net>
Fri, 25 May 2012 12:20:58 +0100
changeset 94957 70cde80fa0954179c84214dbd7f84a94cb0a46d0
parent 94956 5a903d496ab0a4096001dfc8cf30b11e97f739b6
child 94958 f023c835794e331be1dc0b52d7aaa3a24d426d5f
push id22770
push userryanvm@gmail.com
push dateSat, 26 May 2012 12:07:39 +0000
treeherdermozilla-central@cd62c4b8f500 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs722857
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 722857 - Basic sanity test for before/after private browsing DOM storage implementation. r=honzab
browser/components/privatebrowsing/test/browser/Makefile.in
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page.html
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page2.html
dom/indexedDB/test/browser_permissionsPromptDeny.js
--- a/browser/components/privatebrowsing/test/browser/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/Makefile.in
@@ -11,25 +11,30 @@ relativesrcdir  = browser/components/pri
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_TEST_FILES =  \
 		head.js \
 		browser_console_clear.js \
 		browser_privatebrowsing_certexceptionsui.js \
 		browser_privatebrowsing_commandline_toggle.js \
+		browser_privatebrowsing_concurrent.js \
+		browser_privatebrowsing_concurrent_page.html \
 		browser_privatebrowsing_crh.js \
 		browser_privatebrowsing_fastswitch.js \
 		browser_privatebrowsing_findbar.js \
 		browser_privatebrowsing_forgetthissite.js \
 		browser_privatebrowsing_geoprompt.js \
 		browser_privatebrowsing_geoprompt_page.html \
 		browser_privatebrowsing_import.js \
 		browser_privatebrowsing_lastpbcontextexited.js \
 		browser_privatebrowsing_localStorage.js \
+		browser_privatebrowsing_localStorage_before_after.js \
+		browser_privatebrowsing_localStorage_before_after_page.html \
+		browser_privatebrowsing_localStorage_before_after_page2.html \
 		browser_privatebrowsing_localStorage_page1.html \
 		browser_privatebrowsing_localStorage_page2.html \
 		browser_privatebrowsing_newwindow_stopcmd.js \
 		browser_privatebrowsing_opendir.js \
 		browser_privatebrowsing_openlocation.js \
 		browser_privatebrowsing_pageinfo.js \
 		browser_privatebrowsing_placestitle.js \
 		browser_privatebrowsing_popupblocker.js \
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js
@@ -0,0 +1,73 @@
+/* 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/. */
+
+// Test opening two tabs that share a localStorage, but keep one in private mode.
+// Ensure that values from one don't leak into the other, and that values from
+// earlier private storage sessions aren't visible later.
+
+// 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
+
+function test() {
+  let prefix = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html';
+  waitForExplicitFinish();
+  gBrowser.selectedTab = gBrowser.addTab();
+  let non_private_tab = gBrowser.selectedBrowser;
+  non_private_tab.addEventListener('load', function() {
+    non_private_tab.removeEventListener('load', arguments.callee, true);
+    gBrowser.selectedTab = gBrowser.addTab();
+    let private_tab = gBrowser.selectedBrowser;
+    private_tab.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true;
+    private_tab.addEventListener('load', function() {
+      private_tab.removeEventListener('load', arguments.callee, true);
+
+      non_private_tab.addEventListener('load', function() {
+        non_private_tab.removeEventListener('load', arguments.callee, true);
+        var elts = non_private_tab.contentWindow.document.title.split('|');
+        isnot(elts[0], 'value2', "public window shouldn't see private storage");
+        is(elts[1], '1', "public window should only see public items");
+
+        private_tab.addEventListener('load', function() {
+          private_tab.removeEventListener('load', arguments.callee, true);
+          var elts = private_tab.contentWindow.document.title.split('|');
+          isnot(elts[0], 'value', "private window shouldn't see public storage");
+          is(elts[1], '1', "private window should only see private items");
+          private_tab.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = false;
+
+          Components.utils.schedulePreciseGC(function() {
+            private_tab.addEventListener('load', function() {
+              private_tab.removeEventListener('load', arguments.callee, true);
+              var elts = private_tab.contentWindow.document.title.split('|');
+              isnot(elts[0], 'value2', "public window shouldn't see cleared private storage");
+              is(elts[1], '1', "public window should only see public items");
+
+              private_tab.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true;
+              private_tab.addEventListener('load', function() {
+                private_tab.removeEventListener('load', arguments.callee, true);
+                var elts = private_tab.contentWindow.document.title.split('|');
+                is(elts[1], '1', "private window should only see new private items");
+
+                non_private_tab.addEventListener('load', function() {
+                  gBrowser.removeCurrentTab();
+                  gBrowser.removeCurrentTab();
+                  finish();
+                }, true);
+                non_private_tab.loadURI(prefix + '?final=true');
+
+              }, true);
+              private_tab.loadURI(prefix + '?action=set&name=test3&value=value3');
+            }, true);
+            private_tab.loadURI(prefix + '?action=get&name=test2');
+          });
+        }, true);
+        private_tab.loadURI(prefix + '?action=get&name=test');
+      }, true);
+      non_private_tab.loadURI(prefix + '?action=get&name=test2');
+    }, true);
+    private_tab.loadURI(prefix + '?action=set&name=test2&value=value2');
+  }, true);
+  non_private_tab.loadURI(prefix + '?action=set&name=test&value=value&initial=true');
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html
@@ -0,0 +1,33 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script type="text/javascript">
+  var oGetVars = {};  
+      
+  if (window.location.search.length > 1) {  
+    for (var aItKey, nKeyId = 0, aCouples = window.location.search.substr(1).split("&");
+         nKeyId < aCouples.length;
+         nKeyId++) {  
+      aItKey = aCouples[nKeyId].split("=");  
+      oGetVars[unescape(aItKey[0])] = aItKey.length > 1 ? unescape(aItKey[1]) : "";  
+    }  
+  }
+
+  if (oGetVars.initial == 'true') {
+    localStorage.clear();
+  }
+
+  if (oGetVars.action == 'set') {
+    localStorage.setItem(oGetVars.name, oGetVars.value);
+    document.title = localStorage.getItem(oGetVars.name) + "|" + localStorage.length;
+  } else if (oGetVars.action == 'get') {
+    document.title = localStorage.getItem(oGetVars.name) + "|" + localStorage.length;
+  }
+
+  if (oGetVars.final == 'true') {
+    localStorage.clear();
+  }
+</script>
+</head>
+<body>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after.js
@@ -0,0 +1,41 @@
+/* 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/. */
+
+// Ensure that a storage instance used by both private and public sessions at different times does not
+// allow any data to leak due to cached values.
+
+// Step 1: Load browser_privatebrowsing_localStorage_before_after_page.html in a private tab, causing a storage
+//   item to exist. Close the tab.
+// Step 2: Load the same page in a non-private tab, ensuring that the storage instance reports only one item
+//   existing.
+
+function test() {
+  let prefix = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/';
+  waitForExplicitFinish();
+  
+  // We wait for a GC to ensure that all previous PB docshells in this test suite are destroyed
+  // so that the PB localStorage instance is clean.
+  Components.utils.schedulePreciseGC(function() {
+    let tab = gBrowser.selectedTab = gBrowser.addTab();
+    let browser = gBrowser.selectedBrowser;
+    browser.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true;
+    browser.addEventListener('load', function() {
+      browser.removeEventListener('load', arguments.callee, true);
+      is(browser.contentWindow.document.title, '1', "localStorage should contain 1 item");
+      browser.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = false;
+
+      gBrowser.selectedTab = gBrowser.addTab();
+      let browser2 = gBrowser.selectedBrowser;
+      gBrowser.removeTab(tab);
+      browser2.addEventListener('load', function() {
+        browser2.removeEventListener('load', arguments.callee, true);
+        is(browser2.contentWindow.document.title, 'null|0', 'localStorage should contain 0 items');
+        gBrowser.removeCurrentTab();
+        finish();
+      }, true);
+      browser2.loadURI(prefix + 'browser_privatebrowsing_localStorage_before_after_page2.html');
+    }, true);
+    browser.loadURI(prefix + 'browser_privatebrowsing_localStorage_before_after_page.html');
+  });
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page.html
@@ -0,0 +1,11 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script type="text/javascript">
+  localStorage.clear();
+  localStorage.setItem('zzztest', 'zzzvalue');
+  document.title = localStorage.length;
+</script>
+</head>
+<body>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page2.html
@@ -0,0 +1,10 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script type="text/javascript">
+  document.title = localStorage.getItem('zzztest', 'zzzvalue') + '|' + localStorage.length;
+  localStorage.clear();
+</script>
+</head>
+<body>
+</body>
+</html>
--- a/dom/indexedDB/test/browser_permissionsPromptDeny.js
+++ b/dom/indexedDB/test/browser_permissionsPromptDeny.js
@@ -48,16 +48,51 @@ function test1()
   info("loading test page: " + testPageURL);
   content.location = testPageURL;
 }
 
 function test2()
 {
   info("creating tab");
   gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true;
+
+  gBrowser.selectedBrowser.addEventListener("load", function () {
+    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+
+    setFinishedCallback(function(result, exception) {
+      ok(!result, "No database created");
+      is(exception, "InvalidStateError", "Correct exception");
+      is(getPermission(testPageURL, "indexedDB"),
+         Components.interfaces.nsIPermissionManager.DENY_ACTION,
+         "Correct permission set");
+      gBrowser.removeCurrentTab();
+      executeSoon(test3);
+    });
+
+    registerPopupEventHandler("popupshowing", function () {
+      ok(false, "prompt showing");
+    });
+    registerPopupEventHandler("popupshown", function () {
+      ok(false, "prompt shown");
+    });
+    registerPopupEventHandler("popuphidden", function () {
+      ok(false, "prompt hidden");
+    });
+
+  }, true);
+
+  info("loading test page: " + testPageURL);
+  content.location = testPageURL;
+}
+
+function test3()
+{
+  info("creating tab");
+  gBrowser.selectedTab = gBrowser.addTab();
 
   gBrowser.selectedBrowser.addEventListener("load", function () {
     gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
 
     setFinishedCallback(function(result, exception) {
       ok(!result, "No database created");
       is(exception, "InvalidStateError", "Correct exception");
       is(getPermission(testPageURL, "indexedDB"),