Truly independent web browser
Tests: Cover Unicode text fragment matching
Sam Atkins6f4458286a46
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 4455f25ad0a..edfb87edfaf 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -533,6 +533,7 @@ Text/input/wpt-import/content-security-policy/unsafe-eval/eval-scripts-setTimeou; scroll-to-text-fragment tests all rely on loading/fetching other pages.Text/input/scroll-to-text-fragment/history.htmlText/input/scroll-to-text-fragment/searchable-text-visibility.html+Text/input/scroll-to-text-fragment/unicode-matching.htmlText/input/wpt-import/scroll-to-text-fragment/find-range-from-text-directive.htmlText/input/wpt-import/scroll-to-text-fragment/find-range-from-text-directive-no-reveal.htmlText/input/wpt-import/scroll-to-text-fragment/force-load-at-top.htmldiff --git a/Tests/LibWeb/Text/data/scroll-to-text-fragment-unicode-matching-target.html b/Tests/LibWeb/Text/data/scroll-to-text-fragment-unicode-matching-target.htmlnew file mode 100644index 00000000000..4f91123f2d6--- /dev/null+++ b/Tests/LibWeb/Text/data/scroll-to-text-fragment-unicode-matching-target.html@@ -0,0 +1,30 @@+<!doctype html>+<html lang="ja">+<head>+<meta charset="utf-8">+<title>Unicode text-fragment matching target</title>+<style>+.target {+ margin-block: 2000px;+}+</style>+</head>+<body>+<p>Top of page</p>+<p class="target" id="accent">café</p>+<p class="target" id="canonical">résumé</p>+<p class="target" id="cjk">ウィキペディアへようこそ</p>+<script>+const params = new URLSearchParams(location.search);+const resultKey = params.get("resultKey");+if (resultKey) {+ requestAnimationFrame(() => requestAnimationFrame(() => {+ const target = document.getElementById(params.get("target"));+ const rect = target.getBoundingClientRect();+ localStorage.setItem(resultKey, String(scrollY > 0 && rect.top >= 0 && rect.top <= innerHeight));+ close();+ }));+}+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/expected/scroll-to-text-fragment/unicode-matching.txt b/Tests/LibWeb/Text/expected/scroll-to-text-fragment/unicode-matching.txtnew file mode 100644index 00000000000..bd4823f61f3--- /dev/null+++ b/Tests/LibWeb/Text/expected/scroll-to-text-fragment/unicode-matching.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Text fragments use locale-aware primary-strength Unicode matching\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/scroll-to-text-fragment/unicode-matching.html b/Tests/LibWeb/Text/input/scroll-to-text-fragment/unicode-matching.htmlnew file mode 100644index 00000000000..ea2ce576fdf--- /dev/null+++ b/Tests/LibWeb/Text/input/scroll-to-text-fragment/unicode-matching.html@@ -0,0 +1,47 @@+<!doctype html>+<meta charset="utf-8">+<title>Unicode text-fragment matching</title>+<link rel="help" href="https://wicg.github.io/scroll-to-text-fragment/#finding-ranges-in-a-document">+<link rel="help" href="https://wicg.github.io/scroll-to-text-fragment/#word-boundaries">+<script src="../wpt-import/resources/testharness.js"></script>+<script src="../wpt-import/resources/testharnessreport.js"></script>+<script src="../wpt-import/resources/testdriver.js"></script>+<script src="../wpt-import/resources/testdriver-vendor.js"></script>+<script>+promise_test(async t => {+ const cases = [+ {+ fragment: "cafe",+ target: "accent",+ description: "primary-strength matching ignores accents",+ },+ {+ fragment: encodeURIComponent("résumé"),+ target: "canonical",+ description: "canonically equivalent matches may have different UTF-16 lengths",+ },+ {+ fragment: encodeURIComponent("ようこそ"),+ target: "cjk",+ description: "Japanese word boundaries use the document language",+ },+ ];++ for (const [index, testCase] of cases.entries()) {+ const resultKey = `unicode-text-fragment-${index}`;+ localStorage.removeItem(resultKey);+ t.add_cleanup(() => localStorage.removeItem(resultKey));++ const target = new URL("../../data/scroll-to-text-fragment-unicode-matching-target.html", location.href);+ target.searchParams.set("resultKey", resultKey);+ target.searchParams.set("target", testCase.target);+ target.hash = `:~:text=${testCase.fragment}`;+ test_driver.bless("Open a URL with a Unicode text fragment", () => {+ window.open(target, "_blank", "noopener");+ });++ await t.step_wait(() => localStorage.getItem(resultKey), testCase.description);+ assert_equals(localStorage.getItem(resultKey), "true", testCase.description);+ }+}, "Text fragments use locale-aware primary-strength Unicode matching");+</script>