Skip to content

Commit 19da4de

Browse files
avivkelleraduh95
authored andcommitted
test: update performance-timeline wpt
PR-URL: #55197 Reviewed-By: Filip Skokan <[email protected]>
1 parent 4129bc7 commit 19da4de

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‎

Lines changed: 1 addition & 1 deletion
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
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<scriptsrc="/resources/testharness.js"></script>
6+
<scriptsrc="/resources/testharnessreport.js"></script>
7+
<scriptsrc="/common/utils.js"></script>
8+
<scriptsrc="/common/dispatcher/dispatcher.js"></script>
9+
<scriptsrc="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
10+
</head>
11+
12+
<body>
13+
<script>
14+
constBackForwardCacheRestorationName='';
15+
constBackForwardCacheRestorationType='back-forward-cache-restoration';
16+
17+
letgetNavigationId=(i)=>{
18+
letidentifier='mark'+i;
19+
performance.mark(identifier);
20+
returnwindow.performance.getEntriesByName(identifier)[0].navigationId;
21+
}
22+
23+
letgetNumberofBackForwardCacheRestorationEntries=(BackForwardCacheRestorationType)=>{
24+
returnwindow.performance.getEntriesByType(BackForwardCacheRestorationType).length;
25+
}
26+
27+
letgetBackForwardCacheRestorationByType=(BackForwardCacheRestorationType)=>{
28+
letentries=window.performance.getEntriesByType(BackForwardCacheRestorationType);
29+
returnentries[entries.length-1];
30+
}
31+
32+
letgetBackForwardCacheRestorationByGetAllAndFilter=(BackForwardCacheRestorationType)=>{
33+
letentries=window.performance.getEntries().filter(e=>e.entryType==BackForwardCacheRestorationType);
34+
returnentries[entries.length-1];
35+
}
36+
37+
letgetBackForwardCacheRestorationByPerformanceObserverBuffered=async(BackForwardCacheRestorationType)=>{
38+
letp=newPromise(resolve=>{
39+
newPerformanceObserver((list)=>{
40+
constentries=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+
returnawaitp;
47+
}
48+
49+
letcheckEntry=(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(asynct=>{
58+
constpageA=newRemoteContext(token());
59+
constpageB=newRemoteContext(token());
60+
61+
consturlA=executorPath+pageA.context_id;
62+
consturlB=originCrossSite+executorPath+pageB.context_id;
63+
// Open url A.
64+
window.open(urlA,'_blank','noopener');
65+
awaitpageA.execute_script(waitForPageShow);
66+
67+
// Assert no instance of BackForwardCacheRestoration exists without back forward cache navigatoin.
68+
letsize=awaitpageA.execute_script(getNumberofBackForwardCacheRestorationEntries);
69+
assert_equals(0,size);
70+
71+
letentry;
72+
for(i=0;i<2;i++){
73+
letcurr_nav_id=awaitpageA.execute_script(getNavigationId,[i]);
74+
75+
// Navigate away to url B and back.
76+
awaitnavigateAndThenBack(pageA,pageB,urlB);
77+
78+
// Assert Performance Observer API supports BackForwardCacheRestoration.
79+
entry=awaitpageA.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=awaitpageA.execute_script(getBackForwardCacheRestorationByType,[BackForwardCacheRestorationType]);
86+
checkEntry(entry,curr_nav_id);
87+
88+
entry=awaitpageA.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>
Lines changed: 81 additions & 0 deletions
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+
returnnewPromise(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+
newPerformanceObserver(res).observe({type: 'resource'});
10+
fetch('resources/square.png?id=1');
11+
}).then(()=>{
12+
returnnewPromise(resolve=>{
13+
newPerformanceObserver(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(asynct=>{
22+
returnnewPromise(resolve=>{
23+
newPerformanceObserver(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+
returnnewPromise(resolve=>{
33+
newPerformanceObserver(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+
returnnewPromise(resolve=>{
43+
letcallback_ran=false;
44+
newPerformanceObserver(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+
returnnewPromise(resolve=>{
63+
letcallback_ran=false;
64+
letdroppedEntriesCount=-1;
65+
newPerformanceObserver(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!');
Lines changed: 2 additions & 0 deletions
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"]);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
4+
<head>
5+
<metacharset="utf-8">
6+
<title>The navigation_id Detached iframe Parent Page.</title>
7+
<scriptsrc="/resources/testharness.js"></script>
8+
<scriptsrc="/resources/testharnessreport.js"></script>
9+
</head>
10+
11+
<body>
12+
<script>
13+
promise_test(t=>{
14+
returnnewPromise(resolve=>{
15+
constframe=document.createElement("iframe");
16+
frame.addEventListener("load",async()=>{
17+
// Wait for iframe to be detached.
18+
while(frame.contentWindow){
19+
awaitnewPromise(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>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<metaname="timeout" content="long">
3+
<scriptsrc="/resources/testharness.js"></script>
4+
<scriptsrc="/resources/testharnessreport.js"></script>
5+
<scriptsrc="/common/utils.js"></script>
6+
<scriptsrc="/common/dispatcher/dispatcher.js"></script>
7+
<scriptsrc="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<scriptsrc="navigation-id.helper.js"></script>
9+
<script>
10+
runNavigationIdTest({
11+
navigationTimes: 3,
12+
testName: 'element_timing',
13+
},"Element Timing navigation id test");
14+
</script>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE HTML>
2+
<metaname="timeout" content="long">
3+
<scriptsrc="/resources/testharness.js"></script>
4+
<scriptsrc="/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+
asyncfunctionNavigationIdsFromLCP(){
15+
returnnewPromise(resolve=>{
16+
newPerformanceObserver((entryList)=>{
17+
resolve(entryList.getEntries());
18+
}).observe({type: 'largest-contentful-paint',buffered: true});
19+
})
20+
}
21+
22+
promise_test(asynct=>{
23+
// Assert navigation id exists in LCP entries and and are all the same.
24+
constnavigationIdsOfLCP=(awaitNavigationIdsFromLCP()).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+
constnavigationIdOfNavigationTiming=
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+
constnavigationIdsOfPaintTiming=
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+
constnavigationIdsOfAll=
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>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<metaname="timeout" content="long">
3+
<scriptsrc="/resources/testharness.js"></script>
4+
<scriptsrc="/resources/testharnessreport.js"></script>
5+
<scriptsrc="/common/utils.js"></script>
6+
<scriptsrc="/common/dispatcher/dispatcher.js"></script>
7+
<scriptsrc="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<scriptsrc="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>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<metaname="timeout" content="long">
3+
<scriptsrc="/resources/testharness.js"></script>
4+
<scriptsrc="/resources/testharnessreport.js"></script>
5+
<scriptsrc="/common/utils.js"></script>
6+
<scriptsrc="/common/dispatcher/dispatcher.js"></script>
7+
<scriptsrc="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<scriptsrc="navigation-id.helper.js"></script>
9+
<script>
10+
runNavigationIdTest({
11+
navigationTimes: 3,
12+
testName: 'mark_measure',
13+
},"Mark/Measure navigation id test");
14+
</script>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE HTML>
2+
<metaname="timeout" content="long">
3+
<scriptsrc="/resources/testharness.js"></script>
4+
<scriptsrc="/resources/testharnessreport.js"></script>
5+
<scriptsrc="/common/utils.js"></script>
6+
<scriptsrc="/common/dispatcher/dispatcher.js"></script>
7+
<scriptsrc="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
8+
<script>
9+
constreload=()=>{
10+
window.location.reload();
11+
};
12+
13+
constgetNavigationId=()=>{
14+
window.performance.mark('initial_load');
15+
letentries=window.performance.getEntriesByType('mark');
16+
returnentries[entries.length-1].navigationId;
17+
}
18+
19+
promise_test(asynct=>{
20+
constpageA=newRemoteContext(token());
21+
constpageB=newRemoteContext(token());
22+
23+
consturlA=executorPath+pageA.context_id;
24+
consturlB=originCrossSite+executorPath+pageB.context_id;
25+
// Open url A.
26+
window.open(urlA,'_blank','noopener')
27+
awaitpageA.execute_script(waitForPageShow);
28+
29+
letnavigationIdInitial=awaitpageA.execute_script(getNavigationId);
30+
31+
// Navigate away to url B and back.
32+
awaitnavigateAndThenBack(pageA,pageB,urlB);
33+
34+
// Assert navigation id is re-generated and thus different when the
35+
// document is load from bfcache.
36+
navigationIdAfterBFCacheNav=awaitpageA.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+
awaitpageA.execute_script(reload);
42+
awaitpageA.execute_script(waitForPageShow);
43+
44+
navigationIdAfterReset=awaitpageA.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>

0 commit comments

Comments
(0)