tor-browser

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

xhtml-mathml-dtd-entity.htm (2067B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <script>
      4  var parser = new DOMParser();
      5  var parse = parser.parseFromString.bind(parser);
      6 
      7  function generateTestFunction(entitystring, expectedString, publicId, systemId, mimeType, friendlyMime) {
      8    return function () {
      9      var doctypeString = '<!DOCTYPE html';
     10      if (publicId != null)
     11        doctypeString += ' PUBLIC "' + publicId + '" "' + systemId + '">';
     12      else if (systemId != null)
     13        doctypeString += ' SYSTEM "' + systemId + '">';
     14      else // both are null
     15        doctypeString += '>';
     16      var doc = parse(doctypeString + "<html><head></head><body id='test'>"+entitystring+"</body></html>", mimeType);
     17      var root = doc.getElementById('test');
     18      parent.assert_not_equals(root, null, friendlyMime + " parsing the entity reference caused a parse error;");
     19      parent.assert_true(!!root.firstChild);
     20      // Next line because some browsers include the partial parsed result in the parser error returned document.
     21      parent.assert_equals(root.firstChild.nodeType, 3/*Text*/, friendlyMime + " parsing the entity reference caused a parse error;");
     22      var text = root.firstChild.data;
     23      for (var i = 0, len = expectedString.length; i < len; i++) {
     24        parent.assert_equals(text.charCodeAt(i),expectedString.charCodeAt(i));
     25      }
     26    }
     27  }
     28 
     29  function setupTests(jsonEntities, publicId, systemId, mimeType, friendlyMime) {
     30    for (entityName in jsonEntities) {
     31      if ((mimeType == "text/html") || /;$/.test(entityName)) {
     32        parent.test(generateTestFunction(entityName, jsonEntities[entityName].characters, publicId, systemId, mimeType, friendlyMime), friendlyMime + " parsing " + entityName);
     33      }
     34    }
     35  }
     36 
     37  parent.setup(function() {}, {explicit_done: true});
     38 
     39  function run(row) {
     40    var xhr = new XMLHttpRequest();
     41    xhr.open("GET", "entities.json");
     42    xhr.onload = function () {
     43      var entitiesJSON = JSON.parse(xhr.response);
     44      setupTests(entitiesJSON, row[1], row[2], row[0], row[3]);
     45      parent.done();
     46    }
     47    xhr.send();
     48  }
     49 </script>