| <html> |
| <meta http-equiv="content-type" content="text/html; charset=windows-1251"> |
| <body> |
| This test verifies handling of text encoding in workers. The behavior matches FF3.1b2 with a single exclusion (see below).<br> |
| This is what's tested:<br> |
| - If http header 'Content-Type' with 'charset' specified is on response with worker script or XHR payload, that encoding is used.<br> |
| - In absence of http header, the script of the worker is decoded using UTF-8.<br> |
| - In absence of http header, the content of the XHR request is decoded using UTF-8.<br> |
| - 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> |
| - The base URL for the worker (used to resolve relative URLs for subworkers and XHR) is the URL of its script.<br> |
| - importScripts() decodes the scripts using UTF-8.<br> |
| |
| <div style="background:beige; padding:10px;" id="status"></div> |
| |
| <script> |
| if (window.testRunner) { |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| } |
| |
| // Wait for this many workers to finish their tests. |
| // When worker is done, it sends 'exit' message. |
| var workerCount = 2; |
| |
| // Messages from workers in separate threads will come in unstable order. Sort them to have a stable test. |
| var statusStrings = new Array; |
| |
| function finishTest() |
| { |
| statusStrings.sort(); |
| var status_panel = document.getElementById("status"); |
| for (var i = 0; i < statusStrings.length; ++i) { |
| status_panel.appendChild(document.createTextNode(statusStrings[i])); |
| status_panel.appendChild(document.createElement("br")); |
| } |
| if (window.testRunner) |
| testRunner.notifyDone(); |
| } |
| |
| function log(source, msg) |
| { |
| statusStrings.push(source + ": " + msg); |
| |
| if (msg == "exit" && --workerCount == 0) |
| finishTest(); |
| } |
| |
| // Output current charset and a string in that encoding to make |
| // sure this document is decoded as Windows-1251. |
| log("Document encoding", document.inputEncoding); |
| log("Document", "Ïðîâåðêà"); |
| |
| log("Document, Workers", "All XHR responses should match this: " + String.fromCharCode(0x41F, 0x440, 0x438, 0x432, 0x435, 0x442)); |
| |
| // Run a worker w/o http header. It should inherit the encoding of the document. |
| var worker1 = new Worker("resources/worker-encoded.py"); |
| worker1.onmessage = function(evt) { log("worker 1", evt.data); }; |
| |
| // Run a worker with http header specifying charset. This new charset should be in effect. |
| var worker2 = new Worker("resources/worker-encoded.py?charset=koi8-r"); |
| worker2.onmessage = function(evt) { log("worker 2", evt.data); }; |
| |
| // Request some content. It should be decoded using UTF-8 even though current document is Windows-1251. |
| var xhr = new XMLHttpRequest();xhr.open("GET", "resources/xhr-response.py", false); |
| xhr.send();log("Document: ", xhr.responseText); |
| |
| </script> |
| </body> |
| </html> |
| |
| |