parser/htmlparser/tests/mochitest/test_xml_mislabeled.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/htmlparser/tests/mochitest/test_xml_mislabeled.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +<!DOCTYPE html><meta charset=utf-8>
     1.5 +<title>Test for mislabeled or unlabeled XML entities with U+xxD8</title>
     1.6 +<script src="/tests/SimpleTest/SimpleTest.js"></script>
     1.7 +<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
     1.8 +<body>
     1.9 +<script class="testbody">
    1.10 +'use strict';
    1.11 +
    1.12 +SimpleTest.waitForExplicitFinish();
    1.13 +
    1.14 +var declaredEncodings = [null, 'utf-8', 'uTf-8', 'UTF-8', 'utf-16', 'uTf-16', 'UTF-16'];
    1.15 +var actualEncodings = ['utf-8', 'utf-16be', 'utf-16le'];
    1.16 +var i = 0, j = 0
    1.17 +testxhr(declaredEncodings[i], actualEncodings[j]);
    1.18 +
    1.19 +function testxhr(declaredEncoding, actualEncoding) {
    1.20 +  // utf-16 XML requres the BOM
    1.21 +  var bom = actualEncoding.startsWith('utf-16') ? '\uFEFF' : '';
    1.22 +  var xmlDecl = declaredEncoding ? '<?xml version="1.0" encoding="' + declaredEncoding + '" ?>\n' : '';
    1.23 +  // The test string need to contain U+xxD8 (bug 860180)
    1.24 +  var xmlString = bom + xmlDecl + '<test>testハヒフヘホ</test>';
    1.25 +  var xml = new TextEncoder(actualEncoding).encode(xmlString);
    1.26 +  var description = declaredEncoding ? ' labeled with ' + declaredEncoding : ' without XML declaration';
    1.27 +  if (!declaredEncoding || actualEncoding !== declaredEncoding.toLowerCase()) {
    1.28 +    description += ' but actually encoded with ' + actualEncoding;
    1.29 +  }
    1.30 +  var xhr = new XMLHttpRequest();
    1.31 +  var url = URL.createObjectURL(new Blob([xml], {type: 'text/xml'}));
    1.32 +  xhr.open('GET', url);
    1.33 +  xhr.send();
    1.34 +  xhr.onload = xhr.onerror = function(e) {
    1.35 +    URL.revokeObjectURL(url);
    1.36 +    is(e.type, 'load', 'xhr loading should succeed for XML' + description);
    1.37 +    is(xhr.responseXML.documentElement.textContent, 'testハヒフヘホ',
    1.38 +       'response should be available for XML' + description);
    1.39 +    testiframe(description, xml);
    1.40 +  };
    1.41 +}
    1.42 +
    1.43 +function testiframe(description, xml) {
    1.44 +  var iframe = document.createElement('iframe');
    1.45 +  var url = URL.createObjectURL(new Blob([xml], {type: 'text/xml'}))
    1.46 +  iframe.src = url;
    1.47 +  iframe.onload = iframe.onerror = function(e) {
    1.48 +    URL.revokeObjectURL(url);
    1.49 +    is(e.type, 'load', 'iframe loading should succeed for XML' + description);
    1.50 +    is(iframe.contentDocument.documentElement.textContent, 'testハヒフヘホ',
    1.51 +       'iframe content should be available for XML' + description);
    1.52 +    if (++i >= declaredEncodings.length) {
    1.53 +      i = 0;
    1.54 +      if (++j >= actualEncodings.length) {
    1.55 +        SimpleTest.finish();
    1.56 +        return;
    1.57 +      }
    1.58 +    }
    1.59 +    testxhr(declaredEncodings[i], actualEncodings[j]);
    1.60 +  };
    1.61 +  document.body.appendChild(iframe);
    1.62 +}
    1.63 +</script>
    1.64 +<div id="display"></div>
    1.65 +</body>

mercurial