Bug 995844: retrieve mozMobileConnection from 'workingFrame' in mobileconnect marionette tests. r=echen
authorVicamo Yang <vyang@mozilla.com>
Thu, 17 Apr 2014 11:22:38 +0800
changeset 179420 36e61fd7ed89b7d99fb15fa27dcef4fd8061ea90
parent 179419 7cc17a77b90e785adce55a7af9a67e01e8f7778f
child 179421 f69f2fb119386d5b3dc2c581c0c43525c207601c
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersechen
bugs995844
milestone31.0a1
Bug 995844: retrieve mozMobileConnection from 'workingFrame' in mobileconnect marionette tests. r=echen
dom/mobileconnection/tests/marionette/head.js
dom/mobileconnection/tests/marionette/test_dsds_mobile_data_connection.js
dom/mobileconnection/tests/marionette/test_mobile_connections_array_uninitialized.js
--- a/dom/mobileconnection/tests/marionette/head.js
+++ b/dom/mobileconnection/tests/marionette/head.js
@@ -69,16 +69,18 @@ function wrapDomRequestAsPromise(aReques
   });
   aRequest.addEventListener("error", function(aEvent) {
     deferred.reject(aEvent);
   });
 
   return deferred.promise;
 }
 
+let workingFrame;
+
 /**
  * Get mozSettings value specified by @aKey.
  *
  * Resolve if that mozSettings value is retrieved successfully, reject
  * otherwise.
  *
  * Fulfill params:
  *   The corresponding mozSettings value of the key.
@@ -88,17 +90,18 @@ function wrapDomRequestAsPromise(aReques
  *        A string.
  * @param aAllowError [optional]
  *        A boolean value.  If set to true, an error response won't be treated
  *        as test failure.  Default: false.
  *
  * @return A deferred promise.
  */
 function getSettings(aKey, aAllowError) {
-  let request = navigator.mozSettings.createLock().get(aKey);
+  let request =
+    workingFrame.contentWindow.navigator.mozSettings.createLock().get(aKey);
   return wrapDomRequestAsPromise(request)
     .then(function resolve(aEvent) {
       ok(true, "getSettings(" + aKey + ") - success");
       return aEvent.target.result[aKey];
     }, function reject(aEvent) {
       ok(aAllowError, "getSettings(" + aKey + ") - error");
     });
 }
@@ -115,17 +118,18 @@ function getSettings(aKey, aAllowError) 
  *        An object of format |{key1: value1, key2: value2, ...}|.
  * @param aAllowError [optional]
  *        A boolean value.  If set to true, an error response won't be treated
  *        as test failure.  Default: false.
  *
  * @return A deferred promise.
  */
 function setSettings(aSettings, aAllowError) {
-  let request = navigator.mozSettings.createLock().set(aSettings);
+  let request =
+    workingFrame.contentWindow.navigator.mozSettings.createLock().set(aSettings);
   return wrapDomRequestAsPromise(request)
     .then(function resolve() {
       ok(true, "setSettings(" + JSON.stringify(aSettings) + ")");
     }, function reject() {
       ok(aAllowError, "setSettings(" + JSON.stringify(aSettings) + ")");
     });
 }
 
@@ -190,17 +194,16 @@ function getDataApnSettings(aAllowError)
 
 /**
  * Convenient MozSettings setter for SETTINGS_KEY_DATA_APN_SETTINGS.
  */
 function setDataApnSettings(aApnSettings, aAllowError) {
   return setSettings1(SETTINGS_KEY_DATA_APN_SETTINGS, aApnSettings, aAllowError);
 }
 
-let workingFrame;
 let mobileConnection;
 
 /**
  * Push required permissions and test if
  * |navigator.mozMobileConnections[<aServiceId>]| exists. Resolve if it does,
  * reject otherwise.
  *
  * Fulfill params:
@@ -277,17 +280,18 @@ function ensureMobileConnection(aAdditio
  *
  * @return A deferred promise.
  */
 function waitForManagerEvent(aEventName, aServiceId) {
   let deferred = Promise.defer();
 
   let mobileConn = mobileConnection;
   if (aServiceId !== undefined) {
-    mobileConn = navigator.mozMobileConnections[aServiceId];
+    mobileConn =
+      workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
   }
 
   mobileConn.addEventListener(aEventName, function onevent(aEvent) {
     mobileConn.removeEventListener(aEventName, onevent);
 
     ok(true, "MobileConnection event '" + aEventName + "' got.");
     deferred.resolve(aEvent);
   });
@@ -402,17 +406,18 @@ function setDataEnabledAndWait(aEnabled,
   let deferred = Promise.defer();
 
   let promises = [];
   promises.push(waitForManagerEvent("datachange", aServiceId));
   promises.push(setDataEnabled(aEnabled));
   Promise.all(promises).then(function keepWaiting() {
     let mobileConn = mobileConnection;
     if (aServiceId !== undefined) {
-      mobileConn = navigator.mozMobileConnections[aServiceId];
+      mobileConn =
+        workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
     }
     // To ignore some transient states, we only resolve that deferred promise
     // when the |connected| state equals to the expected one and never rejects.
     let connected = mobileConn.data.connected;
     if (connected == aEnabled) {
       deferred.resolve();
       return;
     }
@@ -462,17 +467,18 @@ function setEmulatorVoiceDataStateAndWai
  */
 function setEmulatorRoamingAndWait(aRoaming, aServiceId) {
   function doSetAndWait(aWhich, aRoaming, aServiceId) {
     let state = (aRoaming ? "roaming" : "home");
     return setEmulatorVoiceDataStateAndWait(aWhich, state, aServiceId)
       .then(() => {
         let mobileConn = mobileConnection;
         if (aServiceId !== undefined) {
-          mobileConn = navigator.mozMobileConnections[aServiceId];
+          mobileConn =
+            workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
         }
         is(mobileConn[aWhich].roaming, aRoaming,
                      aWhich + ".roaming")
       });
   }
 
   // Set voice registration state first and then data registration state.
   return doSetAndWait("voice", aRoaming, aServiceId)
--- a/dom/mobileconnection/tests/marionette/test_dsds_mobile_data_connection.js
+++ b/dom/mobileconnection/tests/marionette/test_dsds_mobile_data_connection.js
@@ -1,18 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
 MARIONETTE_HEAD_JS = "head.js";
 
 const SETTINGS_KEY_DATA_DEFAULT_ID = "ril.data.defaultServiceId";
 
-let connections = window.navigator.mozMobileConnections;
-let numOfRadioInterfaces = getNumOfRadioInterfaces();
+let connections;
+let numOfRadioInterfaces;
 let currentDataDefaultId = 0;
 
 function muxModem(id) {
   return runEmulatorCmdSafe("mux modem " + id);
 }
 
 function switchDataDefaultId(defaultId) {
   return Promise.resolve()
@@ -137,15 +137,18 @@ function testDisableData() {
   let connection = connections[currentDataDefaultId];
   is(connection.data.connected, true);
 
   return Promise.resolve()
     .then(() => setDataEnabledAndWait(false, currentDataDefaultId));
 }
 
 startDSDSTestCommon(function() {
+  connections = workingFrame.contentWindow.navigator.mozMobileConnections;
+  numOfRadioInterfaces = getNumOfRadioInterfaces();
+
   return testEnableData()
     .then(testSwitchDefaultDataToSimTwo)
     .then(testDisableDataRoamingWhileRoaming)
     .then(testEnableDataRoamingWhileRoaming)
     .then(testDisableData)
     .then(restoreTestEnvironment);
 }, ["settings-read", "settings-write"]);
--- a/dom/mobileconnection/tests/marionette/test_mobile_connections_array_uninitialized.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_connections_array_uninitialized.js
@@ -3,11 +3,11 @@
 
 MARIONETTE_TIMEOUT = 60000;
 MARIONETTE_HEAD_JS = "head.js";
 
 startTestCommon(function() {
   let connections =
     workingFrame.contentWindow.navigator.mozMobileConnections;
 
-  let num = SpecialPowers.getIntPref("ril.numRadioInterfaces");
+  let num = getNumOfRadioInterfaces();
   is(connections.length, num, "ril.numRadioInterfaces");
 });