Skip to content

Commit 273f84e

Browse files
avivkellerruyadorno
authored andcommitted
test: update performance-timeline wpt
PR-URL: #55197 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 42ac0c2 commit 273f84e

File tree

51 files changed

+2053
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2053
-2
lines changed

test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Last update:
2424
- html/webappapis/structured-clone: https://github.com/web-platform-tests/wpt/tree/47d3fb280c/html/webappapis/structured-clone
2525
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/5873f2d8f1/html/webappapis/timers
2626
- interfaces: https://github.com/web-platform-tests/wpt/tree/e90ece61d6/interfaces
27-
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
27+
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/94caab7038/performance-timeline
2828
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
2929
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
3030
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/common/utils.js"></script>
8+
<script src="/common/dispatcher/dispatcher.js"></script>
9+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
10+
</head>
11+
12+
<body>
13+
<script>
14+
const BackForwardCacheRestorationName = '';
15+
const BackForwardCacheRestorationType = 'back-forward-cache-restoration';
16+
17+
let getNavigationId = (i) => {
18+
let identifier = 'mark' + i;
19+
performance.mark(identifier);
20+
return window.performance.getEntriesByName(identifier)[0].navigationId;
21+
}
22+
23+
let getNumberofBackForwardCacheRestorationEntries = (BackForwardCacheRestorationType) => {
24+
return window.performance.getEntriesByType(BackForwardCacheRestorationType).length;
25+
}
26+
27+
let getBackForwardCacheRestorationByType = (BackForwardCacheRestorationType) => {
28+
let entries = window.performance.getEntriesByType(BackForwardCacheRestorationType);
29+
return entries[entries.length - 1];
30+
}
31+
32+
let getBackForwardCacheRestorationByGetAllAndFilter = (BackForwardCacheRestorationType) => {
33+
let entries = window.performance.getEntries().filter(e => e.entryType == BackForwardCacheRestorationType);
34+
return entries[entries.length - 1];
35+
}
36+
37+
let getBackForwardCacheRestorationByPerformanceObserverBuffered = async (BackForwardCacheRestorationType) => {
38+
let p = new Promise(resolve => {
39+
new PerformanceObserver((list) => {
40+
const entries = list.getEntries().filter(e => e.entryType == BackForwardCacheRestorationType);
41+
if (entries.length > 0) {
42+
resolve(entries[entries.length - 1]);
43+
}
44+
}).observe({ type: BackForwardCacheRestorationType, buffered: true });
45+
});
46+
return await p;
47+
}
48+
49+
let checkEntry = (entry, previousNavigationId) => {
50+
assert_equals(entry.name, BackForwardCacheRestorationName);
51+
assert_equals(entry.entryType, BackForwardCacheRestorationType);
52+
assert_not_equals(entry.navigationId, previousNavigationId);
53+
assert_true(entry.pageshowEventStart > entry.startTime);
54+
assert_true(entry.pageshowEventEnd >= entry.pageshowEventStart);
55+
}
56+
57+
promise_test(async t => {
58+
const pageA = new RemoteContext(token());
59+
const pageB = new RemoteContext(token());
60+
61+
const urlA = executorPath + pageA.context_id;
62+
const urlB = originCrossSite + executorPath + pageB.context_id;
63+
// Open url A.
64+
window.open(urlA, '_blank', 'noopener');
65+
await pageA.execute_script(waitForPageShow);
66+
67+
// Assert no instance of BackForwardCacheRestoration exists without back forward cache navigatoin.
68+
let size = await pageA.execute_script(getNumberofBackForwardCacheRestorationEntries);
69+
assert_equals(0, size);
70+
71+
let entry;
72+
for (i = 0; i < 2; i++) {
73+
let curr_nav_id = await pageA.execute_script(getNavigationId, [i]);
74+
75+
// Navigate away to url B and back.
76+
await navigateAndThenBack(pageA, pageB, urlB);
77+
78+
// Assert Performance Observer API supports BackForwardCacheRestoration.
79+
entry = await pageA.execute_script(getBackForwardCacheRestorationByPerformanceObserverBuffered, [BackForwardCacheRestorationType]);
80+
// The navigation id after a bfcache restoration should be different
81+
// from that before.
82+
checkEntry(entry, curr_nav_id);
83+
84+
// Assert Performance Timeline API supports BackForwardCacheRestoration.
85+
entry = await pageA.execute_script(getBackForwardCacheRestorationByType, [BackForwardCacheRestorationType]);
86+
checkEntry(entry, curr_nav_id);
87+
88+
entry = await pageA.execute_script(getBackForwardCacheRestorationByGetAllAndFilter, [BackForwardCacheRestorationType]);
89+
checkEntry(entry, curr_nav_id);
90+
}
91+
}, 'Performance API for the back forward cache restoration entry.');
92+
</script>
93+
</body>
94+
95+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
promise_test(t => {
2+
// This setup is required for later tests as well.
3+
// Await for a dropped entry.
4+
return new Promise(res => {
5+
// Set a buffer size of 0 so that new resource entries count as dropped.
6+
performance.setResourceTimingBufferSize(0);
7+
// Use an observer to make sure the promise is resolved only when the
8+
// new entry has been created.
9+
new PerformanceObserver(res).observe({type: 'resource'});
10+
fetch('resources/square.png?id=1');
11+
}).then(() => {
12+
return new Promise(resolve => {
13+
new PerformanceObserver(t.step_func((entries, obs, options) => {
14+
assert_equals(options['droppedEntriesCount'], 0);
15+
resolve();
16+
})).observe({type: 'mark'});
17+
performance.mark('test');
18+
})});
19+
}, 'Dropped entries count is 0 when there are no dropped entries of relevant type.');
20+
21+
promise_test(async t => {
22+
return new Promise(resolve => {
23+
new PerformanceObserver(t.step_func((entries, obs, options) => {
24+
assert_equals(options['droppedEntriesCount'], 1);
25+
resolve();
26+
})).observe({entryTypes: ['mark', 'resource']});
27+
performance.mark('meow');
28+
});
29+
}, 'Dropped entries correctly counted with multiple types.');
30+
31+
promise_test(t => {
32+
return new Promise(resolve => {
33+
new PerformanceObserver(t.step_func((entries, obs, options) => {
34+
assert_equals(options['droppedEntriesCount'], 1,
35+
'There should have been some dropped resource timing entries at this point');
36+
resolve();
37+
})).observe({type: 'resource', buffered: true});
38+
});
39+
}, 'Dropped entries counted even if observer was not registered at the time.');
40+
41+
promise_test(t => {
42+
return new Promise(resolve => {
43+
let callback_ran = false;
44+
new PerformanceObserver(t.step_func((entries, obs, options) => {
45+
if (!callback_ran) {
46+
assert_equals(options['droppedEntriesCount'], 2,
47+
'There should be two dropped entries right now.');
48+
fetch('resources/square.png?id=3');
49+
callback_ran = true;
50+
} else {
51+
assert_equals(options['droppedEntriesCount'], undefined,
52+
'droppedEntriesCount should be unset after the first callback!');
53+
resolve();
54+
}
55+
})).observe({type: 'resource'});
56+
fetch('resources/square.png?id=2');
57+
});
58+
}, 'Dropped entries only surfaced on the first callback.');
59+
60+
61+
promise_test(t => {
62+
return new Promise(resolve => {
63+
let callback_ran = false;
64+
let droppedEntriesCount = -1;
65+
new PerformanceObserver(t.step_func((entries, obs, options) => {
66+
if (!callback_ran) {
67+
assert_greater_than(options['droppedEntriesCount'], 0,
68+
'There should be several dropped entries right now.');
69+
droppedEntriesCount = options['droppedEntriesCount'];
70+
callback_ran = true;
71+
obs.observe({type: 'mark'});
72+
performance.mark('woof');
73+
} else {
74+
assert_equals(options['droppedEntriesCount'], droppedEntriesCount,
75+
'There should be droppedEntriesCount due to the new observe().');
76+
resolve();
77+
}
78+
})).observe({type: 'resource'});
79+
fetch('resources/square.png?id=4');
80+
});
81+
}, 'Dropped entries surfaced after an observe() call!');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// META: script=/resources/idlharness-shadowrealm.js
2+
idl_test_shadowrealm(["performance-timeline"], ["hr-time", "dom"]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>The navigation_id Detached iframe Parent Page.</title>
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
</head>
10+
11+
<body>
12+
<script>
13+
promise_test(t => {
14+
return new Promise(resolve => {
15+
const frame = document.createElement("iframe");
16+
frame.addEventListener("load", async () => {
17+
// Wait for iframe to be detached.
18+
while (frame.contentWindow) {
19+
await new Promise(r => t.step_timeout(r, 10));
20+
}
21+
resolve();
22+
});
23+
frame.src = "resources/navigation-id-detached-frame-page.html";
24+
document.body.appendChild(frame);
25+
});
26+
}, "The navigation_id getter does not crash a window of detached frame");
27+
</script>
28+
</body>
29+
30+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
7+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<script src="navigation-id.helper.js"></script>
9+
<script>
10+
runNavigationIdTest({
11+
navigationTimes: 3,
12+
testName: 'element_timing',
13+
}, "Element Timing navigation id test");
14+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE HTML>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<!--
6+
Navigation timing, LCP and paint timing entries are only emitted during initial
7+
load, not after a bfcache navigation. Therefore we only verify the existence of
8+
navigation id, not the increment.
9+
-->
10+
11+
<body>
12+
<p>This text is to trigger a LCP entry emission.</p>
13+
<script>
14+
async function NavigationIdsFromLCP() {
15+
return new Promise(resolve => {
16+
new PerformanceObserver((entryList) => {
17+
resolve(entryList.getEntries());
18+
}).observe({ type: 'largest-contentful-paint', buffered: true });
19+
})
20+
}
21+
22+
promise_test(async t => {
23+
// Assert navigation id exists in LCP entries and and are all the same.
24+
const navigationIdsOfLCP = (await NavigationIdsFromLCP()).map(e => e.navigationId);
25+
assert_true(navigationIdsOfLCP.every(e => e == navigationIdsOfLCP[0]),
26+
'Navigation Ids of LCP entries should be the same at initial navigation');
27+
28+
// Assert navigation id exists in a NavigationTiming entry.
29+
const navigationIdOfNavigationTiming =
30+
performance.getEntriesByType('navigation')[0].navigationId;
31+
assert_true(!!navigationIdOfNavigationTiming,
32+
'Navigation Id of a navigation timing entry should exist at initial navigation');
33+
34+
// Assert navigation id exists in PaintTiming entries and are all the same.
35+
const navigationIdsOfPaintTiming =
36+
performance.getEntriesByType('paint').map(e => e.navigationId);
37+
assert_true(navigationIdsOfPaintTiming.every(e =>
38+
e == navigationIdsOfPaintTiming[0]),
39+
'Navigation Id of PaintTiming entries should be the same as the initial navigation.');
40+
41+
// Assert navigation ids are all the same.
42+
const navigationIdsOfAll =
43+
navigationIdsOfLCP.concat(navigationIdsOfPaintTiming, navigationIdOfNavigationTiming);
44+
assert_true(navigationIdsOfAll.every(e => e == navigationIdsOfAll[0]),
45+
'Navigation Id of all entries should be the same as the initial navigation.');
46+
47+
}, 'Navigation Ids should exist and are all the same as the initial navigation.');
48+
</script>
49+
</body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
7+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<script src="navigation-id.helper.js"></script>
9+
<script>
10+
runNavigationIdTest({
11+
navigationTimes: 3,
12+
testName: 'long_task_task_attribution',
13+
}, "Long Task/Task Attribution navigation id test");
14+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
7+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<script src="navigation-id.helper.js"></script>
9+
<script>
10+
runNavigationIdTest({
11+
navigationTimes: 3,
12+
testName: 'mark_measure',
13+
}, "Mark/Measure navigation id test");
14+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE HTML>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
7+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<script>
9+
const reload = () => {
10+
window.location.reload();
11+
};
12+
13+
const getNavigationId = () => {
14+
window.performance.mark('initial_load');
15+
let entries = window.performance.getEntriesByType('mark');
16+
return entries[entries.length - 1].navigationId;
17+
}
18+
19+
promise_test(async t => {
20+
const pageA = new RemoteContext(token());
21+
const pageB = new RemoteContext(token());
22+
23+
const urlA = executorPath + pageA.context_id;
24+
const urlB = originCrossSite + executorPath + pageB.context_id;
25+
// Open url A.
26+
window.open(urlA, '_blank', 'noopener')
27+
await pageA.execute_script(waitForPageShow);
28+
29+
let navigationIdInitial = await pageA.execute_script(getNavigationId);
30+
31+
// Navigate away to url B and back.
32+
await navigateAndThenBack(pageA, pageB, urlB);
33+
34+
// Assert navigation id is re-generated and thus different when the
35+
// document is load from bfcache.
36+
navigationIdAfterBFCacheNav = await pageA.execute_script(getNavigationId);
37+
assert_not_equals(navigationIdInitial, navigationIdAfterBFCacheNav, 'Navigation Id should be \
38+
re-generated and different from the previous one after back-forward-cache navigation.');
39+
40+
// Reload page.
41+
await pageA.execute_script(reload);
42+
await pageA.execute_script(waitForPageShow);
43+
44+
navigationIdAfterReset = await pageA.execute_script(getNavigationId);
45+
46+
assert_not_equals(navigationIdAfterReset, navigationIdAfterBFCacheNav, 'Navigation Id should\
47+
be re-generated after reload which is different from the previous one.');
48+
49+
assert_not_equals(navigationIdAfterReset, navigationIdInitial, 'Navigation Id should\
50+
be re-generated after reload which is different from the one of the initial load.');
51+
52+
}, 'Navigation Id should be re-generated after reload.');
53+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/utils.js"></script>
6+
<script src="/common/dispatcher/dispatcher.js"></script>
7+
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<script src="navigation-id.helper.js"></script>
9+
<script>
10+
runNavigationIdTest({
11+
navigationTimes: 3,
12+
testName: 'resource_timing',
13+
}, "Resource Timing navigation id test");
14+
</script>

0 commit comments

Comments
 (0)