Update web-platform-tests to revision 615bb572c95add74ca4fb9fed4af5269a49cf4ef

This commit is contained in:
WPT Sync Bot 2018-11-06 20:34:54 -05:00
parent b628b6ef8e
commit 0aa76d7524
162 changed files with 2069 additions and 636 deletions

View file

@ -4,35 +4,26 @@
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
var base_url = 'resources/blank.html'; // This is out-of-scope.
var scope = base_url + '?clients-matchAll-includeUncontrolled';
var frames = [];
const base_url = 'resources/blank.html'; // This is out-of-scope.
const scope = base_url + '?clients-matchAll-includeUncontrolled';
let frames = [];
// Creates 3 iframes, 2 for in-scope and 1 for out-of-scope.
// The frame opened for scope + '#2' is returned via a promise.
function create_iframes(scope) {
return with_iframe(base_url)
.then(function(frame0) {
frames.push(frame0);
return with_iframe(scope + '#1');
})
.then(function(frame1) {
frames.push(frame1);
return with_iframe(scope + '#2');
})
.then(function(frame2) {
frames.push(frame2);
return frame2;
})
// Creates 3 iframes, 2 for in-scope and 1 for out-of-scope. Returns the frame
// opened for scope + '#2'.
async function create_iframes(scope) {
frames.push(await with_iframe(base_url));
frames.push(await with_iframe(scope + '#1'));
frames.push(await with_iframe(scope + '#2'));
return frames[2];
}
var expected_without_include_uncontrolled = [
const expected_without_include_uncontrolled = [
// visibilityState, focused, url, type, frameType
['visible', false, new URL(scope + '#1', location).toString(), 'window', 'nested'],
['visible', true, new URL(scope + '#2', location).toString(), 'window', 'nested']
];
var expected_with_include_uncontrolled = [
const expected_with_include_uncontrolled = [
// visibilityState, focused, url, type, frameType
['visible', true, location.href, 'window', 'top-level'],
['visible', false, new URL(scope + '#1', location).toString(), 'window', 'nested'],
@ -44,21 +35,21 @@ function test_matchall(frame, expected, query_options) {
// Make sure we have focus for '#2' frame and its parent window.
frame.focus();
frame.contentWindow.focus();
expected.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; });
return new Promise(function(resolve, reject) {
var channel = new MessageChannel();
channel.port1.onmessage = function(e) {
expected.sort((a, b) => a[2] > b[2] ? 1 : -1);
return new Promise((resolve, reject) => {
const channel = new MessageChannel();
channel.port1.onmessage = e => {
// Ignore hidden clients which may be coming from background tabs, or
// clients unrelated to this test.
var data = e.data.filter(function(info) {
const data = e.data.filter(info => {
return info[0] == 'visible' &&
info[2].indexOf('service-worker') > -1;
});
data.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; });
data.sort((a, b) => a[2] > b[2] ? 1 : -1);
assert_equals(data.length, expected.length);
for (var i = 0; i < data.length; i++)
for (let i = 0; i < data.length; i++)
assert_array_equals(data[i], expected[i]);
resolve(frame);
resolve();
};
frame.contentWindow.navigator.serviceWorker.controller.postMessage(
{port:channel.port2, options:query_options},
@ -69,27 +60,15 @@ function test_matchall(frame, expected, query_options) {
// Run clients.matchAll without and with includeUncontrolled=true.
// (We want to run the two tests sequentially in the same promise_test
// so that we can use the same set of iframes without intefering each other.
promise_test(function(t) {
return service_worker_unregister_and_register(
t, 'resources/clients-matchall-worker.js', scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return create_iframes(scope); })
.then(function(frame) {
return test_matchall(frame, expected_without_include_uncontrolled);
})
.then(function(frame) {
return test_matchall(frame, expected_with_include_uncontrolled,
{includeUncontrolled:true});
})
.then(function() {
frames.forEach(function(f) { f.remove() });
});
}, 'Verify matchAll() respect includeUncontrolled');
promise_test(async t => {
const registration =
await service_worker_unregister_and_register(
t, 'resources/clients-matchall-worker.js', scope);
t.add_cleanup(() => service_worker_unregister(t, scope));
await wait_for_state(t, registration.installing, 'activated');
const frame = await create_iframes(scope);
await test_matchall(frame, expected_without_include_uncontrolled);
await test_matchall(frame, expected_with_include_uncontrolled,
{includeUncontrolled:true});
}, 'Verify matchAll() respect includeUncontrolled');
</script>

View file

@ -5,50 +5,38 @@
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
promise_test(t => {
var script = 'resources/postmessage-to-client-worker.js';
var scope = 'resources/blank.html';
var w;
promise_test(async t => {
const script = 'resources/postmessage-to-client-worker.js';
const scope = 'resources/blank.html';
return service_worker_unregister_and_register(t, script, scope)
.then(registration => {
t.add_cleanup(() => registration.unregister());
return wait_for_state(t, registration.installing, 'activated');
})
.then(() => with_iframe(scope))
.then(frame => {
t.add_cleanup(() => frame.remove());
const registration =
await service_worker_unregister_and_register(t, script, scope);
t.add_cleanup(() => registration.unregister());
await wait_for_state(t, registration.installing, 'activated');
const frame = await with_iframe(scope);
t.add_cleanup(() => frame.remove());
const w = frame.contentWindow;
return new Promise(resolve => {
w = frame.contentWindow;
w.navigator.serviceWorker.onmessage = resolve;
w.navigator.serviceWorker.controller.postMessage('ping');
});
})
.then(e => {
var message = e.data;
assert_equals(e.constructor, w.MessageEvent,
'message events should use MessageEvent interface.');
assert_equals(e.type, 'message', 'type should be "message".');
assert_equals(e.bubbles, false, 'message events should not bubble.');
assert_equals(e.cancelable, false,
'message events should not be cancelable.');
assert_equals(
e.origin, location.origin,
'origin of message should be origin of Service Worker.');
assert_equals(e.lastEventId, '',
'lastEventId should be an empty string.');
assert_equals(e.source.constructor, w.ServiceWorker,
'source should use ServiceWorker interface.');
assert_equals(
e.source, w.navigator.serviceWorker.controller,
'source should be the service worker that sent the message.');
assert_equals(e.ports.length, 0, 'ports should be an empty array.');
assert_equals(message, 'Sending message via clients');
return new Promise(resolve => {
w.navigator.serviceWorker.onmessage = resolve;
});
})
.then(e => { assert_equals(e.data, 'quit'); });
}, 'postMessage from ServiceWorker to Client.');
w.navigator.serviceWorker.controller.postMessage('ping');
let e = await new Promise(r => w.navigator.serviceWorker.onmessage = r);
assert_equals(e.constructor, w.MessageEvent,
'message events should use MessageEvent interface.');
assert_equals(e.type, 'message', 'type should be "message".');
assert_false(e.bubbles, 'message events should not bubble.');
assert_false(e.cancelable, 'message events should not be cancelable.');
assert_equals(e.origin, location.origin,
'origin of message should be origin of Service Worker.');
assert_equals(e.lastEventId, '',
'lastEventId should be an empty string.');
assert_equals(e.source.constructor, w.ServiceWorker,
'source should use ServiceWorker interface.');
assert_equals(e.source, w.navigator.serviceWorker.controller,
'source should be the service worker that sent the message.');
assert_equals(e.ports.length, 0, 'ports should be an empty array.');
assert_equals(e.data, 'Sending message via clients');
e = await new Promise(r => w.navigator.serviceWorker.onmessage = r);
assert_equals(e.data, 'quit');
}, 'postMessage from ServiceWorker to Client.');
</script>