Bug 806127 - Test that cookies from pages inside <iframe mozbrowser> are not considered third-party. r=bz

The test for the other change in bug 806127 (which affects IndexedDB) is in bug 806168.

--HG--
extra : rebase_source : e1adb7af745953b019d80b8a8c086aba24e8408c
This commit is contained in:
Justin Lebar 2012-10-30 15:55:05 -04:00
parent 43d4d8a8b6
commit e213f2e376
5 changed files with 105 additions and 0 deletions

View File

@ -90,6 +90,9 @@ MOCHITEST_FILES = \
test_browserElement_inproc_PromptCheck.html \
browserElement_PromptConfirm.js \
test_browserElement_inproc_PromptConfirm.html \
browserElement_CookiesNotThirdParty.js \
file_browserElement_CookiesNotThirdParty.html \
test_browserElement_inproc_CookiesNotThirdParty.html \
browserElement_Close.js \
test_browserElement_inproc_Close.html \
browserElement_CloseFromOpener.js \
@ -194,6 +197,7 @@ MOCHITEST_FILES += \
test_browserElement_oop_TargetBlank.html \
test_browserElement_oop_PromptCheck.html \
test_browserElement_oop_PromptConfirm.html \
test_browserElement_oop_CookiesNotThirdParty.html \
test_browserElement_oop_Close.html \
test_browserElement_oop_CloseFromOpener.html \
test_browserElement_oop_CloseApp.html \

View File

@ -0,0 +1,50 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 806127 - Test that cookies set by <iframe mozbrowser> are not considered
// third-party.
"use strict";
SimpleTest.waitForExplicitFinish();
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
const innerPage = 'http://example.com/tests/dom/browser-element/mochitest/file_browserElement_CookiesNotThirdParty.html';
var iframe = document.createElement('iframe');
iframe.mozbrowser = true;
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
if (e.detail.message == 'next') {
iframe.src = innerPage + '?step=2';
return;
}
if (e.detail.message.startsWith('success:')) {
ok(true, e.detail.message);
return;
}
if (e.detail.message.startsWith('failure:')) {
ok(false, e.detail.message);
return;
}
if (e.detail.message == 'finish') {
SimpleTest.finish();
}
});
// innerPage will set a cookie and then alert('next'). We'll load
// innerPage?step=2. That page will check that the cooke exists (despite the
// fact that we've disabled third-party cookies) and alert('success:') or
// alert('failure:'), as appropriate. Finally, the page will
// alert('finish');
iframe.src = innerPage;
document.body.appendChild(iframe);
}
// Disable third-party cookies for this test.
SpecialPowers.pushPrefEnv({'set': [['network.cookie.cookieBehavior', 1]]}, runTest);

View File

@ -0,0 +1,25 @@
<html>
<body>
file_browserElement_CookiesNotThirdParty.html
<script type='text/javascript;version=1.7'>
if (location.search != '?step=2') {
// Step 1: Set a cookie.
document.cookie = 'file_browserElement_CookiesNotThirdParty';
alert('next');
}
else {
// Step 2: Read the cookie.
if (document.cookie == 'file_browserElement_CookiesNotThirdParty') {
alert('success: got the correct cookie');
}
else {
alert('failure: got unexpected cookie: "' + document.cookie + '"');
}
alert('finish');
}
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 806127</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>
<script type="application/javascript;version=1.7" src="browserElement_CookiesNotThirdParty.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 806127</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>
<script type="application/javascript;version=1.7" src="browserElement_CookiesNotThirdParty.js">
</script>
</body>
</html>