tor-browser

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

prefetch-document.html (2666B)


      1 <!DOCTYPE html>
      2 <title>Ensures that prefetch works with documents</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/utils.js"></script>
      6 <script src="/common/get-host-info.sub.js"></script>
      7 <script src="/common/dispatcher/dispatcher.js"></script>
      8 <script src="resources/prefetch-helper.js"></script>
      9 <body>
     10 <script>
     11 
     12 const {ORIGIN, REMOTE_ORIGIN, HTTP_NOTSAMESITE_ORIGIN} = get_host_info();
     13 
     14 async function prefetch_document_and_count_fetches(options, t) {
     15    const {href, uid} = await prefetch({
     16        "cache-control": "public, max-age=3600",
     17        file: "prefetch-exec.html",
     18        type: "text/html",
     19        corssOrigin: "anonymous",
     20        ...options});
     21    const popup = window.open(href);
     22    const remoteContext = new RemoteContext(uid);
     23    t.add_cleanup(() => popup.close());
     24    const result = await remoteContext.execute_script(() => "OK");
     25    assert_equals(result, "OK");
     26    const requests = await get_prefetch_info(href);
     27    return requests.length;
     28 }
     29 
     30 promise_test(async t => {
     31    assert_equals(await prefetch_document_and_count_fetches({origin: ORIGIN}, t), 1);
     32 }, "same origin document prefetch without 'as' should be consumed");
     33 
     34 promise_test(async t => {
     35    // This (pre-)fetch will be blocked by ORB, which will prevent it from
     36    // being cached. Thus this prefetch is not consumed.
     37    assert_equals(await prefetch_document_and_count_fetches({origin: REMOTE_ORIGIN}, t), 2);
     38 }, "same-site different-origin document prefetch without 'as' should not be consumed");
     39 
     40 promise_test(async t => {
     41    assert_equals(await prefetch_document_and_count_fetches({origin: HTTP_NOTSAMESITE_ORIGIN}, t), 2);
     42 }, "different-site document prefetch without 'as' should not be consumed");
     43 
     44 promise_test(async t => {
     45    assert_equals(await prefetch_document_and_count_fetches({origin: HTTP_NOTSAMESITE_ORIGIN, as: "document"}, t), 2);
     46 }, "different-site document prefetch with 'as=document' should not be consumed");
     47 
     48 promise_test(async t => {
     49    const {href, uid} = await prefetch({
     50        file: "prefetch-exec.html",
     51        type: "text/html",
     52        corssOrigin: "anonymous",
     53        origin: ORIGIN});
     54    const popup = window.open(href + "&cache_bust=" + token());
     55    const remoteContext = new RemoteContext(uid);
     56    t.add_cleanup(() => popup.close());
     57    await remoteContext.execute_script(() => "OK");
     58    const results = await get_prefetch_info(href);
     59    assert_equals(results.length, 2);
     60    assert_equals(results[0].headers.accept, results[1].headers.accept);
     61 }, "Document prefetch should send the exact Accept header as navigation")
     62 </script>
     63 </body>