dom/workers/test/test_loadEncoding.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial