gecko/dom/base/test/test_hasFeature.html
2014-08-12 13:50:12 -03:00

79 lines
3.0 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1009645
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1009645</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1009645">Mozilla Bug 1009645</a>
<script type="application/javascript">
function testAPIs() {
function pref(name) {
try {
return SpecialPowers.getBoolPref(name);
} catch (e) {
return false;
}
}
var b2gOnly = (function() {
var isAndroid = !!navigator.userAgent.contains("Android");
var isB2g = !isAndroid && /Mobile|Tablet/.test(navigator.userAgent);
return isB2g ? true : undefined;
})();
var APIEndPoints = [
{ name: "MozMobileNetworkInfo", enabled: pref("dom.mobileconnection.enabled") },
// { name: "Navigator.mozBluetooth", enabled: b2gOnly }, // conditional on MOZ_B2G_BT, tricky to test
{ name: "Navigator.mozContacts", enabled: pref("dom.mozContacts.enabled") },
{ name: "Navigator.getDeviceStorage", enabled: pref("device.storage.enabled") },
{ name: "Navigator.addIdleObserver", enabled: true },
{ name: "Navigator.mozNetworkStats", enabled: pref("dom.mozNetworkStats.enabled") },
{ name: "Navigator.push", enabled: pref("services.push.enabled") },
// { name: "Navigator.mozTime", enabled: b2gOnly }, // conditional on MOZ_TIME_MANAGER, tricky to test
// { name: "Navigator.mozFMRadio", enabled: b2gOnly }, // conditional on MOZ_B2G_FM, tricky to test
{ name: "Navigator.mozCameras", enabled: true },
{ name: "Navigator.mozAlarms", enabled: pref("dom.mozAlarms.enabled") },
{ name: "Navigator.mozTCPSocket", enabled: pref("dom.mozTCPSocket.enabled") },
{ name: "Navigator.mozInputMethod", enabled: pref("dom.mozInputMethod.enabled") },
{ name: "Navigator.mozMobileConnections", enabled: pref("dom.mobileconnection.enabled") },
{ name: "Navigator.getMobileIdAssertion", enabled: b2gOnly },
{ name: "XMLHttpRequest.mozSystem", enabled: true }
];
var promises = [];
APIEndPoints.forEach(function(v) {
promises.push(navigator.hasFeature("api.window." + v.name));
});
Promise.all(promises).then(function(values) {
for (var i = 0; i < values.length; ++i) {
ise(values[i], APIEndPoints[i].enabled,
"Endpoint " + APIEndPoints[i].name + " resolved with the correct value. " +
"If this is failing because you're changing how an API is exposed, you " +
"must contact the Marketplace team to let them know about the change.");
}
SimpleTest.finish();
}, function() {
ok(false, "The Promise should not be rejected");
SimpleTest.finish();
});
}
SpecialPowers.pushPermissions([
{type: "feature-detection", allow: true, context: document}
], function() {
ok('hasFeature' in navigator, "navigator.hasFeature should exist");
testAPIs();
});
SimpleTest.waitForExplicitFinish();
</script>
</body>
</html>