Bug 1175736 - Add iframe referrer attribute tests. r=ckerschb, r=baku

This commit is contained in:
Franziskus Kiefer 2015-07-20 08:40:04 -07:00
parent 4310fa76ec
commit 32ef1d3d0b
5 changed files with 233 additions and 1 deletions

View File

@ -678,6 +678,9 @@ support-files = referrerHelper.js
[test_anchor_area_referrer_changing.html]
[test_anchor_area_referrer_invalid.html]
[test_anchor_area_referrer_rel.html]
[test_iframe_referrer.html]
[test_iframe_referrer_changing.html]
[test_iframe_referrer_invalid.html]
[test_caretPositionFromPoint.html]
[test_classList.html]
# This test fails on the Mac for some reason

View File

@ -15,6 +15,40 @@ function createTestUrl(aPolicy, aAction, aName, aType) {
'type=' + aType;
}
// test page using iframe referrer attribute
function createIframeTestPageUsingRefferer(aMetaPolicy, aAttributePolicy, aNewAttributePolicy, aName, aChangingMethod) {
var metaString = "";
if (aMetaPolicy) {
metaString = '<meta name="referrer" content="' + aMetaPolicy + '">';
}
var changeString = '';
if (aChangingMethod === 'setAttribute') {
changeString = `document.getElementById("myframe").setAttribute("referrer", "${aNewAttributePolicy}")`;
} else if (aChangingMethod === 'property') {
changeString = `document.getElementById("myframe").referrer = "${aNewAttributePolicy}"`;
}
var iFrameString = `<iframe src="" id="myframe" ${aAttributePolicy ? ` referrer='${aAttributePolicy}'` : ""}>iframe</iframe>`;
return `<!DOCTYPE HTML>
<html>
<head>
${metaString}
</head>
<body>
${iFrameString}
<script>
window.addEventListener("load", function() {
${changeString}
document.getElementById("myframe").onload = function(){
parent.postMessage("childLoadComplete", "http://mochi.test:8888");
};
document.getElementById("myframe").src = "${createTestUrl(aAttributePolicy, 'test', aName, 'iframe')}";
}.bind(window), false);
</script>
</body>
</html>`;
}
function buildAnchorString(aMetaPolicy, aReferrerPolicy, aName, aRelString){
if (aReferrerPolicy) {
return `<a href="${createTestUrl(aReferrerPolicy, 'test', aName, 'link')}" referrer="${aReferrerPolicy}" id="link" ${aRelString}>${aReferrerPolicy}</a>`;
@ -123,7 +157,10 @@ function handleRequest(request, response) {
setSharedState(SHARED_KEY, JSON.stringify(result));
if (type === "link") {
if (type === "iframe") {
// return iframe page
response.write("<html><body>I am the iframe</body></html>");
} else if (type === "link") {
// forward link click to redirect URL to finish test
var loc = "http://" + BASE_URL + "?ACTION=redirect";
response.setStatusLine('1.1', 302, 'Found');
@ -170,6 +207,23 @@ function handleRequest(request, response) {
return;
}
// iframe
_getPage = createIframeTestPageUsingRefferer.bind(null, metaPolicy, attributePolicy, newAttributePolicy, name);
// aMetaPolicy, aAttributePolicy, aNewAttributePolicy, aName, aChangingMethod
if (action === 'generate-iframe-policy-test') {
response.write(_getPage());
return;
}
if (action === 'generate-iframe-changing-policy-test-set-attribute') {
response.write(_getPage('setAttribute'));
return;
}
if (action === 'generate-iframe-changing-policy-test-property') {
response.write(_getPage('property'));
return;
}
response.write("I don't know action " + action);
return;
}

View File

@ -0,0 +1,55 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test iframe referrer policy attribute for Bug 1175736</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<!--
Testing that iframe referrer attribute is honoured correctly
* regular loads
* regression tests that meta referrer is still working even if attribute referrers are enabled
https://bugzilla.mozilla.org/show_bug.cgi?id=1175736
-->
<script type="application/javascript;version=1.7">
const SJS = "/tests/dom/base/test/referrer_testserver.sjs?";
const PARAMS = ["ATTRIBUTE_POLICY", "NEW_ATTRIBUTE_POLICY", "META_POLICY"];
const testCases = [
{ACTION: ["generate-iframe-policy-test"],
TESTS: [
{ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'unsafe-url-with-origin-in-meta',
META_POLICY: 'origin',
DESC: "unsafe-url (iframe) with origin in meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin',
NAME: 'origin-with-unsafe-url-in-meta',
META_POLICY: 'unsafe-url',
DESC: "origin (iframe) with unsafe-url in meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'no-referrer',
NAME: 'no-referrer-with-origin-in-meta',
META_POLICY: 'origin',
DESC: "no-referrer (iframe) with origin in meta",
RESULT: 'none'},
{NAME: 'no-referrer-in-meta',
META_POLICY: 'no-referrer',
DESC: "no-referrer in meta",
RESULT: 'none'},
{ATTRIBUTE_POLICY: 'origin',
NAME: 'origin-with-no-meta',
META_POLICY: '',
DESC: "origin (iframe) with no meta",
RESULT: 'origin'}]}
];
</script>
<script type="application/javascript;version=1.7" src="/tests/dom/base/test/referrer_helper.js"></script>
</head>
<body onload="tests.next();">
<iframe id="testframe"></iframe>
</body>
</html>

View File

@ -0,0 +1,50 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test iframe referrer policy attribute for Bug 1175736</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<!--
Testing that iframe referrer attribute is honoured correctly
* testing setAttribute and .referrer
https://bugzilla.mozilla.org/show_bug.cgi?id=1175736
-->
<script type="application/javascript;version=1.7">
const SJS = "/tests/dom/base/test/referrer_testserver.sjs?";
const PARAMS = ["ATTRIBUTE_POLICY", "NEW_ATTRIBUTE_POLICY", "META_POLICY"];
const testCases = [
{ACTION: ["generate-iframe-changing-policy-test-set-attribute"],
TESTS: [
{ATTRIBUTE_POLICY: 'unsafe-url',
NEW_ATTRIBUTE_POLICY: 'no-referrer',
NAME: 'no-referrer-unsafe-url-with-origin-in-meta',
META_POLICY: 'origin',
DESC: "no-referrer (iframe, orginally unsafe-url) with origin in meta",
RESULT: 'none'},
{ATTRIBUTE_POLICY: 'origin',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'unsafe-url-origin-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
DESC: "unsafe-url (iframe, orginally origin) with no-referrer in meta",
RESULT: 'full'}]},
{ACTION: ["generate-iframe-changing-policy-test-property"],
TESTS: [
{ATTRIBUTE_POLICY: 'no-referrer',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'unsafe-url-no-referrer-with-origin-in-meta',
META_POLICY: 'origin',
DESC: "unsafe-url (iframe, orginally no-referrer) with origin in meta",
RESULT: 'full'}]}
];
</script>
<script type="application/javascript;version=1.7" src="/tests/dom/base/test/referrer_helper.js"></script>
</head>
<body onload="tests.next();">
<iframe id="testframe"></iframe>
</body>
</html>

View File

@ -0,0 +1,70 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test iframe referrer policy attribute for Bug 1175736</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<!--
Testing that iframe referrer attribute is honoured correctly
* invalid referrer policies
https://bugzilla.mozilla.org/show_bug.cgi?id=1175736
-->
<script type="application/javascript;version=1.7">
const SJS = "/tests/dom/base/test/referrer_testserver.sjs?";
const PARAMS = ["ATTRIBUTE_POLICY", "NEW_ATTRIBUTE_POLICY", "META_POLICY"];
const testCases = [
{ACTION: ["generate-iframe-policy-test"],
TESTS: [
// setting invalid refer values -> we expect either full referrer (default)
// or whatever is specified in the meta referrer policy
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'origin-when-cross-origin-with-no-meta',
META_POLICY: '',
DESC: "origin-when-cross-origin (iframe) with no meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'default',
NAME: 'default-with-no-meta',
META_POLICY: '',
DESC: "default (iframe) with no meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'something',
NAME: 'something-with-no-meta',
META_POLICY: '',
DESC: "something (iframe) with no meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'origin-when-cross-origin-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
DESC: "origin-when-cross-origin (iframe) with no-referrer in meta",
RESULT: 'none'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'origin-when-cross-origin-with-unsafe-url-in-meta',
META_POLICY: 'unsafe-url',
DESC: "origin-when-cross-origin (iframe) with unsafe-url in meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'origin-when-cross-origin-with-origin-in-meta',
META_POLICY: 'origin',
DESC: "origin-when-cross-origin (iframe) with origin in meta",
RESULT: 'origin'},
{NAME: 'origin-in-meta',
META_POLICY: 'origin',
DESC: "origin in meta",
RESULT: 'origin'},
{NAME: 'no-referrer-in-meta',
META_POLICY: 'no-referrer',
DESC: "no-referrer in meta",
RESULT: 'none'}]}
];
</script>
<script type="application/javascript;version=1.7" src="/tests/dom/base/test/referrer_helper.js"></script>
</head>
<body onload="tests.next();">
<iframe id="testframe"></iframe>
</body>
</html>