dom/workers/test/test_loadError.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/test/test_loadError.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +<!--
     1.5 +  Any copyright is dedicated to the Public Domain.
     1.6 +  http://creativecommons.org/publicdomain/zero/1.0/
     1.7 +-->
     1.8 +<html>
     1.9 +<head>
    1.10 +  <title>Test for DOM Worker Threads</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<pre id="test">
    1.16 +<script class="testbody" type="text/javascript">
    1.17 +"use strict";
    1.18 +
    1.19 +try {
    1.20 +  var worker = new Worker("about:blank");
    1.21 +  ok(false, "Shouldn't success!");
    1.22 +
    1.23 +  worker.onmessage = function(event) {
    1.24 +    ok(false, "Shouldn't get a message!");
    1.25 +    SimpleTest.finish();
    1.26 +  }
    1.27 +
    1.28 +  worker.onerror = function(event) {
    1.29 +    ok(false, "Shouldn't get a error message!");
    1.30 +    SimpleTest.finish();
    1.31 +  }
    1.32 +} catch (e) {
    1.33 +  ok(!worker, "worker should not be created");
    1.34 +  is(e.name, "SecurityError", "SecurityError should be thrown");
    1.35 +  is(e.code, DOMException.SECURITY_ERR, "SECURITY_ERR should be thrown");
    1.36 +}
    1.37 +
    1.38 +(function(){
    1.39 +  function workerfunc() {
    1.40 +    try {
    1.41 +      var subworker = new Worker("about:blank");
    1.42 +      postMessage({});
    1.43 +    } catch (e) {
    1.44 +      postMessage({name: e.name, code: e.code});
    1.45 +    }
    1.46 +  }
    1.47 +  var b = new Blob([workerfunc+'workerfunc();']);
    1.48 +  var u = URL.createObjectURL(b);
    1.49 +  function callworker(i) {
    1.50 +    try {
    1.51 +      var w = new Worker(u);
    1.52 +      URL.revokeObjectURL(u);
    1.53 +      is(i, 0, 'worker creation succeeded');
    1.54 +    } catch (e) {
    1.55 +      is(i, 1, 'worker creation failed');
    1.56 +      SimpleTest.finish();
    1.57 +      return;
    1.58 +    }
    1.59 +    w.onmessage = function(e) {
    1.60 +      is(e.data.name, "SecurityError", "SecurityError should be thrown");
    1.61 +      is(e.data.code, DOMException.SECURITY_ERR, "SECURITY_ERR should be thrown");
    1.62 +      if (++i < 2) callworker(i);
    1.63 +      else SimpleTest.finish();
    1.64 +    };
    1.65 +  }
    1.66 +  callworker(0);
    1.67 +})();
    1.68 +
    1.69 +SimpleTest.waitForExplicitFinish();
    1.70 +
    1.71 +</script>
    1.72 +</pre>
    1.73 +</body>
    1.74 +</html>
    1.75 +

mercurial