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 | 'use strict'; |
michael@0 | 2 | |
michael@0 | 3 | // resolve multiple promise in parallel |
michael@0 | 4 | function expectAll(aValue) { |
michael@0 | 5 | let deferred = new Promise(function(resolve, reject) { |
michael@0 | 6 | let countdown = aValue.length; |
michael@0 | 7 | let resolutionValues = new Array(countdown); |
michael@0 | 8 | |
michael@0 | 9 | for (let i = 0; i < aValue.length; i++) { |
michael@0 | 10 | let index = i; |
michael@0 | 11 | aValue[i].then(function(val) { |
michael@0 | 12 | resolutionValues[index] = val; |
michael@0 | 13 | if (--countdown === 0) { |
michael@0 | 14 | resolve(resolutionValues); |
michael@0 | 15 | } |
michael@0 | 16 | }, reject); |
michael@0 | 17 | } |
michael@0 | 18 | }); |
michael@0 | 19 | |
michael@0 | 20 | return deferred; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function TestInit() { |
michael@0 | 24 | let url = SimpleTest.getTestFileURL("RecordingStatusChromeScript.js") |
michael@0 | 25 | let script = SpecialPowers.loadChromeScript(url); |
michael@0 | 26 | |
michael@0 | 27 | let helper = { |
michael@0 | 28 | finish: function () { |
michael@0 | 29 | script.destroy(); |
michael@0 | 30 | }, |
michael@0 | 31 | fakeShutdown: function () { |
michael@0 | 32 | script.sendAsyncMessage('fake-content-shutdown', {}); |
michael@0 | 33 | } |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | script.addMessageListener('chrome-event', function (message) { |
michael@0 | 37 | if (helper.hasOwnProperty('onEvent')) { |
michael@0 | 38 | helper.onEvent(message); |
michael@0 | 39 | } else { |
michael@0 | 40 | ok(false, 'unexpected message: ' + JSON.stringify(message)); |
michael@0 | 41 | } |
michael@0 | 42 | }); |
michael@0 | 43 | |
michael@0 | 44 | script.sendAsyncMessage("init-chrome-event", { |
michael@0 | 45 | type: 'recording-status' |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | return Promise.resolve(helper); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function expectEvent(expected, eventHelper) { |
michael@0 | 52 | return new Promise(function(resolve, reject) { |
michael@0 | 53 | eventHelper.onEvent = function(message) { |
michael@0 | 54 | delete eventHelper.onEvent; |
michael@0 | 55 | ok(message, JSON.stringify(message)); |
michael@0 | 56 | is(message.type, 'recording-status', 'event type: ' + message.type); |
michael@0 | 57 | is(message.active, expected.active, 'recording active: ' + message.active); |
michael@0 | 58 | is(message.isAudio, expected.isAudio, 'audio recording active: ' + message.isAudio); |
michael@0 | 59 | is(message.isVideo, expected.isVideo, 'video recording active: ' + message.isVideo); |
michael@0 | 60 | resolve(eventHelper); |
michael@0 | 61 | }; |
michael@0 | 62 | info('waiting for recording-status'); |
michael@0 | 63 | }); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function expectStream(params, callback) { |
michael@0 | 67 | return new Promise(function(resolve, reject) { |
michael@0 | 68 | var req = navigator.mozGetUserMedia( |
michael@0 | 69 | params, |
michael@0 | 70 | function(stream) { |
michael@0 | 71 | ok(true, 'create media stream'); |
michael@0 | 72 | callback(stream); |
michael@0 | 73 | resolve(); |
michael@0 | 74 | }, |
michael@0 | 75 | function(err) { |
michael@0 | 76 | ok(false, 'fail to create media stream'); |
michael@0 | 77 | reject(err); |
michael@0 | 78 | } |
michael@0 | 79 | ); |
michael@0 | 80 | info('waiting for gUM result'); |
michael@0 | 81 | }); |
michael@0 | 82 | } |