worker_helper.js (1445B)
1 /* 2 * worker_helper.js 3 * bug 764234 tests 4 */ 5 6 // The undefined items here are used in the tests within the worker that this 7 // runs. 8 /* eslint-disable no-undef */ 9 10 function runTestInWorker(files) { 11 function workerRun() { 12 var tests = []; 13 var asserts; 14 test = function (func, msg) { 15 asserts = []; 16 tests.push({ asserts, msg }); 17 }; 18 assert_equals = function (result, expected, msg) { 19 asserts.push(["assert_equals", result, expected, msg]); 20 }; 21 assert_true = function (condition, msg) { 22 asserts.push(["assert_true", condition, msg]); 23 }; 24 assert_unreached = function (condition, msg) { 25 asserts.push(["assert_unreached", condition, msg]); 26 }; 27 onmessage = function (event) { 28 importScripts.apply(self, event.data); 29 runTest(); 30 postMessage(tests); 31 }; 32 } 33 34 var url = URL.createObjectURL( 35 new Blob([runTest.toString(), "\n\n", "(", workerRun.toString(), ")();"]) 36 ); 37 var worker = new Worker(url); 38 var base = location.toString().replace(/\/[^\/]*$/, "/"); 39 worker.postMessage( 40 files.map(function (f) { 41 return base + f; 42 }) 43 ); 44 worker.onmessage = function (event) { 45 URL.revokeObjectURL(url); 46 event.data.forEach(function (t) { 47 test(function () { 48 t.asserts.forEach(function (a) { 49 let func = a.shift(); 50 self[func].apply(self, a); 51 }); 52 }, "worker " + t.msg); 53 }); 54 done(); 55 }; 56 }