dom/system/gonk/tests/test_ril_worker_voiceprivacy.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 add_test(function test_setVoicePrivacyMode_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.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
michael@0 35 context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
michael@0 36 rilRequestError: ERROR_SUCCESS
michael@0 37 });
michael@0 38 };
michael@0 39
michael@0 40 context.RIL.setVoicePrivacyMode({
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
michael@0 48 run_next_test();
michael@0 49 });
michael@0 50
michael@0 51 add_test(function test_setVoicePrivacyMode_generic_failure() {
michael@0 52 let workerHelper = _getWorker();
michael@0 53 let worker = workerHelper.worker;
michael@0 54 let context = worker.ContextPool._contexts[0];
michael@0 55
michael@0 56 context.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
michael@0 57 context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
michael@0 58 rilRequestError: ERROR_GENERIC_FAILURE
michael@0 59 });
michael@0 60 };
michael@0 61
michael@0 62 context.RIL.setVoicePrivacyMode({
michael@0 63 enabled: true
michael@0 64 });
michael@0 65
michael@0 66 let postedMessage = workerHelper.postedMessage;
michael@0 67
michael@0 68 do_check_eq(postedMessage.errorMsg, "GenericFailure");
michael@0 69
michael@0 70 run_next_test();
michael@0 71 });
michael@0 72
michael@0 73 add_test(function test_queryVoicePrivacyMode_success_enabled_true() {
michael@0 74 let workerHelper = _getWorker();
michael@0 75 let worker = workerHelper.worker;
michael@0 76 let context = worker.ContextPool._contexts[0];
michael@0 77
michael@0 78 context.Buf.readInt32List = function fakeReadUint32List() {
michael@0 79 return [1];
michael@0 80 };
michael@0 81
michael@0 82 context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {
michael@0 83 context.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, {
michael@0 84 rilRequestError: ERROR_SUCCESS
michael@0 85 });
michael@0 86 };
michael@0 87
michael@0 88 context.RIL.queryVoicePrivacyMode();
michael@0 89
michael@0 90 let postedMessage = workerHelper.postedMessage;
michael@0 91
michael@0 92 do_check_eq(postedMessage.errorMsg, undefined);
michael@0 93 do_check_true(postedMessage.enabled);
michael@0 94 run_next_test();
michael@0 95 });
michael@0 96
michael@0 97 add_test(function test_queryVoicePrivacyMode_success_enabled_false() {
michael@0 98 let workerHelper = _getWorker();
michael@0 99 let worker = workerHelper.worker;
michael@0 100 let context = worker.ContextPool._contexts[0];
michael@0 101
michael@0 102 context.Buf.readInt32List = function fakeReadUint32List() {
michael@0 103 return [0];
michael@0 104 };
michael@0 105
michael@0 106 context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {
michael@0 107 context.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, {
michael@0 108 rilRequestError: ERROR_SUCCESS
michael@0 109 });
michael@0 110 };
michael@0 111
michael@0 112 context.RIL.queryVoicePrivacyMode();
michael@0 113
michael@0 114 let postedMessage = workerHelper.postedMessage;
michael@0 115
michael@0 116 do_check_eq(postedMessage.errorMsg, undefined);
michael@0 117 do_check_false(postedMessage.enabled);
michael@0 118 run_next_test();
michael@0 119 });

mercurial