tor-browser

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

required-document-policy.html (2733B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>Test advertised required document policy</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>  </head>
      7  <body>
      8    <h1>Test advertised required document policy</h1>
      9 <script>
     10 // The top-level document has a required document policy. Any requests for
     11 // documents in child frames must be sent with a required policy header
     12 // indicating a required policy at least as strict. (In this case, "at least as
     13 // strict" means that the 'bpp' parameter must be less than or equal to the
     14 // parent document's required value.)
     15 
     16 callbacks = {};
     17 
     18 window.addEventListener('message', ev => {
     19  var id = ev.data.id;
     20  if (id && callbacks[id]) {
     21    callbacks[id](ev.data.requiredPolicy || null);
     22  }
     23 });
     24 
     25 async_test(t => {
     26  var iframe = document.createElement('iframe');
     27  iframe.src = "/document-policy/echo-policy.py?id=1";
     28  callbacks["1"] = t.step_func_done(result => {
     29    assert_equals(result, "sync-xhr=?0");
     30  });
     31  document.body.appendChild(iframe);
     32 }, "Child frame with no explicit policy should have the same required policy as its parent.");
     33 
     34 async_test(t => {
     35  var iframe = document.createElement('iframe');
     36  iframe.src = "/document-policy/echo-policy.py?id=4";
     37  iframe.policy = "force-load-at-top=?0";
     38  callbacks["4"] = t.step_func_done(result => {
     39    assert_equals(result, "force-load-at-top=?0, sync-xhr=?0");
     40  });
     41  document.body.appendChild(iframe);
     42 }, "Any unrelated policy directives should combine with the parent's required policy.");
     43 
     44 // The following scenarios are not currently testable, as there are no configuration points
     45 // defined with numeric value types. They were previously run with this document having a
     46 // header policy of "lossless-images-max-bpp=1.1".
     47 // TODO: Reinstate these tests when such a configuration point is reintroduced.
     48 /*
     49 async_test(t => {
     50  var iframe = document.createElement('iframe');
     51  iframe.src = "/document-policy/echo-policy.py?id=2";
     52  iframe.policy = "lossless-images-max-bpp=4";
     53  callbacks["2"] = t.step_func_done(result => {
     54    assert_equals(result, "lossless-images-max-bpp=1.1");
     55  });
     56  document.body.appendChild(iframe);
     57 }, "Child frame with a less strict required policy should have the stricter value from the parent's policy applied.");
     58 
     59 async_test(t => {
     60  var iframe = document.createElement('iframe');
     61  iframe.src = "/document-policy/echo-policy.py?id=3";
     62  iframe.policy = "lossless-images-max-bpp=1.0";
     63  callbacks["3"] = t.step_func_done(result => {
     64    assert_equals(result, "lossless-images-max-bpp=1.0");
     65  });
     66  document.body.appendChild(iframe);
     67 }, "Child frame may have a stricter policy than the parent.");
     68 */
     69    </script>
     70  </body>
     71 </html>