Bug 1164432 - Update test_try_registering_offline_disabled.html to use mock push server. r=kitcambridge, a=test-only
☠☠ backed out by 332ce77a41c7 ☠ ☠
authorWilliam Chen <wchen@mozilla.com>
Sat, 19 Mar 2016 00:35:57 -0700
changeset 325424 292bc13fdc7fed7f95620dcfd0c98669821c7517
parent 325423 ea25150c4e575b5a4b2ee3697705a678a2997e2f
child 325425 31d81c652c3be990c1589a74f50ccf0a6a9ee326
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge, test-only
bugs1164432
milestone47.0a2
Bug 1164432 - Update test_try_registering_offline_disabled.html to use mock push server. r=kitcambridge, a=test-only
dom/push/test/mochitest.ini
dom/push/test/mockpushserviceparent.js
dom/push/test/test_try_registering_offline_disabled.html
--- a/dom/push/test/mochitest.ini
+++ b/dom/push/test/mochitest.ini
@@ -13,11 +13,10 @@ skip-if = os == "android" || toolkit == 
 [test_permissions.html]
 [test_register.html]
 [test_multiple_register.html]
 [test_multiple_register_during_service_activation.html]
 [test_unregister.html]
 [test_multiple_register_different_scope.html]
 [test_subscription_change.html]
 [test_data.html]
-# Disabled for too many intermittent failures (bug 1164432)
-#  [test_try_registering_offline_disabled.html]
+[test_try_registering_offline_disabled.html]
 [test_serviceworker_lifetime.html]
--- a/dom/push/test/mockpushserviceparent.js
+++ b/dom/push/test/mockpushserviceparent.js
@@ -80,23 +80,27 @@ MockNetworkInfo.prototype = {
 var pushService = Cc["@mozilla.org/push/Service;1"].
                   getService(Ci.nsIPushService).
                   wrappedJSObject;
 
 var mockWebSocket;
 
 addMessageListener("setup", function () {
   mockWebSocket = new Promise((resolve, reject) => {
+    var mockSocket = null;
     pushService.replaceServiceBackend({
       serverURI: "wss://push.example.org/",
       networkInfo: new MockNetworkInfo(),
       makeWebSocket(uri) {
-        var socket = new MockWebSocketParent(uri);
-        resolve(socket);
-        return socket;
+        if (!mockSocket) {
+          mockSocket = new MockWebSocketParent(uri);
+          resolve(mockSocket);
+        }
+
+        return mockSocket;
       }
     });
   });
 });
 
 addMessageListener("teardown", function () {
   mockWebSocket.then(socket => {
     socket.close();
--- a/dom/push/test/test_try_registering_offline_disabled.html
+++ b/dom/push/test/test_try_registering_offline_disabled.html
@@ -5,16 +5,17 @@ Bug 1150812: Try to register when servic
 
 Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/licenses/publicdomain/
 
 -->
 <head>
   <title>Test for Bug 1150812</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/dom/push/test/test_utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
 </head>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150812">Mozilla Bug 1150812</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
@@ -81,16 +82,27 @@ http://creativecommons.org/licenses/publ
         ok(subOld.endpoint == sub.endpoint, "getEndpoint - Got the same endpoint back.");
         return sub;
       }, err => {
           ok(false, "could not register for push notification");
           throw err;
       });
   }
 
+  // Load chrome script to change offline status in the
+  // parent process.
+  var chromeScript = SpecialPowers.loadChromeScript(_ => {
+    var { classes: Cc, interfaces: Ci } = Components;
+    var ioService = Cc["@mozilla.org/network/io-service;1"]
+                      .getService(Ci.nsIIOService);
+    addMessageListener("change-status", function(offline) {
+      ioService.offline = offline;
+    });
+  });
+
   function offlineObserver(res) {
     this._res = res;
   }
   offlineObserver.prototype = {
     _res: null,
 
     observe: function(subject, topic, data) {
       debug("observe: " + subject + " " + topic + " " + data);
@@ -105,26 +117,23 @@ http://creativecommons.org/licenses/publ
 
   function changeOfflineState(offline) {
     return new Promise(function(res, rej) {
       var obsService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
                          .getService(SpecialPowers.Ci.nsIObserverService);
       obsService.addObserver(SpecialPowers.wrapCallbackObject(new offlineObserver(res)),
                              "network:offline-status-changed",
                              false);
-      var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
-                        .getService(SpecialPowers.Ci.nsIIOService);
-      ioService.offline = offline;
+      chromeScript.sendAsyncMessage("change-status", offline);
     });
   }
 
   function changePushServerConnectionEnabled(enable) {
     debug("changePushServerConnectionEnabled");
-    SpecialPowers.pushPrefEnv({"set": [["dom.push.connection.enabled", enable]]},
-                              null);
+    SpecialPowers.setBoolPref("dom.push.connection.enabled", enable);
   }
 
   function unsubscribe(sub) {
     return sub.unsubscribe()
       .then(_ => {ok(true, "Unsubscribed!");});
   }
 
   // go offline then go online
@@ -282,20 +291,14 @@ http://creativecommons.org/licenses/publ
     .then(_ => runTest2())
     .then(_ => runTest3())
     .then(_ => runTest4())
     .then(_ => runTest5())
     .then(_ => runTest6())
     .then(SimpleTest.finish);
   }
 
-  SpecialPowers.pushPrefEnv({"set": [
-    ["dom.push.enabled", true],
-    ["dom.push.connection.enabled", true],
-    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
-    ["dom.serviceWorkers.enabled", true],
-    ["dom.serviceWorkers.testing.enabled", true]
-    ]}, runTest);
+  setupPrefsAndMock(new MockWebSocket()).then(_ => runTest());
   SpecialPowers.addPermission("desktop-notification", true, document);
   SimpleTest.waitForExplicitFinish();
 </script>
 </body>
 </html>