michael@0: /* michael@0: * worker_helper.js michael@0: * bug 764234 tests michael@0: */ michael@0: function runTestInWorker(files) { michael@0: function workerRun() { michael@0: var tests = []; michael@0: var asserts; michael@0: test = function(func, msg) { michael@0: asserts = []; michael@0: tests.push({asserts: asserts, msg: msg}); michael@0: } michael@0: assert_equals = function(result, expected, msg) { michael@0: asserts.push(["assert_equals", result, expected, msg]); michael@0: }; michael@0: assert_true = function(condition, msg) { michael@0: asserts.push(["assert_true", condition, msg]); michael@0: }; michael@0: assert_unreached = function(condition, msg) { michael@0: asserts.push(["assert_unreached", condition, msg]); michael@0: }; michael@0: onmessage = function(event) { michael@0: importScripts.apply(self, event.data); michael@0: runTest(); michael@0: postMessage(tests); michael@0: }; michael@0: } michael@0: michael@0: var url = URL.createObjectURL(new Blob([ michael@0: runTest.toString(), "\n\n", michael@0: "(", workerRun.toString(), ")();" michael@0: ])); michael@0: var worker = new Worker(url); michael@0: var base = location.toString().replace(/\/[^\/]*$/,"/"); michael@0: worker.postMessage(files.map(function(f) { return base + f; })); michael@0: worker.onmessage = function(event) { michael@0: URL.revokeObjectURL(url); michael@0: event.data.forEach(function(t) { michael@0: test(function() { michael@0: t.asserts.forEach(function(a) { michael@0: func = a.shift(); michael@0: self[func].apply(self, a); michael@0: }); michael@0: }, "worker " + t.msg); michael@0: }); michael@0: done(); michael@0: }; michael@0: }