1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/tests/test_ril_worker_clip.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this); 1.8 + 1.9 +function run_test() { 1.10 + run_next_test(); 1.11 +} 1.12 + 1.13 +function _getWorker() { 1.14 + let _postedMessage; 1.15 + let _worker = newWorker({ 1.16 + postRILMessage: function(data) { 1.17 + }, 1.18 + postMessage: function(message) { 1.19 + _postedMessage = message; 1.20 + } 1.21 + }); 1.22 + return { 1.23 + get postedMessage() { 1.24 + return _postedMessage; 1.25 + }, 1.26 + get worker() { 1.27 + return _worker; 1.28 + } 1.29 + }; 1.30 +} 1.31 + 1.32 +add_test(function test_queryCLIP_provisioned() { 1.33 + let workerHelper = _getWorker(); 1.34 + let worker = workerHelper.worker; 1.35 + let context = worker.ContextPool._contexts[0]; 1.36 + 1.37 + context.Buf.readInt32 = function fakeReadUint32() { 1.38 + return context.Buf.int32Array.pop(); 1.39 + }; 1.40 + 1.41 + context.RIL.queryCLIP = function fakeQueryCLIP(options) { 1.42 + context.Buf.int32Array = [ 1.43 + 1, // CLIP provisioned. 1.44 + 1 // Length. 1.45 + ]; 1.46 + context.RIL[REQUEST_QUERY_CLIP](1, { 1.47 + rilRequestError: ERROR_SUCCESS 1.48 + }); 1.49 + }; 1.50 + 1.51 + context.RIL.queryCLIP({}); 1.52 + 1.53 + let postedMessage = workerHelper.postedMessage; 1.54 + 1.55 + do_check_eq(postedMessage.errorMsg, undefined); 1.56 + do_check_true(postedMessage.success); 1.57 + do_check_eq(postedMessage.provisioned, 1); 1.58 + run_next_test(); 1.59 +}); 1.60 + 1.61 +add_test(function test_getCLIP_error_generic_failure_invalid_length() { 1.62 + let workerHelper = _getWorker(); 1.63 + let worker = workerHelper.worker; 1.64 + let context = worker.ContextPool._contexts[0]; 1.65 + 1.66 + context.Buf.readInt32 = function fakeReadUint32() { 1.67 + return context.Buf.int32Array.pop(); 1.68 + }; 1.69 + 1.70 + context.RIL.queryCLIP = function fakeQueryCLIP(options) { 1.71 + context.Buf.int32Array = [ 1.72 + 1, // CLIP provisioned. 1.73 + 0 // Length. 1.74 + ]; 1.75 + context.RIL[REQUEST_QUERY_CLIP](1, { 1.76 + rilRequestError: ERROR_SUCCESS 1.77 + }); 1.78 + }; 1.79 + 1.80 + context.RIL.queryCLIP({}); 1.81 + 1.82 + let postedMessage = workerHelper.postedMessage; 1.83 + 1.84 + do_check_eq(postedMessage.errorMsg, "GenericFailure"); 1.85 + do_check_false(postedMessage.success); 1.86 + run_next_test(); 1.87 +});