Bug 981217 - Make the wifi connection more rubust during testing. r=ahal
authorDavid Clarke <dclarke@mozilla.com>
Wed, 12 Mar 2014 08:29:23 -0400
changeset 173245 2522557e99a6d1941050eb6198bbb11377035489
parent 173244 aa706477360a09fa49aedf8fbbfc64b35983309a
child 173246 5319dbcb61c8ed86cf1cd772fb0503e6111ec310
push id26397
push userkwierso@gmail.com
push dateThu, 13 Mar 2014 02:51:22 +0000
treeherdermozilla-central@c12c92db5588 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs981217
milestone30.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 981217 - Make the wifi connection more rubust during testing. r=ahal
testing/mochitest/b2g_start_script.js
--- a/testing/mochitest/b2g_start_script.js
+++ b/testing/mochitest/b2g_start_script.js
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 let outOfProcess = __marionetteParams[0]
 let mochitestUrl = __marionetteParams[1]
 let onDevice = __marionetteParams[2]
 let wifiSettings = __marionetteParams[3]
 let prefs = Components.classes["@mozilla.org/preferences-service;1"].
                             getService(Components.interfaces.nsIPrefBranch)
+let settings = window.navigator.mozSettings;
 
 if (wifiSettings)
   wifiSettings = JSON.parse(wifiSettings);
 
 const CHILD_SCRIPT = "chrome://specialpowers/content/specialpowers.js";
 const CHILD_SCRIPT_API = "chrome://specialpowers/content/specialpowersAPI.js";
 const CHILD_LOGGER_SCRIPT = "chrome://specialpowers/content/MozillaLogger.js";
 
@@ -83,30 +84,49 @@ if (outOfProcess) {
 
   specialPowersObserver._isFrameScriptLoaded = true;
 }
 
 
 if (onDevice) {
   let manager = navigator.mozWifiManager;
   let con = manager.connection;
-  if(wifiSettings) {
-    if (manager.enabled) {
-      manager.associate(wifiSettings);
-    } else {
-      manager.onenabled = function () {
+  manager.setPowerSavingMode(false);
+
+  manager.onenabled = function () {
+    if(wifiSettings) {
+      var req = manager.getKnownNetworks();
+      req.onsuccess = function () {
+        var networks = req.result;
+        for (var i = 0; i < networks.length; ++i){
+          var network = networks[i];
+          if(network.ssid == wifiSettings.ssid) {
+            manager.forget(network);
+          }
+        }
         manager.associate(wifiSettings);
       };
     }
-  }
-  else if (con.status == 'connected') {
-    container.src = mochitestUrl;
-  }
+  };
 
   manager.onstatuschange = function (event) {
+    prefs.setIntPref("network.proxy.type", 2);
     if (event.status == 'connected') {
-      prefs.setIntPref("network.proxy.type", 2);
       container.src = mochitestUrl;
     }
+  };
+
+  if(wifiSettings) {
+    var req = settings.createLock().set({
+       'wifi.enabled': false,
+       'wifi.suspended': false
+     });
+
+    req.onsuccess = function () {
+      dump("----------------------enabling wifi------------------\n");
+      var req1 = settings.createLock().set({
+          'wifi.enabled': true,
+          'wifi.suspended': false});
+    };
   }
 } else {
   container.src = mochitestUrl;
 }