Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/inspector-protocol/request-referrer-policy.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/request-referrer-policy.html b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/request-referrer-policy.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c40fecb9454464fddd70b358d93bc9c7f52876a1 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/request-referrer-policy.html |
| @@ -0,0 +1,65 @@ |
| +<!DOCTYPE html> |
| +<script src="../inspector-protocol/inspector-protocol-test.js"></script> |
| +<script src="/resources/get-host-info.js"></script> |
| +<script> |
| +var policies; // Will be set by test() |
| + |
| +function sendRequest(policy_num) { |
| + var img = document.createElement("img"); |
| + img.referrerPolicy = policies[policy_num]; |
| + img.src = "/resources/square.png?" + Math.random(); |
| + document.body.appendChild(img); |
| +} |
| + |
| +function test() { |
| + var policy_num = 0; |
| + var policies = [ |
| + "unsafe-url", "no-referrer-when-downgrade", "no-referrer", "origin", |
| + "origin-when-cross-origin" |
| + ]; |
| + |
| + InspectorTest.eventHandler["Network.requestWillBeSent"] = onRequestWillBeSent; |
| + InspectorTest.sendCommand("Runtime.evaluate", { |
| + "expression" : |
| + "policies = [" + policies.map(p => "'" + p + "'").toString() + "]" |
|
dgozman
2016/12/27 19:45:36
It would be easier to pass the policy string in se
jochen (gone - plz use gerrit)
2017/01/02 07:38:05
done
|
| + }); |
| + InspectorTest.sendCommand("Network.enable", {}, didEnableNetwork); |
| + |
| + function onRequestWillBeSent(evt) { |
| + var req = evt.params.request; |
| + if (req.referrerPolicy == policies[policy_num]) { |
| + InspectorTest.log("PASS: Request with expected policy " + |
| + policies[policy_num] + " observed"); |
| + } else { |
| + InspectorTest.log("FAIL: Request with policy " + req.referrerPolicy + |
| + " observed (expected " + policies[policy_num] + ")"); |
| + } |
| + policy_num++; |
| + if (policy_num >= policies.length) { |
| + InspectorTest.completeTest(); |
| + } else { |
| + InspectorTest.sendCommand( |
| + "Runtime.evaluate", |
| + {"expression" : "sendRequest(" + policy_num + ")"}); |
| + } |
| + } |
| + |
| + function didEnableNetwork(messageObject) { |
| + if (messageObject.error) { |
| + InspectorTest.log("FAIL: Couldn't enable network agent " + |
| + messageObject.error.message); |
| + InspectorTest.completeTest(); |
| + return; |
| + } |
| + InspectorTest.log("Network agent enabled"); |
| + InspectorTest.sendCommand("Runtime.evaluate", |
| + {"expression" : "sendRequest(0)"}); |
| + } |
| +} |
| +</script> |
| +<body onload="runTest()"> |
| + <p> |
| + Tests that network requests are annotated with the correct referrer |
| + policy. |
| + </p> |
| +</body> |