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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | 'use strict'; |
michael@0 | 5 | |
michael@0 | 6 | let chrome = require('chrome'); |
michael@0 | 7 | |
michael@0 | 8 | const FIXTURES_URL = module.uri.substr(0, module.uri.lastIndexOf('/') + 1) + |
michael@0 | 9 | 'fixtures/chrome-worker/' |
michael@0 | 10 | |
michael@0 | 11 | exports['test addEventListener'] = function(assert, done) { |
michael@0 | 12 | let uri = FIXTURES_URL + 'addEventListener.js'; |
michael@0 | 13 | |
michael@0 | 14 | let worker = new chrome.ChromeWorker(uri); |
michael@0 | 15 | worker.addEventListener('message', function(event) { |
michael@0 | 16 | assert.equal(event.data, 'Hello', 'message received'); |
michael@0 | 17 | worker.terminate(); |
michael@0 | 18 | done(); |
michael@0 | 19 | }); |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | exports['test onmessage'] = function(assert, done) { |
michael@0 | 23 | let uri = FIXTURES_URL + 'onmessage.js'; |
michael@0 | 24 | |
michael@0 | 25 | let worker = new chrome.ChromeWorker(uri); |
michael@0 | 26 | worker.onmessage = function(event) { |
michael@0 | 27 | assert.equal(event.data, 'ok', 'message received'); |
michael@0 | 28 | worker.terminate(); |
michael@0 | 29 | done(); |
michael@0 | 30 | }; |
michael@0 | 31 | worker.postMessage('ok'); |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | exports['test setTimeout'] = function(assert, done) { |
michael@0 | 35 | let uri = FIXTURES_URL + 'setTimeout.js'; |
michael@0 | 36 | |
michael@0 | 37 | let worker = new chrome.ChromeWorker(uri); |
michael@0 | 38 | worker.onmessage = function(event) { |
michael@0 | 39 | assert.equal(event.data, 'ok', 'setTimeout fired'); |
michael@0 | 40 | worker.terminate(); |
michael@0 | 41 | done(); |
michael@0 | 42 | }; |
michael@0 | 43 | }; |
michael@0 | 44 | |
michael@0 | 45 | exports['test jsctypes'] = function(assert, done) { |
michael@0 | 46 | let uri = FIXTURES_URL + 'jsctypes.js'; |
michael@0 | 47 | |
michael@0 | 48 | let worker = new chrome.ChromeWorker(uri); |
michael@0 | 49 | worker.onmessage = function(event) { |
michael@0 | 50 | assert.equal(event.data, 'function', 'ctypes.open is a function'); |
michael@0 | 51 | worker.terminate(); |
michael@0 | 52 | done(); |
michael@0 | 53 | }; |
michael@0 | 54 | }; |
michael@0 | 55 | |
michael@0 | 56 | exports['test XMLHttpRequest'] = function(assert, done) { |
michael@0 | 57 | let uri = FIXTURES_URL + 'xhr.js'; |
michael@0 | 58 | |
michael@0 | 59 | let worker = new chrome.ChromeWorker(uri); |
michael@0 | 60 | worker.onmessage = function(event) { |
michael@0 | 61 | assert.equal(event.data, 'ok', 'XMLHttpRequest works'); |
michael@0 | 62 | worker.terminate(); |
michael@0 | 63 | done(); |
michael@0 | 64 | }; |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | exports['test onerror'] = function(assert, done) { |
michael@0 | 68 | let uri = FIXTURES_URL + 'onerror.js'; |
michael@0 | 69 | |
michael@0 | 70 | let worker = new chrome.ChromeWorker(uri); |
michael@0 | 71 | worker.onerror = function(event) { |
michael@0 | 72 | assert.equal(event.filename, uri, 'event reports the correct uri'); |
michael@0 | 73 | assert.equal(event.lineno, 6, 'event reports the correct line number'); |
michael@0 | 74 | assert.equal(event.target, worker, 'event reports the correct worker'); |
michael@0 | 75 | assert.ok(event.message.match(/ok/), |
michael@0 | 76 | 'event contains the exception message'); |
michael@0 | 77 | // Call preventDefault in order to avoid being displayed in JS console. |
michael@0 | 78 | event.preventDefault(); |
michael@0 | 79 | worker.terminate(); |
michael@0 | 80 | done(); |
michael@0 | 81 | }; |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | require('sdk/test').run(exports); |