-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Storage Access commands for TestDriver
This change implements the Set Storage Access command for TestDriver in Blink and content_shell: https://privacycg.github.io/storage-access/#automation This is needed to support more in-depth WPT tests for the Storage Access API. The current WPT tests for this feature cover basic IDL behavior, but are not able to verify that the requestStorageAccess API itself is functional because the browser must first be put into a state where third-party cookies are blocked. A new set_storage_access method has been added to testdriver.js. It functions similarly to the existing set_permission method. This calls a Blink-internal method that forwards the passed in arguments to the content shell via Mojo. A new WebTestStorageAccessManager class in the content shell converts the arguments into ContentSettingsPatterns and passes these settings to the CookieManager. The WebTestStorageAccessManager also enables third-party cookie blocking so that these rules will take effect. Bug: 1096803 Change-Id: I635687e7d00cf95fa2cf54fb86e1f65a0fe85f3f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2253280 Reviewed-by: Martin Šrámek <msramek@chromium.org> Reviewed-by: Mike West <mkwst@chromium.org> Commit-Queue: Brandon Walderman <brwalder@microsoft.com> Cr-Commit-Position: refs/heads/master@{#790441}
- Loading branch information
1 parent
48180e6
commit 48846ad
Showing
3 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
def main(request, response): | ||
name = request.GET.first(b"name") | ||
value = request.GET.first(b"value") | ||
testcase = request.GET.first(b"testcase") | ||
response_headers = [(b"Set-Cookie", name + b"=" + value)] | ||
|
||
body = b""" | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Set Storage Access Subframe</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script> | ||
let querystring = window.location.search.substring(1).split("&"); | ||
const allowed = querystring.some(param => param.toLowerCase() === "allowed=true"); | ||
test(() => { | ||
if (allowed) { | ||
assert_equals(document.cookie, "%s=%s"); | ||
} else { | ||
assert_equals(document.cookie, ""); | ||
} | ||
}, "[%s] Cookie access is allowed: " + allowed); | ||
</script> | ||
""" % (name, value, testcase) | ||
|
||
return (200, response_headers, body) |
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,31 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title>TestDriver - Set Storage Access Command Tests</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="helpers.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
"use strict"; | ||
|
||
promise_test(async t => { | ||
// Allow a third-party site embedded in this first-party site. | ||
await window.test_driver.set_storage_access("http://{{domains[www]}}:{{ports[http][0]}}/", "http://{{domains[]}}:{{ports[http][0]}}/", "allowed"); | ||
// Block a third-party site embedded in this first-party site. | ||
await window.test_driver.set_storage_access("http://{{domains[www1]}}:{{ports[http][0]}}/", "http://{{domains[]}}:{{ports[http][0]}}/", "blocked"); | ||
// Block a third-party site on all first-party sites. | ||
await window.test_driver.set_storage_access("http://{{domains[www2]}}:{{ports[http][0]}}/", "*", "blocked"); | ||
}, "Set up storage access rules"); | ||
|
||
RunTestsInIFrame("http://{{domains[]}}:{{ports[http][0]}}/storage-access-api/resources/set-cookie.py?name=hello0&value=world0&allowed=true&testcase=same-site"); | ||
|
||
RunTestsInIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/resources/set-cookie.py?name=hello&value=world&allowed=true&testcase=third-party-allowed-on-first-party-site"); | ||
|
||
RunTestsInIFrame("http://{{domains[www1]}}:{{ports[http][0]}}/storage-access-api/resources/set-cookie.py?name=hello1&value=world1&allowed=false&testcase=third-party-blocked-on-first-party-site"); | ||
|
||
RunTestsInIFrame("http://{{domains[www2]}}:{{ports[http][0]}}/storage-access-api/resources/set-cookie.py?name=hello2&value=world2&allowed=false&testcase=third-party-blocked-all"); | ||
</script> | ||
</body> |