Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update performance-timeline wpt #55197

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Last update:
- html/webappapis/structured-clone: https://github.com/web-platform-tests/wpt/tree/47d3fb280c/html/webappapis/structured-clone
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/5873f2d8f1/html/webappapis/timers
- interfaces: https://github.com/web-platform-tests/wpt/tree/e90ece61d6/interfaces
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/94caab7038/performance-timeline
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!doctype html>
<html>

<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
</head>

<body>
<script>
const BackForwardCacheRestorationName = '';
const BackForwardCacheRestorationType = 'back-forward-cache-restoration';

let getNavigationId = (i) => {
let identifier = 'mark' + i;
performance.mark(identifier);
return window.performance.getEntriesByName(identifier)[0].navigationId;
}

let getNumberofBackForwardCacheRestorationEntries = (BackForwardCacheRestorationType) => {
return window.performance.getEntriesByType(BackForwardCacheRestorationType).length;
}

let getBackForwardCacheRestorationByType = (BackForwardCacheRestorationType) => {
let entries = window.performance.getEntriesByType(BackForwardCacheRestorationType);
return entries[entries.length - 1];
}

let getBackForwardCacheRestorationByGetAllAndFilter = (BackForwardCacheRestorationType) => {
let entries = window.performance.getEntries().filter(e => e.entryType == BackForwardCacheRestorationType);
return entries[entries.length - 1];
}

let getBackForwardCacheRestorationByPerformanceObserverBuffered = async (BackForwardCacheRestorationType) => {
let p = new Promise(resolve => {
new PerformanceObserver((list) => {
const entries = list.getEntries().filter(e => e.entryType == BackForwardCacheRestorationType);
if (entries.length > 0) {
resolve(entries[entries.length - 1]);
}
}).observe({ type: BackForwardCacheRestorationType, buffered: true });
});
return await p;
}

let checkEntry = (entry, previousNavigationId) => {
assert_equals(entry.name, BackForwardCacheRestorationName);
assert_equals(entry.entryType, BackForwardCacheRestorationType);
assert_not_equals(entry.navigationId, previousNavigationId);
assert_true(entry.pageshowEventStart > entry.startTime);
assert_true(entry.pageshowEventEnd >= entry.pageshowEventStart);
}

promise_test(async t => {
const pageA = new RemoteContext(token());
const pageB = new RemoteContext(token());

const urlA = executorPath + pageA.context_id;
const urlB = originCrossSite + executorPath + pageB.context_id;
// Open url A.
window.open(urlA, '_blank', 'noopener');
await pageA.execute_script(waitForPageShow);

// Assert no instance of BackForwardCacheRestoration exists without back forward cache navigatoin.
let size = await pageA.execute_script(getNumberofBackForwardCacheRestorationEntries);
assert_equals(0, size);

let entry;
for (i = 0; i < 2; i++) {
let curr_nav_id = await pageA.execute_script(getNavigationId, [i]);

// Navigate away to url B and back.
await navigateAndThenBack(pageA, pageB, urlB);

// Assert Performance Observer API supports BackForwardCacheRestoration.
entry = await pageA.execute_script(getBackForwardCacheRestorationByPerformanceObserverBuffered, [BackForwardCacheRestorationType]);
// The navigation id after a bfcache restoration should be different
// from that before.
checkEntry(entry, curr_nav_id);

// Assert Performance Timeline API supports BackForwardCacheRestoration.
entry = await pageA.execute_script(getBackForwardCacheRestorationByType, [BackForwardCacheRestorationType]);
checkEntry(entry, curr_nav_id);

entry = await pageA.execute_script(getBackForwardCacheRestorationByGetAllAndFilter, [BackForwardCacheRestorationType]);
checkEntry(entry, curr_nav_id);
}
}, 'Performance API for the back forward cache restoration entry.');
</script>
</body>

</html>
81 changes: 81 additions & 0 deletions test/fixtures/wpt/performance-timeline/droppedentriescount.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
promise_test(t => {
// This setup is required for later tests as well.
// Await for a dropped entry.
return new Promise(res => {
// Set a buffer size of 0 so that new resource entries count as dropped.
performance.setResourceTimingBufferSize(0);
// Use an observer to make sure the promise is resolved only when the
// new entry has been created.
new PerformanceObserver(res).observe({type: 'resource'});
fetch('resources/square.png?id=1');
}).then(() => {
return new Promise(resolve => {
new PerformanceObserver(t.step_func((entries, obs, options) => {
assert_equals(options['droppedEntriesCount'], 0);
resolve();
})).observe({type: 'mark'});
performance.mark('test');
})});
}, 'Dropped entries count is 0 when there are no dropped entries of relevant type.');

promise_test(async t => {
return new Promise(resolve => {
new PerformanceObserver(t.step_func((entries, obs, options) => {
assert_equals(options['droppedEntriesCount'], 1);
resolve();
})).observe({entryTypes: ['mark', 'resource']});
performance.mark('meow');
});
}, 'Dropped entries correctly counted with multiple types.');

promise_test(t => {
return new Promise(resolve => {
new PerformanceObserver(t.step_func((entries, obs, options) => {
assert_equals(options['droppedEntriesCount'], 1,
'There should have been some dropped resource timing entries at this point');
resolve();
})).observe({type: 'resource', buffered: true});
});
}, 'Dropped entries counted even if observer was not registered at the time.');

promise_test(t => {
return new Promise(resolve => {
let callback_ran = false;
new PerformanceObserver(t.step_func((entries, obs, options) => {
if (!callback_ran) {
assert_equals(options['droppedEntriesCount'], 2,
'There should be two dropped entries right now.');
fetch('resources/square.png?id=3');
callback_ran = true;
} else {
assert_equals(options['droppedEntriesCount'], undefined,
'droppedEntriesCount should be unset after the first callback!');
resolve();
}
})).observe({type: 'resource'});
fetch('resources/square.png?id=2');
});
}, 'Dropped entries only surfaced on the first callback.');


promise_test(t => {
return new Promise(resolve => {
let callback_ran = false;
let droppedEntriesCount = -1;
new PerformanceObserver(t.step_func((entries, obs, options) => {
if (!callback_ran) {
assert_greater_than(options['droppedEntriesCount'], 0,
'There should be several dropped entries right now.');
droppedEntriesCount = options['droppedEntriesCount'];
callback_ran = true;
obs.observe({type: 'mark'});
performance.mark('woof');
} else {
assert_equals(options['droppedEntriesCount'], droppedEntriesCount,
'There should be droppedEntriesCount due to the new observe().');
resolve();
}
})).observe({type: 'resource'});
fetch('resources/square.png?id=4');
});
}, 'Dropped entries surfaced after an observe() call!');
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// META: script=/resources/idlharness-shadowrealm.js
idl_test_shadowrealm(["performance-timeline"], ["hr-time", "dom"]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>

<head>
<meta charset="utf-8">
<title>The navigation_id Detached iframe Parent Page.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<script>
promise_test(t => {
return new Promise(resolve => {
const frame = document.createElement("iframe");
frame.addEventListener("load", async () => {
// Wait for iframe to be detached.
while (frame.contentWindow) {
await new Promise(r => t.step_timeout(r, 10));
}
resolve();
});
frame.src = "resources/navigation-id-detached-frame-page.html";
document.body.appendChild(frame);
});
}, "The navigation_id getter does not crash a window of detached frame");
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
<script src="navigation-id.helper.js"></script>
<script>
runNavigationIdTest({
navigationTimes: 3,
testName: 'element_timing',
}, "Element Timing navigation id test");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!--
Navigation timing, LCP and paint timing entries are only emitted during initial
load, not after a bfcache navigation. Therefore we only verify the existence of
navigation id, not the increment.
-->

<body>
<p>This text is to trigger a LCP entry emission.</p>
<script>
async function NavigationIdsFromLCP() {
return new Promise(resolve => {
new PerformanceObserver((entryList) => {
resolve(entryList.getEntries());
}).observe({ type: 'largest-contentful-paint', buffered: true });
})
}

promise_test(async t => {
// Assert navigation id exists in LCP entries and and are all the same.
const navigationIdsOfLCP = (await NavigationIdsFromLCP()).map(e => e.navigationId);
assert_true(navigationIdsOfLCP.every(e => e == navigationIdsOfLCP[0]),
'Navigation Ids of LCP entries should be the same at initial navigation');

// Assert navigation id exists in a NavigationTiming entry.
const navigationIdOfNavigationTiming =
performance.getEntriesByType('navigation')[0].navigationId;
assert_true(!!navigationIdOfNavigationTiming,
'Navigation Id of a navigation timing entry should exist at initial navigation');

// Assert navigation id exists in PaintTiming entries and are all the same.
const navigationIdsOfPaintTiming =
performance.getEntriesByType('paint').map(e => e.navigationId);
assert_true(navigationIdsOfPaintTiming.every(e =>
e == navigationIdsOfPaintTiming[0]),
'Navigation Id of PaintTiming entries should be the same as the initial navigation.');

// Assert navigation ids are all the same.
const navigationIdsOfAll =
navigationIdsOfLCP.concat(navigationIdsOfPaintTiming, navigationIdOfNavigationTiming);
assert_true(navigationIdsOfAll.every(e => e == navigationIdsOfAll[0]),
'Navigation Id of all entries should be the same as the initial navigation.');

}, 'Navigation Ids should exist and are all the same as the initial navigation.');
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
<script src="navigation-id.helper.js"></script>
<script>
runNavigationIdTest({
navigationTimes: 3,
testName: 'long_task_task_attribution',
}, "Long Task/Task Attribution navigation id test");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
<script src="navigation-id.helper.js"></script>
<script>
runNavigationIdTest({
navigationTimes: 3,
testName: 'mark_measure',
}, "Mark/Measure navigation id test");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
<script>
const reload = () => {
window.location.reload();
};

const getNavigationId = () => {
window.performance.mark('initial_load');
let entries = window.performance.getEntriesByType('mark');
return entries[entries.length - 1].navigationId;
}

promise_test(async t => {
const pageA = new RemoteContext(token());
const pageB = new RemoteContext(token());

const urlA = executorPath + pageA.context_id;
const urlB = originCrossSite + executorPath + pageB.context_id;
// Open url A.
window.open(urlA, '_blank', 'noopener')
await pageA.execute_script(waitForPageShow);

let navigationIdInitial = await pageA.execute_script(getNavigationId);

// Navigate away to url B and back.
await navigateAndThenBack(pageA, pageB, urlB);

// Assert navigation id is re-generated and thus different when the
// document is load from bfcache.
navigationIdAfterBFCacheNav = await pageA.execute_script(getNavigationId);
assert_not_equals(navigationIdInitial, navigationIdAfterBFCacheNav, 'Navigation Id should be \
re-generated and different from the previous one after back-forward-cache navigation.');

// Reload page.
await pageA.execute_script(reload);
await pageA.execute_script(waitForPageShow);

navigationIdAfterReset = await pageA.execute_script(getNavigationId);

assert_not_equals(navigationIdAfterReset, navigationIdAfterBFCacheNav, 'Navigation Id should\
be re-generated after reload which is different from the previous one.');

assert_not_equals(navigationIdAfterReset, navigationIdInitial, 'Navigation Id should\
be re-generated after reload which is different from the one of the initial load.');

}, 'Navigation Id should be re-generated after reload.');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
<script src="navigation-id.helper.js"></script>
<script>
runNavigationIdTest({
navigationTimes: 3,
testName: 'resource_timing',
}, "Resource Timing navigation id test");
</script>
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading