Bug 1235050 - Add basic SimplePush testing. r=kitcambridge

This commit is contained in:
Alexandre Lissy 2015-12-28 17:23:00 +01:00
parent 6ab3d8f9ca
commit 1e750d0b2d
5 changed files with 190 additions and 0 deletions

View File

@ -12,3 +12,7 @@ EXTRA_COMPONENTS += [
EXTRA_JS_MODULES += [
'PushService.jsm',
]
MOCHITEST_MANIFESTS += [
'test/mochitest.ini',
]

View File

@ -0,0 +1,6 @@
[DEFAULT]
run-if = toolkit == "gonk"
[test_permissions.html]
[test_register.html]
[test_prefs.html]

View File

@ -0,0 +1,60 @@
<!DOCTYPE HTML>
<html>
<!--
Bug 1235050: SimplePush permissions tests.
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<head>
<title>Test for Bug 1235050</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1235050">Mozilla Bug 1235050</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script class="testbody" type="text/javascript">
function already_has_permission() {
return SpecialPowers.hasPermission("push", document);
}
function add_permission() {
var allow = SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION;
SpecialPowers.addPermission("push", allow, document);
window.location.reload();
}
function test_no_permission() {
ok((!("push" in navigator)), "push object is NOT exposed");
}
function test_has_permission() {
ok(("push" in navigator), "push object is exposed");
}
function runTest() {
if (already_has_permission()) {
test_has_permission();
SimpleTest.finish();
} else {
test_no_permission();
add_permission();
}
}
SimpleTest.waitForExplicitFinish();
runTest();
</script>
</body>
</html>

View File

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html>
<!--
Bug 1235050: SimplePush basics tests.
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<head>
<title>Test for Bug 1235050</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1235050">Mozilla Bug 1235050</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script class="testbody" type="text/javascript">
function test_navigator() {
ok(("push" in navigator), "push object is exposed");
}
function test_register(expected, next) {
var pushReq = navigator.push.register();
pushReq.onsuccess = e => {
ok(expected, "push.register() triggered onsuccess");
next();
};
pushReq.onerror = e => {
ok(!expected, "push.register() triggered onerror");
next();
};
}
function runTest() {
test_navigator();
test_register(false, () => {
SpecialPowers.pushPrefEnv({"set": [
["services.push.connection.enabled", true],
]}, () => {
test_register(true, () => {
SimpleTest.finish();
});
});
});
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.addPermission("push", true, document);
SpecialPowers.pushPrefEnv({"set": [
["services.push.connection.enabled", false],
]}, runTest);
</script>
</body>
</html>

View File

@ -0,0 +1,57 @@
<!DOCTYPE HTML>
<html>
<!--
Bug 1235050: SimplePush basics tests.
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<head>
<title>Test for Bug 1235050</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1235050">Mozilla Bug 1235050</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script class="testbody" type="text/javascript">
function test_navigator() {
ok(("push" in navigator), "push object is exposed");
ok(("register" in navigator.push), "push object is exposed with register");
ok(("unregister" in navigator.push), "push object is exposed with unregister");
}
function test_register(next) {
var pushReq = navigator.push.register();
pushReq.onsuccess = e => {
ok(true, "push.register() triggered onsuccess");
next();
};
pushReq.onerror = e => {
ok(false, "push.register() triggered onerror");
next();
};
}
function runTest() {
test_navigator();
test_register(() => {
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.addPermission("push", true, document);
runTest();
</script>
</body>
</html>