tor-browser

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

non-html-documents.html (2059B)


      1 <!doctype html>
      2 <title>Allow text fragments in HTML documents only</title>
      3 <meta charset=utf-8>
      4 <meta name="timeout" content="long">
      5 <link rel="help" href="https://wicg.github.io/ScrollToTextFragment/">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="/resources/testdriver.js"></script>
      9 <script src="/resources/testdriver-vendor.js"></script>
     10 <script src="/common/utils.js"></script>
     11 <script src="stash.js"></script>
     12 
     13 <script>
     14 function rAF(win) {
     15  return new Promise((resolve) => {
     16    win.requestAnimationFrame(resolve);
     17  });
     18 }
     19 
     20 function openPopup(url) {
     21  return new Promise((resolve) => {
     22    test_driver.bless('Open a URL with a text fragment directive', () => {
     23      const popup = window.open(url, '_blank', 'width=300,height=300');
     24      popup.onload = () => resolve(popup);
     25    });
     26  });
     27 }
     28 
     29 const test_cases = [
     30  {
     31    filename: 'text-html.html',
     32    expected: 'allowed',
     33  },
     34  {
     35    filename: 'text-css.css',
     36    expected: 'blocked',
     37  },
     38  {
     39    filename: 'text-javascript.js',
     40    expected: 'blocked',
     41  },
     42  {
     43    filename: 'text-plain.txt',
     44    expected: 'allowed',
     45  },
     46  {
     47    filename: 'application-xml.xml',
     48    expected: 'blocked',
     49  },
     50 ];
     51 
     52 for (let test_case of test_cases) {
     53  const filename = test_case.filename;
     54  const expected = test_case.expected;
     55  const mediaType = filename.split('.')[0].replace('-', '/');
     56 
     57  promise_test(async function (t) {
     58    const popup = await openPopup(`resources/${filename}#:~:text=target`);
     59 
     60    // The WPT server should provide the correct content-type header from the
     61    // file extension.
     62    assert_equals(popup.document.contentType, mediaType);
     63 
     64    // rAF twice in case there is any asynchronicity in scrolling to the target.
     65    await rAF(popup);
     66    await rAF(popup);
     67 
     68    const did_scroll = popup.scrollY > 0;
     69    const expected_scroll = expected == 'allowed';
     70    assert_equals(did_scroll, expected_scroll, 'scrolled to fragment');
     71 
     72    popup.close();
     73  }, `Text directive ${expected} in ${mediaType}`);
     74 }
     75 
     76 </script>