Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | Components.utils.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 5 | |
michael@0 | 6 | let WORKER_SOURCE_URI = "chrome://test_lz4/content/worker_lz4.js"; |
michael@0 | 7 | do_load_manifest("data/chrome.manifest"); |
michael@0 | 8 | |
michael@0 | 9 | function run_test() { |
michael@0 | 10 | run_next_test(); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | add_task(function() { |
michael@0 | 15 | let worker = new ChromeWorker(WORKER_SOURCE_URI); |
michael@0 | 16 | let deferred = Promise.defer(); |
michael@0 | 17 | worker.onmessage = function(event) { |
michael@0 | 18 | let data = event.data; |
michael@0 | 19 | switch (data.kind) { |
michael@0 | 20 | case "do_check_true": |
michael@0 | 21 | try { |
michael@0 | 22 | do_check_true(data.args[0]); |
michael@0 | 23 | } catch (ex) { |
michael@0 | 24 | // Ignore errors |
michael@0 | 25 | } |
michael@0 | 26 | return; |
michael@0 | 27 | case "do_test_complete": |
michael@0 | 28 | deferred.resolve(); |
michael@0 | 29 | worker.terminate(); |
michael@0 | 30 | break; |
michael@0 | 31 | case "do_print": |
michael@0 | 32 | do_print(data.args[0]); |
michael@0 | 33 | } |
michael@0 | 34 | }; |
michael@0 | 35 | worker.onerror = function(event) { |
michael@0 | 36 | let error = new Error(event.message, event.filename, event.lineno); |
michael@0 | 37 | worker.terminate(); |
michael@0 | 38 | deferred.reject(error); |
michael@0 | 39 | }; |
michael@0 | 40 | worker.postMessage("START"); |
michael@0 | 41 | return deferred.promise; |
michael@0 | 42 | }); |
michael@0 | 43 |