tor-browser

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

navigation.https.html (2226B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <script src="/resources/testharness.js"></script>
      5    <script src="/resources/testharnessreport.js"></script>
      6    <script src="support/test_utils.sub.js"></script>
      7  </head>
      8 
      9  <body>
     10    <script>
     11      /**
     12       * @param Array.<Array.<Datatype>> combination A combination of datatypes.
     13       * @param Dict.<string, boolean> report A map between a datatype name and
     14       *     whether it is empty.
     15       * @return boolean Whether all datatypes are empty if and only if they are
     16       *     included in the |combination|.
     17       */
     18      function verifyDatatypes(combination, report) {
     19        TestUtils.DATATYPES.forEach(function(datatype) {
     20          if (combination.indexOf(datatype) != -1) {
     21            assert_true(
     22                report[datatype.name],
     23                datatype.name + " should have been cleared.");
     24          } else {
     25            assert_false(
     26                report[datatype.name],
     27                datatype.name + " should NOT have been cleared.");
     28          }
     29        });
     30      }
     31 
     32      TestUtils.COMBINATIONS.forEach(function(combination) {
     33        var test_name =
     34            "Clear datatypes on navigation: " +
     35            combination.map(function(e) { return e.name; }).join(", ");
     36 
     37        promise_test(function(test) {
     38          return new Promise(function(resolve_test, reject_test) {
     39            TestUtils.populateDatatypes()
     40                .then(function() {
     41                  // Navigate to a resource with a Clear-Site-Data header in
     42                  // an iframe, then verify that the correct types have been
     43                  // deleted.
     44                  return new Promise(function(resolve, reject) {
     45                    window.addEventListener("message", resolve);
     46                    var iframe = document.createElement("iframe");
     47                    iframe.src = TestUtils.getClearSiteDataUrl(combination);
     48                    document.body.appendChild(iframe);
     49                  }).then(function(messageEvent) {
     50                    verifyDatatypes(combination, messageEvent.data);
     51                    resolve_test();
     52                  });
     53                });
     54          });
     55        }, test_name);
     56      });
     57    </script>
     58  </body>
     59 </html>