Bug 1504935 [wpt PR 13941] - ServiceWorker: Modernize clients-matchall-include-uncontrolled.https.html using async/await, a=testonly

Automatic update from web-platform-testsServiceWorker: Modernize clients-matchall-include-uncontrolled.https.html using async/await

Bug: 902201
Change-Id: Ib9fd5a5f0e9cc49cf653b6af768d00912c008deb
Reviewed-on: https://chromium-review.googlesource.com/c/1319392
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605617}

--

wpt-commits: 4c3ee3da47cafa07a045d99a2bca8a3ef688b1b3
wpt-pr: 13941
This commit is contained in:
Hiroki Nakagawa 2018-11-13 11:52:51 +00:00 коммит произвёл moz-wptsync-bot
Родитель 4c72a3c85b
Коммит 782e4db477
1 изменённых файлов: 31 добавлений и 52 удалений

Просмотреть файл

@ -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>