Bug 832700 - Add private browsing to b2g, tests r=smaug

This commit is contained in:
Fabrice Desré 2014-10-10 14:28:04 -07:00
parent 6b40a1a9b6
commit 597d7ba1a9
6 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,50 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that the mozprivatebrowsing attribute works.
"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
function createFrame(aIsPrivate) {
var iframe = document.createElement("iframe");
SpecialPowers.wrap(iframe).mozbrowser = true;
if (aIsPrivate) {
iframe.setAttribute("mozprivatebrowsing", "true");
}
return iframe;
}
function createTest(aIsPrivate, aExpected, aClearStorage) {
info("createTest " + aIsPrivate + " " + aExpected);
var deferred = Promise.defer();
var iframe = createFrame(aIsPrivate);
document.body.appendChild(iframe);
iframe.addEventListener("mozbrowsershowmodalprompt", function(e) {
is(e.detail.message, aExpected, "Checking localstorage");
deferred.resolve();
});
var src = "file_browserElement_PrivateBrowsing.html";
iframe.src = aClearStorage ? src + "?clear=true" : src;
return deferred.promise;
}
function runTest() {
// We first create a iframe in non private browsing mode, set up some
// localstorage, reopen it to check that we get the previously set value.
// Finally, open it in private browsing mode and check that localstorage
// is clear.
createTest(false, "CLEAR", true)
.then(() => { return createTest(false, "EMPTY", false); })
.then(() => { return createTest(false, "bar", false); })
.then(() => { return createTest(true, "EMPTY", false); })
.then(SimpleTest.finish);
}
addEventListener("testready", runTest);

View File

@ -0,0 +1,15 @@
<html>
<body>
<script>
if (location.href.indexOf("clear=true") != -1) {
localStorage.removeItem("foo");
alert("CLEAR");
} else {
var initialValue = localStorage.getItem("foo") || "EMPTY";
localStorage.setItem("foo", "bar");
alert(initialValue);
}
</script>
</body>
</html>

View File

@ -59,6 +59,7 @@ skip-if = (toolkit == 'gonk' && !debug)
[test_browserElement_oop_OpenWindowRejected.html]
skip-if = (toolkit == 'gonk' && !debug)
[test_browserElement_oop_Opensearch.html]
[test_browserElement_oop_PrivateBrowsing.html]
[test_browserElement_oop_PromptCheck.html]
[test_browserElement_oop_PromptConfirm.html]
[test_browserElement_oop_PurgeHistory.html]

View File

@ -43,6 +43,7 @@ support-files =
browserElement_OpenWindowInFrame.js
browserElement_OpenWindowRejected.js
browserElement_Opensearch.js
browserElement_PrivateBrowsing.js
browserElement_PromptCheck.js
browserElement_PromptConfirm.js
browserElement_PurgeHistory.js
@ -89,6 +90,7 @@ support-files =
file_browserElement_OpenWindowDifferentOrigin.html
file_browserElement_OpenWindowInFrame.html
file_browserElement_OpenWindowRejected.html
file_browserElement_PrivateBrowsing.html
file_browserElement_SecurityChange.html
file_browserElement_SetVisibleFrames2_Outer.html
file_browserElement_SetVisibleFrames_Inner.html
@ -170,6 +172,7 @@ skip-if = (toolkit == 'gonk' && !debug)
[test_browserElement_inproc_OpenWindowRejected.html]
skip-if = (toolkit == 'gonk' && !debug)
[test_browserElement_inproc_Opensearch.html]
[test_browserElement_inproc_PrivateBrowsing.html]
[test_browserElement_inproc_PromptCheck.html]
[test_browserElement_inproc_PromptConfirm.html]
[test_browserElement_inproc_PurgeHistory.html]

View File

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=832700
-->
<head>
<title>Test for Bug 832700</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=832700">Mozilla Bug 832700</a>
<script type="application/javascript;version=1.7" src="browserElement_PrivateBrowsing.js">
</script>
</body>
</html>

View File

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=832700
-->
<head>
<title>Test for Bug 832700</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=832700">Mozilla Bug 832700</a>
<script type="application/javascript;version=1.7" src="browserElement_PrivateBrowsing.js">
</script>
</body>
</html>