tor-browser

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

invalid-json.https.tentative.html (1714B)


      1 <!DOCTYPE html>
      2 <title>WebBundle subresource loading with script API and invalid JSON</title>
      3 <link
      4  rel="help"
      5  href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md"
      6 />
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <body>
     10  <script>
     11    setup(
     12      () => {
     13        assert_true(HTMLScriptElement.supports("webbundle"));
     14      },
     15      { allow_uncaught_exception: true }
     16    );
     17    promise_test((t) => {
     18      const script = document.createElement("script");
     19      script.type = "webbundle";
     20      script.textContent = "invalid json";
     21      return new Promise((resolve, reject) => {
     22        script.onload = () => reject(script);
     23        script.onerror = () => reject(script);
     24        window.onerror = function (message, url, line, col, error) {
     25          assert_equals(error.name, "SyntaxError");
     26          resolve(script);
     27        };
     28        document.body.appendChild(script);
     29      });
     30    }, "Invalid JSON rule should throw a SyntaxError on the window.");
     31    promise_test((t) => {
     32      const script = document.createElement("script");
     33      script.type = "webbundle";
     34      const json_rule = { resources: [] };
     35      script.textContent = JSON.stringify(json_rule);
     36      return new Promise((resolve, reject) => {
     37        script.onload = () => reject(script);
     38        script.onerror = () => reject(script);
     39        window.onerror = function (message, url, line, col, error) {
     40          assert_equals(error.name, "TypeError");
     41          resolve(script);
     42        };
     43        document.body.appendChild(script);
     44      });
     45    }, "JSON rule with a type error should throw a TypeError on the window.");
     46  </script>
     47 </body>