tor-browser

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

sethtml-safety.tentative.html (1709B)


      1 <!DOCTYPE html>
      2 <head>
      3 <title>Testcases from the previous Sanitizer API</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="support/html5lib-testcase-support.js"></script>
      7 <script>
      8 promise_test(async _ => {
      9  const safety = await fetch("sethtml-safety.sub.dat").
     10          then(response => response.text()).
     11          then(parse_html5lib_testcases);
     12  const unsafety = await fetch("sethtml-unsafety.sub.dat").
     13          then(response => response.text()).
     14          then(parse_html5lib_testcases);
     15 
     16  // Ensure that the "safe" and "unsafe" testcase inputs are the same and that
     17  // they only differ only in the expected outcome.
     18  assert_equals(safety.length, unsafety.length);
     19  for (let i = 0; i < safety.length; i++) {
     20    assert_equals(safety[i].data, unsafety[i].data);
     21    assert_equals(safety[i].config, unsafety[i].config);
     22    assert_equals(safety[i]["document-fragment"], unsafety[i]["document-fragment"]);
     23  }
     24 
     25  // The main tests here are non-async. Let's run them here, to make sure the
     26  // two fetches have completed.
     27  test_each("setHTML", safety);
     28  test_each("setHTMLUnsafe", unsafety);
     29 }, "wrapper");
     30 
     31 function test_each(method, testcases) {
     32  testcases.forEach((testcase, index) => {
     33    test(_ => {
     34      const context = document.createElement(testcase["document-fragment"] ?? "div");
     35      let config = undefined;
     36      try {
     37        config = JSON.parse(testcase.config);
     38      } catch { }
     39 
     40      context[method].call(context, testcase.data, { sanitizer: config });
     41      assert_testcase(context, testcase);
     42    }, `Testcase #${index}, ${method}("${testcase.data})".`);
     43  });
     44 }
     45 </script>
     46 </head>
     47 <body>
     48 </body>