percent-encoding.html (2612B)
1 <!DOCTYPE html> 2 <title>Percent-encoding in a text directive</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="resources/util.js"></script> 10 <style> 11 .target { 12 margin-top: 2000px; 13 margin-bottom: 2000px; 14 } 15 </style> 16 <script> 17 18 function determineResult() { 19 if (window.scrollY == 0) 20 return 'noscroll'; 21 22 for (let target of document.querySelectorAll('.target')) { 23 if (isInViewport(target)) { 24 return target.id; 25 } 26 } 27 return 'UNEXPECTED'; 28 } 29 30 let test_cases = [ 31 { 32 fragment: '#:~:text=%25', 33 expect: 'singlepercent', 34 description: 'Percent-encoded "%" char.' 35 }, 36 { 37 fragment: '#:~:text=%', 38 expect: 'singlepercent', 39 description: 'Percent char without hex digits is invalid.' 40 }, 41 { 42 fragment: '#:~:text=%%', 43 expect: 'doublepercent', 44 description: 'Percent char followed by percent char is invalid.' 45 }, 46 { 47 fragment: '#:~:text=%F', 48 expect: 'percentf', 49 description: 'Single digit percent-encoding is invalid.' 50 }, 51 { 52 fragment: '#:~:text=%25F', 53 expect: 'percentf', 54 description: 'Percent-encoding limited to two digits.' 55 }, 56 { 57 fragment: '#:~:text=%25%25F', 58 expect: 'doublepercentf', 59 description: 'Percent-encoded "%%F"' 60 }, 61 { 62 fragment: '#:~:text=%E2%9C%85', 63 expect: 'checkmark', 64 description: 'Percent-encoding multibyte codepoint (CHECKMARK).' 65 }, 66 ]; 67 68 function runTests() { 69 for (const test_case of test_cases) { 70 promise_test(t => new Promise(resolve => { 71 // Clear the fragment and reset the scroll offset to prepare for the next 72 // test case. 73 location = `${location.pathname}#`; 74 scrollTo(0, 0); 75 76 location = `${location.pathname}${test_case.fragment}`; 77 requestAnimationFrame( () => requestAnimationFrame(resolve) ); 78 }).then(() => { 79 assert_equals(determineResult(), test_case.expect); 80 }), `Test navigation with fragment: ${test_case.description}.`); 81 } 82 } 83 </script> 84 <body onload="runTests()"> 85 <p class="target" id="singlepercent"> 86 % 87 </p> 88 <p class="target" id="doublepercent"> 89 %% 90 </p> 91 <p class="target" id="percentf"> 92 %F 93 </p> 94 <p class="target" id="doublepercentf"> 95 %%f 96 </p> 97 <p class="target" id="checkmark"> 98 <!-- U+2705 WHITE HEAVY CHECK MARK - UTF-8 percent encoding: %E2%9C%85 --> 99 ✅ 100 </p> 101 <p class="target" id="helloworld"> 102 Hello world 103 </p> 104 105 </body>