Skip to content

Commit

Permalink
Text Fragments: Separate json test case to let others pass.
Browse files Browse the repository at this point in the history
The test to check if scrolling is allowed in non-html documents times out for JSON,
because it depends on the `onload` event, which Gecko is not firing for JSON (Bug 1905106).

Additionally, other test cases in that file can time out on CI as well.

With this patch, the JSON test case is separated into its own file and is expected to `TIMEOUT`. The other test cases get a longer timeout so that they pass in all configurations.

Differential Revision: https://phabricator.services.mozilla.com/D216565

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1907901
gecko-commit: 72e40f9471c4f8348d84d2e211b97f26c4a84d7b
gecko-reviewers: dom-core, sefeng
  • Loading branch information
jnjaeschke authored and moz-wptsync-bot committed Jul 17, 2024
1 parent e9503de commit 0291480
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
52 changes: 52 additions & 0 deletions scroll-to-text-fragment/non-html-documents-json.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!doctype html>
<title>Allow text fragments in HTML documents only</title>
<meta charset=utf-8>
<link rel="help" href="https://wicg.github.io/ScrollToTextFragment/">
<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 src="/common/utils.js"></script>
<script src="stash.js"></script>

<script>
// This test originates from non-html-documents.html and was moved into its own
// file because JSON does not emit `onload` in Gecko and this test would timeout
// See https://bugzil.la/1907901

function rAF(win) {
return new Promise((resolve) => {
win.requestAnimationFrame(resolve);
});
}

function openPopup(url) {
return new Promise((resolve) => {
test_driver.bless('Open a URL with a text fragment directive', () => {
const popup = window.open(url, '_blank', 'width=300,height=300');
popup.onload = () => resolve(popup);
});
});
}
const filename = 'application-json.json'
const expected = 'blocked';
const mediaType = filename.split('.')[0].replace('-', '/');

promise_test(async function (t) {
const popup = await openPopup(`resources/${filename}#:~:text=target`);

// The WPT server should provide the correct content-type header from the
// file extension.
assert_equals(popup.document.contentType, mediaType);

// rAF twice in case there is any asynchronicity in scrolling to the target.
await rAF(popup);
await rAF(popup);

const did_scroll = popup.scrollY > 0;
const expected_scroll = expected == 'allowed';
assert_equals(did_scroll, expected_scroll, 'scrolled to fragment');

popup.close();
}, `Text directive ${expected} in ${mediaType}`);
</script>
5 changes: 1 addition & 4 deletions scroll-to-text-fragment/non-html-documents.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<title>Allow text fragments in HTML documents only</title>
<meta charset=utf-8>
<meta name="timeout" content="long">
<link rel="help" href="https://wicg.github.io/ScrollToTextFragment/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down Expand Up @@ -46,10 +47,6 @@
filename: 'application-xml.xml',
expected: 'blocked',
},
{
filename: 'application-json.json',
expected: 'blocked',
},
];

for (let test_case of test_cases) {
Expand Down

0 comments on commit 0291480

Please sign in to comment.