summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-to-text-fragment/percent-encoding.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/scroll-to-text-fragment/percent-encoding.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/scroll-to-text-fragment/percent-encoding.html')
-rw-r--r--testing/web-platform/tests/scroll-to-text-fragment/percent-encoding.html102
1 files changed, 102 insertions, 0 deletions
diff --git a/testing/web-platform/tests/scroll-to-text-fragment/percent-encoding.html b/testing/web-platform/tests/scroll-to-text-fragment/percent-encoding.html
new file mode 100644
index 0000000000..1f1794bdae
--- /dev/null
+++ b/testing/web-platform/tests/scroll-to-text-fragment/percent-encoding.html
@@ -0,0 +1,102 @@
+<!DOCTYPE html>
+<title>Percent-encoding in a text directive</title>
+<meta charset=utf-8>
+<link rel="help" href="https://wicg.github.io/ScrollToTextFragment/">
+<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="resources/util.js"></script>
+<style>
+ .target {
+ margin-top: 2000px;
+ margin-bottom: 2000px;
+ }
+</style>
+<script>
+
+function determineResult() {
+ if (window.scrollY == 0)
+ return 'noscroll';
+
+ for (let target of document.querySelectorAll('.target')) {
+ if (isInViewport(target)) {
+ return target.id;
+ }
+ }
+ return 'UNEXPECTED';
+}
+
+let test_cases = [
+ {
+ fragment: '#:~:text=%25',
+ expect: 'singlepercent',
+ description: 'Percent-encoded "%" char.'
+ },
+ {
+ fragment: '#:~:text=%',
+ expect: 'noscroll',
+ description: 'Percent char without hex digits is invalid.'
+ },
+ {
+ fragment: '#:~:text=%%',
+ expect: 'noscroll',
+ description: 'Percent char followed by percent char is invalid.'
+ },
+ {
+ fragment: '#:~:text=%F',
+ expect: 'noscroll',
+ description: 'Single digit percent-encoding is invalid.'
+ },
+ {
+ fragment: '#:~:text=%25F',
+ expect: 'percentf',
+ description: 'Percent-encoding limited to two digits.'
+ },
+ {
+ fragment: '#:~:text=%25%25F',
+ expect: 'doublepercentf',
+ description: 'Percent-encoded "%%F"'
+ },
+ {
+ fragment: '#:~:text=%E2%9C%85',
+ expect: 'checkmark',
+ description: 'Percent-encoding multibyte codepoint (CHECKMARK).'
+ },
+];
+
+for (const test_case of test_cases) {
+ promise_test(t => new Promise(resolve => {
+ // Clear the fragment and reset the scroll offset to prepare for the next
+ // test case.
+ location = `${location.pathname}#`;
+ scrollTo(0, 0);
+
+ location = `${location.pathname}${test_case.fragment}`;
+ requestAnimationFrame( () => requestAnimationFrame(resolve) );
+ }).then(() => {
+ assert_equals(determineResult(), test_case.expect);
+ }), `Test navigation with fragment: ${test_case.description}.`);
+}
+</script>
+
+<p class="target" id="singlepercent">
+ %
+</p>
+<p class="target" id="doublepercent">
+ %%
+</p>
+<p class="target" id="percentf">
+ %F
+</p>
+<p class="target" id="doublepercentf">
+ %%f
+</p>
+<p class="target" id="checkmark">
+ <!-- U+2705 WHITE HEAVY CHECK MARK - UTF-8 percent encoding: %E2%9C%85 -->
+ &#x2705;
+</p>
+<p class="target" id="helloworld">
+ Hello world
+</p>
+