Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / workers / text-encoding.html
blob7e909ec27a9e77e5193e46f13ec8e5268e3278d3
1 <html>
2 <meta http-equiv="content-type" content="text/html; charset=windows-1251">
3 <body>
4 This test verifies handling of text encoding in workers. The behavior matches FF3.1b2 with a single exclusion (see below).<br>
5 This is what's tested:<br>
6 - If http header 'Content-Type' with 'charset' specified is on response with worker script or XHR payload, that encoding is used.<br>
7 - In absence of http header, the script of the worker is decoded using UTF-8.<br>
8 - In absence of http header, the content of the XHR request is decoded using UTF-8.<br>
9 - The URLs used in workers (for subworkers or XHR) are always encoded using UTF-8 (in regular html documents parts of the query an hash may be encoded with other encodings).<br>
10 - The base URL for the worker (used to resolve relative URLs for subworkers and XHR) is the URL of its script.<br>
11 - importScripts() decodes the scripts using UTF-8.<br>
13 <div style="background:beige; padding:10px;" id="status"></div>
15 <script>
16 if (window.testRunner) {
17 testRunner.dumpAsText();
18 testRunner.waitUntilDone();
21 // Wait for this many workers to finish their tests.
22 // When worker is done, it sends 'exit' message.
23 var workerCount = 2;
25 // Messages from workers in separate threads will come in unstable order. Sort them to have a stable test.
26 var statusStrings = new Array;
28 function finishTest()
30 statusStrings.sort();
31 var status_panel = document.getElementById("status");
32 for (var i = 0; i < statusStrings.length; ++i) {
33 status_panel.appendChild(document.createTextNode(statusStrings[i]));
34 status_panel.appendChild(document.createElement("br"));
36 if (window.testRunner)
37 testRunner.notifyDone();
40 function log(source, msg)
42 statusStrings.push(source + ": " + msg);
44 if (msg == "exit" && --workerCount == 0)
45 finishTest();
48 // Output current charset and a string in that encoding to make
49 // sure this document is decoded as Windows-1251.
50 log("Document encoding", document.inputEncoding);
51 log("Document", "Ïðîâåðêà");
53 log("Document, Workers", "All XHR responses should match this: " + String.fromCharCode(0x41F, 0x440, 0x438, 0x432, 0x435, 0x442));
55 // Run a worker w/o http header. It should inherit the encoding of the document.
56 var worker1 = new Worker("resources/worker-encoded.php");
57 worker1.onmessage = function(evt) { log("worker 1", evt.data); };
59 // Run a worker with http header specifying charset. This new charset should be in effect.
60 var worker2 = new Worker("resources/worker-encoded.php?charset=koi8-r");
61 worker2.onmessage = function(evt) { log("worker 2", evt.data); };
63 // Request some content. It should be decoded using UTF-8 even though current document is Windows-1251.
64 var xhr = new XMLHttpRequest();xhr.open("GET", "resources/xhr-response.php", false);
65 xhr.send();log("Document: ", xhr.responseText);
67 </script>
68 </body>
69 </html>