tenfourfox/dom/mobilemessage/tests/mochitest/test_sms_basics.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

146 lines
4.5 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for WebSMS</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<iframe></iframe>
</div>
<pre id="test">
<script type="application/javascript;version=1.8">
/** Test for WebSMS **/
// webidl interfaces guarded by [AvailableIn=CertifiedApps].
const WEBIDL_IFACE_WITH_PREFIX = ["SmsEvent", "MmsEvent", "MessageDeletedEvent"];
const WEBIDL_IFACE = [
"DOMMobileMessageError",
"MmsMessage",
"MobileMessageThread",
"SmsMessage",
];
function checkSmsDisabled() {
ok(!('mozMobileMessage' in frames[0].navigator), "navigator.mozMobileMessage should not exist");
ok(frames[0].navigator.mozMobileMessage === undefined,
"navigator.mozMobileMessage should return undefined");
}
function checkSmsEnabled() {
// Bug 784617: WebSms is disabled on all platforms except Android for the moment.
if (navigator.appVersion.indexOf("Android") == -1 && SpecialPowers.Services.appinfo.name != "B2G") {
checkSmsDisabled();
return;
}
ok('mozMobileMessage' in frames[0].navigator, "navigator.mozMobileMessage should exist");
ok(frames[0].navigator.mozMobileMessage, "navigator.mozMobileMessage returns an object");
ok(frames[0].navigator.mozMobileMessage instanceof MozMobileMessageManager,
"navigator.mozMobileMessage is an MobileMessageManager object");
}
function checkWebidlInterfaceInWindow() {
for (let i = 0; i < WEBIDL_IFACE_WITH_PREFIX.length; i++) {
let iface = WEBIDL_IFACE_WITH_PREFIX[i];
ok(!(iface in window), iface + " should be prefixed");
ok(("Moz" + iface) in window, iface + " should be prefixed");
}
for (let i = 0; i < WEBIDL_IFACE.length; i++) {
let iface = WEBIDL_IFACE[i];
ok((iface in window), iface + " should be there");
}
}
function checkWebidlInterfaceNotInWindow() {
for (let i = 0; i < WEBIDL_IFACE_WITH_PREFIX.length; i++) {
let iface = WEBIDL_IFACE_WITH_PREFIX[i];
ok(!(iface in window), iface + " should not be there");
ok(!(("Moz" + iface) in window), "Moz" + iface + " should not be there");
}
for (let i = 0; i < WEBIDL_IFACE.length; i++) {
let iface = WEBIDL_IFACE[i];
ok(!(iface in window), iface + " should not be there");
}
}
function test() {
checkWebidlInterfaceNotInWindow();
// If sms is disabled and permission is removed, sms is disabled.
SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", false]]}, function() {
SpecialPowers.pushPermissions([{'type': 'sms', 'remove': true, 'context': document}], test2);
});
}
function test2() {
checkSmsDisabled();
// If sms is enabled and permission is removed, sms is disabled.
SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", true]]}, function() {
SpecialPowers.pushPermissions([{'type': 'sms', 'remove': true, 'context': document}], test3);
});
}
function test3() {
checkSmsDisabled();
// If sms is disabled and permission is granted, sms is disabled.
SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", false]]}, function() {
SpecialPowers.pushPermissions([{'type': 'sms', 'allow': true, 'context': document}], test4);
});
}
function test4() {
checkSmsDisabled();
// Even if sms is enabled and permission is granted, sms is still disabled due
// to the webidl check "AvailableIn=CertifiedApps."
SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", true]]}, function() {
SpecialPowers.pushPermissions([{'type': 'sms', 'allow': true, 'context': document}], test5);
});
}
function test5() {
checkSmsDisabled();
var iframeElt = document.getElementsByTagName('iframe')[0];
iframeElt.addEventListener("load", function() {
iframeElt.removeEventListener("load", arguments.callee);
checkSmsEnabled();
checkWebidlInterfaceInWindow();
iframeElt.addEventListener("load", function() {
iframeElt.removeEventListener("load", arguments.callee);
checkSmsDisabled();
SimpleTest.finish();
});
// Disabling sms takes effect on reload.
SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", false]]}, function() {
frames[0].location.reload();
});
});
// Ignore webidl checks, then enabling sms takes effect on reload.
SpecialPowers.pushPrefEnv({"set": [["dom.ignore_webidl_scope_checks", true],
["dom.sms.enabled", true]]}, function() {
frames[0].location.reload();
});
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(test);
</script>
</pre>
</body>
</html>