tor-browser

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

test_bug704320_preload.html (4273B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 This is a spot check for whether the speculative parser reuses style, script or image loads after the referrer policy has changed.
      5 https://bugzilla.mozilla.org/show_bug.cgi?id=704320
      6 -->
      7 
      8 <head>
      9  <meta charset="utf-8">
     10  <title>Test preloads for Bug 704320</title>
     11  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     12  <script type="application/javascript" src="referrerHelper.js"></script>
     13  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     14 
     15 <script type="application/javascript">
     16 
     17 SimpleTest.waitForExplicitFinish();
     18 var advance = function() { tests.next(); };
     19 
     20 /**
     21 * This is the main test routine -- serialized by use of a generator.
     22 * It resets the counter, then performs two tests in sequence using
     23 * the same iframe.
     24 */
     25 var tests = (function*() {
     26  var iframe = document.getElementById("testframe");
     27 
     28  // reset the counter
     29  yield resetCounter();
     30 
     31  // load the second test frame
     32  // it will call back into this function via postMessage when it finishes loading.
     33  // and continue beyond the yield.
     34  yield iframe.src = 'file_bug704320_preload_reuse.html';
     35 
     36  // check the second test
     37  yield checkResults(finalizePreloadReuse);
     38 
     39  // reset the counter
     40  yield resetCounter();
     41 
     42  // load the third test frame
     43  // it will call back into this function via postMessage when it finishes loading.
     44  // and continue beyond the yield.
     45  yield iframe.src = 'file_bug704320_preload_attr.html';
     46 
     47  // check the third test
     48  yield checkResults(finalizePreloadReferrerPolicyAttr);
     49 
     50  // complete.
     51  SimpleTest.finish();
     52 })();
     53 
     54 // Helper functions below.
     55 
     56 /**
     57 * This checks the second test: a test where preloads SHOULD be reused.
     58 * We expect one request for each image, script, js request since
     59 * the referrer policy does not change after speculative loads.
     60 */
     61 function finalizePreloadReuse(results) {
     62  var expected = {'css': {'count': 1, 'referrers': ['origin']},
     63                  'img': {'count': 1, 'referrers': ['origin']},
     64                  'js':  {'count': 1, 'referrers': ['origin']}};
     65 
     66  for (var x in expected) {
     67    ok(x in results, "some " + x + " loads required in results object.");
     68 
     69    is(results[x].count, expected[x].count,
     70       "Expected " + expected[x].count + " loads for " + x + " requests.");
     71 
     72    // 'origin' is required
     73    ok(results[x].referrers.includes('origin'),
     74       "One load for " + x + " should have had 'origin' referrer.");
     75 
     76    // no other values should be in the referrers.
     77    is(results[x].referrers.indexOf('none'), -1,
     78       "No loads for " + x + " should have a missing referrer.");
     79    is(results[x].referrers.indexOf('full'), -1,
     80       "No loads for " + x + " should have an 'full' referrer.")
     81  }
     82 
     83  advance();
     84 }
     85 
     86 /**
     87 * This checks the third test: a test where preload requests of image, style
     88 * should use referrerpolicy attribute and we expect the preloads should not
     89 * be reused
     90 */
     91 function finalizePreloadReferrerPolicyAttr(results) {
     92  var expected = {'css': {'count': 1, 'referrers': ['origin']},
     93                  'img': {'count': 1, 'referrers': ['origin']},
     94                  'js':  {'count': 1, 'referrers': ['origin']}};
     95 
     96  for (var x in expected) {
     97    ok(x in results, "some " + x + " loads required in results object.");
     98 
     99    is(results[x].count, expected[x].count,
    100       "Expected " + expected[x].count + " loads for " + x + " requests.");
    101 
    102    // 'origin' is required
    103    ok(results[x].referrers.includes('origin'),
    104       "One load for " + x + " should have had 'origin' referrer.");
    105 
    106    // no other values should be in the referrers.
    107    is(results[x].referrers.indexOf('none'), -1,
    108       "No loads for " + x + " should have a missing referrer.");
    109    is(results[x].referrers.indexOf('full'), -1,
    110       "No loads for " + x + " should have an 'full' referrer.")
    111  }
    112 
    113  advance();
    114 }
    115 
    116 /**
    117 * Grabs the results via XHR and passes to checker.
    118 */
    119 function checkResults(checker) {
    120  doXHR('/tests/dom/base/test/bug704320_counter.sjs?results',
    121        function(xhr) {
    122          checker(JSON.parse(xhr.responseText));
    123        },
    124        function(xhr) {
    125          ok(false, "Can't get results from the counter server.");
    126        });
    127 }
    128 
    129 </script>
    130 </head>
    131 
    132 <body onload="tests.next();">
    133  <iframe id="testframe"></iframe>
    134 
    135 </body>
    136 </html>