Bug 1055145 - Part 2: Fix failing loop tests: prevent spurious network access attempts r=mattn

This commit is contained in:
Paul Kerr [:pkerr] 2014-12-24 13:12:18 -08:00
parent e1602a6fb5
commit a4fb1268ba
7 changed files with 21 additions and 18 deletions

View File

@ -38,8 +38,6 @@ function* checkFxA401() {
}
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
@ -50,8 +48,6 @@ add_task(function* setup() {
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];
@ -134,6 +130,7 @@ 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();
@ -145,7 +142,7 @@ add_task(function* params_nonJSON() {
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() {

View File

@ -77,10 +77,6 @@ function promiseGetMozLoopAPI() {
* 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
@ -90,8 +86,6 @@ function loadLoopPanel(aOverrideOptions = {}) {
}
registerCleanupFunction(function() {
Services.prefs.clearUserPref("services.push.serverURL");
Services.prefs.clearUserPref("loop.server");
Services.io.offline = WAS_OFFLINE;
});

View File

@ -46,6 +46,9 @@ function handleRequest(request, response) {
case "/profile/profile":
profile(request, response);
return;
case "/push-server-config":
push_server(request, response);
return;
}
response.setStatusLine(request.httpVersion, 404, "Not Found");
}
@ -190,6 +193,18 @@ function profile(request, response) {
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
*

View File

@ -19,7 +19,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "MozLoopPushHandler",
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";
@ -39,8 +39,6 @@ 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);

View File

@ -147,6 +147,8 @@
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);
});

View File

@ -261,15 +261,11 @@ 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

View File

@ -264,6 +264,7 @@ 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