Commit db4ce895 authored by Martin Sramek's avatar Martin Sramek Committed by Commit Bot

Add Clear-Site-Data [in]secure resource load WPTs

resource.html runs 4 test cases, representing [in]secure resource load
on an [in]secure page.

The expected result is that Clear-Site-Data is honored iff the resource
is secure. The embedding page does not matter.

Bug: 607897
Change-Id: Id17bc6d52bca4da46fab214bcc71ca7c7070cdb0
Reviewed-on: https://chromium-review.googlesource.com/571458Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Martin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487490}
parent 13b1999a
......@@ -3,7 +3,7 @@
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test_utils.js"></script>
<script src="support/test_utils.sub.js"></script>
</head>
<body>
......
......@@ -3,7 +3,7 @@
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test_utils.js"></script>
<script src="support/test_utils.sub.js"></script>
</head>
<body>
......
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test_utils.sub.js"></script>
</head>
<body>
<script>
/**
* @typedef{TestCase}
* @type{object}
* @property{string} frame The scheme of the url of the iframe.
* @property{string} resource The scheme of the resource in the iframe.
* @property{boolean} deleted Whether it is expected that Clear-Site-Data
* will be respected when loading |resource| in |frame|.
*/
var TestCase;
/** Array<TestCase> Test cases. */
var test_cases = [
{ "frame": "https", "resource": "https", "deleted": true },
{ "frame": "http", "resource": "https", "deleted": true },
{ "frame": "https", "resource": "http", "deleted": false },
{ "frame": "http", "resource": "http", "deleted": false },
];
/**
* @param TestCase test_case The test case that is tested.
* @param Dict.<string, boolean> report A map between a datatype name and
* whether it is empty.
*/
function verifyDatatypes(test_case, report) {
if (test_case.deleted) {
assert_true(
report["storage"],
"Storage should have been cleared.");
} else {
assert_false(
report["storage"],
"Storage should NOT have been cleared.");
}
}
test_cases.forEach(function(test_case) {
var test_name =
test_case.resource + " resource on a " + test_case.frame + " page";
promise_test(function(test) {
return new Promise(function(resolve_test, reject_test) {
TestUtils.populateDatatypes()
.then(function() {
// Navigate to a page with a resource that is loaded with
// the Clear-Site-Data header, then verify that storage
// has been deleted if and only if the resource was loaded
// via HTTPS.
return new Promise(function(resolve, reject) {
window.addEventListener("message", resolve);
var iframe = document.createElement("iframe");
iframe.src = TestUtils.getPageWithResourceUrl(
test_case.frame, test_case.resource);
document.body.appendChild(iframe);
}).then(function(messageEvent) {
verifyDatatypes(test_case, messageEvent.data);
resolve_test();
});
});
});
}, test_name);
});
</script>
</body>
</html>
......@@ -5,7 +5,7 @@ RESPONSE = """
<html>
<head>
<title>Clear-Site-Data</title>
<script src="test_utils.js"></script>
<script src="test_utils.sub.js"></script>
</head>
<body>
<script>
......
<!DOCTYPE html>
<html>
<head>
<title>Clear-Site-Data</title>
<script src="test_utils.sub.js"></script>
</head>
<body>
<script>
var scheme = location.search.match("scheme=([^&$]+)")[1];
// TODO(@msramek): Move this logic to TestUtils.
var base_url = location.origin
.replace(/https?/, scheme)
.replace(/:[0-9]+/, ":" + (scheme == "https" ? {{ports[https][0]}}
: {{ports[http][0]}})) +
"/clear-site-data/support/";
var image = new Image();
image.onload = image.onerror = function() {
location.href = base_url + "send_report.html";
}
// TODO(@msramek): Move this logic to TestUtils.
image.src = base_url + "echo-clear-site-data.py?storage";
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Clear-Site-Data</title>
<script src="test_utils.sub.js"></script>
</head>
<body>
<script>
/**
* A map between a datatype name and whether it is empty.
* @property Object.<string, boolean>
*/
var report = {};
Promise.all(TestUtils.DATATYPES.map(function(datatype) {
return datatype.isEmpty().then(function(isEmpty) {
report[datatype.name] = isEmpty;
});
})).then(function() {
window.top.postMessage(report, "*");
});
</script>
</body>
</html>
......@@ -105,5 +105,22 @@ var TestUtils = (function() {
return "support/echo-clear-site-data.py?" + names.join("&");
}
/**
* @param{string} page_scheme Scheme of the page. "http" or "https".
* @param{string} resource_scheme Scheme of the resource. "http" or "https".
* @return The URL of a page that contains a resource requesting the deletion
* of storage.
*/
TestUtils.getPageWithResourceUrl = function(page_scheme, resource_scheme) {
if (page_scheme != "https" && page_scheme != "http")
throw "Unsupported scheme: " + page_scheme;
if (resource_scheme != "https" && resource_scheme != "http")
throw "Unsupported scheme: " + resource_scheme;
return page_scheme + "://web-platform.test:" +
(page_scheme == "https" ? {{ports[https][0]}} : {{ports[http][0]}}) +
"/clear-site-data/support/page_with_resource.sub.html?scheme=" +
resource_scheme;
}
return TestUtils;
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment