Update web-platform-tests to revision 04cd5eb8e5c47e4fe341f2fb541d39fa2346f464

This commit is contained in:
WPT Sync Bot 2018-11-16 21:03:13 -05:00
parent 0ab2c3f8a3
commit 1d0624b343
226 changed files with 4495 additions and 903 deletions

View file

@ -49,6 +49,162 @@ promise_test(function(t) {
});
}, 'Test Clients.get()');
promise_test((t) => {
let frame = null;
const scope = 'resources/simple.html';
const outerSwContainer = navigator.serviceWorker;
let innerSwReg = null;
let innerSw = null;
return service_worker_unregister_and_register(
t, 'resources/clients-get-resultingClientId-worker.js', scope)
.then((registration) => {
innerSwReg = registration;
add_completion_callback(function() { registration.unregister(); });
return wait_for_state(t, registration.installing, 'activated');
})
.then(() => {
// load frame and get resulting client id
let channel = new MessageChannel();
innerSw = innerSwReg.active;
let p = new Promise(resolve => {
function getResultingClientId(e) {
if (e.data.msg == 'getResultingClientId') {
const { resultingClientId } = e.data;
channel.port1.removeEventListener('message', getResultingClientId);
resolve({ resultingClientId, port: channel.port1 });
}
}
channel.port1.onmessage = getResultingClientId;
});
return with_iframe(scope).then((iframe) => {
innerSw.postMessage(
{ port: channel.port2, msg: 'getResultingClientId' },
[channel.port2],
);
frame = iframe;
frame.focus();
add_completion_callback(() => iframe.remove());
return p;
});
})
.then(({ resultingClientId, port }) => {
// query service worker for clients.get(resultingClientId)
let channel = new MessageChannel();
let p = new Promise(resolve => {
function getIsResultingClientUndefined(e) {
if (e.data.msg == 'getIsResultingClientUndefined') {
let { isResultingClientUndefined } = e.data;
port.removeEventListener('message', getIsResultingClientUndefined);
resolve(isResultingClientUndefined);
}
}
port.onmessage = getIsResultingClientUndefined;
});
innerSw.postMessage(
{ port: channel.port2, msg: 'getIsResultingClientUndefined', resultingClientId },
[channel.port2],
);
return p;
})
.then((isResultingClientUndefined) => {
assert_false(isResultingClientUndefined, 'Clients.get(FetchEvent.resultingClientId) resolved with a Client');
});
}, 'Test successful Clients.get(FetchEvent.resultingClientId)');
promise_test((t) => {
const scope = 'resources/simple.html?fail';
const outerSwContainer = navigator.serviceWorker;
let innerSwReg = null;
let innerSw = null;
return service_worker_unregister_and_register(
t, 'resources/clients-get-resultingClientId-worker.js', scope)
.then((registration) => {
innerSwReg = registration;
add_completion_callback(function() { registration.unregister(); });
return wait_for_state(t, registration.installing, 'activated');
})
.then(() => {
// load frame, destroying it while loading, and get resulting client id
innerSw = innerSwReg.active;
let iframe = document.createElement('iframe');
iframe.className = 'test-iframe';
iframe.src = scope;
function destroyIframe(e) {
if (e.data.msg == 'destroyResultingClient') {
iframe.remove();
iframe = null;
innerSw.postMessage({ msg: 'resultingClientDestroyed' });
}
}
outerSwContainer.addEventListener('message', destroyIframe);
let p = new Promise(resolve => {
function resultingClientDestroyedAck(e) {
if (e.data.msg == 'resultingClientDestroyedAck') {
let { resultingDestroyedClientId } = e.data;
outerSwContainer.removeEventListener('message', resultingClientDestroyedAck);
resolve(resultingDestroyedClientId);
}
}
outerSwContainer.addEventListener('message', resultingClientDestroyedAck);
});
document.body.appendChild(iframe);
return p;
})
.then((resultingDestroyedClientId) => {
// query service worker for clients.get(resultingDestroyedClientId)
let channel = new MessageChannel();
let p = new Promise((resolve, reject) => {
function getIsResultingClientUndefined(e) {
if (e.data.msg == 'getIsResultingClientUndefined') {
let { isResultingClientUndefined } = e.data;
channel.port1.removeEventListener('message', getIsResultingClientUndefined);
resolve(isResultingClientUndefined);
}
}
channel.port1.onmessage = getIsResultingClientUndefined;
});
innerSw.postMessage(
{ port: channel.port2, msg: 'getIsResultingClientUndefined', resultingClientId: resultingDestroyedClientId },
[channel.port2],
);
return p;
})
.then((isResultingClientUndefined) => {
assert_true(isResultingClientUndefined, 'Clients.get(FetchEvent.resultingClientId) resolved with `undefined`');
});
}, 'Test unsuccessful Clients.get(FetchEvent.resultingClientId)');
function wait_for_clientId() {
return new Promise(function(resolve, reject) {
function get_client_id(e) {

View file

@ -116,7 +116,6 @@ promise_test(t => {
})
.then(function(response) { return response.text(); })
.then(function(response_text) {
var new_client_id = response_text.substr(17);
assert_equals(
response_text.substr(0, 15),
'Client ID Found',
@ -124,6 +123,28 @@ promise_test(t => {
});
}, 'Service Worker responds to fetch event with an existing client id');
promise_test(t => {
const page_url = 'resources/simple.html?resultingClientId';
const expected_found = 'Resulting Client ID Found';
const expected_not_found = 'Resulting Client ID Not Found';
return with_iframe(page_url)
.then(function(frame) {
t.add_cleanup(() => { frame.remove(); });
assert_equals(
frame.contentDocument.body.textContent.substr(0, expected_found.length),
expected_found,
'Service Worker should respond with an existing resulting client id for non-subresource requests');
return frame.contentWindow.fetch('resources/other.html?resultingClientId');
})
.then(function(response) { return response.text(); })
.then(function(response_text) {
assert_equals(
response_text.substr(0),
expected_not_found,
'Service Worker should respond with an empty resulting client id for subresource requests');
});
}, 'Service Worker responds to fetch event with the correct resulting client id');
promise_test(t => {
const page_url = 'resources/simple.html?ignore';
return with_iframe(page_url)

View file

@ -13,6 +13,7 @@ function import_test(testCase) {
navigator.serviceWorker.onmessage = resolve;
});
await service_worker_unregister(t, testCase.scriptURL);
t.add_cleanup(() => service_worker_unregister(t, testCase.scriptURL));
const registration = await navigator.serviceWorker.register(
testCase.scriptURL,
{ scope: testCase.scriptURL, type: 'module' });

View file

@ -0,0 +1,64 @@
let savedPort = null;
let savedResultingClientId = null;
async function destroyResultingClient(e) {
const outer = await self.clients.matchAll({ type: 'window', includeUncontrolled: true })
.then((clientList) => {
for (let c of clientList) {
if (c.url.endsWith('clients-get.https.html')) {
c.focus();
return c;
}
}
});
const p = new Promise(resolve => {
function resultingClientDestroyed(evt) {
if (evt.data.msg == 'resultingClientDestroyed') {
self.removeEventListener('message', resultingClientDestroyed);
resolve(outer);
}
}
self.addEventListener('message', resultingClientDestroyed);
});
outer.postMessage({ msg: 'destroyResultingClient' });
return await p;
}
self.addEventListener('fetch', async (e) => {
let { resultingClientId } = e;
savedResultingClientId = resultingClientId;
if (e.request.url.endsWith('simple.html?fail')) {
e.waitUntil(new Promise(async (resolve) => {
let outer = await destroyResultingClient(e);
outer.postMessage({ msg: 'resultingClientDestroyedAck',
resultingDestroyedClientId: savedResultingClientId });
resolve();
}));
} else {
e.respondWith(fetch(e.request));
}
});
self.addEventListener('message', (e) => {
let { msg, port, resultingClientId } = e.data;
savedPort = savedPort || port;
if (msg == 'getIsResultingClientUndefined') {
self.clients.get(resultingClientId).then((client) => {
let isUndefined = typeof client == 'undefined';
savedPort.postMessage({ msg: 'getIsResultingClientUndefined',
isResultingClientUndefined: isUndefined });
});
}
if (msg == 'getResultingClientId') {
savedPort.postMessage({ msg: 'getResultingClientId',
resultingClientId: savedResultingClientId });
}
});

View file

@ -37,6 +37,16 @@ function handleClientId(event) {
event.respondWith(new Response(body));
}
function handleResultingClientId(event) {
var body;
if (event.resultingClientId !== "") {
body = 'Resulting Client ID Found: ' + event.resultingClientId;
} else {
body = 'Resulting Client ID Not Found';
}
event.respondWith(new Response(body));
}
function handleNullBody(event) {
event.respondWith(new Response());
}
@ -155,6 +165,7 @@ self.addEventListener('fetch', function(event) {
{ pattern: '?referrerPolicy', fn: handleReferrerPolicy },
{ pattern: '?referrer', fn: handleReferrer },
{ pattern: '?clientId', fn: handleClientId },
{ pattern: '?resultingClientId', fn: handleResultingClientId },
{ pattern: '?ignore', fn: function() {} },
{ pattern: '?null', fn: handleNullBody },
{ pattern: '?fetch', fn: handleFetch },

View file

@ -94,9 +94,9 @@ function registration_tests_scope(register_method, check_error_types) {
var script = 'resources/empty-worker.js';
var scope = 'filesystem:' + normalizeURL('resources/scope/filesystem-scope-url');
return promise_rejects(t,
check_error_types ? 'SecurityError' : null,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
'Registering with the scope that has same-origin filesystem: URL ' +
'should fail with SecurityError.');
'should fail with TypeError.');
}, 'Scope URL is same-origin filesystem: URL');
}

View file

@ -70,9 +70,9 @@ function registration_tests_security_error(register_method, check_error_types) {
var script = 'filesystem:' + normalizeURL('resources/empty-worker.js');
var scope = 'resources/scope/filesystem-script-url';
return promise_rejects(t,
check_error_types ? 'SecurityError' : null,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
'Registering a script which has same-origin filesystem: URL should ' +
'fail with SecurityError.');
'fail with TypeError.');
}, 'Script URL is same-origin filesystem: URL');
}