Bug 999458 - 2.b/2: add two more utility functions to head.js. r=echen
authorVicamo Yang <vyang@mozilla.com>
Fri, 02 May 2014 00:24:12 +0800
changeset 181690 f8468bd898d6f32cb5dcc12ddecf2815051fcd39
parent 181689 6d0323d19035ce1efd3c520832164d92fb6954d1
child 181691 3e8b96116e13295b54ca57f02fa43d767f9c92ab
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersechen
bugs999458
milestone32.0a1
Bug 999458 - 2.b/2: add two more utility functions to head.js. r=echen * setEmulatorGsmLocationAndWait * setEmulatorOperatorNamesAndWait
dom/mobileconnection/tests/marionette/head.js
dom/mobileconnection/tests/marionette/test_mobile_data_location.js
dom/mobileconnection/tests/marionette/test_mobile_operator_names.js
dom/mobileconnection/tests/marionette/test_mobile_operator_names_plmnlist.js
dom/mobileconnection/tests/marionette/test_mobile_operator_names_roaming.js
dom/mobileconnection/tests/marionette/test_mobile_voice_location.js
--- a/dom/mobileconnection/tests/marionette/head.js
+++ b/dom/mobileconnection/tests/marionette/head.js
@@ -543,16 +543,43 @@ function getEmulatorGsmLocation() {
  * @return A deferred promise.
  */
 function setEmulatorGsmLocation(aLac, aCid) {
   let cmd = "gsm location " + aLac + " " + aCid;
   return runEmulatorCmdSafe(cmd);
 }
 
 /**
+ * Set GSM location and wait for voice and/or data state change.
+ *
+ * Fulfill params: (none)
+ *
+ * @param aLac
+ * @param aCid
+ * @param aWaitVoice [optional]
+ *        A boolean value.  Default true.
+ * @param aWaitData [optional]
+ *        A boolean value.  Default false.
+ *
+ * @return A deferred promise.
+ */
+function setEmulatorGsmLocationAndWait(aLac, aCid,
+                                       aWaitVoice = true, aWaitData = false) {
+  let promises = [];
+  if (aWaitVoice) {
+    promises.push(waitForManagerEvent("voicechange"));
+  }
+  if (aWaitData) {
+    promises.push(waitForManagerEvent("datachange"));
+  }
+  promises.push(setEmulatorGsmLocation(aLac, aCid));
+  return Promise.all(promises);
+}
+
+/**
  * Get emulator operators info.
  *
  * Fulfill params:
  *   An array of { longName: <string>, shortName: <string>, mccMnc: <string> }.
  * Reject params:
  *   result -- an array of emulator response lines.
  *
  * @return A deferred promise.
@@ -617,16 +644,53 @@ function setEmulatorOperatorNames(aOpera
       }
 
       let re = new RegExp(exp);
       ok(aResults[index].match(new RegExp(exp)),
          "Long/short name and/or mcc/mnc should be changed.");
     });
 }
 
+/**
+ * Set emulator operators info and wait for voice and/or data state change.
+ *
+ * Fulfill params: (none)
+ *
+ * @param aOperator
+ *        "home" or "roaming".
+ * @param aLongName
+ *        A string.
+ * @param aShortName
+ *        A string.
+ * @param aMcc [optional]
+ *        A string.
+ * @param aMnc [optional]
+ *        A string.
+ * @param aWaitVoice [optional]
+ *        A boolean value.  Default true.
+ * @param aWaitData [optional]
+ *        A boolean value.  Default false.
+ *
+ * @return A deferred promise.
+ */
+function setEmulatorOperatorNamesAndWait(aOperator, aLongName, aShortName,
+                                         aMcc, aMnc,
+                                         aWaitVoice = true, aWaitData = false) {
+  let promises = [];
+  if (aWaitVoice) {
+    promises.push(waitForManagerEvent("voicechange"));
+  }
+  if (aWaitData) {
+    promises.push(waitForManagerEvent("datachange"));
+  }
+  promises.push(setEmulatorOperatorNames(aOperator, aLongName, aShortName,
+                                         aMcc, aMnc));
+  return Promise.all(promises);
+}
+
 let _networkManager;
 
 /**
  * Get internal NetworkManager service.
  */
 function getNetworkManager() {
   if (!_networkManager) {
     _networkManager = Cc["@mozilla.org/network/manager;1"]
--- a/dom/mobileconnection/tests/marionette/test_mobile_data_location.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_data_location.js
@@ -21,20 +21,17 @@ function verifyDataCellLocationInfo(aLac
   is(cell.cdmaNetworkId, -1, "data.cell.cdmaNetworkId");
 }
 
 /* Test Data Cell Location Info Change */
 function testDataCellLocationUpdate(aLac, aCid) {
   // Set emulator's lac/cid and wait for 'ondatachange' event.
   log("Test cell location with lac=" + aLac + " and cid=" + aCid);
 
-  let promises = [];
-  promises.push(waitForManagerEvent("datachange"));
-  promises.push(setEmulatorGsmLocation(aLac, aCid));
-  return Promise.all(promises)
+  return setEmulatorGsmLocationAndWait(aLac, aCid, false, true)
     .then(() => verifyDataCellLocationInfo(aLac, aCid));
 }
 
 startTestCommon(function() {
   return getEmulatorGsmLocation()
     .then(function(aResult) {
       log("Test initial data location info");
       verifyDataCellLocationInfo(aResult.lac, aResult.cid);
--- a/dom/mobileconnection/tests/marionette/test_mobile_operator_names.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_operator_names.js
@@ -11,20 +11,18 @@ function check(aLongName, aShortName) {
   is(network.shortName, aShortName, "network.shortName");
   is(network.mcc, "310", "network.mcc");
   is(network.mnc, "260", "network.mnc");
 }
 
 function test(aLongName, aShortName) {
   log("Testing '" + aLongName + "', '" + aShortName + "':");
 
-  let promises = [];
-  promises.push(waitForManagerEvent("voicechange"));
-  promises.push(setEmulatorOperatorNames("home", aLongName, aShortName));
-  return Promise.all(promises)
+  return setEmulatorOperatorNamesAndWait("home", aLongName, aShortName,
+                                         null, null, true, false)
     .then(() => check(aLongName, aShortName));
 }
 
 startTestCommon(function() {
   return getEmulatorOperatorNames()
     .then(function(aOperators) {
       return Promise.resolve()
 
--- a/dom/mobileconnection/tests/marionette/test_mobile_operator_names_plmnlist.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_operator_names_plmnlist.js
@@ -12,20 +12,18 @@ function check(aLongName, aShortName, aM
   is(network.mcc, aMcc, "network.mcc");
   is(network.mnc, aMnc, "network.mnc");
 }
 
 function test(aLongName, aShortName, aMcc, aMnc, aExpectedLongName,
               aExpectedShortName) {
   log("Testing mcc = " + aMcc + ", mnc = " + aMnc + ":");
 
-  let promises = [];
-  promises.push(waitForManagerEvent("voicechange"));
-  promises.push(setEmulatorOperatorNames("home", aLongName, aShortName, aMcc, aMnc));
-  return Promise.all(promises)
+  return setEmulatorOperatorNamesAndWait("home", aLongName, aShortName,
+                                         aMcc, aMnc, true, false)
     .then(() => check(aExpectedLongName, aExpectedShortName, aMcc, aMnc));
 }
 
 startTestCommon(function() {
   return getEmulatorOperatorNames()
     .then(function(aOperators) {
       let {longName: longName, shortName: shortName} = aOperators[0];
       let {mcc: mcc, mnc: mnc} = mobileConnection.voice.network;
--- a/dom/mobileconnection/tests/marionette/test_mobile_operator_names_roaming.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_operator_names_roaming.js
@@ -8,38 +8,32 @@ function check(aLongName, aShortName, aR
   let voice = mobileConnection.voice;
   let network = voice.network;
 
   is(network.longName, aLongName, "network.longName");
   is(network.shortName, aShortName, "network.shortName");
   is(voice.roaming, aRoaming, "voice.roaming");
 }
 
-function setEmulatorOperatorNamesAndWait(aWhich, aLongName, aShortName) {
-  let promises = [];
-  promises.push(waitForManagerEvent("voicechange"));
-  promises.push(setEmulatorOperatorNames(aWhich, aLongName, aShortName));
-  return Promise.all(promises);
-}
-
 // See bug 797972 - B2G RIL: False roaming situation
 //
 // Steps to test:
 // 1. set roaming operator names
 // 2. set emulator roaming
 // 3. wait for onvoicechange event and test passing conditions
 // 4. set emulator roaming back to false
 // 5. wait for onvoicechange event again and callback
 function test(aLongName, aShortName, aRoaming) {
   log("Testing roaming check '" + aLongName + "', '" + aShortName + "':");
 
   return Promise.resolve()
 
     // We should not have voicechange here, but, yes, we do.
-    .then(() => setEmulatorOperatorNamesAndWait("roaming", aLongName, aShortName))
+    .then(() => setEmulatorOperatorNamesAndWait("roaming", aLongName, aShortName,
+                                                null, null, true, false))
 
     .then(() => setEmulatorVoiceDataStateAndWait("voice", "roaming"))
     .then(() => check(aLongName, aShortName, aRoaming))
     .then(() => setEmulatorVoiceDataStateAndWait("voice", "home"));
 }
 
 startTestCommon(function() {
   return getEmulatorOperatorNames()
--- a/dom/mobileconnection/tests/marionette/test_mobile_voice_location.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_voice_location.js
@@ -21,20 +21,17 @@ function verifyVoiceCellLocationInfo(aLa
   is(cell.cdmaNetworkId, -1, "check voice.cell.cdmaNetworkId");
 }
 
 /* Test Voice Cell Location Info Change */
 function testVoiceCellLocationUpdate(aLac, aCid) {
   // Set emulator's lac/cid and wait for 'onvoicechange' event.
   log("Test cell location with lac=" + aLac + " and cid=" + aCid);
 
-  let promises = [];
-  promises.push(waitForManagerEvent("voicechange"));
-  promises.push(setEmulatorGsmLocation(aLac, aCid));
-  return Promise.all(promises)
+  return setEmulatorGsmLocationAndWait(aLac, aCid, true, false)
     .then(() => verifyVoiceCellLocationInfo(aLac, aCid));
 }
 
 startTestCommon(function() {
   return getEmulatorGsmLocation()
     .then(function(aResult) {
       log("Test initial voice location info");
       verifyVoiceCellLocationInfo(aResult.lac, aResult.cid);