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 | subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); |
michael@0 | 5 | |
michael@0 | 6 | function run_test() { |
michael@0 | 7 | run_next_test(); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function _getWorker() { |
michael@0 | 11 | let _postedMessage; |
michael@0 | 12 | let _worker = newWorker({ |
michael@0 | 13 | postRILMessage: function(data) { |
michael@0 | 14 | }, |
michael@0 | 15 | postMessage: function(message) { |
michael@0 | 16 | _postedMessage = message; |
michael@0 | 17 | } |
michael@0 | 18 | }); |
michael@0 | 19 | return { |
michael@0 | 20 | get postedMessage() { |
michael@0 | 21 | return _postedMessage; |
michael@0 | 22 | }, |
michael@0 | 23 | get worker() { |
michael@0 | 24 | return _worker; |
michael@0 | 25 | } |
michael@0 | 26 | }; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | var timeoutCallback = null; |
michael@0 | 30 | var timeoutDelayMs = 0; |
michael@0 | 31 | const TIMER_ID = 1234; |
michael@0 | 32 | const TIMEOUT_VALUE = 300000; // 5 mins. |
michael@0 | 33 | |
michael@0 | 34 | // No window in xpcshell-test. Create our own timer mechanism. |
michael@0 | 35 | |
michael@0 | 36 | function setTimeout(callback, timeoutMs) { |
michael@0 | 37 | timeoutCallback = callback; |
michael@0 | 38 | timeoutDelayMs = timeoutMs; |
michael@0 | 39 | do_check_eq(timeoutMs, TIMEOUT_VALUE); |
michael@0 | 40 | return TIMER_ID; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function clearTimeout(timeoutId) { |
michael@0 | 44 | do_check_eq(timeoutId, TIMER_ID); |
michael@0 | 45 | timeoutCallback = null; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function fireTimeout() { |
michael@0 | 49 | do_check_neq(timeoutCallback, null); |
michael@0 | 50 | if (timeoutCallback) { |
michael@0 | 51 | timeoutCallback(); |
michael@0 | 52 | timeoutCallback = null; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | add_test(function test_enter_emergencyCbMode() { |
michael@0 | 57 | let workerHelper = _getWorker(); |
michael@0 | 58 | let worker = workerHelper.worker; |
michael@0 | 59 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 60 | |
michael@0 | 61 | // Do it twice. Should always send the event. |
michael@0 | 62 | for (let i = 0; i < 2; ++i) { |
michael@0 | 63 | context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE](); |
michael@0 | 64 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 65 | |
michael@0 | 66 | // Should store the mode. |
michael@0 | 67 | do_check_eq(context.RIL._isInEmergencyCbMode, true); |
michael@0 | 68 | |
michael@0 | 69 | // Should notify change. |
michael@0 | 70 | do_check_eq(postedMessage.rilMessageType, "emergencyCbModeChange"); |
michael@0 | 71 | do_check_eq(postedMessage.active, true); |
michael@0 | 72 | do_check_eq(postedMessage.timeoutMs, TIMEOUT_VALUE); |
michael@0 | 73 | |
michael@0 | 74 | // Should start timer. |
michael@0 | 75 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | run_next_test(); |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | add_test(function test_exit_emergencyCbMode() { |
michael@0 | 82 | let workerHelper = _getWorker(); |
michael@0 | 83 | let worker = workerHelper.worker; |
michael@0 | 84 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 85 | |
michael@0 | 86 | context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE](); |
michael@0 | 87 | context.RIL[UNSOLICITED_EXIT_EMERGENCY_CALLBACK_MODE](); |
michael@0 | 88 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 89 | |
michael@0 | 90 | // Should store the mode. |
michael@0 | 91 | do_check_eq(context.RIL._isInEmergencyCbMode, false); |
michael@0 | 92 | |
michael@0 | 93 | // Should notify change. |
michael@0 | 94 | do_check_eq(postedMessage.rilMessageType, "emergencyCbModeChange"); |
michael@0 | 95 | do_check_eq(postedMessage.active, false); |
michael@0 | 96 | |
michael@0 | 97 | // Should clear timer. |
michael@0 | 98 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null); |
michael@0 | 99 | |
michael@0 | 100 | run_next_test(); |
michael@0 | 101 | }); |
michael@0 | 102 | |
michael@0 | 103 | add_test(function test_request_exit_emergencyCbMode_when_timeout() { |
michael@0 | 104 | let workerHelper = _getWorker(); |
michael@0 | 105 | let worker = workerHelper.worker; |
michael@0 | 106 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 107 | |
michael@0 | 108 | context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE](); |
michael@0 | 109 | do_check_eq(context.RIL._isInEmergencyCbMode, true); |
michael@0 | 110 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID); |
michael@0 | 111 | |
michael@0 | 112 | let parcelTypes = []; |
michael@0 | 113 | context.Buf.newParcel = function(type, options) { |
michael@0 | 114 | parcelTypes.push(type); |
michael@0 | 115 | }; |
michael@0 | 116 | |
michael@0 | 117 | // Timeout. |
michael@0 | 118 | fireTimeout(); |
michael@0 | 119 | |
michael@0 | 120 | // Should clear timeout event. |
michael@0 | 121 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null); |
michael@0 | 122 | |
michael@0 | 123 | // Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE. |
michael@0 | 124 | do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1); |
michael@0 | 125 | |
michael@0 | 126 | run_next_test(); |
michael@0 | 127 | }); |
michael@0 | 128 | |
michael@0 | 129 | add_test(function test_request_exit_emergencyCbMode_when_dial() { |
michael@0 | 130 | let workerHelper = _getWorker(); |
michael@0 | 131 | let worker = workerHelper.worker; |
michael@0 | 132 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 133 | |
michael@0 | 134 | context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE](); |
michael@0 | 135 | do_check_eq(context.RIL._isInEmergencyCbMode, true); |
michael@0 | 136 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID); |
michael@0 | 137 | |
michael@0 | 138 | let parcelTypes = []; |
michael@0 | 139 | context.Buf.newParcel = function(type, options) { |
michael@0 | 140 | parcelTypes.push(type); |
michael@0 | 141 | }; |
michael@0 | 142 | |
michael@0 | 143 | // Dial non-emergency call. |
michael@0 | 144 | context.RIL.dial({number: "0912345678", |
michael@0 | 145 | isDialEmergency: false}); |
michael@0 | 146 | |
michael@0 | 147 | // Should clear timeout event. |
michael@0 | 148 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null); |
michael@0 | 149 | |
michael@0 | 150 | // Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE. |
michael@0 | 151 | do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1); |
michael@0 | 152 | |
michael@0 | 153 | run_next_test(); |
michael@0 | 154 | }); |
michael@0 | 155 | |
michael@0 | 156 | add_test(function test_request_exit_emergencyCbMode_explicitly() { |
michael@0 | 157 | let workerHelper = _getWorker(); |
michael@0 | 158 | let worker = workerHelper.worker; |
michael@0 | 159 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 160 | |
michael@0 | 161 | context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE](); |
michael@0 | 162 | do_check_eq(context.RIL._isInEmergencyCbMode, true); |
michael@0 | 163 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID); |
michael@0 | 164 | |
michael@0 | 165 | let parcelTypes = []; |
michael@0 | 166 | context.Buf.newParcel = function(type, options) { |
michael@0 | 167 | parcelTypes.push(type); |
michael@0 | 168 | }; |
michael@0 | 169 | |
michael@0 | 170 | context.RIL.handleChromeMessage({rilMessageType: "exitEmergencyCbMode"}); |
michael@0 | 171 | context.RIL[REQUEST_EXIT_EMERGENCY_CALLBACK_MODE](1, { |
michael@0 | 172 | rilMessageType: "exitEmergencyCbMode", |
michael@0 | 173 | rilRequestError: ERROR_SUCCESS |
michael@0 | 174 | }); |
michael@0 | 175 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 176 | |
michael@0 | 177 | // Should clear timeout event. |
michael@0 | 178 | do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null); |
michael@0 | 179 | |
michael@0 | 180 | // Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE. |
michael@0 | 181 | do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1); |
michael@0 | 182 | |
michael@0 | 183 | // Send back the response. |
michael@0 | 184 | do_check_eq(postedMessage.rilMessageType, "exitEmergencyCbMode"); |
michael@0 | 185 | |
michael@0 | 186 | run_next_test(); |
michael@0 | 187 | }); |
michael@0 | 188 |