|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<script src="/resources/testharness.js"></script> |
| 4 | +<script src="/resources/testharnessreport.js"></script> |
| 5 | +<script src="/resources/testdriver.js"></script> |
| 6 | +<script src="/resources/testdriver-vendor.js"></script> |
| 7 | +<script src="/soft-navigation-heuristics/resources/soft-navigation-test-helper.js"></script> |
| 8 | + |
| 9 | +<button id="navigateButton">Click here!</button> |
| 10 | +<div id="content"></div> |
| 11 | + |
| 12 | +<script> |
| 13 | + promise_test(async t => { |
| 14 | + const URL = '/late-url-change'; |
| 15 | + |
| 16 | + navigateButton.addEventListener("click", async () => { |
| 17 | + content.innerHTML = '<img src="/images/lcp-256x256.png" elementtiming="test-image"></img>'; |
| 18 | + |
| 19 | + const entries = await new Promise(resolve => { |
| 20 | + new PerformanceObserver((list, observer) => { |
| 21 | + resolve(list.getEntries()); |
| 22 | + observer.disconnect(); |
| 23 | + }).observe({type: 'element', buffered: true}); |
| 24 | + }); |
| 25 | + assert_equals( |
| 26 | + entries.length, 1, 'Expected exactly one ElementTiming entry'); |
| 27 | + assert_equals( |
| 28 | + entries[0].identifier, 'test-image', 'Unexpected ElementTiming entry.'); |
| 29 | + history.pushState({}, '', URL); |
| 30 | + }, {once: true}); |
| 31 | + |
| 32 | + const softNavPromise = SoftNavigationTestHelper.getPerformanceEntries( |
| 33 | + /*type=*/ "soft-navigation", |
| 34 | + /*include_soft_navigation_observations=*/ false, |
| 35 | + /*min_num_entries=*/ 1, |
| 36 | + ); |
| 37 | + |
| 38 | + if (test_driver) { |
| 39 | + test_driver.click(navigateButton); |
| 40 | + } |
| 41 | + |
| 42 | + const helper = new SoftNavigationTestHelper(t); |
| 43 | + const entries = await helper.withTimeoutMessage( |
| 44 | + softNavPromise, "Soft navigation entry never arrived.", 3000); |
| 45 | + assert_equals(entries.length, 1, 'Expected exactly one soft navigation.'); |
| 46 | + assert_true( |
| 47 | + entries[0].name.endsWith(URL), |
| 48 | + 'Unexpected Soft Navigation URL.'); |
| 49 | + }, 'Soft Navigation Detection supports setting URL after paint'); |
| 50 | +</script> |
0 commit comments