Automatic update from web-platform-tests [SAA] Fix test failures due to default cookie availability This fixes the tests such that they no longer assume that third-party cookies are blocked by default (or that test_driver.set_storage_access does anything; see https://github.com/privacycg/storage-access/issues/162 for discussion). Fixed: b:446148374 Change-Id: I11c1e4fee88cbde810d31445357b233fcebc566b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6973284 Commit-Queue: Chris Fredrickson <cfredric@chromium.org> Auto-Submit: Chris Fredrickson <cfredric@chromium.org> Reviewed-by: Dylan Cutler <dylancutler@google.com> Cr-Commit-Position: refs/heads/main@{#1519499} -- Remove new assertion -- wpt-commits: c3f887e7f1f9ff410de609304f95e550d4a37570, 8539bf6cb4b87d36ceef4cee1b951f203cfda2e8 wpt-pr: 55018
67 lines
3.1 KiB
JavaScript
67 lines
3.1 KiB
JavaScript
// META: script=helpers.js
|
|
// META: script=/resources/testdriver.js
|
|
// META: script=/resources/testdriver-vendor.js
|
|
// META: script=/cookies/resources/cookie-helper.sub.js
|
|
'use strict';
|
|
|
|
const {testPrefix, topLevelDocument} = processQueryParams();
|
|
|
|
// Common tests to run in all frames.
|
|
promise_test(async () => {
|
|
assert_not_equals(document.hasStorageAccess, undefined);
|
|
}, "[" + testPrefix + "] document.hasStorageAccess() should exist on the document interface");
|
|
|
|
promise_test(async () => {
|
|
const hasAccess = await document.hasStorageAccess();
|
|
if (topLevelDocument || testPrefix.includes('same-origin')) {
|
|
assert_true(hasAccess, "Access should be granted in top-level frame or iframe that is in first-party context by default.");
|
|
return;
|
|
}
|
|
if (CanAccessCookiesViaJS()) {
|
|
// Nothing to test here, since cross-site cookies are not blocked.
|
|
// See https://github.com/privacycg/storage-access/issues/162.
|
|
return;
|
|
}
|
|
if (testPrefix == "ABA") {
|
|
assert_false(
|
|
hasAccess,
|
|
"Access should not be granted in secure same-origin iframe that is in a third-party context by default when cookies are blocked.");
|
|
return;
|
|
}
|
|
assert_false(
|
|
hasAccess,
|
|
"Access should not be granted in secure cross-origin iframes.");
|
|
}, "[" + testPrefix + "] document.hasStorageAccess() should not be allowed by default unless in top-level frame or same-origin iframe.");
|
|
|
|
promise_test(async (t) => {
|
|
const description = "Promise should reject when called on a generated document not part of the DOM.";
|
|
const createdDocument = document.implementation.createDocument("", null);
|
|
|
|
// Can't use `promise_rejects_dom` here, since the error comes from the wrong global.
|
|
await createdDocument.hasStorageAccess().then(
|
|
t.unreached_func("Should have rejected: " + description), (e) => {
|
|
assert_equals(e.name, 'InvalidStateError', description);
|
|
});
|
|
}, "[" + testPrefix + "] document.hasStorageAccess() should reject in a document that isn't fully active.");
|
|
|
|
// Logic to load test cases within combinations of iFrames.
|
|
if (topLevelDocument) {
|
|
// This specific test will run only as a top level test (not as a worker).
|
|
// Specific hasStorageAccess() scenarios will be tested within the context
|
|
// of various iFrames
|
|
|
|
// Create a test with a single-child same-origin iframe.
|
|
RunTestsInIFrame("resources/hasStorageAccess-iframe.https.html?testCase=same-origin-frame");
|
|
|
|
// Create a test with a single-child cross-site iframe.
|
|
RunTestsInIFrame("https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/hasStorageAccess-iframe.https.html?testCase=cross-site-frame");
|
|
|
|
// Validate the nested-iframe scenario where the same-origin frame containing
|
|
// the tests is not the first child.
|
|
RunTestsInNestedIFrame("resources/hasStorageAccess-iframe.https.html?testCase=nested-same-origin-frame");
|
|
|
|
// Validate the nested-iframe scenario where the cross-site frame containing
|
|
// the tests is not the first child.
|
|
RunTestsInNestedIFrame("https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/hasStorageAccess-iframe.https.html?testCase=nested-cross-site-frame");
|
|
}
|