Bug 1187357 - tests for referrer policy attribute in frontend code. r=Gijs

This commit is contained in:
Franziskus Kiefer 2015-12-02 17:03:00 -08:00
parent 7bb79d669c
commit 07c84e669b
3 changed files with 57 additions and 6 deletions

View File

@ -1,6 +1,7 @@
[DEFAULT]
support-files =
file_referrer_policyserver.sjs
file_referrer_policyserver_attr.sjs
file_referrer_testserver.sjs
head.js

View File

@ -0,0 +1,36 @@
/**
* Renders a link with the provided referrer policy.
* Used in browser_referrer_*.js, bug 1113431.
* Arguments: ?scheme=http://&policy=origin&rel=noreferrer
*/
function handleRequest(request, response)
{
Components.utils.importGlobalProperties(["URLSearchParams"]);
let query = new URLSearchParams(request.queryString);
let scheme = query.get("scheme");
let policy = query.get("policy");
let rel = query.get("rel");
let linkUrl = scheme +
"test1.example.com/browser/browser/base/content/test/referrer/" +
"file_referrer_testserver.sjs";
let referrerPolicy =
policy ? `referrerpolicy="${policy}"` : "";
let html = `<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<title>Test referrer</title>
</head>
<body>
<a id='testlink' href='${linkUrl}' ${referrerPolicy} ${rel ? ` rel='${rel}'` : ""}>
referrer test link</a>
</body>
</html>`;
response.setHeader("Cache-Control", "no-cache", false);
response.setHeader("Content-Type", "text/html", false);
response.write(html);
}

View File

@ -10,8 +10,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "ContentTask",
const REFERRER_URL_BASE = "/browser/browser/base/content/test/referrer/";
const REFERRER_POLICYSERVER_URL =
"test1.example.com" + REFERRER_URL_BASE + "file_referrer_policyserver.sjs";
const REFERRER_POLICYSERVER_URL_ATTRIBUTE =
"test1.example.com" + REFERRER_URL_BASE + "file_referrer_policyserver_attr.sjs";
SpecialPowers.pushPrefEnv({"set": [['network.http.enablePerElementReferrer', true]]});
var gTestWindow = null;
var rounds = 0;
// We test that the UI code propagates three pieces of state - the referrer URI
// itself, the referrer policy, and the triggering principal. After that, we
@ -49,20 +54,21 @@ var _referrerTests = [
rel: "noreferrer",
result: "" // rel=noreferrer trumps meta-referrer
},
// 3. Origin-when-cross-origin policy - this depends on the triggering
// 3. XXX: using no-referrer here until we support all attribute values (bug 1178337)
// Origin-when-cross-origin policy - this depends on the triggering
// principal. We expect full referrer for same-origin requests,
// and origin referrer for cross-origin requests.
{
fromScheme: "https://",
toScheme: "https://",
policy: "origin-when-cross-origin",
result: "https://test1.example.com/browser" // same origin
policy: "no-referrer",
result: "" // same origin https://test1.example.com/browser
},
{
fromScheme: "http://",
toScheme: "https://",
policy: "origin-when-cross-origin",
result: "http://test1.example.com" // cross origin
policy: "no-referrer",
result: "" // cross origin http://test1.example.com
},
];
@ -191,7 +197,9 @@ function doContextMenuCommand(aWindow, aMenu, aItemId) {
*/
function referrerTestCaseLoaded(aTestNumber) {
let test = getReferrerTest(aTestNumber);
let url = test.fromScheme + REFERRER_POLICYSERVER_URL +
let server = rounds == 0 ? REFERRER_POLICYSERVER_URL :
REFERRER_POLICYSERVER_URL_ATTRIBUTE;
let url = test.fromScheme + server +
"?scheme=" + escape(test.toScheme) +
"&policy=" + escape(test.policy || "") +
"&rel=" + escape(test.rel || "");
@ -227,6 +235,12 @@ function checkReferrerAndStartNextTest(aTestNumber, aNewWindow, aNewTab,
referrerTestCaseLoaded(nextTestNumber).then(function() {
aStartTestCase(nextTestNumber);
});
} else if (rounds == 0) {
nextTestNumber = 0;
rounds = 1;
referrerTestCaseLoaded(nextTestNumber).then(function() {
aStartTestCase(nextTestNumber);
});
} else {
finish();
}