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>
15 promise_test(t
=> new Promise((resolve
, reject
) => {
17 test_driver
.bless('Open a scroll to text fragment URL', () => {
19 `resources/beforematch-scroll-to-text-fragment-basic.html?key=${key}#:~:text=foo`,
23 fetchResults(key
, resolve
, reject
);
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
) => {
37 test_driver
.bless('Open a scroll to text fragment URL', () => {
39 `resources/beforematch-scroll-to-text-fragment-with-anchor.html?key=${key}#:~:text=foo`,
43 fetchResults(key
, resolve
, reject
);
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
) => {
53 test_driver
.bless('Open a scroll to text fragment URL', () => {
55 `resources/beforematch-scroll-to-text-fragment-bubble.html?key=${key}#:~:text=foo`,
59 fetchResults(key
, resolve
, reject
);
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