Bug 793192 - MMI Codes: support call forwarding. Part 3 - Tests; r=marshall_law
authorFernando Jiménez <ferjmoreno@gmail.com>
Wed, 07 Nov 2012 14:13:53 -0800
changeset 112659 85867b1963cff8a319e6848b1492e6a18f72b127
parent 112658 8ce4b53fb01505f20a9b4aef8b73e6a6597ca01a
child 112660 1082da6b9dc2f88950918dd3432dc07889bd740d
push id23833
push useremorley@mozilla.com
push dateThu, 08 Nov 2012 10:20:57 +0000
treeherdermozilla-central@e0d7b394462b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarshall_law
bugs793192
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 793192 - MMI Codes: support call forwarding. Part 3 - Tests; r=marshall_law
dom/system/gonk/tests/test_ril_worker_mmi.js
--- a/dom/system/gonk/tests/test_ril_worker_mmi.js
+++ b/dom/system/gonk/tests/test_ril_worker_mmi.js
@@ -14,27 +14,46 @@ function parseMMI(mmi) {
     },
     postMessage: function fakePostMessage(message) {
       // Do nothing
     }
   });
   return worker.RIL._parseMMI(mmi);
 }
 
-function testSendMMI(mmi, error) {
-  let postedMessage;
-  let worker = newWorker({
+function getWorker() {
+  let _postedMessage;
+  let _worker = newWorker({
     postRILMessage: function fakePostRILMessage(data) {
     },
     postMessage: function fakePostMessage(message) {
-      postedMessage = message;
+      _postedMessage = message;
+    },
+  });
+
+  return {
+    get postedMessage() {
+      return _postedMessage;
+    },
+    get worker() {
+      return _worker;
     }
-  })
+  };
+}
+
+function testSendMMI(mmi, error) {
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
+
+  do_print("worker.postMessage " + worker.postMessage);
+
   worker.RIL.sendMMI({mmi: mmi});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_eq(postedMessage.rilMessageType, "sendMMI");
   do_check_eq(postedMessage.errorMsg, error);
 }
 
 add_test(function test_parseMMI_empty() {
   let mmi = parseMMI("");
 
   do_check_null(mmi);
@@ -304,41 +323,169 @@ add_test(function test_sendMMI_invalid()
 });
 
 add_test(function test_sendMMI_dial_string() {
   testSendMMI("123", "NO_VALID_MMI_STRING");
 
   run_next_test();
 });
 
-add_test(function test_sendMMI_call_forwarding() {
-  // TODO: Bug 793192 - MMI Codes: support call forwarding
-  testSendMMI("*21#", "CALL_FORWARDING_NOT_SUPPORTED_VIA_MMI");
+function setCallForwardSuccess(mmi) {
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
+
+  worker.RIL.setCallForward = function fakeSetCallForward(options) {
+    worker.RIL[REQUEST_SET_CALL_FORWARD](0, {
+      rilRequestError: ERROR_SUCCESS
+    });
+  };
+
+  worker.RIL.sendMMI({mmi: mmi});
+
+  let postedMessage = workerhelper.postedMessage;
+
+  do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
+  do_check_true(postedMessage.success);
+}
+
+add_test(function test_sendMMI_call_forwarding_activation() {
+  setCallForwardSuccess("*21*12345*99*10#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_deactivation() {
+  setCallForwardSuccess("#21*12345*99*10#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_interrogation() {
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
+
+  worker.Buf.readUint32 = function fakeReadUint32() {
+    return worker.Buf.int32Array.pop();
+  };
+
+  worker.Buf.readString = function fakeReadString() {
+    return "+34666222333";
+  };
+
+  worker.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
+    worker.Buf.int32Array = [
+      0,   // rules.timeSeconds
+      145, // rules.toa
+      49,  // rules.serviceClass
+      Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL, // rules.reason
+      1,   // rules.active
+      1    // rulesLength
+    ];
+    worker.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
+      rilRequestError: ERROR_SUCCESS
+    });
+  };
+
+  worker.RIL.sendMMI({mmi: "*#21#"});
+
+  let postedMessage = workerhelper.postedMessage;
+
+  do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
+  do_check_true(postedMessage.success);
+  do_check_true(Array.isArray(postedMessage.rules));
+  do_check_eq(postedMessage.rules.length, 1);
+  do_check_true(postedMessage.rules[0].active);
+  do_check_eq(postedMessage.rules[0].reason,
+              Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL);
+  do_check_eq(postedMessage.rules[0].number, "+34666222333");
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_interrogation_no_rules() {
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
+
+  worker.Buf.readUint32 = function fakeReadUint32() {
+    return 0;
+  };
+
+  worker.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
+    worker.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
+      rilRequestError: ERROR_SUCCESS
+    });
+  };
+
+  worker.RIL.sendMMI({mmi: "*#21#"});
+
+  let postedMessage = workerhelper.postedMessage;
+
+  do_check_eq(postedMessage.errorMsg,
+              "Invalid rule length while querying call forwarding status.");
+  do_check_false(postedMessage.success);
+
+  run_next_test();
+});
+
+
+add_test(function test_sendMMI_call_forwarding_registration() {
+  setCallForwardSuccess("**21*12345*99*10#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_erasure() {
+  setCallForwardSuccess("##21*12345*99#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_CFB() {
+  setCallForwardSuccess("*67*12345*99*10#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_CFNRy() {
+  setCallForwardSuccess("*61*12345*99*10#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_CFNRc() {
+  setCallForwardSuccess("*62*12345*99*10#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_CFAll() {
+  setCallForwardSuccess("*004*12345*99*10#");
+
+  run_next_test();
+});
+
+add_test(function test_sendMMI_call_forwarding_CFAllConditional() {
+  setCallForwardSuccess("*002*12345*99*10#");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_change_PIN() {
-  let postedMessage;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
 
-  worker.RIL.changeICCPIN = function fakeChangeICCPIN(options){
+  worker.RIL.changeICCPIN = function fakeChangeICCPIN(options) {
     worker.RIL[REQUEST_ENTER_SIM_PIN](0, {
       rilRequestError: ERROR_SUCCESS
     });
   }
 
   worker.RIL.sendMMI({mmi: "**04*1234*4567*4567#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_change_PIN_no_new_PIN() {
   testSendMMI("**04*1234**4567#", "MISSING_SUPPLEMENTARY_INFORMATION");
@@ -360,33 +507,29 @@ add_test(function test_sendMMI_change_PI
 
 add_test(function test_sendMMI_change_PIN_new_PIN_mismatch() {
   testSendMMI("**04*4567*1234*4567#", "NEW_PIN_MISMATCH");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_change_PIN2() {
-  let postedMessage;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
 
   worker.RIL.changeICCPIN2 = function fakeChangeICCPIN2(options){
     worker.RIL[REQUEST_ENTER_SIM_PIN2](0, {
       rilRequestError: ERROR_SUCCESS
     });
   }
 
   worker.RIL.sendMMI({mmi: "**042*1234*4567*4567#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_change_PIN2_no_new_PIN2() {
   testSendMMI("**042*1234**4567#", "MISSING_SUPPLEMENTARY_INFORMATION");
@@ -408,33 +551,29 @@ add_test(function test_sendMMI_change_PI
 
 add_test(function test_sendMMI_change_PIN2_new_PIN2_mismatch() {
   testSendMMI("**042*4567*1234*4567#", "NEW_PIN_MISMATCH");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_unblock_PIN() {
-  let postedMessage;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
 
   worker.RIL.enterICCPUK = function fakeEnterICCPUK(options){
     worker.RIL[REQUEST_ENTER_SIM_PUK](0, {
       rilRequestError: ERROR_SUCCESS
     });
   }
 
   worker.RIL.sendMMI({mmi: "**05*1234*4567*4567#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_unblock_PIN_no_new_PIN() {
   testSendMMI("**05*1234**4567#", "MISSING_SUPPLEMENTARY_INFORMATION");
@@ -456,33 +595,29 @@ add_test(function test_sendMMI_unblock_P
 
 add_test(function test_sendMMI_unblock_PIN_new_PIN_mismatch() {
   testSendMMI("**05*4567*1234*4567#", "NEW_PIN_MISMATCH");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_unblock_PIN2() {
-  let postedMessage;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
 
   worker.RIL.enterICCPUK2 = function fakeEnterICCPUK2(options){
     worker.RIL[REQUEST_ENTER_SIM_PUK2](0, {
       rilRequestError: ERROR_SUCCESS
     });
   }
 
   worker.RIL.sendMMI({mmi: "**052*1234*4567*4567#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_unblock_PIN2_no_new_PIN2() {
   testSendMMI("**052*1234**4567#", "MISSING_SUPPLEMENTARY_INFORMATION");
@@ -504,62 +639,54 @@ add_test(function test_sendMMI_unblock_P
 
 add_test(function test_sendMMI_unblock_PIN2_new_PIN_mismatch() {
   testSendMMI("**052*4567*1234*4567#", "NEW_PIN_MISMATCH");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_get_IMEI() {
-  let postedMessage;
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
   let mmiOptions;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
 
   worker.RIL.getIMEI = function getIMEI(options){
     mmiOptions = options;
     worker.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_SUCCESS,
     });
   }
 
   worker.RIL.sendMMI({mmi: "*#06#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_true(mmiOptions.mmi);
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_get_IMEI_error() {
-  let postedMessage;
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
   let mmiOptions;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
 
   worker.RIL.getIMEI = function getIMEI(options){
     mmiOptions = options;
     worker.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_RADIO_NOT_AVAILABLE,
     });
   }
 
   worker.RIL.sendMMI({mmi: "*#06#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_true(mmiOptions.mmi);
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_RADIO_NOT_AVAILABLE);
   do_check_false(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_call_barring() {
@@ -570,62 +697,54 @@ add_test(function test_sendMMI_call_barr
 
 add_test(function test_sendMMI_call_waiting() {
   testSendMMI("*43#", "CALL_WAITING_NOT_SUPPORTED_VIA_MMI");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_USSD() {
-  let postedMessage;
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
   let ussdOptions;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
 
   worker.RIL.sendUSSD = function fakeSendUSSD(options){
     ussdOptions = options;
     worker.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_SUCCESS
     });
   }
 
   worker.RIL.sendMMI({mmi: "*123#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_eq(ussdOptions.ussd, "*123#");
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
   do_check_true(worker.RIL._ussdSession);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_USSD_error() {
-  let postedMessage;
+  let workerhelper = getWorker();
+  let worker = workerhelper.worker;
   let ussdOptions;
-  let worker = newWorker({
-    postRILMessage: function fakePostRILMessage(data) {
-    },
-    postMessage: function fakePostMessage(message) {
-      postedMessage = message;
-    },
-  });
 
   worker.RIL.sendUSSD = function fakeSendUSSD(options){
     ussdOptions = options;
     worker.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_GENERIC_FAILURE
     });
   }
 
   worker.RIL.sendMMI({mmi: "*123#"});
 
+  let postedMessage = workerhelper.postedMessage;
+
   do_check_eq(ussdOptions.ussd, "*123#");
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_GENERIC_FAILURE);
   do_check_false(postedMessage.success);
   do_check_false(worker.RIL._ussdSession);
 
   run_next_test();
 });