tor-browser

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

test_xml_parse_error.html (3196B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title><!-- TODO: insert title here --></title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      8  <script>
      9    function getExpectedError(string, filename=location.href) {
     10      let lines = string.split(/\r\n|\r|\n/);
     11      let line, column;
     12      let errorLine;
     13      for (line = 0; line < lines.length; ++line) {
     14        errorLine = lines[line];
     15        // The error starts at the opening '<' of '<b>'.
     16        column = errorLine.search("<<b>") + 1;
     17        if (column > 0) {
     18          // Line and column are 1-based.
     19          line += 1;
     20          column += 1;
     21          break;
     22        }
     23      }
     24 
     25      let expectedError = `XML Parsing Error: not well-formed
     26 Location: ${filename}
     27 Line Number ${line}, Column ${column}:${errorLine}
     28 ${"^".padStart(column, "-")}`;
     29      return expectedError;
     30    }
     31 
     32    function getParseError(string) {
     33      let error = new window.DOMParser()
     34        .parseFromString(string, "text/xml")
     35        .getElementsByTagName("parsererror")[0].textContent;
     36      return [error, getExpectedError(string)];
     37    }
     38 
     39    SimpleTest.waitForExplicitFinish();
     40 
     41    function runTest() {
     42      let [error, expectedError] = getParseError("<p>Not a <<b>well-formed</b> xml string</p>");
     43      is(error, expectedError, "Check that parsererror contains the right data.");
     44 
     45      [error, expectedError] = getParseError("<p>Not \na <<b>well-formed</b> xml string</p>");
     46      is(error, expectedError, "Check that parsererror contains the right data.");
     47 
     48      [error, expectedError] = getParseError("<p>Not \na <<b>well-formed</b> xml string</p>");
     49      is(error, expectedError, "Check that parsererror contains the right data.");
     50 
     51      [error, expectedError] = getParseError("<p>Not a <<b>well-fo\nrmed</b> xml string</p>");
     52      is(error, expectedError, "Check that parsererror contains the right data.");
     53 
     54      [error, expectedError] = getParseError(`<p>Not ${' '.repeat(512)} a <<b>well-formed</b> xml string</p>`);
     55      is(error, expectedError, "Check that parsererror contains the right data.");
     56 
     57      [error, expectedError] = getParseError(`<p>${' '.repeat(505)}<br>${' '.repeat(512)}<<b>Not a well-formed</b> xml string</p>`);
     58      is(error, expectedError, "Check that parsererror contains the right data.");
     59 
     60      [error, expectedError] = getParseError(`<p>${' '.repeat(2048)}<br>${' '.repeat(512)}<<b>Not a well-formed</b> xml string</p>`);
     61      is(error, expectedError, "Check that parsererror contains the right data.");
     62 
     63      fetch("file_xml_parse_error.xml").then(response => response.text()).then(string => {
     64        let doc = document.getElementById("frame").contentDocument;
     65        error = doc.documentElement.textContent;
     66        expectedError = getExpectedError(string, doc.location);
     67        is(error, expectedError, "Check that parsererror contains the right data.");
     68 
     69        SimpleTest.finish();
     70      });
     71    }
     72  </script>
     73 </head>
     74 <body onload="runTest()">
     75 <p id="display"><iframe id="frame" src="file_xml_parse_error.xml"></iframe></p>
     76 <div id="content" style="display: none"></div>
     77 <pre id="test"></pre>
     78 </body>
     79 </html>