Bug 1462512 [wpt PR 11058] - Add a simple test for ResourceTiming |name| with Service Workers, a=testonly

Automatic update from web-platform-testsAdd a simple test for ResourceTiming |name| with Service Workers

This CL adds a test to check that the |name| of Resource Timing entries
is the original request URL even when a service worker uses
respondWith(fetch()) to respond with a different response URL.

Change-Id: I4fe61395c6d7c3b1b5fb5e4f131b131d90c33154
Reviewed-on: https://chromium-review.googlesource.com/1065013
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561228}

--

wpt-commits: 9633890103f1a7025405cab78b00bb318ed9ebc4
wpt-pr: 11058
This commit is contained in:
Nicolas Pena 2018-05-31 19:28:53 +00:00 коммит произвёл James Graham
Родитель aee1205c4b
Коммит fee8c46d22
4 изменённых файлов: 48 добавлений и 23 удалений

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

@ -607811,7 +607811,7 @@
"testharness"
],
"service-workers/service-worker/resource-timing.https.html": [
"23cadb03b48a885dbbd9a5dfdc38b5b58f99d18a",
"18979624d3fec57451f3eb41a67c2c0967f7da4f",
"testharness"
],
"service-workers/service-worker/resources/404.py": [
@ -608663,11 +608663,11 @@
"support"
],
"service-workers/service-worker/resources/resource-timing-iframe.sub.html": [
"75bd224a9680af0557c53fb6e77645e4e0b8173d",
"d14ea4b8a8418f20b126e835eec4c82871cce81a",
"support"
],
"service-workers/service-worker/resources/resource-timing-worker.js": [
"04a965dc0324c035bb3331e546d9bb43230d5eac",
"021564cc105a8a2a0340e95fbf7bfc4bffe49c35",
"support"
],
"service-workers/service-worker/resources/respond-then-throw-worker.js": [

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

@ -13,15 +13,18 @@ function crossOriginUrl(path) {
}
function verify(options) {
var url = options.mode === 'cross-origin' ? crossOriginUrl(options.resource)
const url = options.mode === 'cross-origin' ? crossOriginUrl(options.resource)
: resourceUrl(options.resource);
var entryList = options.performance.getEntriesByName(url);
if (entryList.length === 0 && options.allow_no_performance_entry) {
const entryList = options.performance.getEntriesByName(url);
if (options.should_no_performance_entry) {
// The performance timeline may not have an entry for a resource
// which failed to load.
assert_equals(entryList.length, 0, options.description);
return;
}
var entry = entryList[0];
assert_equals(entryList.length, 1, options.description);
const entry = entryList[0];
assert_equals(entry.entryType, 'resource', options.description);
assert_greater_than(entry.workerStart, 0, options.description);
assert_greater_than_equal(entry.workerStart, entry.startTime, options.description);
assert_less_than_equal(entry.workerStart, entry.fetchStart, options.description);
@ -42,12 +45,12 @@ function verify(options) {
}
}
async_test(function(t) {
var worker_url = 'resources/resource-timing-worker.js';
var scope = 'resources/resource-timing-iframe.sub.html';
var registration;
promise_test(function(t) {
const worker_url = 'resources/resource-timing-worker.js';
const scope = 'resources/resource-timing-iframe.sub.html';
let registration;
service_worker_unregister_and_register(t, worker_url, scope)
return service_worker_unregister_and_register(t, worker_url, scope)
.then(function(r) {
registration = r;
return wait_for_state(t, r.installing, 'activated');
@ -56,7 +59,7 @@ async_test(function(t) {
return with_iframe(scope);
})
.then(function(frame) {
var performance = frame.contentWindow.performance;
const performance = frame.contentWindow.performance;
verify({
performance: performance,
resource: 'resources/dummy.js',
@ -96,28 +99,45 @@ async_test(function(t) {
resource: 'resources/missing.jpg',
mode: 'same-origin',
description: 'Network fallback load failure',
allow_no_performance_entry: true,
should_no_performance_entry: true,
});
verify({
performance: performance,
resource: 'resources/missing.jpg',
mode: 'cross-origin',
description: 'Network fallback cross-origin load failure',
allow_no_performance_entry: true,
should_no_performance_entry: true,
});
// Tests for respondWith(fetch()).
verify({
performance: performance,
resource: 'resources/missing.jpg?SWRespondsWithFetch',
mode: 'same-origin',
description: 'Resource in iframe, nonexistent but responded with fetch to another.',
});
verify({
performance: performance,
resource: 'resources/dummy.txt?SWFetched',
mode: 'same-origin',
description: 'Resource fetched as response from missing.jpg?SWRespondsWithFetch.',
should_no_performance_entry: true,
});
// Test for a normal resource that is unaffected by the Service Worker.
verify({
performance: performance,
resource: 'resources/empty-worker.js',
mode: 'same-origin',
description: 'Resource untouched by the Service Worker.',
});
frame.remove();
return registration.unregister();
})
.then(function() {
t.done();
})
.catch(unreached_rejection(t));
});
}, 'Controlled resource loads');
test(function() {
var url = resourceUrl('resources/test-helpers.sub.js');
var entry = window.performance.getEntriesByName(url)[0];
test(() => {
const url = resourceUrl('resources/test-helpers.sub.js');
const entry = window.performance.getEntriesByName(url)[0];
assert_equals(entry.workerStart, 0, 'Non-controlled');
}, 'Non-controlled resource loads');

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

@ -6,3 +6,5 @@
<img src="https://{{domains[www1]}}:{{ports[https][0]}}/service-workers/service-worker/resources/square.png">
<img src="missing.jpg">
<img src="https://{{domains[www1]}}:{{ports[https][0]}}/service-workers/service-worker/resources/missing.jpg">
<img src='missing.jpg?SWRespondsWithFetch'>
<script src='empty-worker.js'></script>

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

@ -6,4 +6,7 @@ self.addEventListener('fetch', function(event) {
setTimeout(_ => resolve(new Response('// Empty javascript')), 50);
}));
}
else if (event.request.url.indexOf('missing.jpg?SWRespondsWithFetch') != -1) {
event.respondWith(fetch('dummy.txt?SWFetched'));
}
});