parser/htmlparser/tests/mochitest/test_xml_mislabeled.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE html><meta charset=utf-8>
michael@0 2 <title>Test for mislabeled or unlabeled XML entities with U+xxD8</title>
michael@0 3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 4 <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
michael@0 5 <body>
michael@0 6 <script class="testbody">
michael@0 7 'use strict';
michael@0 8
michael@0 9 SimpleTest.waitForExplicitFinish();
michael@0 10
michael@0 11 var declaredEncodings = [null, 'utf-8', 'uTf-8', 'UTF-8', 'utf-16', 'uTf-16', 'UTF-16'];
michael@0 12 var actualEncodings = ['utf-8', 'utf-16be', 'utf-16le'];
michael@0 13 var i = 0, j = 0
michael@0 14 testxhr(declaredEncodings[i], actualEncodings[j]);
michael@0 15
michael@0 16 function testxhr(declaredEncoding, actualEncoding) {
michael@0 17 // utf-16 XML requres the BOM
michael@0 18 var bom = actualEncoding.startsWith('utf-16') ? '\uFEFF' : '';
michael@0 19 var xmlDecl = declaredEncoding ? '<?xml version="1.0" encoding="' + declaredEncoding + '" ?>\n' : '';
michael@0 20 // The test string need to contain U+xxD8 (bug 860180)
michael@0 21 var xmlString = bom + xmlDecl + '<test>testハヒフヘホ</test>';
michael@0 22 var xml = new TextEncoder(actualEncoding).encode(xmlString);
michael@0 23 var description = declaredEncoding ? ' labeled with ' + declaredEncoding : ' without XML declaration';
michael@0 24 if (!declaredEncoding || actualEncoding !== declaredEncoding.toLowerCase()) {
michael@0 25 description += ' but actually encoded with ' + actualEncoding;
michael@0 26 }
michael@0 27 var xhr = new XMLHttpRequest();
michael@0 28 var url = URL.createObjectURL(new Blob([xml], {type: 'text/xml'}));
michael@0 29 xhr.open('GET', url);
michael@0 30 xhr.send();
michael@0 31 xhr.onload = xhr.onerror = function(e) {
michael@0 32 URL.revokeObjectURL(url);
michael@0 33 is(e.type, 'load', 'xhr loading should succeed for XML' + description);
michael@0 34 is(xhr.responseXML.documentElement.textContent, 'testハヒフヘホ',
michael@0 35 'response should be available for XML' + description);
michael@0 36 testiframe(description, xml);
michael@0 37 };
michael@0 38 }
michael@0 39
michael@0 40 function testiframe(description, xml) {
michael@0 41 var iframe = document.createElement('iframe');
michael@0 42 var url = URL.createObjectURL(new Blob([xml], {type: 'text/xml'}))
michael@0 43 iframe.src = url;
michael@0 44 iframe.onload = iframe.onerror = function(e) {
michael@0 45 URL.revokeObjectURL(url);
michael@0 46 is(e.type, 'load', 'iframe loading should succeed for XML' + description);
michael@0 47 is(iframe.contentDocument.documentElement.textContent, 'testハヒフヘホ',
michael@0 48 'iframe content should be available for XML' + description);
michael@0 49 if (++i >= declaredEncodings.length) {
michael@0 50 i = 0;
michael@0 51 if (++j >= actualEncodings.length) {
michael@0 52 SimpleTest.finish();
michael@0 53 return;
michael@0 54 }
michael@0 55 }
michael@0 56 testxhr(declaredEncodings[i], actualEncodings[j]);
michael@0 57 };
michael@0 58 document.body.appendChild(iframe);
michael@0 59 }
michael@0 60 </script>
michael@0 61 <div id="display"></div>
michael@0 62 </body>

mercurial