Skip to content

Commit

Permalink
service worker: Update WPT test for resource timing
Browse files Browse the repository at this point in the history
Before this CL, the test assumed that there should be a
PerformanceResourceTiming for fetching 'resources/missing.jpg'.
As the spec says [1], this assumption is not guaranteed. In fact,
Chromium doesn't add PerformanceResourceTiming for resouces which
failed to load. This CL updates the test to check there is a
corresponding PerformanceResourceTiming entry before doing
verifications.

[1] https://w3c.github.io/resource-timing/#resources-included-in-the-performanceresourcetiming-interface

Bug: 782958
Change-Id: I85e75a8dade9f6620d22a54eaf97468f00360023
Reviewed-on: https://chromium-review.googlesource.com/930109
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538648}
  • Loading branch information
bashi authored and chromium-wpt-export-bot committed Feb 23, 2018
1 parent 7bfbc0f commit 30c0131
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 29 deletions.
98 changes: 69 additions & 29 deletions service-workers/service-worker/resource-timing.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@
return get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() + path;
}

function verify(performance, resource, mode, description) {
var url = mode === 'cross-origin' ? crossOriginUrl(resource)
: resourceUrl(resource);
var entryList = performance.getEntries();
var entry = performance.getEntriesByName(url)[0];
assert_greater_than(entry.workerStart, 0, description);
assert_greater_than_equal(entry.workerStart, entry.startTime, description);
assert_less_than_equal(entry.workerStart, entry.fetchStart, description);
if (mode === 'cross-origin') {
assert_equals(entry.responseStart, 0, description);
assert_greater_than_equal(entry.responseEnd, entry.fetchStart, description);
function verify(options) {
var 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) {
// The performance timeline may not have an entry for a resource
// which failed to load.
return;
}
var entry = entryList[0];
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);
if (options.mode === 'cross-origin') {
assert_equals(entry.responseStart, 0, options.description);
assert_greater_than_equal(entry.responseEnd, entry.fetchStart, options.description);
} else {
assert_greater_than_equal(entry.responseStart, entry.fetchStart, description);
assert_greater_than_equal(entry.responseEnd, entry.responseStart, description);
assert_greater_than_equal(entry.responseStart, entry.fetchStart, options.description);
assert_greater_than_equal(entry.responseEnd, entry.responseStart, options.description);
}
assert_greater_than(entry.responseEnd, entry.fetchStart, description);
assert_greater_than(entry.duration, 0, description);
if (resource.indexOf('redirect.py') != -1) {
assert_greater_than(entry.responseEnd, entry.fetchStart, options.description);
assert_greater_than(entry.duration, 0, options.description);
if (options.resource.indexOf('redirect.py') != -1) {
assert_less_than_equal(entry.workerStart, entry.redirectStart,
description);
options.description);
} else {
assert_equals(entry.redirectStart, 0, description);
assert_equals(entry.redirectStart, 0, options.description);
}
}

Expand All @@ -52,19 +57,54 @@
})
.then(function(frame) {
var performance = frame.contentWindow.performance;
verify(performance, 'resources/dummy.js', 'same-origin',
'Generated response');
verify(performance, 'resources/empty.js', 'same-origin',
'Network fallback');
verify(performance, 'resources/redirect.py?Redirect=empty.js',
'same-origin', 'Redirect');
verify(performance, 'resources/missing.jpg', 'same-origin',
'Network fallback image');

verify({
performance: performance,
resource: 'resources/dummy.js',
mode: 'same-origin',
description: 'Generated response',
});
verify({
performance: performance,
resource: 'resources/empty.js',
mode: 'same-origin',
description: 'Network fallback',
});
verify({
performance: performance,
resource: 'resources/redirect.py?Redirect=empty.js',
mode: 'same-origin',
description: 'Redirect',
});
verify({
performance: performance,
resource: 'resources/square.png',
mode: 'same-origin',
description: 'Network fallback image',
});
// Test that worker start is available on cross-origin no-cors
// subresources.
verify(performance, 'resources/missing.jpg', 'cross-origin',
'Network fallback cross-origin image');
verify({
performance: performance,
resource: 'resources/square.png',
mode: 'cross-origin',
description: 'Network fallback cross-origin image',
});

// Tests for resouces which failed to load.
verify({
performance: performance,
resource: 'resources/missing.jpg',
mode: 'same-origin',
description: 'Network fallback load failure',
allow_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,
});

frame.remove();
return registration.unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<script src="empty.js"></script>
<script src="dummy.js"></script>
<script src="redirect.py?Redirect=empty.js"></script>
<img src="square.png">
<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">

0 comments on commit 30c0131

Please sign in to comment.