Bug 1160145 - Fix eslint warnings in Loop's xpcshell and mochitest files and turn on linting for them. r=dmose

This commit is contained in:
Mark Banner 2015-05-01 10:42:46 +01:00
parent 84bbd186d9
commit dae9f1d2c7
32 changed files with 330 additions and 238 deletions

View File

@ -9,9 +9,6 @@ content/libs
content/shared/libs
standalone/content/libs
standalone/node_modules
# We should look at turning these on when we fix the warnings
test/xpcshell
test/mochitest
# Libs we don't need to check
test/shared/vendor

View File

@ -54,7 +54,7 @@ If you install eslint and the react plugin globally:
You can also run it by hand in the browser/components/loop directory:
eslint -ext .js -ext .jsx --ext .jsm .
eslint --ext .js --ext .jsx --ext .jsm .
Front-End Unit Tests
====================

View File

@ -0,0 +1,17 @@
{
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"destructuring": true,
"generators": true,
"restParams": true,
"spread": true,
"objectLiteralShorthandMethods": true,
},
"rules": {
"generator-star-spacing": [2, "after"],
// We should fix the errors and enable this (set to 2)
"no-var": 0,
"strict": [2, "global"]
}
}

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {CardDavImporter} = Cu.import("resource:///modules/loop/CardDavImporter.jsm", {});
const kAuth = {

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {GoogleImporter} = Cu.import("resource:///modules/loop/GoogleImporter.jsm", {});
let importer = new GoogleImporter();

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {LoopContacts} = Cu.import("resource:///modules/loop/LoopContacts.jsm", {});
const {LoopStorage} = Cu.import("resource:///modules/loop/LoopStorage.jsm", {});
@ -221,8 +223,13 @@ add_task(function* () {
Assert.ok(!err, "There shouldn't be an error");
Assert.equal(result.length, toRetrieve.length, "Result list should be the same " +
"size as the list of items to retrieve");
function resultFilter(c) {
return c._guid == this._guid;
}
for (let contact of toRetrieve) {
let found = result.filter(c => c._guid == contact._guid);
let found = result.filter(resultFilter.bind(contact));
Assert.ok(found.length, "Contact " + contact._guid + " should be in the list");
compareContacts(found[0], contact);
}

View File

@ -6,6 +6,8 @@
* effects - rather than just testing MozLoopAPI alone.
*/
"use strict";
Components.utils.import("resource://gre/modules/Promise.jsm", this);
add_task(loadLoopPanel);

View File

@ -6,6 +6,8 @@
* effects - rather than just testing MozLoopAPI alone.
*/
"use strict";
Components.utils.import("resource://gre/modules/Promise.jsm", this);
add_task(loadLoopPanel);

View File

@ -1,21 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* This is an integration test from navigator.mozLoop through to the end
* effects - rather than just testing MozLoopAPI alone.
*/
Components.utils.import("resource://gre/modules/Promise.jsm", this);
add_task(loadLoopPanel);
add_task(function* test_mozLoop_pluralStrings() {
Assert.ok(gMozLoopAPI, "mozLoop should exist");
var strings = JSON.parse(gMozLoopAPI.getStrings("feedback_window_will_close_in2"));
Assert.equal(gMozLoopAPI.getPluralForm(0, strings.textContent),
"This window will close in {{countdown}} seconds");
Assert.equal(gMozLoopAPI.getPluralForm(1, strings.textContent),
"This window will close in {{countdown}} second");
});
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* This is an integration test from navigator.mozLoop through to the end
* effects - rather than just testing MozLoopAPI alone.
*/
"use strict";
Components.utils.import("resource://gre/modules/Promise.jsm", this);
add_task(loadLoopPanel);
add_task(function* test_mozLoop_pluralStrings() {
Assert.ok(gMozLoopAPI, "mozLoop should exist");
var strings = JSON.parse(gMozLoopAPI.getStrings("feedback_window_will_close_in2"));
Assert.equal(gMozLoopAPI.getPluralForm(0, strings.textContent),
"This window will close in {{countdown}} seconds");
Assert.equal(gMozLoopAPI.getPluralForm(1, strings.textContent),
"This window will close in {{countdown}} second");
});

View File

@ -6,6 +6,8 @@
* effects - rather than just testing MozLoopAPI alone.
*/
"use strict";
Components.utils.import("resource://gre/modules/Promise.jsm", this);
add_task(loadLoopPanel);

View File

@ -6,6 +6,8 @@
* effects - rather than just testing MozLoopAPI alone.
*/
"use strict";
Cu.import("resource://gre/modules/Promise.jsm");
const {SocialService} = Cu.import("resource://gre/modules/SocialService.jsm", {});

View File

@ -4,6 +4,9 @@
/*
* This file contains tests for the mozLoop telemetry API.
*/
"use strict";
Components.utils.import("resource://gre/modules/Promise.jsm", this);
add_task(loadLoopPanel);

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const HAWK_TOKEN_LENGTH = 64;
const {
LOOP_SESSION_TYPE,
@ -123,8 +125,8 @@ function loadLoopPanel(aOverrideOptions = {}) {
let loopPanel = document.getElementById("loop-notification-panel");
loopPanel.setAttribute("animate", "false");
// Now get the actual API.
yield promiseGetMozLoopAPI();
// Now get the actual API loaded into gMozLoopAPI.
return promiseGetMozLoopAPI();
}
function promiseOAuthParamsSetup(baseURL, params) {
@ -319,7 +321,7 @@ const mockDb = {
callback(null, details);
},
remove: function(guid, callback) {
if (!guid in this._store) {
if (!(guid in this._store)) {
callback(new Error("Could not find _guid '" + guid + "' in database"));
return;
}

View File

@ -0,0 +1,17 @@
{
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"destructuring": true,
"generators": true,
"restParams": true,
"spread": true,
"objectLiteralShorthandMethods": true,
},
"rules": {
"generator-star-spacing": [2, "after"],
// We should fix the errors and enable this (set to 2)
"no-var": 0,
"strict": [2, "global"]
}
}

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

View File

@ -1,222 +1,223 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
{
let dummyCallback = () => {};
let mockWebSocket = new MockWebSocketChannel();
let pushServerRequestCount = 0;
add_test(function test_initalize_offline() {
Services.io.offline = true;
do_check_false(MozLoopPushHandler.initialize());
Services.io.offline = false;
run_next_test();
});
"use strict";
add_test(function test_initalize_missing_chanid() {
Assert.throws(() => MozLoopPushHandler.register(null, dummyCallback, dummyCallback));
run_next_test();
});
let dummyCallback = () => {};
let mockWebSocket = new MockWebSocketChannel();
let pushServerRequestCount = 0;
add_test(function test_initalize_missing_regcallback() {
Assert.throws(() => MozLoopPushHandler.register("chan-1", null, dummyCallback));
run_next_test();
});
add_test(function test_initalize_offline() {
Services.io.offline = true;
do_check_false(MozLoopPushHandler.initialize());
Services.io.offline = false;
run_next_test();
});
add_test(function test_initalize_missing_notifycallback() {
Assert.throws(() => MozLoopPushHandler.register("chan-1", dummyCallback, null));
run_next_test();
});
add_test(function test_initalize_missing_chanid() {
Assert.throws(() => MozLoopPushHandler.register(null, dummyCallback, dummyCallback));
run_next_test();
});
add_test(function test_initalize_websocket() {
do_check_true(MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket}));
MozLoopPushHandler.register(
"chan-1",
function(err, url, id) {
Assert.equal(err, null, "err should be null to indicate success");
Assert.equal(url, kEndPointUrl, "Should return push server application URL");
Assert.equal(id, "chan-1", "Should have channel id = chan-1");
Assert.equal(mockWebSocket.uri.prePath, kServerPushUrl,
"Should have the url from preferences");
Assert.equal(mockWebSocket.origin, kServerPushUrl,
"Should have the origin url from preferences");
Assert.equal(mockWebSocket.protocol, "push-notification",
"Should have the protocol set to push-notifications");
mockWebSocket.notify(15);
},
function(version, id) {
Assert.equal(version, 15, "Should have version number 15");
Assert.equal(id, "chan-1", "Should have channel id = chan-1");
run_next_test();
});
});
add_test(function test_initalize_missing_regcallback() {
Assert.throws(() => MozLoopPushHandler.register("chan-1", null, dummyCallback));
run_next_test();
});
add_test(function test_register_twice_same_channel() {
MozLoopPushHandler.register(
"chan-2",
function(err, url, id) {
Assert.equal(err, null, "Should return null for success");
Assert.equal(url, kEndPointUrl, "Should return push server application URL");
Assert.equal(id, "chan-2", "Should have channel id = chan-2");
Assert.equal(mockWebSocket.uri.prePath, kServerPushUrl,
"Should have the url from preferences");
Assert.equal(mockWebSocket.origin, kServerPushUrl,
"Should have the origin url from preferences");
Assert.equal(mockWebSocket.protocol, "push-notification",
"Should have the protocol set to push-notifications");
add_test(function test_initalize_missing_notifycallback() {
Assert.throws(() => MozLoopPushHandler.register("chan-1", dummyCallback, null));
run_next_test();
});
// Register again for the same channel
MozLoopPushHandler.register(
"chan-2",
function(err, url, id) {
Assert.equal(err, null, "Should return null for success");
Assert.equal(id, "chan-2", "Should have channel id = chan-2");
run_next_test();
},
dummyCallback
);
},
dummyCallback
);
});
// Test that the PushHander will re-connect after the near-end disconnect.
// The uaID is cleared to force re-registration of all notification channels.
add_test(function test_reconnect_websocket() {
MozLoopPushHandler.uaID = undefined;
mockWebSocket.stop();
// Previously registered onRegistration callbacks will fire and be checked (see above).
});
// Test that the PushHander will re-connect after the far-end disconnect.
// The uaID is cleared to force re-regsitration of all notification channels.
add_test(function test_reopen_websocket() {
MozLoopPushHandler.uaID = undefined;
MozLoopPushHandler.registeredChannels = {}; //Do this to force a new registration callback.
mockWebSocket.serverClose();
// Previously registered onRegistration callbacks will fire and be checked (see above).
});
// Force a re-registration cycle and have the PushServer return a 500.
// A retry should occur and the registration then complete.
add_test(function test_retry_registration() {
MozLoopPushHandler.uaID = undefined;
mockWebSocket.initRegStatus = 500;
mockWebSocket.stop();
});
add_test(function test_reconnect_no_registration() {
let regCnt = 0;
MozLoopPushHandler.shutdown();
MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket});
MozLoopPushHandler.register(
"test-chan",
function(err, url, id) {
Assert.equal(++regCnt, 1, "onRegistered should only be called once");
Assert.equal(err, null, "err should be null to indicate success");
Assert.equal(url, kEndPointUrl, "Should return push server application URL");
Assert.equal(id, "test-chan", "Should have channel id = test-chan");
mockWebSocket.stop();
setTimeout(run_next_test(), 0);
},
dummyCallback
);
});
add_test(function test_ping_websocket() {
let pingReceived = false,
socketClosed = false;
mockWebSocket.defaultMsgHandler = (msg) => {
pingReceived = true;
// Do not send a ping response.
}
mockWebSocket.close = () => {
socketClosed = true;
}
MozLoopPushHandler.shutdown();
MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket});
MozLoopPushHandler.register(
"test-chan",
function(err, url) {
Assert.equal(err, null, "err should be null to indicate success");
waitForCondition(() => pingReceived).then(() => {
waitForCondition(() => socketClosed).then(() => {
run_next_test();
}, () => {
do_throw("should have closed the websocket");
});
}, () => {
do_throw("should have sent ping");
});
},
dummyCallback
);
});
add_test(function test_retry_pushurl() {
MozLoopPushHandler.shutdown();
loopServer.registerPathHandler("/push-server-config", (request, response) => {
// The PushHandler should retry the request for the push-server-config for
// each of these cases without throwing an error.
let n = 0;
switch (++pushServerRequestCount) {
case ++n:
// Non-200 response
response.setStatusLine(null, 500, "Retry");
response.processAsync();
response.finish();
break;
case ++n:
// missing parameter
response.setStatusLine(null, 200, "OK");
response.write(JSON.stringify({pushServerURI: null}));
response.processAsync();
response.finish();
break;
case ++n:
// json parse error
response.setStatusLine(null, 200, "OK");
response.processAsync();
response.finish();
break;
case ++n:
response.setStatusLine(null, 200, "OK");
response.write(JSON.stringify({pushServerURI: kServerPushUrl}));
response.processAsync();
response.finish();
run_next_test();
break;
}
add_test(function test_initalize_websocket() {
do_check_true(MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket}));
MozLoopPushHandler.register(
"chan-1",
function(err, url, id) {
Assert.equal(err, null, "err should be null to indicate success");
Assert.equal(url, kEndPointUrl, "Should return push server application URL");
Assert.equal(id, "chan-1", "Should have channel id = chan-1");
Assert.equal(mockWebSocket.uri.prePath, kServerPushUrl,
"Should have the url from preferences");
Assert.equal(mockWebSocket.origin, kServerPushUrl,
"Should have the origin url from preferences");
Assert.equal(mockWebSocket.protocol, "push-notification",
"Should have the protocol set to push-notifications");
mockWebSocket.notify(15);
},
function(version, id) {
Assert.equal(version, 15, "Should have version number 15");
Assert.equal(id, "chan-1", "Should have channel id = chan-1");
run_next_test();
});
});
do_check_true(MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket}));
});
add_test(function test_register_twice_same_channel() {
MozLoopPushHandler.register(
"chan-2",
function(err, url, id) {
Assert.equal(err, null, "Should return null for success");
Assert.equal(url, kEndPointUrl, "Should return push server application URL");
Assert.equal(id, "chan-2", "Should have channel id = chan-2");
Assert.equal(mockWebSocket.uri.prePath, kServerPushUrl,
"Should have the url from preferences");
Assert.equal(mockWebSocket.origin, kServerPushUrl,
"Should have the origin url from preferences");
Assert.equal(mockWebSocket.protocol, "push-notification",
"Should have the protocol set to push-notifications");
function run_test() {
setupFakeLoopServer();
// Register again for the same channel
MozLoopPushHandler.register(
"chan-2",
function(err, url, id) {
Assert.equal(err, null, "Should return null for success");
Assert.equal(id, "chan-2", "Should have channel id = chan-2");
run_next_test();
},
dummyCallback
);
},
dummyCallback
);
});
loopServer.registerPathHandler("/push-server-config", (request, response) => {
// Test that the PushHander will re-connect after the near-end disconnect.
// The uaID is cleared to force re-registration of all notification channels.
add_test(function test_reconnect_websocket() {
MozLoopPushHandler.uaID = undefined;
mockWebSocket.stop();
// Previously registered onRegistration callbacks will fire and be checked (see above).
});
// Test that the PushHander will re-connect after the far-end disconnect.
// The uaID is cleared to force re-regsitration of all notification channels.
add_test(function test_reopen_websocket() {
MozLoopPushHandler.uaID = undefined;
MozLoopPushHandler.registeredChannels = {}; //Do this to force a new registration callback.
mockWebSocket.serverClose();
// Previously registered onRegistration callbacks will fire and be checked (see above).
});
// Force a re-registration cycle and have the PushServer return a 500.
// A retry should occur and the registration then complete.
add_test(function test_retry_registration() {
MozLoopPushHandler.uaID = undefined;
mockWebSocket.initRegStatus = 500;
mockWebSocket.stop();
});
add_test(function test_reconnect_no_registration() {
let regCnt = 0;
MozLoopPushHandler.shutdown();
MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket});
MozLoopPushHandler.register(
"test-chan",
function(err, url, id) {
Assert.equal(++regCnt, 1, "onRegistered should only be called once");
Assert.equal(err, null, "err should be null to indicate success");
Assert.equal(url, kEndPointUrl, "Should return push server application URL");
Assert.equal(id, "test-chan", "Should have channel id = test-chan");
mockWebSocket.stop();
setTimeout(run_next_test(), 0);
},
dummyCallback
);
});
add_test(function test_ping_websocket() {
let pingReceived = false,
socketClosed = false;
mockWebSocket.defaultMsgHandler = (msg) => {
pingReceived = true;
// Do not send a ping response.
}
mockWebSocket.close = () => {
socketClosed = true;
}
MozLoopPushHandler.shutdown();
MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket});
MozLoopPushHandler.register(
"test-chan",
function(err, url) {
Assert.equal(err, null, "err should be null to indicate success");
waitForCondition(() => pingReceived).then(() => {
waitForCondition(() => socketClosed).then(() => {
run_next_test();
}, () => {
do_throw("should have closed the websocket");
});
}, () => {
do_throw("should have sent ping");
});
},
dummyCallback
);
});
add_test(function test_retry_pushurl() {
MozLoopPushHandler.shutdown();
loopServer.registerPathHandler("/push-server-config", (request, response) => {
// The PushHandler should retry the request for the push-server-config for
// each of these cases without throwing an error.
let n = 0;
switch (++pushServerRequestCount) {
case ++n:
// Non-200 response
response.setStatusLine(null, 500, "Retry");
response.processAsync();
response.finish();
break;
case ++n:
// missing parameter
response.setStatusLine(null, 200, "OK");
response.write(JSON.stringify({pushServerURI: null}));
response.processAsync();
response.finish();
break;
case ++n:
// json parse error
response.setStatusLine(null, 200, "OK");
response.processAsync();
response.finish();
break;
case ++n:
response.setStatusLine(null, 200, "OK");
response.write(JSON.stringify({pushServerURI: kServerPushUrl}));
response.processAsync();
response.finish();
});
Services.prefs.setCharPref("services.push.serverURL", kServerPushUrl);
Services.prefs.setIntPref("loop.retry_delay.start", 10); // 10 ms
Services.prefs.setIntPref("loop.retry_delay.limit", 20); // 20 ms
Services.prefs.setIntPref("loop.ping.interval", 50); // 50 ms
Services.prefs.setIntPref("loop.ping.timeout", 20); // 20 ms
run_next_test();
break;
}
});
do_register_cleanup(function() {
Services.prefs.clearUserPref("services.push.serverULR");
Services.prefs.clearUserPref("loop.retry_delay.start");
Services.prefs.clearUserPref("loop.retry_delay.limit");
Services.prefs.clearUserPref("loop.ping.interval");
Services.prefs.clearUserPref("loop.ping.timeout");
});
do_check_true(MozLoopPushHandler.initialize({mockWebSocket: mockWebSocket}));
});
run_next_test();
};
}
function run_test() {
setupFakeLoopServer();
loopServer.registerPathHandler("/push-server-config", (request, response) => {
response.setStatusLine(null, 200, "OK");
response.write(JSON.stringify({pushServerURI: kServerPushUrl}));
response.processAsync();
response.finish();
});
Services.prefs.setCharPref("services.push.serverURL", kServerPushUrl);
Services.prefs.setIntPref("loop.retry_delay.start", 10); // 10 ms
Services.prefs.setIntPref("loop.retry_delay.limit", 20); // 20 ms
Services.prefs.setIntPref("loop.ping.interval", 50); // 50 ms
Services.prefs.setIntPref("loop.ping.timeout", 20); // 20 ms
do_register_cleanup(function() {
Services.prefs.clearUserPref("services.push.serverULR");
Services.prefs.clearUserPref("loop.retry_delay.start");
Services.prefs.clearUserPref("loop.retry_delay.limit");
Services.prefs.clearUserPref("loop.ping.interval");
Services.prefs.clearUserPref("loop.ping.timeout");
});
run_next_test();
};

View File

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
Cu.import("resource://services-common/utils.js");
Cu.import("resource:///modules/loop/LoopRooms.jsm");
Cu.import("resource:///modules/Chat.jsm");

View File

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { LoopCallsInternal } = Cu.import("resource:///modules/loop/LoopCalls.jsm", {});
XPCOMUtils.defineLazyModuleGetter(this, "Chat",

View File

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
XPCOMUtils.defineLazyModuleGetter(this, "Chat",
"resource:///modules/Chat.jsm");
let openChatOrig = Chat.open;

View File

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
XPCOMUtils.defineLazyModuleGetter(this, "Chat",
"resource:///modules/Chat.jsm");
let openChatOrig = Chat.open;
@ -41,7 +43,7 @@ add_test(function test_do_not_disturb_disabled_should_open_chat_window() {
mockPushHandler.notify(1, MozLoopService.channelIDs.callsFxA);
waitForCondition(function() opened).then(() => {
waitForCondition(() => opened).then(() => {
run_next_test();
}, () => {
do_throw("should have opened a chat window");

View File

@ -2,6 +2,8 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
/* global Services, Assert */
"use strict";
const kGuestKeyPref = "loop.key";
const kFxAKeyPref = "loop.key.fxa";

View File

@ -1,13 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let startTimerCalled = false;
/**
* Tests that registration doesn't happen when the expiry time is
* not set.
*/
add_task(function test_initialize_no_expiry() {
add_task(function* test_initialize_no_expiry() {
startTimerCalled = false;
let initializedPromise = yield MozLoopService.initialize();

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function test_locale() {
// Set the pref to something controlled.
Services.prefs.setCharPref("general.useragent.locale", "ab-CD");

View File

@ -2,6 +2,8 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
/*global XPCOMUtils, Services, Assert */
"use strict";
var fakeCharPrefName = "color";
var fakeBoolPrefName = "boolean";
var fakePrefValue = "green";

View File

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
XPCOMUtils.defineLazyModuleGetter(this, "Chat",
"resource:///modules/Chat.jsm");
@ -20,7 +22,7 @@ add_test(function test_openChatWindow_on_notification() {
mockPushHandler.notify(1, MozLoopService.channelIDs.callsFxA);
waitForCondition(function() opened).then(() => {
waitForCondition(() => opened).then(() => {
do_check_true(opened, "should open a chat window");
do_check_eq(Services.prefs.getCharPref("loop.seenToS"), "seen",

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
Cu.import("resource://services-common/utils.js");
/**

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://services-common/utils.js");

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const FAKE_FXA_TOKEN_DATA = JSON.stringify({
"token_type": "bearer",
"access_token": "1bad3e44b12f77a88fe09f016f6a37c42e40f974bc7a8b432bb0d2f0e37e1752",
@ -20,7 +22,7 @@ const LOOP_INITIAL_DELAY_PREF = "loop.initialDelay";
* This file is to test restart+reauth.
*/
add_task(function test_initialize_with_no_guest_rooms_and_no_auth_token() {
add_task(function* test_initialize_with_no_guest_rooms_and_no_auth_token() {
// Set time to be 2 seconds in the past.
var nowSeconds = Date.now() / 1000;
Services.prefs.setBoolPref(LOOP_CREATED_ROOM_PREF, false);
@ -34,7 +36,7 @@ add_task(function test_initialize_with_no_guest_rooms_and_no_auth_token() {
});
});
add_task(function test_initialize_with_created_room_and_no_auth_token() {
add_task(function* test_initialize_with_created_room_and_no_auth_token() {
Services.prefs.setBoolPref(LOOP_CREATED_ROOM_PREF, true);
Services.prefs.clearUserPref(LOOP_FXA_TOKEN_PREF);
@ -50,7 +52,7 @@ add_task(function test_initialize_with_created_room_and_no_auth_token() {
});
});
add_task(function test_initialize_with_invalid_fxa_token() {
add_task(function* test_initialize_with_invalid_fxa_token() {
Services.prefs.setCharPref(LOOP_FXA_PROFILE_PREF, FAKE_FXA_PROFILE);
Services.prefs.setCharPref(LOOP_FXA_TOKEN_PREF, FAKE_FXA_TOKEN_DATA);
@ -83,7 +85,7 @@ add_task(function test_initialize_with_invalid_fxa_token() {
});
});
add_task(function test_initialize_with_fxa_token() {
add_task(function* test_initialize_with_fxa_token() {
Services.prefs.setCharPref(LOOP_FXA_PROFILE_PREF, FAKE_FXA_PROFILE);
Services.prefs.setCharPref(LOOP_FXA_TOKEN_PREF, FAKE_FXA_TOKEN_DATA);

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const LOOP_HAWK_PREF = "loop.hawk-session-token";
const fakeSessionToken1 = "1bad3e44b12f77a88fe09f016f6a37c42e40f974bc7a8b432bb0d2f0e37e1751";
const fakeSessionToken2 = "1bad3e44b12f77a88fe09f016f6a37c42e40f974bc7a8b432bb0d2f0e37e1750";

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test that things behave reasonably when a reasonable Hawk-Session-Token
* header is returned with the registration response.

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_test(function test_registration_uses_hawk_session_token() {
Services.prefs.setCharPref("loop.hawk-session-token",
"1bad3e44b12f77a88fe09f016f6a37c42e40f974bc7a8b432bb0d2f0e37e1750");

View File

@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// XXX should report error if Hawk-Session-Token is lexically invalid
// (not a string of 64 hex digits) to help resist other possible injection
// attacks. For now, however, we're just checking if it's the right length.