forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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/571458 Commit-Queue: Martin Šrámek <[email protected]> Cr-Commit-Position: refs/heads/master@{#487333} WPT-Export-Revision: 4871602c8ba48a2086ba883acf3b9f6c0edf5fb8
- Loading branch information
1 parent
40e04eb
commit 9eb60c3
Showing
7 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters