Bug 1055145 - Part 2: Fix failing loop tests: prevent spurious network access attempts r=mattn a=lsblakk
authorPaul Kerr [:pkerr] <pkerr@mozilla.com>
Wed, 24 Dec 2014 13:12:18 -0800
changeset 242621 ed337ac276164545b588ab6793e6e065146c3e59
parent 242620 a868d59d6964b71a3037e4e07b66777e3756e1cc
child 242622 ab9da5f43c4be47bec285cee66c108a05bd136c3
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)
reviewersmattn, lsblakk
bugs1055145
milestone36.0a2
Bug 1055145 - Part 2: Fix failing loop tests: prevent spurious network access attempts r=mattn a=lsblakk
browser/components/loop/test/mochitest/browser_fxa_login.js
browser/components/loop/test/mochitest/head.js
browser/components/loop/test/mochitest/loop_fxa.sjs
browser/components/loop/test/xpcshell/head.js
browser/components/loop/test/xpcshell/test_looppush_initialize.js
browser/modules/test/browser_UITour_loop.js
testing/profiles/prefs_general.js
--- a/browser/components/loop/test/mochitest/browser_fxa_login.js
+++ b/browser/components/loop/test/mochitest/browser_fxa_login.js
@@ -33,30 +33,26 @@ function* checkFxA401() {
      "Check error bar details message");
   is(loopDoc.querySelector(".details-error .detailsButton").textContent,
      getLoopString("retry_button"),
      "Check error bar details button");
   loopPanel.hidePopup();
 }
 
 add_task(function* setup() {
-  Services.prefs.setCharPref("loop.server", BASE_URL);
-  Services.prefs.setCharPref("services.push.serverURL", "ws://localhost/");
   Services.prefs.setBoolPref("loop.gettingStarted.seen", true);
   MozLoopServiceInternal.mocks.pushHandler = mockPushHandler;
   // Normally the same pushUrl would be registered but we change it in the test
   // to be able to check for success on the second registration.
   mockPushHandler.registeredChannels[MozLoopService.channelIDs.callsFxA] = "https://localhost/pushUrl/fxa-calls";
   mockPushHandler.registeredChannels[MozLoopService.channelIDs.roomsFxA] = "https://localhost/pushUrl/fxa-rooms";
 
   registerCleanupFunction(function* () {
     info("cleanup time");
     yield promiseDeletedOAuthParams(BASE_URL);
-    Services.prefs.clearUserPref("loop.server");
-    Services.prefs.clearUserPref("services.push.serverURL");
     Services.prefs.clearUserPref("loop.gettingStarted.seen");
     MozLoopServiceInternal.mocks.pushHandler = undefined;
     delete mockPushHandler.registeredChannels[MozLoopService.channelIDs.callsFxA];
     delete mockPushHandler.registeredChannels[MozLoopService.channelIDs.roomsFxA];
 
     yield resetFxA();
     Services.prefs.clearUserPref(MozLoopServiceInternal.getSessionTokenPrefName(LOOP_SESSION_TYPE.GUEST));
   });
@@ -129,28 +125,29 @@ add_task(function* params_no_hawk_sessio
   ok(caught, "Should have caught the rejection");
   let prefName = MozLoopServiceInternal.getSessionTokenPrefName(LOOP_SESSION_TYPE.FXA);
   ise(Services.prefs.getPrefType(prefName),
       Services.prefs.PREF_INVALID,
       "Check FxA hawk token is not set");
 });
 
 add_task(function* params_nonJSON() {
+  let loopServerUrl = Services.prefs.getCharPref("loop.server");
   Services.prefs.setCharPref("loop.server", "https://localhost:3000/invalid");
   // Reset after changing the server so a new HawkClient is created
   yield resetFxA();
 
   let loginPromise = MozLoopService.logInToFxA();
   let caught = false;
   yield loginPromise.catch(() => {
     ok(true, "The login promise should be rejected due to non-JSON params");
     caught = true;
   });
   ok(caught, "Should have caught the rejection");
-  Services.prefs.setCharPref("loop.server", BASE_URL);
+  Services.prefs.setCharPref("loop.server", loopServerUrl);
 });
 
 add_task(function* invalidState() {
   yield resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
--- a/browser/components/loop/test/mochitest/head.js
+++ b/browser/components/loop/test/mochitest/head.js
@@ -72,31 +72,25 @@ function promiseGetMozLoopAPI() {
 
 /**
  * Loads the loop panel by clicking the button and waits for its open to complete.
  * It also registers
  *
  * This assumes that the tests are running in a generatorTest.
  */
 function loadLoopPanel(aOverrideOptions = {}) {
-  // Set prefs to ensure we don't access the network externally.
-  Services.prefs.setCharPref("services.push.serverURL", aOverrideOptions.pushURL || "ws://localhost/");
-  Services.prefs.setCharPref("loop.server", aOverrideOptions.loopURL || "http://localhost/");
-
   // Turn off the network for loop tests, so that we don't
   // try to access the remote servers. If we want to turn this
   // back on in future, be careful to check for intermittent
   // failures.
   if (!aOverrideOptions.stayOnline) {
     Services.io.offline = true;
   }
 
   registerCleanupFunction(function() {
-    Services.prefs.clearUserPref("services.push.serverURL");
-    Services.prefs.clearUserPref("loop.server");
     Services.io.offline = WAS_OFFLINE;
   });
 
   // Turn off animations to make tests quicker.
   let loopPanel = document.getElementById("loop-notification-panel");
   loopPanel.setAttribute("animate", "false");
 
   // Now get the actual API.
--- a/browser/components/loop/test/mochitest/loop_fxa.sjs
+++ b/browser/components/loop/test/mochitest/loop_fxa.sjs
@@ -41,16 +41,19 @@ function handleRequest(request, response
       }
       return;
     case "/get_registration": // Test-only
       get_registration(request, response);
       return;
     case "/profile/profile":
       profile(request, response);
       return;
+    case "/push-server-config":
+      push_server(request, response);
+      return;
   }
   response.setStatusLine(request.httpVersion, 404, "Not Found");
 }
 
 /**
  * POST /setup_params
  * DELETE /setup_params
  *
@@ -186,16 +189,28 @@ function profile(request, response) {
   let profile = {
     email: "test@example.com",
     uid: "1234abcd",
   };
   response.write(JSON.stringify(profile, null, 2));
 }
 
 /**
+ * GET /push-server-config
+ *
+ */
+function push_server(request, response) {
+  response.setHeader("Content-Type", "application/json; charset=utf-8", false);
+  let msg = {
+    pushServerURI: "ws://localhost/"
+  };
+  response.write(JSON.stringify(msg, null, 2));
+}
+
+/**
  * POST /registration
  *
  * Mock Loop registration endpoint. Hawk Authorization headers are expected only for FxA sessions.
  */
 function registration(request, response) {
   let isFxARequest = function(payload) {
     return (payload.simplePushURL == "https://localhost/pushUrl/fxa" ||
             payload.simplePushURLs.calls == "https://localhost/pushUrl/fxa-calls" ||
--- a/browser/components/loop/test/xpcshell/head.js
+++ b/browser/components/loop/test/xpcshell/head.js
@@ -14,17 +14,17 @@ Cu.import("resource:///modules/loop/Loop
 const { MozLoopServiceInternal } = Cu.import("resource:///modules/loop/MozLoopService.jsm", {});
 
 XPCOMUtils.defineLazyModuleGetter(this, "MozLoopPushHandler",
                                   "resource:///modules/loop/MozLoopPushHandler.jsm");
 
 const kMockWebSocketChannelName = "Mock WebSocket Channel";
 const kWebSocketChannelContractID = "@mozilla.org/network/protocol;1?name=wss";
 
-const kServerPushUrl = "http://localhost:3456";
+const kServerPushUrl = "ws://localhost";
 const kLoopServerUrl = "http://localhost:3465";
 const kEndPointUrl = "http://example.com/fake";
 const kUAID = "f47ac11b-58ca-4372-9567-0e02b2c3d479";
 
 // Fake loop server
 var loopServer;
 
 // Ensure loop is always enabled for tests
@@ -34,18 +34,16 @@ Services.prefs.setBoolPref("loop.enabled
 do_register_cleanup(() => {
   MozLoopService.errors.clear();
 });
 
 function setupFakeLoopServer() {
   loopServer = new HttpServer();
   loopServer.start(-1);
 
-  Services.prefs.setCharPref("services.push.serverURL", kServerPushUrl);
-
   Services.prefs.setCharPref("loop.server",
     "http://localhost:" + loopServer.identity.primaryPort);
 
   MozLoopServiceInternal.mocks.pushHandler = mockPushHandler;
 
   do_register_cleanup(function() {
     loopServer.stop(function() {});
     MozLoopServiceInternal.mocks.pushHandler = undefined;
--- a/browser/components/loop/test/xpcshell/test_looppush_initialize.js
+++ b/browser/components/loop/test/xpcshell/test_looppush_initialize.js
@@ -142,14 +142,16 @@
 
   function run_test() {
     setupFakeLoopServer();
 
     Services.prefs.setIntPref("loop.retry_delay.start", 10); // 10 ms
     Services.prefs.setIntPref("loop.retry_delay.limit", 20); // 20 ms
 
     do_register_cleanup(function() {
+      Services.prefs.clearUserPref("loop.retry_delay.start");
+      Services.prefs.clearUserPref("loop.retry_delay.limit");
       Services.prefs.setCharPref("loop.server", kLoopServerUrl);
     });
 
     run_next_test();
   };
 }
--- a/browser/modules/test/browser_UITour_loop.js
+++ b/browser/modules/test/browser_UITour_loop.js
@@ -256,25 +256,21 @@ function setupFakeRoom() {
   LoopRooms.stubCache(roomsMap);
   return roomsMap;
 }
 
 if (Services.prefs.getBoolPref("loop.enabled")) {
   loopButton = window.LoopUI.toolbarButton.node;
   // The targets to highlight only appear after getting started is launched.
   Services.prefs.setBoolPref("loop.gettingStarted.seen", true);
-  Services.prefs.setCharPref("loop.server", "http://localhost");
-  Services.prefs.setCharPref("services.push.serverURL", "ws://localhost/");
 
   registerCleanupFunction(() => {
     Services.prefs.clearUserPref("loop.gettingStarted.resumeOnFirstJoin");
     Services.prefs.clearUserPref("loop.gettingStarted.seen");
     Services.prefs.clearUserPref("loop.gettingStarted.url");
-    Services.prefs.clearUserPref("loop.server");
-    Services.prefs.clearUserPref("services.push.serverURL");
 
     // Copied from browser/components/loop/test/mochitest/head.js
     // Remove the iframe after each test. This also avoids mochitest complaining
     // about leaks on shutdown as we intentionally hold the iframe open for the
     // life of the application.
     let frameId = loopButton.getAttribute("notificationFrameId");
     let frame = document.getElementById(frameId);
     if (frame) {
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -257,16 +257,17 @@ user_pref("browser.newtabpage.directory.
 user_pref("browser.newtabpage.directory.ping", "");
 
 // Enable Loop
 user_pref("loop.enabled", true);
 user_pref("loop.throttled", false);
 user_pref("loop.oauth.google.URL", "http://%(server)s/browser/browser/components/loop/test/mochitest/google_service.sjs?action=");
 user_pref("loop.oauth.google.getContactsURL", "http://%(server)s/browser/browser/components/loop/test/mochitest/google_service.sjs?action=contacts");
 user_pref("loop.oauth.google.getGroupsURL", "http://%(server)s/browser/browser/components/loop/test/mochitest/google_service.sjs?action=groups");
+user_pref("loop.server", "http://%(server)s/browser/browser/components/loop/test/mochitest/loop_fxa.sjs?");
 user_pref("loop.CSP","default-src 'self' about: file: chrome: data: wss://* http://* https://*");
 
 // Ensure UITour won't hit the network
 user_pref("browser.uitour.pinnedTabUrl", "http://%(server)s/uitour-dummy/pinnedTab");
 user_pref("browser.uitour.url", "http://%(server)s/uitour-dummy/tour");
 
 // Don't show the search first run UI by default
 user_pref("browser.search.highlightCount", 0);