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 | 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 | add_test(function test_setCallWaiting_success() { |
michael@0 | 30 | let workerHelper = _getWorker(); |
michael@0 | 31 | let worker = workerHelper.worker; |
michael@0 | 32 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 33 | |
michael@0 | 34 | context.RIL.setCallWaiting = function fakeSetCallWaiting(options) { |
michael@0 | 35 | context.RIL[REQUEST_SET_CALL_WAITING](0, { |
michael@0 | 36 | rilRequestError: ERROR_SUCCESS |
michael@0 | 37 | }); |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | context.RIL.setCallWaiting({ |
michael@0 | 41 | enabled: true |
michael@0 | 42 | }); |
michael@0 | 43 | |
michael@0 | 44 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 45 | |
michael@0 | 46 | do_check_eq(postedMessage.errorMsg, undefined); |
michael@0 | 47 | do_check_true(postedMessage.success); |
michael@0 | 48 | |
michael@0 | 49 | run_next_test(); |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | add_test(function test_setCallWaiting_generic_failure() { |
michael@0 | 53 | let workerHelper = _getWorker(); |
michael@0 | 54 | let worker = workerHelper.worker; |
michael@0 | 55 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 56 | |
michael@0 | 57 | context.RIL.setCallWaiting = function fakeSetCallWaiting(options) { |
michael@0 | 58 | context.RIL[REQUEST_SET_CALL_WAITING](0, { |
michael@0 | 59 | rilRequestError: ERROR_GENERIC_FAILURE |
michael@0 | 60 | }); |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | context.RIL.setCallWaiting({ |
michael@0 | 64 | enabled: true |
michael@0 | 65 | }); |
michael@0 | 66 | |
michael@0 | 67 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 68 | |
michael@0 | 69 | do_check_eq(postedMessage.errorMsg, "GenericFailure"); |
michael@0 | 70 | do_check_false(postedMessage.success); |
michael@0 | 71 | |
michael@0 | 72 | run_next_test(); |
michael@0 | 73 | }); |
michael@0 | 74 | |
michael@0 | 75 | add_test(function test_queryCallWaiting_success_enabled_true() { |
michael@0 | 76 | let workerHelper = _getWorker(); |
michael@0 | 77 | let worker = workerHelper.worker; |
michael@0 | 78 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 79 | |
michael@0 | 80 | context.Buf.readInt32 = function fakeReadUint32() { |
michael@0 | 81 | return context.Buf.int32Array.pop(); |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) { |
michael@0 | 85 | context.Buf.int32Array = [ |
michael@0 | 86 | 1, // serviceClass |
michael@0 | 87 | 1, // enabled |
michael@0 | 88 | 1 // length |
michael@0 | 89 | ]; |
michael@0 | 90 | context.RIL[REQUEST_QUERY_CALL_WAITING](1, { |
michael@0 | 91 | rilRequestError: ERROR_SUCCESS |
michael@0 | 92 | }); |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | context.RIL.queryCallWaiting({}); |
michael@0 | 96 | |
michael@0 | 97 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 98 | |
michael@0 | 99 | do_check_eq(postedMessage.errorMsg, undefined); |
michael@0 | 100 | do_check_true(postedMessage.success); |
michael@0 | 101 | do_check_eq(postedMessage.length, 1); |
michael@0 | 102 | do_check_true(postedMessage.enabled); |
michael@0 | 103 | run_next_test(); |
michael@0 | 104 | }); |
michael@0 | 105 | |
michael@0 | 106 | add_test(function test_queryCallWaiting_success_enabled_false() { |
michael@0 | 107 | let workerHelper = _getWorker(); |
michael@0 | 108 | let worker = workerHelper.worker; |
michael@0 | 109 | let context = worker.ContextPool._contexts[0]; |
michael@0 | 110 | |
michael@0 | 111 | context.Buf.readInt32 = function fakeReadUint32() { |
michael@0 | 112 | return context.Buf.int32Array.pop(); |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) { |
michael@0 | 116 | context.Buf.int32Array = [ |
michael@0 | 117 | 1, // serviceClass |
michael@0 | 118 | 0, // enabled |
michael@0 | 119 | 1 // length |
michael@0 | 120 | ]; |
michael@0 | 121 | context.RIL[REQUEST_QUERY_CALL_WAITING](1, { |
michael@0 | 122 | rilRequestError: ERROR_SUCCESS |
michael@0 | 123 | }); |
michael@0 | 124 | }; |
michael@0 | 125 | |
michael@0 | 126 | context.RIL.queryCallWaiting({}); |
michael@0 | 127 | |
michael@0 | 128 | let postedMessage = workerHelper.postedMessage; |
michael@0 | 129 | |
michael@0 | 130 | do_check_eq(postedMessage.errorMsg, undefined); |
michael@0 | 131 | do_check_true(postedMessage.success); |
michael@0 | 132 | do_check_eq(postedMessage.length, 1); |
michael@0 | 133 | do_check_false(postedMessage.enabled); |
michael@0 | 134 | run_next_test(); |
michael@0 | 135 | }); |