Bug 1058305 - Part 4: use defined network types in nsIRadioInterface (tests). r=echen
authorJessica Jong <jjong@mozilla.com>
Tue, 25 Nov 2014 09:44:37 +0800
changeset 241664 a573c8e256ea9b3c8fd6a9dbea2ebc3688ff0ac5
parent 241663 316905ac2460c864d1565cbf2a1281bdbaf91bb8
child 241665 5aa41e3614f699904092172d09248d4a3fa9f21c
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechen
bugs1058305
milestone36.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 1058305 - Part 4: use defined network types in nsIRadioInterface (tests). r=echen
dom/system/gonk/tests/marionette/head.js
dom/system/gonk/tests/marionette/test_data_connection.js
dom/system/gonk/tests/marionette/test_multiple_data_connection.js
dom/system/gonk/tests/marionette/test_network_active_changed.js
--- a/dom/system/gonk/tests/marionette/head.js
+++ b/dom/system/gonk/tests/marionette/head.js
@@ -4,16 +4,30 @@
 MARIONETTE_CONTEXT = "chrome";
 
 const SETTINGS_KEY_DATA_ENABLED = "ril.data.enabled";
 const SETTINGS_KEY_DATA_APN_SETTINGS  = "ril.data.apnSettings";
 
 const TOPIC_CONNECTION_STATE_CHANGED = "network-connection-state-changed";
 const TOPIC_NETWORK_ACTIVE_CHANGED = "network-active-changed";
 
+const NETWORK_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
+const NETWORK_TYPE_MOBILE_MMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS;
+const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL;
+const NETWORK_TYPE_MOBILE_IMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_IMS;
+const NETWORK_TYPE_MOBILE_DUN = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_DUN;
+
+const networkTypes = [
+  NETWORK_TYPE_MOBILE,
+  NETWORK_TYPE_MOBILE_MMS,
+  NETWORK_TYPE_MOBILE_SUPL,
+  NETWORK_TYPE_MOBILE_IMS,
+  NETWORK_TYPE_MOBILE_DUN
+];
+
 let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
 
 let ril = Cc["@mozilla.org/ril;1"].getService(Ci.nsIRadioInterfaceLayer);
 ok(ril, "ril.constructor is " + ril.constructor);
 
 let radioInterface = ril.getRadioInterface(0);
 ok(radioInterface, "radioInterface.constructor is " + radioInterface.constrctor);
 
@@ -102,24 +116,16 @@ function waitForObserverEvent(aTopic) {
       obs.removeObserver(observer, aTopic);
       deferred.resolve(subject);
     }
   }, aTopic, false);
 
   return deferred.promise;
 }
 
-let mobileTypeMapping = {
-  "default": Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
-  "mms": Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS,
-  "supl": Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL,
-  "ims": Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_IMS,
-  "dun": Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_DUN
-};
-
 /**
  * Set the default data connection enabling state, wait for
  * "network-connection-state-changed" event and verify state.
  *
  * Fulfill params: (none)
  *
  * @param aEnabled
  *        A boolean state.
@@ -127,84 +133,82 @@ let mobileTypeMapping = {
  * @return A deferred promise.
  */
 function setDataEnabledAndWait(aEnabled) {
   let promises = [];
   promises.push(waitForObserverEvent(TOPIC_CONNECTION_STATE_CHANGED)
     .then(function(aSubject) {
       ok(aSubject instanceof Ci.nsIRilNetworkInterface,
          "subject should be an instance of nsIRILNetworkInterface");
-      is(aSubject.type, Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
-         "subject.type should be " + Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE);
+      is(aSubject.type, NETWORK_TYPE_MOBILE,
+         "subject.type should be " + NETWORK_TYPE_MOBILE);
       is(aSubject.state,
          aEnabled ? Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED
                   : Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED,
          "subject.state should be " + aEnabled ? "CONNECTED" : "DISCONNECTED");
     }));
   promises.push(setSettings(SETTINGS_KEY_DATA_ENABLED, aEnabled));
 
   return Promise.all(promises);
 }
 
 /**
  * Setup a certain type of data connection, wait for
  * "network-connection-state-changed" event and verify state.
  *
  * Fulfill params: (none)
  *
- * @param aType
- *        The string of the type of data connection to setup.
+ * @param aNetworkType
+ *        The mobile network type to setup.
  *
  * @return A deferred promise.
  */
-function setupDataCallAndWait(aType) {
-  log("setupDataCallAndWait: " + aType);
+function setupDataCallAndWait(aNetworkType) {
+  log("setupDataCallAndWait: " + aNetworkType);
 
   let promises = [];
   promises.push(waitForObserverEvent(TOPIC_CONNECTION_STATE_CHANGED)
     .then(function(aSubject) {
-      let networkType = mobileTypeMapping[aType];
       ok(aSubject instanceof Ci.nsIRilNetworkInterface,
          "subject should be an instance of nsIRILNetworkInterface");
-      is(aSubject.type, networkType,
-         "subject.type should be " + networkType);
+      is(aSubject.type, aNetworkType,
+         "subject.type should be " + aNetworkType);
       is(aSubject.state, Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED,
          "subject.state should be CONNECTED");
     }));
-  promises.push(radioInterface.setupDataCallByType(aType));
+  promises.push(radioInterface.setupDataCallByType(aNetworkType));
 
   return Promise.all(promises);
 }
 
 /**
  * Deactivate a certain type of data connection, wait for
  * "network-connection-state-changed" event and verify state.
  *
  * Fulfill params: (none)
  *
- * @param aType
- *        The string of the type of data connection to deactivate.
+ * @param aNetworkType
+ *        The mobile network type to deactivate.
  *
  * @return A deferred promise.
  */
-function deactivateDataCallAndWait(aType) {
-  log("deactivateDataCallAndWait: " + aType);
+function deactivateDataCallAndWait(aNetworkType) {
+  log("deactivateDataCallAndWait: " + aNetworkType);
 
   let promises = [];
   promises.push(waitForObserverEvent(TOPIC_CONNECTION_STATE_CHANGED)
     .then(function(aSubject) {
-      let networkType = mobileTypeMapping[aType];
       ok(aSubject instanceof Ci.nsIRilNetworkInterface,
          "subject should be an instance of nsIRILNetworkInterface");
-      is(aSubject.type, networkType,
-         "subject.type should be " + networkType);
+      is(aSubject.type, aNetworkType,
+         "subject.type should be " + aNetworkType);
       is(aSubject.state, Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED,
          "subject.state should be DISCONNECTED");
     }));
-  promises.push(radioInterface.deactivateDataCallByType(aType));
+  promises.push(radioInterface.deactivateDataCallByType(aNetworkType));
 
   return Promise.all(promises);
 }
 
 /**
  * Basic test routine helper.
  *
  * This helper does nothing but clean-ups.
--- a/dom/system/gonk/tests/marionette/test_data_connection.js
+++ b/dom/system/gonk/tests/marionette/test_data_connection.js
@@ -48,20 +48,20 @@ function testNonDefaultDataConnection() 
   }
 
   let currentApn;
   return getSettings(SETTINGS_KEY_DATA_APN_SETTINGS)
     .then(value => {
       currentApn = value;
     })
     .then(setEmulatorAPN)
-    .then(() => doTestNonDefaultDataConnection("mms"))
-    .then(() => doTestNonDefaultDataConnection("supl"))
-    .then(() => doTestNonDefaultDataConnection("ims"))
-    .then(() => doTestNonDefaultDataConnection("dun"))
+    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_MMS))
+    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_SUPL))
+    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_IMS))
+    .then(() => doTestNonDefaultDataConnection(NETWORK_TYPE_MOBILE_DUN))
     // Restore APN settings
     .then(() => setSettings(SETTINGS_KEY_DATA_APN_SETTINGS, currentApn));
 }
 
 // Start test
 startTestBase(function() {
   return testInitialState()
     .then(() => testDefaultDataConnection())
--- a/dom/system/gonk/tests/marionette/test_multiple_data_connection.js
+++ b/dom/system/gonk/tests/marionette/test_multiple_data_connection.js
@@ -39,33 +39,31 @@ function testInitialState() {
       is(value, false, "Data must be off");
     });
 }
 
 function testSetupConcurrentDataCalls() {
   log("= testSetupConcurrentDataCalls =");
 
   let promise = Promise.resolve();
-  let types = Object.keys(mobileTypeMapping);
   // Skip default mobile type.
   for (let i = 1; i < MAX_DATA_CONTEXTS; i++) {
-    let type = types[i];
+    let type = networkTypes[i];
     promise = promise.then(() => setupDataCallAndWait(type));
   }
   return promise;
 }
 
 function testDeactivateConcurrentDataCalls() {
   log("= testDeactivateConcurrentDataCalls =");
 
   let promise = Promise.resolve();
-  let types = Object.keys(mobileTypeMapping);
   // Skip default mobile type.
   for (let i = 1; i < MAX_DATA_CONTEXTS; i++) {
-    let type = types[i];
+    let type = networkTypes[i];
     promise = promise.then(() => deactivateDataCallAndWait(type));
   }
   return promise;
 }
 
 // Start test
 startTestBase(function() {
 
--- a/dom/system/gonk/tests/marionette/test_network_active_changed.js
+++ b/dom/system/gonk/tests/marionette/test_network_active_changed.js
@@ -28,17 +28,17 @@ function testActiveNetworkChangedBySwitc
   return Promise.all(promises).then(function(results) {
     let subject = results[0];
 
     if (aDataCallEnabled) {
       ok(subject instanceof Ci.nsINetworkInterface,
          "subject should be an instance of nsINetworkInterface");
       ok(subject instanceof Ci.nsIRilNetworkInterface,
          "subject should be an instance of nsIRILNetworkInterface");
-      is(subject.type, Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE,
+      is(subject.type, NETWORK_TYPE_MOBILE,
          "subject.type should be NETWORK_TYPE_MOBILE");
     }
 
     is(subject, networkManager.active,
        "subject should be equal with networkManager.active");
   });
 }