tor-browser

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

avoid-prefetching-on-text-plain.html (2319B)


      1 <!DOCTYPE html>
      2 <title>Ensures content delivered with Content-Type: text/plain header is not prefetched</title>
      3 <!-- Regression test for https://crbug.com/1160665 -->
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/preload/resources/preload_helper.js"></script>
      7 <body>
      8    <script>
      9        setup({single_test: true});
     10        window.addEventListener("load", function() {
     11            verifyPreloadAndRTSupport();
     12            // This test works by loading a text/plain iframe containing a <script> tag.
     13            // It then injects some post-load JavaScript to serialize the Performance API
     14            // data and pass it back to this document.
     15            var prefetchingIframe = document.getElementById('prefetching-frame');
     16            window.addEventListener("message", function(msg) {
     17                // Parse the Performance API data passed from the plain text iframe.
     18                const entries = JSON.parse(msg.data);
     19                const resource_types = [];
     20                for (const entry of entries) {
     21                    resource_types.push(entry.entryType);
     22                }
     23                // If preloading is working correctly, should only see the text document
     24                // represented in the performance information. A 'resource' type indicates
     25                // that we've prefetched something.
     26                let resource_found = false;
     27                for (const t of resource_types) {
     28                    if (t == "resource") {
     29                        resource_found = true;
     30                        break;
     31                    }
     32                }
     33                assert_false(resource_found, "no resources should be present");
     34                done();
     35            });
     36            prefetchingIframe.addEventListener('load', function() {
     37                // Pass performance API info back to this document, process in above event handler.
     38                const passMsg = 'parent.postMessage(JSON.stringify(performance.getEntries()));';
     39                prefetchingIframe.contentWindow.eval(passMsg);
     40            });
     41            // Start the iframe load.
     42            prefetchingIframe.src = "avoid-prefetching-on-text-plain-inner.html";
     43        });
     44    </script>
     45 
     46    <iframe id="prefetching-frame"></iframe>
     47 </body>