dom/workers/test/test_loadError.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial