Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /soft-navigation-heuristics/smoke/tentative/task-attribution-hash-change.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/soft-navigation-heuristics/resources/soft-navigation-test-helper.js"></script>
<button id="navigateButton">Click here!</button>
<div id="content"></div>
<script>
promise_test(async t => {
navigateButton.addEventListener('click', () => {
window.location.hash = '#hash1';
}, {once: true});
window.addEventListener('hashchange', () => {
content.innerHTML = '<h1>Content</h1>'
}, {once: true});
const softNavPromise = SoftNavigationTestHelper.getPerformanceEntries(
/*type=*/'soft-navigation', /*min_num_entries=*/1);
if (test_driver) {
test_driver.click(navigateButton);
}
const helper = new SoftNavigationTestHelper(t);
const entries = await helper.withTimeoutMessage(
softNavPromise, 'Soft navigation entry never arrived.', 3000);
assert_equals(entries.length, 1, 'Expected exactly one soft navigation.');
assert_true(
entries[0].name.endsWith('#hash1'), 'Unexpected Soft Navigation URL.');
}, 'Soft Navigation Detection supports propagating through the hashchange event');
</script>