non-html-documents-json.html (1778B)
1 <!doctype html> 2 <title>Allow text fragments in HTML documents only</title> 3 <meta charset=utf-8> 4 <link rel="help" href="https://wicg.github.io/ScrollToTextFragment/"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script src="/common/utils.js"></script> 10 <script src="stash.js"></script> 11 12 <script> 13 // This test originates from non-html-documents.html and was moved into its own 14 // file because JSON does not emit `onload` in Gecko and this test would timeout 15 // See https://bugzil.la/1907901 16 17 function rAF(win) { 18 return new Promise((resolve) => { 19 win.requestAnimationFrame(resolve); 20 }); 21 } 22 23 function openPopup(url) { 24 return new Promise((resolve) => { 25 test_driver.bless('Open a URL with a text fragment directive', () => { 26 const popup = window.open(url, '_blank', 'width=300,height=300'); 27 popup.onload = () => resolve(popup); 28 }); 29 }); 30 } 31 const filename = 'application-json.json' 32 const expected = 'blocked'; 33 const mediaType = filename.split('.')[0].replace('-', '/'); 34 35 promise_test(async function (t) { 36 const popup = await openPopup(`resources/${filename}#:~:text=target`); 37 38 // The WPT server should provide the correct content-type header from the 39 // file extension. 40 assert_equals(popup.document.contentType, mediaType); 41 42 // rAF twice in case there is any asynchronicity in scrolling to the target. 43 await rAF(popup); 44 await rAF(popup); 45 46 const did_scroll = popup.scrollY > 0; 47 const expected_scroll = expected == 'allowed'; 48 assert_equals(did_scroll, expected_scroll, 'scrolled to fragment'); 49 50 popup.close(); 51 }, `Text directive ${expected} in ${mediaType}`); 52 </script>