зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1018208 - Write missing tests for Loop "do not disturb" feature. r=Standard8
This commit is contained in:
Родитель
f4f4b816a5
Коммит
d545069052
|
@ -57,6 +57,16 @@ MockWebSocketChannel.prototype = {
|
|||
this.listener.onStart(this.context);
|
||||
},
|
||||
|
||||
notify: function(version) {
|
||||
this.listener.onMessageAvailable(this.context,
|
||||
JSON.stringify({
|
||||
messageType: "notification", updates: [{
|
||||
channelID: "8b1081ce-9b35-42b5-b8f5-3ff8cb813a50",
|
||||
version: version
|
||||
}]
|
||||
}));
|
||||
},
|
||||
|
||||
sendMsg: function(aMsg) {
|
||||
var message = JSON.parse(aMsg);
|
||||
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
* 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/. */
|
||||
|
||||
do_register_cleanup(function() {
|
||||
Services.prefs.clearUserPref("loop.do_not_disturb");
|
||||
});
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Chat",
|
||||
"resource:///modules/Chat.jsm");
|
||||
|
||||
function test_get_do_not_disturb() {
|
||||
var openChatOrig = Chat.open;
|
||||
|
||||
add_test(function test_get_do_not_disturb() {
|
||||
Services.prefs.setBoolPref("loop.do_not_disturb", false);
|
||||
|
||||
do_check_false(MozLoopService.doNotDisturb);
|
||||
|
@ -14,18 +15,80 @@ function test_get_do_not_disturb() {
|
|||
Services.prefs.setBoolPref("loop.do_not_disturb", true);
|
||||
|
||||
do_check_true(MozLoopService.doNotDisturb);
|
||||
}
|
||||
|
||||
function test_set_do_not_disturb() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_set_do_not_disturb() {
|
||||
Services.prefs.setBoolPref("loop.do_not_disturb", false);
|
||||
|
||||
MozLoopService.doNotDisturb = true;
|
||||
|
||||
do_check_true(Services.prefs.getBoolPref("loop.do_not_disturb"));
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_do_not_disturb_disabled_should_open_chat_window() {
|
||||
MozLoopService.doNotDisturb = false;
|
||||
|
||||
MozLoopService.register().then(() => {
|
||||
let webSocket = gMockWebSocketChannelFactory.createdInstances[0];
|
||||
|
||||
let opened = false;
|
||||
Chat.open = function() {
|
||||
opened = true;
|
||||
};
|
||||
|
||||
webSocket.notify(1);
|
||||
|
||||
do_check_true(opened, "should open a chat window");
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
||||
add_test(function test_do_not_disturb_enabled_shouldnt_open_chat_window() {
|
||||
MozLoopService.doNotDisturb = true;
|
||||
|
||||
MozLoopService.register().then(() => {
|
||||
let webSocket = gMockWebSocketChannelFactory.createdInstances[0];
|
||||
|
||||
let opened = false;
|
||||
Chat.open = function() {
|
||||
opened = true;
|
||||
};
|
||||
|
||||
webSocket.notify(1);
|
||||
|
||||
do_check_false(opened, "should not open a chat window");
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
||||
function run_test()
|
||||
{
|
||||
test_get_do_not_disturb();
|
||||
test_set_do_not_disturb();
|
||||
setupFakeLoopServer();
|
||||
|
||||
loopServer.registerPathHandler("/registration", (request, response) => {
|
||||
response.setStatusLine(null, 200, "OK");
|
||||
response.processAsync();
|
||||
response.finish();
|
||||
});
|
||||
|
||||
// Registrations and pref settings.
|
||||
gMockWebSocketChannelFactory.register();
|
||||
|
||||
do_register_cleanup(function() {
|
||||
gMockWebSocketChannelFactory.unregister();
|
||||
|
||||
// Revert original Chat.open implementation
|
||||
Chat.open = openChatOrig;
|
||||
|
||||
// clear test pref
|
||||
Services.prefs.clearUserPref("loop.do_not_disturb");
|
||||
});
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче