Bug 929701 - Part 4-2: Add marionette test for changing pin via mmi. r=hsinyi
authorEdgar Chen <echen@mozilla.com>
Wed, 23 Apr 2014 17:00:33 +0800
changeset 181395 f8e0340f374aa473bdf8da303d7f29dcc342c460
parent 181394 e77760fd73329f5a620175ba6773e637508bc4c7
child 181396 79cd3d6e0c520d3fe7eb77ff55673c36df09dd8c
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewershsinyi
bugs929701
milestone32.0a1
Bug 929701 - Part 4-2: Add marionette test for changing pin via mmi. r=hsinyi
dom/mobileconnection/tests/marionette/manifest.ini
dom/mobileconnection/tests/marionette/test_mobile_mmi_change_pin.js
--- a/dom/mobileconnection/tests/marionette/manifest.ini
+++ b/dom/mobileconnection/tests/marionette/manifest.ini
@@ -9,16 +9,17 @@ qemu = true
 [test_mobile_operator_names.js]
 [test_mobile_operator_names_plmnlist.js]
 [test_mobile_operator_names_roaming.js]
 [test_mobile_preferred_network_type.js]
 [test_mobile_data_connection.js]
 [test_mobile_data_location.js]
 [test_mobile_data_state.js]
 [test_mobile_mmi.js]
+[test_mobile_mmi_change_pin.js]
 [test_mobile_roaming_preference.js]
 [test_call_barring_get_option.js]
 [test_call_barring_set_error.js]
 [test_call_barring_change_password.js]
 [test_mobile_set_radio.js]
 [test_mobile_last_known_network.js]
 [test_mobile_icc_change.js]
 [test_mobile_connections_array_uninitialized.js]
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/marionette/test_mobile_mmi_change_pin.js
@@ -0,0 +1,111 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = "head.js";
+
+// PIN is hardcoded as "0000" by default.
+// See it here {B2G_HOME}/external/qemu/telephony/sim_card.c,
+// in asimcard_create().
+const TEST_DATA = [
+  // Test passing no pin.
+  {
+    pin: "",
+    newPin: "0000",
+    newPinAgain: "1111",
+    expectedError: {
+      name: "emMmiError",
+      additionalInformation: null
+    }
+  },
+  // Test passing no newPin.
+  {
+    pin: "0000",
+    newPin: "",
+    newPinAgain: "",
+    expectedError: {
+      name: "emMmiError",
+      additionalInformation: null
+    }
+  },
+  // Test passing mismatched newPin.
+  {
+    pin: "0000",
+    newPin: "0000",
+    newPinAgain: "1111",
+    expectedError: {
+      name: "emMmiErrorMismatchPin",
+      additionalInformation: null
+    }
+  },
+  // Test passing invalid pin (< 4 digit).
+  {
+    pin: "000",
+    newPin: "0000",
+    newPinAgain: "0000",
+    expectedError: {
+      name: "emMmiErrorInvalidPin",
+      additionalInformation: null
+    }
+  },
+  // Test passing invalid newPin (> 8 digit).
+  {
+    pin: "0000",
+    newPin: "000000000",
+    newPinAgain: "000000000",
+    expectedError: {
+      name: "emMmiErrorInvalidPin",
+      additionalInformation: null
+    }
+  },
+  // Test passing incorrect pin.
+  {
+    pin: "1234",
+    newPin: "0000",
+    newPinAgain: "0000",
+    expectedError: {
+      name: "emMmiErrorBadPin",
+      // The default pin retries is 3, failed once becomes to 2
+      additionalInformation: 2
+    }
+  },
+  // Test changing pin successfully (Reset the retries).
+  {
+    pin: "0000",
+    newPin: "0000",
+    newPinAgain: "0000"
+  }
+];
+
+function testChangePin(aPin, aNewPin, aNewPinAgain, aExpectedError) {
+  let MMI_CODE = "**04*" + aPin + "*" + aNewPin + "*" + aNewPinAgain + "#";
+  log("Test " + MMI_CODE);
+
+  return sendMMI(MMI_CODE)
+    .then(function resolve(aResult) {
+      ok(!aExpectedError, MMI_CODE + " success");
+      is(aResult.serviceCode, "scPin", "Check service code");
+      is(aResult.statusMessage, "smPinChanged", "Check status message");
+      is(aResult.additionalInformation, undefined, "Check additional information");
+    }, function reject(aError) {
+      ok(aExpectedError, MMI_CODE + " fail");
+      is(aError.name, aExpectedError.name, "Check name");
+      is(aError.message, "", "Check message");
+      is(aError.serviceCode, "scPin", "Check service code");
+      is(aError.additionalInformation, aExpectedError.additionalInformation,
+         "Chech additional information");
+    });
+}
+
+// Start test
+startTestCommon(function() {
+  let promise = Promise.resolve();
+  for (let i = 0; i < TEST_DATA.length; i++) {
+    let data = TEST_DATA[i];
+    promise = promise.then(() => testChangePin(data.pin,
+                                               data.newPin,
+                                               data.newPinAgain,
+                                               data.expectedError));
+  }
+  return promise;
+});