dom/workers/test/test_loadError.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 <html>
     6 <head>
     7   <title>Test for DOM Worker Threads</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body>
    12 <pre id="test">
    13 <script class="testbody" type="text/javascript">
    14 "use strict";
    16 try {
    17   var worker = new Worker("about:blank");
    18   ok(false, "Shouldn't success!");
    20   worker.onmessage = function(event) {
    21     ok(false, "Shouldn't get a message!");
    22     SimpleTest.finish();
    23   }
    25   worker.onerror = function(event) {
    26     ok(false, "Shouldn't get a error message!");
    27     SimpleTest.finish();
    28   }
    29 } catch (e) {
    30   ok(!worker, "worker should not be created");
    31   is(e.name, "SecurityError", "SecurityError should be thrown");
    32   is(e.code, DOMException.SECURITY_ERR, "SECURITY_ERR should be thrown");
    33 }
    35 (function(){
    36   function workerfunc() {
    37     try {
    38       var subworker = new Worker("about:blank");
    39       postMessage({});
    40     } catch (e) {
    41       postMessage({name: e.name, code: e.code});
    42     }
    43   }
    44   var b = new Blob([workerfunc+'workerfunc();']);
    45   var u = URL.createObjectURL(b);
    46   function callworker(i) {
    47     try {
    48       var w = new Worker(u);
    49       URL.revokeObjectURL(u);
    50       is(i, 0, 'worker creation succeeded');
    51     } catch (e) {
    52       is(i, 1, 'worker creation failed');
    53       SimpleTest.finish();
    54       return;
    55     }
    56     w.onmessage = function(e) {
    57       is(e.data.name, "SecurityError", "SecurityError should be thrown");
    58       is(e.data.code, DOMException.SECURITY_ERR, "SECURITY_ERR should be thrown");
    59       if (++i < 2) callworker(i);
    60       else SimpleTest.finish();
    61     };
    62   }
    63   callworker(0);
    64 })();
    66 SimpleTest.waitForExplicitFinish();
    68 </script>
    69 </pre>
    70 </body>
    71 </html>

mercurial