Update web-platform-tests to revision a3a4442b04c37155f81c4ad4ae9c06339f76ce14

This commit is contained in:
WPT Sync Bot 2019-09-19 10:23:35 +00:00
parent 7b653cad7b
commit ba0f5f096a
204 changed files with 4645 additions and 1001 deletions

View file

@ -0,0 +1,59 @@
// META: script=helpers.js
'use strict';
// Unless overridden by a query string we expect access to be granted. This lets
// us re-use this test file within various iframes of differing origin.
let expectAccessAllowed = true;
// Prefix each test case with an indicator so we know what context they are run in
// if they are used in multiple iframes.
let testPrefix = "top-level-context";
// Keep track of if we run these tests in a nested context, we don't want to
// recurse forever.
let topLevelDocument = true;
// Check if we were called with a query string of allowed=false. This would
// indicate we expect the access to be denied.
let queryParams = window.location.search.substring(1).split("&");
queryParams.forEach(function (param, index) {
if (param.toLowerCase() == "allowed=false") {
expectAccessAllowed = false;
} else if (param.toLowerCase() == "rootdocument=false") {
topLevelDocument = false;
} else if (param.split("=")[0].toLowerCase() == "testcase") {
testPrefix = param.split("=")[1];
}
});
// Common tests to run in all frames.
test(() => {
assert_not_equals(document.hasStorageAccess, undefined);
}, "[" + testPrefix + "] document.hasStorageAccess() should be supported on the document interface");
promise_test(() => {
return document.hasStorageAccess().then(hasAccess => {
assert_equals(hasAccess, expectAccessAllowed, "Access should be granted by default: " + expectAccessAllowed);
});
}, "[" + testPrefix + "] document.hasStorageAccess() should be allowed by default: " + expectAccessAllowed);
// 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("hasStorageAccess.sub.window.html?testCase=same-origin-frame&rootdocument=false");
// Create a test with a single-child cross-origin iframe.
RunTestsInIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/hasStorageAccess.sub.window.html?testCase=cross-origin-frame&allowed=false&rootdocument=false");
// Validate the nested-iframe scenario where the same-origin frame containing
// the tests is not the first child.
RunTestsInNestedIFrame("hasStorageAccess.sub.window.html?testCase=nested-same-origin-frame&rootdocument=false");
// Validate the nested-iframe scenario where the cross-origin frame containing
// the tests is not the first child.
RunTestsInNestedIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/hasStorageAccess.sub.window.html?testCase=nested-cross-origin-frame&allowed=false&rootdocument=false");
}

View file

@ -0,0 +1,25 @@
'use strict';
function RunTestsInIFrame(sourceURL) {
let frame = document.createElement('iframe');
frame.src = sourceURL;
document.body.appendChild(frame);
fetch_tests_from_window(frame.contentWindow);
}
function RunTestsInNestedIFrame(sourceURL) {
let nestedFrame = document.createElement('iframe');
document.body.appendChild(nestedFrame);
let content = `
<script src="/resources/testharness.js"></script>
<script src="helpers.js"></script>
<body>
<script>
RunTestsInIFrame("${sourceURL}");
</sc` + `ript>
`;
nestedFrame.contentDocument.write(content);
nestedFrame.contentDocument.close();
fetch_tests_from_window(nestedFrame.contentWindow);
}

View file

@ -0,0 +1,23 @@
// META: global=window,worker
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js
'use strict';
const idl = `
[OverrideBuiltins]
partial interface Document {
Promise<bool> hasStorageAccess();
Promise<void> requestStorageAccess();
};`;
idl_test(
// Since we are testing a locally defined idl we'll manually manage our deps below.
[],
[],
idl_array => {
return fetch_spec('dom').then(function(idl_text) {
idl_array.add_idls(idl);
idl_array.add_dependency_idls(idl_text);
});
}
);

View file

@ -0,0 +1,55 @@
// META: script=helpers.js
'use strict';
// Prefix each test case with an indicator so we know what context they are run in
// if they are used in multiple iframes.
let testPrefix = "top-level-context";
// Keep track of if we run these tests in a nested context, we don't want to
// recurse forever.
let topLevelDocument = true;
// Check if we were called with a query string of allowed=false. This would
// indicate we expect the access to be denied.
let queryParams = window.location.search.substring(1).split("&");
queryParams.forEach(function (param, index) {
if (param.toLowerCase() == "rootdocument=false") {
topLevelDocument = false;
} else if (param.split("=")[0].toLowerCase() == "testcase") {
testPrefix = param.split("=")[1];
}
});
// Common tests to run in all frames.
test(() => {
assert_not_equals(document.requestStorageAccess, undefined);
}, "[" + testPrefix + "] document.requestStorageAccess() should be supported on the document interface");
promise_test(t => {
let promise = document.requestStorageAccess();
let description = "document.requestStorageAccess() call without user gesture";
return promise.then(t.unreached_func("Should have rejected: " + description)).catch(function(e) {
assert_equals(undefined, e, description);
});
}, "[" + testPrefix + "] document.requestStorageAccess() should be rejected by default with no user gesture");
// 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 requestStorageAccess() scenarios will be tested within the context
// of various iFrames
// Create a test with a single-child same-origin iframe.
RunTestsInIFrame("requestStorageAccess.sub.window.html?testCase=same-origin-frame&rootdocument=false");
// Create a test with a single-child cross-origin iframe.
RunTestsInIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/requestStorageAccess.sub.window.html?testCase=cross-origin-frame&rootdocument=false");
// Validate the nested-iframe scenario where the same-origin frame containing
// the tests is not the first child.
RunTestsInNestedIFrame("requestStorageAccess.sub.window.html?testCase=nested-same-origin-frame&rootdocument=false");
// Validate the nested-iframe scenario where the cross-origin frame containing
// the tests is not the first child.
RunTestsInNestedIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/requestStorageAccess.sub.window.html?testCase=nested-cross-origin-frame&rootdocument=false");
}

View file

@ -0,0 +1,7 @@
'use strict';
test(() => {
let iframe = document.createElement('iframe');
assert_true(iframe.sandbox.supports('allow-storage-access-by-user-activation'), '`allow-storage-access-by-user-activation`' +
'sandbox attribute should be supported');
}, "`allow-storage-access-by-user-activation` sandbox attribute is supported");