Skip to content

Commit

Permalink
Fix test.
Browse files Browse the repository at this point in the history
The event listener doesn't block the promise, so the asserts inside the
listener don't run without this change (it's trivial to check by
expanding the asserts in the test summary).

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1908907
gecko-commit: ba4dc8ba4f47a10c94d5c738afd0099a53060774
gecko-reviewers: jjaschke
  • Loading branch information
emilio authored and moz-wptsync-bot committed Jul 22, 2024
1 parent 19788ed commit df05e53
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions scroll-to-text-fragment/sequential-focus.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
const link = document.getElementById('link');
const nextButton = document.getElementById('next-button');

window.addEventListener('hashchange', async () => {
// Assert that the link element does not have focus initially
assert_not_equals(document.activeElement, link, 'Link element should not have focus initially');
const hashChange = new Promise(r => window.addEventListener('hashchange', r, { once: true }));

// Simulate pressing TAB to shift focus to the next element
await test_driver.send_keys(document.body, '\uE004'); // '\uE004' is the WebDriver key code for TAB
// Simulate a same-document load to the text fragment
location.hash = '#some-hash-to-trigger-hashchange:~:text=foo';

// Assert that the next focusable element (button) has focus
assert_equals(document.activeElement, nextButton, 'Next focusable element should have focus after pressing TAB');
await hashChange;

t.done();
});
// Assert that the link element does not have focus initially
assert_not_equals(document.activeElement, link, 'Link element should not have focus initially');

// Simulate a same-document load to the text fragment
location.hash = '#some-hash-to-trigger-hashchange:~:text=foo';
// Simulate pressing TAB to shift focus to the next element
await test_driver.send_keys(document.body, '\uE004'); // '\uE004' is the WebDriver key code for TAB

// Assert that the next focusable element (button) has focus
assert_equals(document.activeElement, nextButton, 'Next focusable element should have focus after pressing TAB');
}, 'Text Fragment focus behavior');
</script>
</body>
Expand Down

0 comments on commit df05e53

Please sign in to comment.