tor-browser

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

sethtml-tree-construction.tentative.html (2475B)


      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 
      9 // Testcases from the old(er) support/testcases.sub.js file, ported over to
     10 // the HTML5Lib testcase format.
     11 promise_test(_ => {
     12  return html5lib_testcases_from_response(fetch("sethtml-tree-construction.sub.dat")).
     13      then(testcases => {
     14        testcases.forEach((testcase, index) => {
     15          test(_ => {
     16            const div = document.createElement("div");
     17            let config = undefined;
     18            try {
     19              config = JSON.parse(testcase.config);
     20            } catch { }
     21            try {
     22              div.setHTML(testcase.data, { sanitizer: config });
     23            } catch (error) {
     24              assert_equals(
     25                error.name, testcase.error,
     26                `Expect exception ${testcase.error}, but got ${error}.`);
     27              return;  // Early return in order to not trigger the subsequent
     28                       // assertions.
     29            }
     30            assert_false(
     31              !!testcase.error,
     32              `Expect exception ${testcase.error}, but nothing was thrown.`);
     33            assert_testcase(div, testcase);
     34          }, `Testcase #${index}, "${testcase.data}", config: "${testcase.config}".`);
     35        });
     36      });
     37 }, "wrapper");
     38 
     39 // support/testcases.sub.js contained a few testcases with non-strings as
     40 // input. The html5lib format doesn't support that, so we'll just add them here:
     41 test(_ => {
     42  const div = document.createElement("div");
     43  div.setHTML({});
     44  assert_equals(div.outerHTML, "<div>[object Object]</div>");
     45 }, "Non-string input: empty object.");
     46 test(_ => {
     47  const div = document.createElement("div");
     48  div.setHTML(1);
     49  assert_equals(div.outerHTML, "<div>1</div>");
     50 }, "Non-string input: number.");
     51 test(_ => {
     52  const div = document.createElement("div");
     53  div.setHTML(000);
     54  assert_equals(div.outerHTML, "<div>0</div>");
     55 }, "Non-string input: octal number.");
     56 test(_ => {
     57  const div = document.createElement("div");
     58  div.setHTML(1 + 2);
     59  assert_equals(div.outerHTML, "<div>3</div>");
     60 }, "Non-string input: expression.");
     61 test(_ => {
     62  const div = document.createElement("div");
     63  div.setHTML(undefined);
     64  assert_equals(div.outerHTML, "<div>undefined</div>");
     65 }, "Non-string input: undefined.");
     66 
     67 </script>
     68 </head>
     69 <body>
     70 </body>