Bug 1860196 [wpt PR 42652] - Upstream wpt_internal display-lock WPTs, a=testonly
[gecko.git] / testing / web-platform / tests / html / editing / the-hidden-attribute / beforematch-scroll-to-text-fragment.html
blobdddab4c6ba8621fb27e63835311930f2b53f41df
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>beforematch fired on ScrollToTextFragment</title>
4 <link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
5 <link rel="help" href="https://github.com/WICG/display-locking">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <script src="/resources/testdriver.js"></script>
9 <script src="/resources/testdriver-vendor.js"></script>
11 <script src="/common/utils.js"></script>
12 <script src="/scroll-to-text-fragment/stash.js"></script>
14 <script>
15 promise_test(t => new Promise((resolve, reject) => {
16 const key = token();
17 test_driver.bless('Open a scroll to text fragment URL', () => {
18 window.open(
19 `resources/beforematch-scroll-to-text-fragment-basic.html?key=${key}#:~:text=foo`,
20 '_blank',
21 'noopener');
22 });
23 fetchResults(key, resolve, reject);
24 }).then(results => {
25 assert_equals(results.pageYOffsetDuringBeforematch, 0,
26 'Scrolling should happen after beforematch is fired.');
27 assert_true(results.beforematchFiredOnFoo,
28 'Foo was searched for, so it should get a beforematch event.');
29 assert_false(results.beforematchFiredOnBar,
30 'Bar was not searched for, so it should not get a beforematch event.');
31 assert_true(results.pageYOffsetAfterRaf > 0,
32 'The page should be scrolled down to foo.');
33 }), 'Verifies that the beforematch event is fired on the matching element of a ScrollToTextFragment navigation.');
35 promise_test(t => new Promise((resolve, reject) => {
36 const key = token();
37 test_driver.bless('Open a scroll to text fragment URL', () => {
38 window.open(
39 `resources/beforematch-scroll-to-text-fragment-with-anchor.html?key=${key}#:~:text=foo`,
40 '_blank',
41 'noopener');
42 });
43 fetchResults(key, resolve, reject);
44 }).then(results => {
45 assert_true(results.beforematchFiredOnFoo,
46 'foo was searched for, so it should get the beforematch event.');
47 assert_false(results.beforematchFiredOnBar,
48 'bar should not get the beforematch event despite being the target of an element fragment due to the text fragment.');
49 }), 'Verifies that beforematch is only fired on elements targeted by a text fragment when there is both a text fragment and an element fragment.');
51 promise_test(t => new Promise((resolve, reject) => {
52 const key = token();
53 test_driver.bless('Open a scroll to text fragment URL', () => {
54 window.open(
55 `resources/beforematch-scroll-to-text-fragment-bubble.html?key=${key}#:~:text=foo`,
56 '_blank',
57 'noopener');
58 });
59 fetchResults(key, resolve, reject);
60 }).then(results => {
61 assert_true(results.beforematchFiredOnChild,
62 'The element containing the searched text should have beforematch fired on it.');
63 assert_true(results.beforematchFiredOnParent,
64 'The parent element of the element containing the matching text should have the beforematch event fired on it because the event should bubble.');
65 }), 'Verifies that the beforematch event bubbles with scroll to text fragment.');
67 // TODO(jarhar): Write more tests here once we decide on a behavior here: https://github.com/WICG/display-locking/issues/150
68 </script>