mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 13:25:37 +00:00
Bug 722857 - Basic sanity test for before/after private browsing DOM storage implementation. r=honzab
This commit is contained in:
parent
bf85084d66
commit
f0ba4d0fbd
@ -16,6 +16,8 @@ _BROWSER_TEST_FILES = \
|
||||
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 \
|
||||
@ -25,6 +27,9 @@ _BROWSER_TEST_FILES = \
|
||||
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 \
|
||||
|
@ -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');
|
||||
}
|
@ -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>
|
@ -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');
|
||||
});
|
||||
}
|
@ -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>
|
@ -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>
|
@ -50,6 +50,43 @@ function test1()
|
||||
}
|
||||
|
||||
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.selectedBrowser.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = false;
|
||||
unregisterAllPopupEventHandlers();
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user