From f632c8537da63e41f032bd29eb2672adf04eed81 Mon Sep 17 00:00:00 2001 From: "Paul Kerr [:pkerr]" Date: Fri, 26 Dec 2014 12:30:01 -0800 Subject: [PATCH] Bug 1115186: prevent network connections during loop module tests. r=MattN --- .../loop/test/mochitest/browser_fxa_login.js | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/browser/components/loop/test/mochitest/browser_fxa_login.js b/browser/components/loop/test/mochitest/browser_fxa_login.js index 6d6c4e7e8611..041e31dcd5bc 100644 --- a/browser/components/loop/test/mochitest/browser_fxa_login.js +++ b/browser/components/loop/test/mochitest/browser_fxa_login.js @@ -7,7 +7,7 @@ "use strict"; -const BASE_URL = "http://mochi.test:8888/browser/browser/components/loop/test/mochitest/loop_fxa.sjs?"; +const BASE_URL = Services.prefs.getCharPref("loop.server"); function* checkFxA401() { let err = MozLoopService.errors.get("login"); @@ -23,7 +23,7 @@ function* checkFxA401() { "state of loop button should be error after a 401 with login"); let loopPanel = document.getElementById("loop-notification-panel"); - yield loadLoopPanel({loopURL: BASE_URL }); + yield loadLoopPanel(); let loopDoc = document.getElementById("loop").contentDocument; is(loopDoc.querySelector(".alert-error .message").textContent, getLoopString("could_not_authenticate"), @@ -132,17 +132,22 @@ add_task(function* params_no_hawk_session() { 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(); + try { + // 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", loopServerUrl); + 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"); + } catch (err) { + throw err; + } finally { + Services.prefs.setCharPref("loop.server", loopServerUrl); + } }); add_task(function* invalidState() { @@ -286,7 +291,7 @@ add_task(function* basicAuthorizationAndRegistration() { yield MozLoopService.promiseRegisteredWithServers(); let statusChangedPromise = promiseObserverNotified("loop-status-changed"); - yield loadLoopPanel({loopURL: BASE_URL, stayOnline: true}); + yield loadLoopPanel({stayOnline: true}); yield statusChangedPromise; let loopDoc = document.getElementById("loop").contentDocument; let visibleEmail = loopDoc.getElementsByClassName("user-identity")[0]; @@ -316,7 +321,7 @@ add_task(function* basicAuthorizationAndRegistration() { let loopPanel = document.getElementById("loop-notification-panel"); loopPanel.hidePopup(); statusChangedPromise = promiseObserverNotified("loop-status-changed"); - yield loadLoopPanel({loopURL: BASE_URL, stayOnline: true}); + yield loadLoopPanel({stayOnline: true}); yield statusChangedPromise; is(loopButton.getAttribute("state"), "", "state of loop button should return to empty after panel is opened"); loopPanel.hidePopup();