tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

same-document-tests.js (1972B)


      1 function reset() {
      2  location.hash = '';
      3  window.scrollTo(0, 0);
      4 }
      5 
      6 function runTests() {
      7  promise_test(async t => {
      8    assert_implements(document.fragmentDirective, 'Text directive not implemented');
      9    reset();
     10 
     11    location.hash = 'elementid';
     12    await t.step_wait(() => window.scrollY > 0, "Wait for scroll");
     13    assert_true(isInViewport(document.getElementById('elementid')), 'Scrolled to text');
     14  }, 'Basic element fragment navigation');
     15 
     16  // Ensure a simple text directive works correctly when navigated to the
     17  // same document using `location.hash`.
     18  promise_test(async t => {
     19    assert_implements(document.fragmentDirective, 'Text directive not implemented');
     20    reset();
     21 
     22    location.hash = ':~:text=line%20of%20text';
     23    await t.step_wait(() => window.scrollY > 0, "Wait for scroll");
     24    assert_true(isInViewport(document.getElementById('text')), 'Scrolled to text');
     25  }, 'Basic text directive navigation');
     26 
     27  // Test that we correctly fallback to the element id when we have a text
     28  // directive that doesn't match any text in the page.
     29  promise_test(async t => {
     30    assert_implements(document.fragmentDirective, 'Text directive not implemented');
     31    reset();
     32 
     33    location.hash = 'elementid:~:text=textDoesntExist';
     34    await t.step_wait(() => window.scrollY > 0, "Wait for scroll");
     35    assert_true(isInViewport(document.getElementById('elementid')), 'Scrolled to `elementid`');
     36  }, 'Basic element id fallback');
     37 
     38  // Test that we correctly fallback to the element id when we have a text
     39  // directive that's malformed and won't be parsed.
     40  promise_test(async t => {
     41    assert_implements(document.fragmentDirective, 'Text directive not implemented');
     42    reset();
     43 
     44    location.hash = 'elementid:~:text=,,,,,';
     45    await t.step_wait(() => window.scrollY > 0, "Wait for scroll");
     46    assert_true(isInViewport(document.getElementById('elementid')), 'Scrolled to `elementid`');
     47  }, 'Malformed text directive element id fallback');
     48 }