Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | // Worker must be loaded from a chrome:// uri, not a file:// |
michael@0 | 7 | // uri, so we first need to load it. |
michael@0 | 8 | let WORKER_SOURCE_URI = "chrome://workers/content/worker.js"; |
michael@0 | 9 | do_load_manifest("data/chrome.manifest"); |
michael@0 | 10 | |
michael@0 | 11 | function run_test() { |
michael@0 | 12 | run_next_test(); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function talk_with_worker(worker) { |
michael@0 | 16 | let deferred = Promise.defer(); |
michael@0 | 17 | worker.onmessage = function(event) { |
michael@0 | 18 | let success = true; |
michael@0 | 19 | if (event.data == "OK") { |
michael@0 | 20 | deferred.resolve(); |
michael@0 | 21 | } else { |
michael@0 | 22 | success = false; |
michael@0 | 23 | deferred.reject(event); |
michael@0 | 24 | } |
michael@0 | 25 | do_check_true(success); |
michael@0 | 26 | worker.terminate(); |
michael@0 | 27 | }; |
michael@0 | 28 | worker.onerror = function(event) { |
michael@0 | 29 | let error = new Error(event.message, event.filename, event.lineno); |
michael@0 | 30 | worker.terminate(); |
michael@0 | 31 | deferred.reject(error); |
michael@0 | 32 | }; |
michael@0 | 33 | worker.postMessage("START"); |
michael@0 | 34 | return deferred.promise; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | add_task(function test_chrome_worker() { |
michael@0 | 39 | return talk_with_worker(new ChromeWorker(WORKER_SOURCE_URI)); |
michael@0 | 40 | }); |
michael@0 | 41 | |
michael@0 | 42 | add_task(function test_worker() { |
michael@0 | 43 | return talk_with_worker(new Worker(WORKER_SOURCE_URI)); |
michael@0 | 44 | }); |