Bug 1087968 - Part 1: Split test_stk_proactive_command.js into localInfo and timerManagement. r=hsinyi
authorEdgar Chen <echen@mozilla.com>
Fri, 07 Nov 2014 00:37:58 +0800
changeset 225642 f972d9f7d3a138bf27a4da0e3aa6060573705731
parent 225641 6c54902867a3608f869b24e0749788ed79840891
child 225643 28ed9a1001302eb08766b6062209d19837d98185
push id13452
push userechen@mozilla.com
push dateMon, 26 Jan 2015 15:05:15 +0000
treeherderb2g-inbound@0e4c49b5337a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs1087968
milestone38.0a1
Bug 1087968 - Part 1: Split test_stk_proactive_command.js into localInfo and timerManagement. r=hsinyi
dom/icc/tests/marionette/head.js
dom/icc/tests/marionette/manifest.ini
dom/icc/tests/marionette/test_stk_local_info.js
dom/icc/tests/marionette/test_stk_proactive_command.js
dom/icc/tests/marionette/test_stk_timer_management.js
--- a/dom/icc/tests/marionette/head.js
+++ b/dom/icc/tests/marionette/head.js
@@ -53,16 +53,31 @@ function runEmulatorCmdSafe(aCommand) {
     } else {
       deferred.reject(aResult);
     }
   });
 
   return deferred.promise;
 }
 
+/**
+ * Send stk proactive pdu.
+ *
+ * Fulfill params: (none)
+ * Reject params: (none)
+ *
+ * @param aPdu
+ *
+ * @return A deferred promise.
+ */
+function sendEmulatorStkPdu(aPdu) {
+  let cmd = "stk pdu " + aPdu;
+  return runEmulatorCmdSafe(cmd);
+}
+
 let workingFrame;
 let iccManager;
 
 /**
  * Push required permissions and test if
  * |navigator.mozIccManager| exists. Resolve if it does,
  * reject otherwise.
  *
--- a/dom/icc/tests/marionette/manifest.ini
+++ b/dom/icc/tests/marionette/manifest.ini
@@ -1,14 +1,13 @@
 [DEFAULT]
 b2g = true
 browser = false
 qemu = true
 
-[test_stk_proactive_command.js]
 [test_icc_contact.js]
 [test_icc_card_lock_get_retry_count.js]
 [test_icc_card_lock_change_pin.js]
 [test_icc_card_lock_enable_pin.js]
 [test_icc_card_lock_unlock_pin.js]
 [test_icc_card_lock_unlock_puk.js]
 [test_icc_card_state.js]
 [test_icc_info.js]
@@ -23,12 +22,14 @@ qemu = true
 [test_stk_launch_browser.js]
 [test_stk_display_text.js]
 [test_stk_get_inkey.js]
 [test_stk_get_input.js]
 [test_stk_select_item.js]
 [test_stk_setup_menu.js]
 [test_stk_setup_idle_mode_text.js]
 [test_stk_bip_command.js]
+[test_stk_local_info.js]
+[test_stk_timer_management.js]
 [test_icc_access_invalid_object.js]
 [test_icc_detected_undetected_event.js]
 [test_icc_match_mvno.js]
 [test_icc_service_state.js]
new file mode 100644
--- /dev/null
+++ b/dom/icc/tests/marionette/test_stk_local_info.js
@@ -0,0 +1,56 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = "head.js";
+
+const TEST_DATA = [
+  // Location
+  {command: "d009810301260082028182",
+   expect: {commandNumber: 0x01,
+            commandQualifier: MozIccManager.STK_LOCAL_INFO_LOCATION_INFO,
+            localInfoType: MozIccManager.STK_LOCAL_INFO_LOCATION_INFO}},
+  // Imei
+  {command: "d009810301260182028182",
+   expect: {commandNumber: 0x01,
+            commandQualifier: MozIccManager.STK_LOCAL_INFO_IMEI,
+            localInfoType: MozIccManager.STK_LOCAL_INFO_IMEI}},
+  // Data
+  {command: "d009810301260382028182",
+   expect: {commandNumber: 0x01,
+            commandQualifier: MozIccManager.STK_LOCAL_INFO_DATE_TIME_ZONE,
+            localInfoType: MozIccManager.STK_LOCAL_INFO_DATE_TIME_ZONE}},
+  // Language
+  {command: "d009810301260482028182",
+   expect: {commandNumber: 0x01,
+            commandQualifier: MozIccManager.STK_LOCAL_INFO_LANGUAGE,
+            localInfoType: MozIccManager.STK_LOCAL_INFO_LANGUAGE}},
+];
+
+function testLocalInfo(aCommand, aExpect) {
+  is(aCommand.typeOfCommand, MozIccManager.STK_CMD_PROVIDE_LOCAL_INFO, "typeOfCommand");
+  is(aCommand.commandQualifier, aExpect.commandQualifier, "commandQualifier");
+  is(aCommand.options.localInfoType, aExpect.localInfoType, "options.localInfoType");
+}
+
+// Start tests
+startTestCommon(function() {
+  let icc = getMozIcc();
+  let promise = Promise.resolve();
+  for (let i = 0; i < TEST_DATA.length; i++) {
+    let data = TEST_DATA[i];
+    promise = promise.then(() => {
+      log("local_info_cmd: " + data.command);
+
+      let promises = [];
+      // Wait onstkcommand event.
+      promises.push(waitForTargetEvent(icc, "stkcommand")
+        .then((aEvent) => testLocalInfo(aEvent.command, data.expect)));
+      // Send emulator command to generate stk unsolicited event.
+      promises.push(sendEmulatorStkPdu(data.command));
+
+      return Promise.all(promises);
+    });
+  }
+  return promise;
+});
deleted file mode 100644
--- a/dom/icc/tests/marionette/test_stk_proactive_command.js
+++ /dev/null
@@ -1,107 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-MARIONETTE_HEAD_JS = "stk_helper.js";
-
-function testLocalInfoLocation(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_PROVIDE_LOCAL_INFO);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, iccManager.STK_LOCAL_INFO_LOCATION_INFO);
-  is(cmd.options.localInfoType, iccManager.STK_LOCAL_INFO_LOCATION_INFO);
-
-  runNextTest();
-}
-
-function testLocalInfoImei(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_PROVIDE_LOCAL_INFO);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, iccManager.STK_LOCAL_INFO_IMEI);
-  is(cmd.options.localInfoType, iccManager.STK_LOCAL_INFO_IMEI);
-
-  runNextTest();
-}
-
-function testLocalInfoDate(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_PROVIDE_LOCAL_INFO);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, iccManager.STK_LOCAL_INFO_DATE_TIME_ZONE);
-  is(cmd.options.localInfoType, iccManager.STK_LOCAL_INFO_DATE_TIME_ZONE);
-
-  runNextTest();
-}
-
-function testLocalInfoLanguage(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_PROVIDE_LOCAL_INFO);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, iccManager.STK_LOCAL_INFO_LANGUAGE);
-  is(cmd.options.localInfoType, iccManager.STK_LOCAL_INFO_LANGUAGE);
-
-  runNextTest();
-}
-
-function testRefresh(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_REFRESH);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, 0x01);
-  is(cmd.options, null);
-
-  runNextTest();
-}
-
-function testTimerManagementStart(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_TIMER_MANAGEMENT);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, iccManager.STK_TIMER_START);
-  is(cmd.options.timerAction, iccManager.STK_TIMER_START);
-  is(cmd.options.timerId, 0x01);
-  is(cmd.options.timerValue, (0x01 * 60 * 60) + (0x02 * 60) + 0x03);
-
-  runNextTest();
-}
-
-function testTimerManagementDeactivate(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_TIMER_MANAGEMENT);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, iccManager.STK_TIMER_DEACTIVATE);
-  is(cmd.options.timerAction, iccManager.STK_TIMER_DEACTIVATE);
-  is(cmd.options.timerId, 0x04);
-
-  runNextTest();
-}
-
-function testTimerManagementGetCurrentValue(cmd) {
-  log("STK CMD " + JSON.stringify(cmd));
-  is(cmd.typeOfCommand, iccManager.STK_CMD_TIMER_MANAGEMENT);
-  is(cmd.commandNumber, 0x01);
-  is(cmd.commandQualifier, iccManager.STK_TIMER_GET_CURRENT_VALUE);
-  is(cmd.options.timerAction, iccManager.STK_TIMER_GET_CURRENT_VALUE);
-  is(cmd.options.timerId, 0x08);
-
-  runNextTest();
-}
-
-let tests = [
-  {command: "d009810301260082028182",
-   func: testLocalInfoLocation},
-  {command: "d009810301260182028182",
-   func: testLocalInfoImei},
-  {command: "d009810301260382028182",
-   func: testLocalInfoDate},
-  {command: "d009810301260482028182",
-   func: testLocalInfoLanguage},
-  {command: "d011810301270082028182a40101a503102030",
-   func: testTimerManagementStart},
-  {command: "d00c810301270182028182a40104",
-   func: testTimerManagementDeactivate},
-  {command: "d00c810301270282028182a40108",
-   func: testTimerManagementGetCurrentValue},
- ];
-
-runNextTest();
new file mode 100644
--- /dev/null
+++ b/dom/icc/tests/marionette/test_stk_timer_management.js
@@ -0,0 +1,61 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = "head.js";
+
+const TEST_DATA = [
+  // Start
+  {command: "d011810301270082028182a40101a503102030",
+   expect: {commandNumber: 0x01,
+            commandQualifier: MozIccManager.STK_TIMER_START,
+            timerAction: MozIccManager.STK_TIMER_START,
+            timerId: 0x01,
+            timerValue: (0x01 * 60 * 60) + (0x02 * 60) + 0x03}},
+  // Deactivate
+  {command: "d00c810301270182028182a40104",
+   expect: {commandNumber: 0x01,
+            commandQualifier: MozIccManager.STK_TIMER_DEACTIVATE,
+            timerAction: MozIccManager.STK_TIMER_DEACTIVATE,
+            timerId: 0x04}},
+  // Get current value
+  {command: "d00c810301270282028182a40108",
+   expect: {commandNumber: 0x01,
+            commandQualifier: MozIccManager.STK_TIMER_GET_CURRENT_VALUE,
+            timerAction: MozIccManager.STK_TIMER_GET_CURRENT_VALUE,
+            timerId: 0x08}},
+];
+
+function testTimerManagement(aCommand, aExpect) {
+  is(aCommand.typeOfCommand, MozIccManager.STK_CMD_TIMER_MANAGEMENT,
+     "typeOfCommand");
+  is(aCommand.commandQualifier, aExpect.commandQualifier, "commandQualifier");
+  is(aCommand.options.timerAction, aExpect.timerAction, "options.timerAction");
+  is(aCommand.options.timerId, aExpect.timerId, "options.timerId");
+
+  if (aExpect.timerValue) {
+    is(aCommand.options.timerValue, aExpect.timerValue, "options.timerValue");
+  }
+}
+
+// Start tests
+startTestCommon(function() {
+  let icc = getMozIcc();
+  let promise = Promise.resolve();
+  for (let i = 0; i < TEST_DATA.length; i++) {
+    let data = TEST_DATA[i];
+    promise = promise.then(() => {
+      log("timer_management_cmd: " + data.command);
+
+      let promises = [];
+      // Wait onstkcommand event.
+      promises.push(waitForTargetEvent(icc, "stkcommand")
+        .then((aEvent) => testTimerManagement(aEvent.command, data.expect)));
+      // Send emulator command to generate stk unsolicited event.
+      promises.push(sendEmulatorStkPdu(data.command));
+
+      return Promise.all(promises);
+    });
+  }
+  return promise;
+});