Skip to content

Commit

Permalink
Make Server-Timing tests more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
cvazac committed Oct 30, 2018
1 parent 7b078f0 commit b6ccb69
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
7 changes: 7 additions & 0 deletions common/performance-timeline-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ function test_entries(actualEntries, expectedEntries) {
}
})
}

function delayedLoadListener(callback) {
window.addEventListener('load', function() {
// TODO(cvazac) Remove this setTimeout when spec enforces sync entries
setTimeout(callback, 0)
})
}
4 changes: 2 additions & 2 deletions server-timing/cross_origin.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<meta charset='utf-8' />
<script src="/resources/testharness.js"></script>
<script src='/resources/testharnessreport.js'></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/performance-timeline-utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
Expand All @@ -20,7 +20,7 @@
document.getElementsByTagName('script')[0].parentNode.appendChild(img)
})

window.addEventListener('load', function() {
delayedLoadListener(function() {
function assertServerTimingEntries(url, expectedEntryCount) {
test_equals(performance.getEntriesByName(url)[0].serverTiming.length,
expectedEntryCount,
Expand Down
5 changes: 3 additions & 2 deletions server-timing/navigation_timing_idl.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<head>
<meta charset='utf-8' />
<script src="/resources/testharness.js"></script>
<script src='/resources/testharnessreport.js'></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/performance-timeline-utils.js"></script>
<script>
setup({explicit_done: true})
window.addEventListener('load', function(){
delayedLoadListener(function(){
assert_not_equals(typeof performance.getEntriesByType('navigation')[0].serverTiming, 'undefined',
'An instance of `PerformanceNavigationTiming` should have a `serverTiming` attribute.')
done()
Expand Down
5 changes: 3 additions & 2 deletions server-timing/resource_timing_idl.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<head>
<meta charset='utf-8' />
<script src="/resources/testharness.js"></script>
<script src='/resources/testharnessreport.js'></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/performance-timeline-utils.js"></script>
<script>
setup({explicit_done: true})
window.addEventListener('load', function(){
delayedLoadListener(function(){
assert_not_equals(typeof performance.getEntriesByType('resource')[0].serverTiming, 'undefined',
'An instance of `PerformanceResourceTiming` should have a `serverTiming` attribute.')
done()
Expand Down
5 changes: 3 additions & 2 deletions server-timing/server_timing_header-parsing.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<head>
<meta charset='utf-8' />
<script src="/resources/testharness.js"></script>
<script src='/resources/testharnessreport.js'></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/performance-timeline-utils.js"></script>
<script src="/common/performance-timeline-utils.js"></script>
<script>
setup({explicit_done: true})
Expand Down Expand Up @@ -49,6 +50,6 @@
document.getElementsByTagName('head')[0].appendChild(script)
urlToIndex[script.src] = i
}
window.addEventListener('load', runTests)
delayedLoadListener(runTests)
</script>
</head>
2 changes: 1 addition & 1 deletion server-timing/service_worker_idl.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<meta charset='utf-8' />
<script src="/resources/testharness.js"></script>
<script src='/resources/testharnessreport.js'></script>
<script src="/resources/testharnessreport.js"></script>
<script>
(async () => {
const scope = 'does/not/exist'
Expand Down
4 changes: 2 additions & 2 deletions server-timing/test_server_timing.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<head>
<meta charset='utf-8' />
<script src="/resources/testharness.js"></script>
<script src='/resources/testharnessreport.js'></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/performance-timeline-utils.js"></script>
<script>
setup({explicit_done: true})

window.addEventListener('load', function() {
delayedLoadListener(function() {
// there should be exactly three server-timing entries, 2 for document, 1 for img#one
test_entries(performance.getEntriesByType('navigation')[0].serverTiming, [{
duration: 1.1,
Expand Down

0 comments on commit b6ccb69

Please sign in to comment.