dom/workers/test/test_loadEncoding.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!--
michael@0 2 Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 -->
michael@0 5 <!DOCTYPE HTML>
michael@0 6 <html>
michael@0 7 <head>
michael@0 8 <title>Bug 484305 - Load workers as UTF-8</title>
michael@0 9 <meta http-equiv="content-type" content="text/html; charset=KOI8-R">
michael@0 10 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 12 </head>
michael@0 13 <body>
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484305">Bug 484305 - Load workers as UTF-8</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none">
michael@0 17
michael@0 18 </div>
michael@0 19 <pre id="test">
michael@0 20 <script class="testbody" type="text/javascript">
michael@0 21
michael@0 22 SimpleTest.waitForExplicitFinish();
michael@0 23
michael@0 24 var canonical = String.fromCharCode(0x41F, 0x440, 0x438, 0x432, 0x435, 0x442);
michael@0 25 ok(document.inputEncoding === "KOI8-R", "Document encoding is KOI8-R");
michael@0 26
michael@0 27 // Worker sends two strings, one with `canonical` encoded in KOI8-R and one as UTF-8.
michael@0 28 // Since Worker scripts should always be decoded using UTF-8, even if the owning document's charset is different, the UTF-8 decode should match, while KOI8-R should fail.
michael@0 29 var counter = 0;
michael@0 30 var worker = new Worker("loadEncoding_worker.js");
michael@0 31 worker.onmessage = function(e) {
michael@0 32 if (e.data.encoding === "KOI8-R") {
michael@0 33 ok(e.data.text !== canonical, "KOI8-R decoded text should not match");
michael@0 34 } else if (e.data.encoding === "UTF-8") {
michael@0 35 ok(e.data.text === canonical, "UTF-8 decoded text should match");
michael@0 36 }
michael@0 37 counter++;
michael@0 38 if (counter === 2)
michael@0 39 SimpleTest.finish();
michael@0 40 }
michael@0 41
michael@0 42 worker.onerror = function(e) {
michael@0 43 ok(false, "Worker error");
michael@0 44 SimpleTest.finish();
michael@0 45 }
michael@0 46 </script>
michael@0 47
michael@0 48 </pre>
michael@0 49 </body>
michael@0 50 </html>

mercurial