зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1033362 Implement basic mochitests for MozLoopAPI. r=dolske,r=glandium
This commit is contained in:
Родитель
5bf2d4e941
Коммит
67067f4790
|
@ -10,6 +10,10 @@ JS_MODULES_PATH = 'modules/loop'
|
|||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell/xpcshell.ini']
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += [
|
||||
'test/mochitest/browser.ini',
|
||||
]
|
||||
|
||||
EXTRA_JS_MODULES += [
|
||||
'MozLoopAPI.jsm',
|
||||
'MozLoopPushHandler.jsm',
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
[DEFAULT]
|
||||
support-files =
|
||||
head.js
|
||||
|
||||
[browser_mozLoop_charPref.js]
|
||||
[browser_mozLoop_doNotDisturb.js]
|
|
@ -0,0 +1,26 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
add_task(loadLoopPanel);
|
||||
|
||||
add_task(function* test_mozLoop_charPref() {
|
||||
registerCleanupFunction(function () {
|
||||
Services.prefs.clearUserPref("loop.test");
|
||||
});
|
||||
|
||||
Assert.ok(gMozLoopAPI, "mozLoop should exist");
|
||||
|
||||
// Test setLoopCharPref
|
||||
gMozLoopAPI.setLoopCharPref("test", "foo");
|
||||
Assert.equal(Services.prefs.getCharPref("loop.test"), "foo",
|
||||
"should set loop pref value correctly");
|
||||
|
||||
// Test getLoopCharPref
|
||||
Assert.equal(gMozLoopAPI.getLoopCharPref("test"), "foo",
|
||||
"should get loop pref value correctly");
|
||||
});
|
|
@ -0,0 +1,27 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
add_task(loadLoopPanel);
|
||||
|
||||
add_task(function* test_mozLoop_doNotDisturb() {
|
||||
registerCleanupFunction(function () {
|
||||
Services.prefs.clearUserPref("loop.do_not_disturb");
|
||||
});
|
||||
|
||||
Assert.ok(gMozLoopAPI, "mozLoop should exist");
|
||||
|
||||
// Test doNotDisturb (getter)
|
||||
Services.prefs.setBoolPref("loop.do_not_disturb", true);
|
||||
Assert.equal(gMozLoopAPI.doNotDisturb, true,
|
||||
"Do not disturb should be true");
|
||||
|
||||
// Test doNotDisturb (setter)
|
||||
gMozLoopAPI.doNotDisturb = false;
|
||||
Assert.equal(Services.prefs.getBoolPref("loop.do_not_disturb"), false,
|
||||
"Do not disturb should be false");
|
||||
});
|
|
@ -0,0 +1,71 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
var gMozLoopAPI;
|
||||
|
||||
function promiseGetMozLoopAPI() {
|
||||
let deferred = Promise.defer();
|
||||
let loopPanel = document.getElementById("loop-notification-panel");
|
||||
let btn = document.getElementById("loop-call-button");
|
||||
|
||||
// Wait for the popup to be shown, then we can get the iframe and
|
||||
// wait for the iframe's load to be completed.
|
||||
loopPanel.addEventListener("popupshown", function onpopupshown() {
|
||||
loopPanel.removeEventListener("popupshown", onpopupshown, true);
|
||||
let iframe = document.getElementById(btn.getAttribute("notificationFrameId"));
|
||||
|
||||
if (iframe.contentDocument &&
|
||||
iframe.contentDocument.readyState == "complete") {
|
||||
gMozLoopAPI = iframe.contentWindow.navigator.wrappedJSObject.mozLoop;
|
||||
|
||||
deferred.resolve();
|
||||
} else {
|
||||
iframe.addEventListener("load", function panelOnLoad(e) {
|
||||
iframe.removeEventListener("load", panelOnLoad, true);
|
||||
|
||||
gMozLoopAPI = iframe.contentWindow.navigator.wrappedJSObject.mozLoop;
|
||||
|
||||
// We do this in an execute soon to allow any other event listeners to
|
||||
// be handled, just in case.
|
||||
deferred.resolve();
|
||||
}, true);
|
||||
}
|
||||
}, true);
|
||||
|
||||
// Now we're setup, click the button.
|
||||
btn.click();
|
||||
|
||||
// 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.
|
||||
registerCleanupFunction(function() {
|
||||
loopPanel.hidePopup();
|
||||
loopPanel.removeChild(document.getElementById(btn.getAttribute("notificationFrameId")));
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
// Set prefs to ensure we don't access the network externally.
|
||||
Services.prefs.setCharPref("services.push.serverURL", "ws://localhost/");
|
||||
Services.prefs.setCharPref("loop.server", "http://localhost/");
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
Services.prefs.clearUserPref("services.push.serverURL");
|
||||
Services.prefs.clearUserPref("loop.server");
|
||||
});
|
||||
|
||||
// Turn off animations to make tests quicker.
|
||||
let loopPanel = document.getElementById("loop-notification-panel");
|
||||
loopPanel.setAttribute("animate", "false");
|
||||
|
||||
// Now get the actual API.
|
||||
yield promiseGetMozLoopAPI();
|
||||
}
|
Загрузка…
Ссылка в новой задаче