Skip to content

Commit

Permalink
scroll-to-text: Make percent encoding test fast
Browse files Browse the repository at this point in the history
Flakiness of this test was due to slowness, with passing runs often
hovering hear the timeout threshold.

The test was using the stash framework and navigating a popup. This was
typically done since early implementation had restrictions on
same-document navigations but these have since been lifted (in the
same-origin case) so we can remove the complexity. This makes the test
significantly faster to run (300% speedup locally).

Bug: 1487234
Change-Id: Iad611046e1a6fdb3d2dd3b782bd9f7f95c871958
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5117979
Reviewed-by: Vladimir Levin <vmpstr@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1236584}
  • Loading branch information
bokand authored and chromium-wpt-export-bot committed Dec 12, 2023
1 parent 2b77720 commit c878bec
Showing 1 changed file with 56 additions and 75 deletions.
131 changes: 56 additions & 75 deletions scroll-to-text-fragment/percent-encoding.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/common/utils.js"></script>
<script src="stash.js"></script>
<script src="resources/util.js"></script>
<style>
.target {
Expand All @@ -16,86 +14,69 @@
}
</style>
<script>
const params = new URLSearchParams(location.search);
const is_popup = params.has('key');

// This test opens a popup to this document which invokes a text directive. The
// popup checks the result of navigating the text directive and communicates it
// back to the original page via Stash (since text fragments require noopener).
if (is_popup) {
const key = params.get('key');
function determineResult() {
if (window.scrollY == 0)
return 'noscroll';

function sendResult() {
let result = 'unknown';
if (window.scrollY == 0)
result = 'noscroll';
else {
for (let target of document.querySelectorAll('.target')) {
if (isInViewport(target)) {
result = target.id;
break;
}
}
for (let target of document.querySelectorAll('.target')) {
if (isInViewport(target)) {
return target.id;
}

stashResultsThenClose(key, result);
}
return 'UNEXPECTED';
}

// Ensure two animation frames on load to test the fallback to element anchor,
// which gets queued for the next frame if the text fragment is not found.
onload = () => { requestAnimationFrame( () => requestAnimationFrame(sendResult) ); };
} else {
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, reject) => {
let key = token();
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).'
},
];

test_driver.bless('Open a URL with a text fragment directive', () => {
window.open(`${location.href}?key=${key}${test_case.fragment}`, '_blank', 'noopener');
});
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);

fetchResults(key, resolve, reject);
}).then(result => {
assert_equals(result, test_case.expect);
}), `Test navigation with fragment: ${test_case.description}.`);
}
location = `${location.pathname}${test_case.fragment}`;
requestAnimationFrame( () => requestAnimationFrame(resolve) );
}).then(() => {
assert_equals(determineResult(), test_case.expect);
}), `Test navigation with fragment: ${test_case.description}.`);
}
</script>

Expand Down

0 comments on commit c878bec

Please sign in to comment.