WorkerHandler.js (1309B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * Sets the worker message and error event handlers to respond to SimpleTest 6 * style messages. 7 */ 8 function listenForTests(worker, opts = { verbose: true }) { 9 worker.onerror = function (error) { 10 error.preventDefault(); 11 ok(false, "Worker error " + error.message); 12 }; 13 worker.onmessage = function (msg) { 14 if (opts && opts.verbose) { 15 ok(true, "MAIN: onmessage " + JSON.stringify(msg.data)); 16 } 17 switch (msg.data.kind) { 18 case "is": 19 SimpleTest.ok( 20 msg.data.outcome, 21 msg.data.description + "( " + msg.data.a + " ==? " + msg.data.b + ")" 22 ); 23 return; 24 case "isnot": 25 SimpleTest.ok( 26 msg.data.outcome, 27 msg.data.description + "( " + msg.data.a + " !=? " + msg.data.b + ")" 28 ); 29 return; 30 case "ok": 31 SimpleTest.ok(msg.data.condition, msg.data.description); 32 return; 33 case "info": 34 SimpleTest.info(msg.data.description); 35 return; 36 case "finish": 37 SimpleTest.finish(); 38 return; 39 default: 40 SimpleTest.ok( 41 false, 42 "test_osfile.xul: wrong message " + JSON.stringify(msg.data) 43 ); 44 } 45 }; 46 }