test_loadError.html (1555B)
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 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"; 15 16 function nextTest() { 17 (function(){ 18 function workerfunc() { 19 var subworker = new Worker("about:blank"); 20 subworker.onerror = function(e) { 21 e.preventDefault(); 22 postMessage("ERROR"); 23 } 24 } 25 var b = new Blob([workerfunc+'workerfunc();']); 26 var u = URL.createObjectURL(b); 27 function callworker(i) { 28 var w = new Worker(u); 29 URL.revokeObjectURL(u); 30 w.onmessage = function(e) { 31 is(i, 0, 'Message received'); 32 is(e.data, "ERROR", 33 "Should catch the error when loading inner script"); 34 if (++i < 2) callworker(i); 35 else SimpleTest.finish(); 36 }; 37 w.onerror = function(e) { 38 is(i, 1, 'OnError received'); 39 SimpleTest.finish(); 40 } 41 } 42 callworker(0); 43 })(); 44 } 45 46 try { 47 var worker = new Worker("about:blank"); 48 worker.onerror = function(e) { 49 e.preventDefault(); 50 nextTest(); 51 } 52 53 worker.onmessage = function(event) { 54 ok(false, "Shouldn't get a message!"); 55 SimpleTest.finish(); 56 } 57 } catch (e) { 58 ok(false, "This should not happen."); 59 } 60 61 62 SimpleTest.waitForExplicitFinish(); 63 64 </script> 65 </pre> 66 </body> 67 </html>