Update web-platform-tests to revision e03a9b1341ae9bdb1e4fa03765257b84d26fe2f1

This commit is contained in:
Josh Matthews 2017-10-16 11:11:04 -04:00
parent 7d05c76d18
commit 20a833eb75
5167 changed files with 4696 additions and 297370 deletions

View file

@ -74,6 +74,37 @@ function test_feature_availability_with_post_message_result(
test_feature_availability(null, test, src, test_result, allow_attribute);
}
// If this page is intended to test the named feature (according to the URL),
// tests the feature availability and posts the result back to the parent.
// Otherwise, does nothing.
function test_feature_in_iframe(feature_name, feature_promise_factory) {
if (location.hash.includes(feature_name)) {
feature_promise_factory().then(
() => window.parent.postMessage('#OK', '*'),
(e) => window.parent.postMessage('#' + e.toString(), '*'));
}
}
// Returns true if the URL for this page indicates that it is embedded in an
// iframe.
function page_loaded_in_iframe() {
return location.hash.startsWith('#iframe');
}
// Returns a same-origin (relative) URL suitable for embedding in an iframe for
// testing the availability of the feature.
function same_origin_url(feature_name) {
// Append #iframe to the URL so we can detect the iframe'd version of the
// page.
return location.pathname + '#iframe#' + feature_name;
}
// Returns a cross-origin (absolute) URL suitable for embedding in an iframe for
// testing the availability of the feature.
function cross_origin_url(base_url, feature_name) {
return base_url + same_origin_url(feature_name);
}
// This function runs all feature policy tests for a particular feature that
// has a default policy of "self". This includes testing:
// 1. Feature usage succeeds by default in the top level frame.
@ -103,28 +134,20 @@ function run_all_fp_tests_allow_self(
cross_origin, feature_name, error_name, feature_promise_factory) {
// This may be the version of the page loaded up in an iframe. If so, just
// post the result of running the feature promise back to the parent.
if (location.hash.startsWith('#iframe')) {
// This makes it possible to test multiple features in the one test file.
if (!location.hash.includes(feature_name))
return;
feature_promise_factory().then(
() => window.parent.postMessage('#OK', '*'),
(e) => window.parent.postMessage('#' + e.toString(), '*'));
if (page_loaded_in_iframe()) {
test_feature_in_iframe(feature_name, feature_promise_factory);
return;
}
// Run the various tests.
// 1. Top level frame.
// 1. Allowed in top-level frame.
promise_test(
() => feature_promise_factory(),
'Default "' + feature_name +
'" feature policy ["self"] allows the top-level document.');
// 2. Same-origin iframe.
// Append #iframe to the URL so we can detect the iframe'd version of the
// page.
const same_origin_frame_pathname =
location.pathname + '#iframe#' + feature_name;
// 2. Allowed in same-origin iframe.
const same_origin_frame_pathname = same_origin_url(feature_name);
async_test(
t => {
test_feature_availability_with_post_message_result(
@ -133,8 +156,8 @@ function run_all_fp_tests_allow_self(
'Default "' + feature_name +
'" feature policy ["self"] allows same-origin iframes.');
// 3. Cross-origin iframe.
const cross_origin_frame_url = cross_origin + same_origin_frame_pathname;
// 3. Blocked in cross-origin iframe.
const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);
async_test(
t => {
test_feature_availability_with_post_message_result(
@ -143,7 +166,7 @@ function run_all_fp_tests_allow_self(
'Default "' + feature_name +
'" feature policy ["self"] disallows cross-origin iframes.');
// 4. Cross-origin iframe with "allow" attribute.
// 4. Allowed in cross-origin iframe with "allow" attribute.
async_test(
t => {
test_feature_availability_with_post_message_result(
@ -152,3 +175,75 @@ function run_all_fp_tests_allow_self(
'Feature policy "' + feature_name +
'" can be enabled in cross-origin iframes using "allow" attribute.');
}
// This function runs all feature policy tests for a particular feature that
// has a default policy of "*". This includes testing:
// 1. Feature usage succeeds by default in the top level frame.
// 2. Feature usage succeeds by default in a same-origin iframe.
// 3. Feature usage succeeds by default in a cross-origin iframe.
// 4. Feature usage fails when an allow attribute is specified on a
// cross-origin iframe with a value of "feature-name 'none'".
//
// The same page which called this function will be loaded in the iframe in
// order to test feature usage there. When this function is called in that
// context it will simply run the feature and return a result back via
// postMessage.
//
// Arguments:
// cross_origin: A cross-origin URL base to be used to load the page which
// called into this function.
// feature_name: The name of the feature as it should be specified in an
// allow attribute.
// error_name: If feature usage does not succeed, this is the string
// representation of the error that will be passed in the rejected
// promise.
// feature_promise_factory: A function which returns a promise which tests
// feature usage. If usage succeeds, the promise should resolve. If it
// fails, the promise should reject with an error that can be
// represented as a string.
function run_all_fp_tests_allow_all(
cross_origin, feature_name, error_name, feature_promise_factory) {
// This may be the version of the page loaded up in an iframe. If so, just
// post the result of running the feature promise back to the parent.
if (page_loaded_in_iframe()) {
test_feature_in_iframe(feature_name, feature_promise_factory);
return;
}
// Run the various tests.
// 1. Allowed in top-level frame.
promise_test(
() => feature_promise_factory(),
'Default "' + feature_name +
'" feature policy ["*"] allows the top-level document.');
// 2. Allowed in same-origin iframe.
const same_origin_frame_pathname = same_origin_url(feature_name);
async_test(
t => {
test_feature_availability_with_post_message_result(
t, same_origin_frame_pathname, '#OK');
},
'Default "' + feature_name +
'" feature policy ["*"] allows same-origin iframes.');
// 3. Allowed in cross-origin iframe.
const cross_origin_frame_url = cross_origin_url(cross_origin, feature_name);
async_test(
t => {
test_feature_availability_with_post_message_result(
t, cross_origin_frame_url, '#OK');
},
'Default "' + feature_name +
'" feature policy ["*"] allows cross-origin iframes.');
// 4. Blocked in cross-origin iframe with "allow" attribute set to 'none'.
async_test(
t => {
test_feature_availability_with_post_message_result(
t, cross_origin_frame_url, '#' + error_name,
feature_name + " 'none'");
},
'Feature policy "' + feature_name +
'" can be disabled in cross-origin iframes using "allow" attribute.');
}