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