video-src-change.html (1905B)
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 <video id="testVideo" src="/media/test.webm"></img> 11 12 <script> 13 function waitForVideoRender() { 14 return new Promise(resolve => { 15 new PerformanceObserver((list, observer) => { 16 if (list.getEntries().filter((e) => e.id === 'testVideo').length) { 17 resolve(); 18 observer.disconnect(); 19 } 20 }).observe({type: 'largest-contentful-paint', buffered: true}); 21 }); 22 } 23 24 async function runTest(t, url, newVideoSrc) { 25 navigateButton.addEventListener("click", () => { 26 history.pushState({}, '', url); 27 testVideo.src = newVideoSrc; 28 }, {once: true}); 29 30 const softNavPromise = 31 SoftNavigationTestHelper.getPerformanceEntries("soft-navigation"); 32 33 if (test_driver) { 34 test_driver.click(navigateButton); 35 } 36 37 const helper = new SoftNavigationTestHelper(t); 38 const entries = await helper.withTimeoutMessage( 39 softNavPromise, "Soft navigation entry never arrived.", 5000); 40 assert_equals(entries.length, 1, 'Expected exactly one soft navigation.'); 41 assert_true( 42 entries[0].name.endsWith(url), 43 'Unexpected Soft Navigation URL.'); 44 } 45 46 // Wait for the video to initially load and make its way through the image 47 // timing pipeline before changing its source. 48 promise_setup(waitForVideoRender); 49 50 promise_test(async t => { 51 const url = '/video-src-change-1'; 52 const src = '/media/A4.webm'; 53 return runTest(t, url, src); 54 }, 'Soft Navigation Detection supports HTMLVideoElment.src'); 55 </script>