Skip to content

Commit

Permalink
Add Clear-Site-Data [in]secure resource load WPTs
Browse files Browse the repository at this point in the history
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/571458
Commit-Queue: Martin Šrámek <[email protected]>
Cr-Commit-Position: refs/heads/master@{#487333}
WPT-Export-Revision: 4871602c8ba48a2086ba883acf3b9f6c0edf5fb8
  • Loading branch information
msramek authored and chromium-wpt-export-bot committed Jul 18, 2017
1 parent 40e04eb commit 9eb60c3
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clear-site-data/navigation-insecure.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion clear-site-data/navigation.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
74 changes: 74 additions & 0 deletions clear-site-data/resource.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!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>
2 changes: 1 addition & 1 deletion clear-site-data/support/echo-clear-site-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<html>
<head>
<title>Clear-Site-Data</title>
<script src="test_utils.js"></script>
<script src="test_utils.sub.js"></script>
</head>
<body>
<script>
Expand Down
27 changes: 27 additions & 0 deletions clear-site-data/support/page_with_resource.sub.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!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>
24 changes: 24 additions & 0 deletions clear-site-data/support/send_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!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>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})();

0 comments on commit 9eb60c3

Please sign in to comment.