Bug 1264165 - Update and add test cases. r=franziskus

This commit is contained in:
Thomas Nguyen 2016-06-22 18:28:40 +08:00
parent 545e22fb16
commit 7bcc37e4d7
7 changed files with 420 additions and 4 deletions

View File

@ -735,6 +735,9 @@ skip-if = e10s || os != 'linux' || buildapp != 'browser' # Already tests multipr
[test_innersize_scrollport.html] [test_innersize_scrollport.html]
[test_integer_attr_with_leading_zero.html] [test_integer_attr_with_leading_zero.html]
[test_ipc_messagemanager_blob.html] [test_ipc_messagemanager_blob.html]
[test_link_prefetch.html]
skip-if = !e10s # Track Bug 1281415
[test_link_stylesheet.html]
[test_messagemanager_targetchain.html] [test_messagemanager_targetchain.html]
[test_meta_viewport0.html] [test_meta_viewport0.html]
skip-if = (os != 'b2g' && os != 'android') # meta-viewport tag support is mobile-only skip-if = (os != 'b2g' && os != 'android') # meta-viewport tag support is mobile-only

View File

@ -152,6 +152,61 @@ function createRedirectImgTestCase(aParams, aAttributePolicy) {
</html>`; </html>`;
} }
// test page using link referrer attribute
function createLinkPageUsingRefferer(aMetaPolicy, aAttributePolicy, aNewAttributePolicy, aName, aRel, aStringBuilder, aSchemeFrom, aSchemeTo, aTestType) {
var metaString = "";
if (aMetaPolicy) {
metaString = `<meta name="referrer" content="${aMetaPolicy}">`;
}
var relString = "";
if (aRel) {
relString = `rel=${aRel}`;
}
var changeString = "";
var policy = aAttributePolicy ? aAttributePolicy : aMetaPolicy;
var elementString = aStringBuilder(policy, aName, relString, aSchemeFrom, aSchemeTo, aTestType);
if (aTestType === "setAttribute") {
changeString = `var link = document.getElementById("test_link");
link.setAttribute("referrerpolicy", "${aNewAttributePolicy}");
link.href = "${createTestUrl(policy, "test", aName, "link_element", aSchemeFrom, aSchemeTo)}";`;
} else if (aTestType === "property") {
changeString = `var link = document.getElementById("test_link");
link.referrerPolicy = "${aNewAttributePolicy}";
link.href = "${createTestUrl(policy, "test", aName, "link_element", aSchemeFrom, aSchemeTo)}";`;
}
return `<!DOCTYPE HTML>
<html>
<head>
${metaString}
${elementString}
</head>
<body>
<script>
${changeString}
</script>
</body>
</html>`;
}
function buildLinkString(aPolicy, aName, aRelString, aSchemeFrom, aSchemeTo, aTestType) {
var result;
var href = '';
var onChildComplete = `window.parent.postMessage("childLoadComplete", "http://mochi.test:8888");`
if (!aTestType) {
href = `href=${createTestUrl(aPolicy, "test", aName, "link_element", aSchemeFrom, aSchemeTo)}`;
}
if (!aPolicy) {
result = `<link ${aRelString} ${href} id="test_link" onload='${onChildComplete}' onerror='${onChildComplete}'>`;
} else {
result = `<link ${aRelString} ${href} referrerpolicy=${aPolicy} id="test_link" onload='${onChildComplete}' onerror='${onChildComplete}'>`;
}
return result;
}
function handleRequest(request, response) { function handleRequest(request, response) {
var params = new URLSearchParams(request.queryString); var params = new URLSearchParams(request.queryString);
var action = params.get("ACTION"); var action = params.get("ACTION");
@ -314,6 +369,23 @@ function handleRequest(request, response) {
return; return;
} }
var _getPage = createLinkPageUsingRefferer.bind(null, metaPolicy, attributePolicy, newAttributePolicy, name, rel);
var _getLinkPage = _getPage.bind(null, buildLinkString, schemeFrom, schemeTo);
// link
if (action === "generate-link-policy-test") {
response.write(_getLinkPage());
return;
}
if (action === "generate-link-policy-test-set-attribute") {
response.write(_getLinkPage("setAttribute"));
return;
}
if (action === "generate-link-policy-test-property") {
response.write(_getLinkPage("property"));
return;
}
response.write("I don't know action " + action); response.write("I don't know action " + action);
return; return;
} }

View File

@ -0,0 +1,176 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test link policy attribute for Bug 1264165</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<!--
Testing that link referrer attributes are honoured correctly
https://bugzilla.mozilla.org/show_bug.cgi?id=1264165
-->
<script type="application/javascript;version=1.8">
const SJS = "://example.com/tests/dom/base/test/referrer_testserver.sjs?";
const PARAMS = ["ATTRIBUTE_POLICY", "NEW_ATTRIBUTE_POLICY", "META_POLICY", "REL", "SCHEME_FROM", "SCHEME_TO"];
const testCases = [
{ACTION: ["generate-link-policy-test"],
TESTS: [
{ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'prefetch-unsafe-url-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'prefetch',
DESC: "prefetch-unsafe-url with origin in meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin',
NAME: 'prefetch-origin-with-unsafe-url-in-meta',
META_POLICY: 'unsafe-url',
REL: 'prefetch',
DESC: "prefetch-origin with unsafe-url in meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'no-referrer',
NAME: 'prefetch-no-referrer-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'prefetch',
DESC: "prefetch-no-referrer with origin in meta",
RESULT: 'none'},
{NAME: 'prefetch-no-referrer-in-meta',
META_POLICY: 'no-referrer',
REL: 'prefetch',
DESC: "prefetch-no-referrer in meta",
RESULT: 'none'},
// Downgrade.
{ATTRIBUTE_POLICY: 'no-referrer-when-downgrade',
NAME: 'prefetch-origin-in-meta-downgrade-in-attr',
META_POLICY: 'origin',
DESC: 'prefetch-origin in meta downgrade in attr',
REL: 'prefetch',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
RESULT: 'none'},
// No downgrade.
{ATTRIBUTE_POLICY: 'no-referrer-when-downgrade',
NAME: 'prefetch-origin-in-meta-downgrade-in-attr',
META_POLICY: 'origin',
DESC: 'prefetch-origin in meta downgrade in attr',
REL: 'prefetch',
SCHEME_FROM: 'https',
SCHEME_TO: 'https',
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin',
NAME: 'prefetch-origin-with-no-meta',
META_POLICY: '',
REL: 'prefetch',
DESC: "prefetch-origin with no meta",
RESULT: 'origin'},
// Cross origin
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'prefetch-origin-when-cross-origin-with-no-meta',
META_POLICY: '',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'prefetch',
DESC: "prefetch-origin-when-cross-origin with no meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'prefetch-origin-when-cross-origin-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'prefetch',
DESC: "prefetch-origin-when-cross-origin with no-referrer in meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'prefetch-origin-when-cross-origin-with-unsafe-url-in-meta',
META_POLICY: 'unsafe-url',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'prefetch',
DESC: "prefetch-origin-when-cross-origin with unsafe-url in meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'prefetch-origin-when-cross-origin-with-origin-in-meta',
META_POLICY: 'origin',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'prefetch',
DESC: "prefetch-origin-when-cross-origin with origin in meta",
RESULT: 'origin'},
// Invalid
{ATTRIBUTE_POLICY: 'default',
NAME: 'prefetch-default-with-no-meta',
META_POLICY: '',
REL: 'prefetch',
DESC: "prefetch-default with no meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'something',
NAME: 'prefetch-something-with-no-meta',
META_POLICY: '',
REL: 'prefetch',
DESC: "prefetch-something with no meta",
RESULT: 'full'},
]},
{ACTION: ["generate-link-policy-test-set-attribute"],
TESTS: [
{ATTRIBUTE_POLICY: 'unsafe-url',
NEW_ATTRIBUTE_POLICY: 'no-referrer',
NAME: 'prefetch-no-referrer-unsafe-url-set-attribute-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'prefetch',
DESC: "prefetch-no-referrer-set-attribute (orginally unsafe-url) with origin in meta",
RESULT: 'none'},
{ATTRIBUTE_POLICY: 'origin',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'prefetch-unsafe-url-origin-set-attribute-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
REL: 'prefetch',
DESC: "prefetch-unsafe-url-set-attribute(orginally origin) with no-referrer in meta",
RESULT: 'full'},
]},
{ACTION: ["generate-link-policy-test-property"],
TESTS: [
{ATTRIBUTE_POLICY: 'no-referrer',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'prefetch-unsafe-url-no-referrer-property-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'prefetch',
DESC: "prefetch-unsafe-url-property (orginally no-referrer) with origin in meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'prefetch-unsafe-url-origin-property-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
REL: 'prefetch',
DESC: "prefetch-unsafe-url-property (orginally origin) with no-referrer 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();">
<script type="application/javascript;version=1.7">
/**
* Listen for notifications that pretching finishes.
* XXX Bug 1268962 - Fire load/error events on <link rel="prefetch">
* Because there's no onload/onerror event fired, we catch prefetch-load-completed
* to test
* Simply remove this after bug 1268962 is fixed
*/
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
SpecialPowers.Services.obs.addObserver(function() { tests.next(); }, "prefetch-load-completed", false);
</script>
<iframe id="testframe"></iframe>
</body>
</html>

View File

@ -0,0 +1,166 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test link policy attribute for Bug 1264165</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<!--
Testing that link referrer attributes are honoured correctly
https://bugzilla.mozilla.org/show_bug.cgi?id=1264165
-->
<script type="application/javascript;version=1.8">
const SJS = "://example.com/tests/dom/base/test/referrer_testserver.sjs?";
const PARAMS = ["ATTRIBUTE_POLICY", "NEW_ATTRIBUTE_POLICY", "META_POLICY", "REL", "SCHEME_FROM", "SCHEME_TO"];
const testCases = [
{ACTION: ["generate-link-policy-test"],
TESTS: [
{ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'stylesheet-unsafe-url-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'stylesheet',
DESC: "stylesheet-unsafe-url with origin in meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin',
NAME: 'stylesheet-origin-with-unsafe-url-in-meta',
META_POLICY: 'unsafe-url',
REL: 'stylesheet',
DESC: "stylesheet-origin with unsafe-url in meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'no-referrer',
NAME: 'stylesheet-no-referrer-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'stylesheet',
DESC: "stylesheet-no-referrer with origin in meta",
RESULT: 'none'},
{NAME: 'stylesheet-no-referrer-in-meta',
META_POLICY: 'no-referrer',
REL: 'stylesheet',
DESC: "stylesheet-no-referrer in meta",
RESULT: 'none'},
// Downgrade.
{ATTRIBUTE_POLICY: 'no-referrer-when-downgrade',
NAME: 'stylesheet-origin-in-meta-downgrade-in-attr',
META_POLICY: 'origin',
DESC: 'stylesheet-origin in meta downgrade in attr',
REL: 'stylesheet',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
RESULT: 'none'},
// No downgrade.
{ATTRIBUTE_POLICY: 'no-referrer-when-downgrade',
NAME: 'stylesheet-origin-in-meta-downgrade-in-attr',
META_POLICY: 'origin',
DESC: 'stylesheet-origin in meta downgrade in attr',
REL: 'stylesheet',
SCHEME_FROM: 'https',
SCHEME_TO: 'https',
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin',
NAME: 'stylesheet-origin-with-no-meta',
META_POLICY: '',
REL: 'stylesheet',
DESC: "stylesheet-origin with no meta",
RESULT: 'origin'},
// Cross origin
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'stylesheet-origin-when-cross-origin-with-no-meta',
META_POLICY: '',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'stylesheet',
DESC: "stylesheet-origin-when-cross-origin with no meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'stylesheet-origin-when-cross-origin-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'stylesheet',
DESC: "stylesheet-origin-when-cross-origin with no-referrer in meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'stylesheet-origin-when-cross-origin-with-unsafe-url-in-meta',
META_POLICY: 'unsafe-url',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'stylesheet',
DESC: "stylesheet-origin-when-cross-origin with unsafe-url in meta",
RESULT: 'origin'},
{ATTRIBUTE_POLICY: 'origin-when-cross-origin',
NAME: 'stylesheet-origin-when-cross-origin-with-origin-in-meta',
META_POLICY: 'origin',
SCHEME_FROM: 'https',
SCHEME_TO: 'http',
REL: 'stylesheet',
DESC: "stylesheet-origin-when-cross-origin with origin in meta",
RESULT: 'origin'},
// Invalid
{ATTRIBUTE_POLICY: 'default',
NAME: 'stylesheet-default-with-no-meta',
META_POLICY: '',
REL: 'stylesheet',
DESC: "stylesheet-default with no meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'something',
NAME: 'stylesheet-something-with-no-meta',
META_POLICY: '',
REL: 'stylesheet',
DESC: "stylesheet-something with no meta",
RESULT: 'full'},
]},
{ACTION: ["generate-link-policy-test-set-attribute"],
TESTS: [
{ATTRIBUTE_POLICY: 'unsafe-url',
NEW_ATTRIBUTE_POLICY: 'no-referrer',
NAME: 'stylesheet-no-referrer-unsafe-url-set-attribute-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'stylesheet',
DESC: "stylesheet-no-referrer-set-attribute (orginally unsafe-url) with origin in meta",
RESULT: 'none'},
{ATTRIBUTE_POLICY: 'origin',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'stylesheet-unsafe-url-origin-set-attribute-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
REL: 'stylesheet',
DESC: "stylesheet-unsafe-url-set-attribute (orginally origin) with no-referrer in meta",
RESULT: 'full'},
]},
{ACTION: ["generate-link-policy-test-property"],
TESTS: [
{ATTRIBUTE_POLICY: 'no-referrer',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'stylesheet-unsafe-url-no-referrer-property-with-origin-in-meta',
META_POLICY: 'origin',
REL: 'stylesheet',
DESC: "stylesheet-unsafe-url-property (orginally no-referrer) with origin in meta",
RESULT: 'full'},
{ATTRIBUTE_POLICY: 'origin',
NEW_ATTRIBUTE_POLICY: 'unsafe-url',
NAME: 'stylesheet-unsafe-url-origin-property-with-no-referrer-in-meta',
META_POLICY: 'no-referrer',
REL: 'stylesheet',
DESC: "stylesheet-unsafe-url-property (orginally origin) with no-referrer 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

@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1260664
<title>Test for Bug 1260664</title> <title>Test for Bug 1260664</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="reflect.js"></script> <script type="application/javascript" src="reflect.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head> </head>
<body> <body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1260664">Mozilla Bug 1260664</a> <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1260664">Mozilla Bug 1260664</a>
@ -25,7 +24,7 @@ SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTests); SimpleTest.waitForFocus(runTests);
function runTests() { function runTests() {
var elements = [ "iframe", "img", "a", "area" ]; var elements = [ "iframe", "img", "a", "area", "link" ];
for (var i = 0; i < elements.length; ++i) { for (var i = 0; i < elements.length; ++i) {
reflectLimitedEnumerated({ reflectLimitedEnumerated({

View File

@ -1412,7 +1412,7 @@ pref("network.http.referer.XOriginPolicy", 0);
// By default this is enabled for compatibility (see bug 141641) // By default this is enabled for compatibility (see bug 141641)
pref("network.http.sendSecureXSiteReferrer", true); pref("network.http.sendSecureXSiteReferrer", true);
// Controls whether referrer attributes in <a>, <img>, <area>, and <iframe> are honoured // Controls whether referrer attributes in <a>, <img>, <area>, <iframe>, and <link> are honoured
pref("network.http.enablePerElementReferrer", true); pref("network.http.enablePerElementReferrer", true);
// Maximum number of consecutive redirects before aborting. // Maximum number of consecutive redirects before aborting.

View File

@ -11,7 +11,7 @@
<script> <script>
test(function () { test(function () {
var elements = ["iframe", "img", "a", "area"]; var elements = ["iframe", "img", "a", "area", "link"];
for (var i = 0; i < elements.length; i++) { for (var i = 0; i < elements.length; i++) {
var elem = document.createElement(elements[i]); var elem = document.createElement(elements[i]);
elem.referrerPolicy = "unsafe-url"; elem.referrerPolicy = "unsafe-url";