Commit c9bcba93 authored by Nick Burris's avatar Nick Burris Committed by Commit Bot

Create Web Platform Tests for Scroll to text

Add a web platform test that performs navigations to a test page with
various targetText parameters and checks if the target page
successfully scrolled as expected. Using a BroadcastChannel is the only
way to communicate whether the target page scrolled, since scroll to
text is specifically restricted from iframes or pages with an opener,
so there's no other way for the test page to track the status of the
child target page.

Bug: 994299
Change-Id: I69243e739c3a7469ac48647508e379f204ccfbf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1756707
Commit-Queue: Nick Burris <nburris@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689453}
parent be4bf460
......@@ -6533,3 +6533,6 @@ crbug.com/994034 [ Linux Win ] http/tests/devtools/elements/styles-3/styles-add-
crbug.com/994027 [ Linux Win ] http/tests/devtools/elements/styles-2/force-pseudo-state.js [ Pass Failure ]
crbug.com/995142 crbug.com/900706 [ Mac ] fast/canvas/canvas-large-pattern.html [ Pass Failure ]
crbug.com/995142 crbug.com/900706 [ Mac ] virtual/gpu/fast/canvas/canvas-large-pattern.html [ Pass Failure ]
# Pending enabling scroll to text feature
crbug.com/919204 external/wpt/scroll-to-text-fragment/scroll-to-text-fragment.html [ Skip ]
<!doctype html>
<title>Navigating to a text fragment anchor</title>
<script>
function checkScroll() {
let bc = new BroadcastChannel('scroll-to-text-fragment');
bc.postMessage({ didScrollToTarget: window.scrollY > 0 });
bc.close();
window.close();
}
</script>
<style>
body {
height: 3200px;
}
p {
position: absolute;
top: 3000px;
}
</style>
<body onload="checkScroll()">
<p id="text">This is a test page</p>
</body>
<!doctype html>
<title>Navigating to a text fragment anchor</title>
<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>
let test_cases = [
{ fragment: '#', expect_scroll: false },
{ fragment: '##targetText=test', expect_scroll: true },
{ fragment: '##targetText=this,page', expect_scroll: true },
{ fragment: '##targetText=this-,is,test', expect_scroll: true },
{ fragment: '##targetText=this-,is,test,-page', expect_scroll: true },
{ fragment: '##targetText=this-,is,page,-none', expect_scroll: false },
{ fragment: '##targetText=this,test,-page', expect_scroll: true },
{ fragment: '##targetText=this%20is%20a%20test%20page', expect_scroll: true },
{ fragment: '##targetText=this&targetText=test,page', expect_scroll: true },
{ fragment: '#pagestate##targetText=test', expect_scroll: true },
{ fragment: '#pagestate##targetText=nomatch', expect_scroll: false },
];
for (const test_case of test_cases) {
promise_test(t => new Promise(resolve => {
let channel = new BroadcastChannel('scroll-to-text-fragment');
channel.addEventListener("message", e => {
resolve(e.data.didScrollToTarget);
}, {once: true});
test_driver.bless('Open a URL with a text fragment anchor', () => {
window.open('scroll-to-text-fragment-target.html' + test_case.fragment, '_blank', 'noopener');
});
}).then(scroll => {
assert_equals(scroll, test_case.expect_scroll,
'Expected ' + test_case.fragment + (test_case.expect_scroll ? ' to scroll.' : ' to not scroll.'));
}), 'Test navigation with text fragment anchor ' + test_case.fragment);
}
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment