gecko-dev/dom/base/test/test_getFeature_with_perm.html

140 строки
3.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=979109
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 979109</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=983502">Mozilla Bug 983502</a>
<script type="application/javascript">
function testSupported() {
var mem;
navigator.getFeature("hardware.memory").then(function(mem) {
var isLinux = (navigator.platform.indexOf('Linux') != -1);
var isAndroid = !!navigator.userAgent.includes("Android");
var isB2G = !isAndroid && /Mobile|Tablet/.test(navigator.userAgent);
if (isLinux) {
info("It is Linux version:");
}
if (isAndroid) {
info("It is Android version");
}
if (isB2G) {
info("It is B2G version");
}
if (isLinux || isAndroid || isB2G) {
ok(typeof mem === 'number' && (mem) % 1 === 0, "We should receive an integer on this platform");
ok(mem > 0, "hardware.memory is supported on this platform. mem=" + mem + "MiB");
} else {
ok(typeof mem === 'undefined', "hardware.memory is not support on this platform");
}
runNextTest();
},function(mem) {
ok(false, "The Promise should not be rejected");
});
}
function testNotSupported() {
var tv;
navigator.getFeature("hardware.tv").then(function(tv) {
ok(typeof tv === 'undefined', "Resolve the Promise with undefined value (hardware.tv)");
runNextTest();
},function(tv) {
ok(false, "The Promise should not be rejected");
});
}
function testNotSupportedManifest() {
navigator.getFeature("manifest.origin").then(function(feature) {
ok(typeof feature == 'undefined', "manifest.* resolves with undefined on getFeature");
runNextTest();
}, function() {
ok(false, "The Promise should not be rejected");
});
}
function createManifestTest(aFeature) {
return function() {
var res;
navigator.hasFeature(aFeature).then(function(res) {
ok(res === true, "Resolve the Promise with 'true' for " + aFeature);
runNextTest();
}, function(tv) {
ok(false, "The Promise should not be rejected");
});
}
}
function testDevMode(aExpected) {
return function() {
navigator.getFeature("dom.apps.developer_mode").then(res => {
is(res, aExpected, "dom.apps.developer_mode is " + aExpected);
runNextTest();
}, function() {
ok(false, "The Promise should not be rejected");
});
}
}
function enableDevMode() {
SpecialPowers.pushPrefEnv({"set": [["dom.apps.developer_mode", true]]}, runNextTest);
}
var currentTest = -1;
var tests = [
testNotSupported,
testNotSupportedManifest,
testSupported,
createManifestTest("manifest.origin"),
createManifestTest("manifest.redirects"),
testDevMode(false),
enableDevMode,
testDevMode(true)
];
function runNextTest() {
currentTest++;
if (currentTest < tests.length) {
tests[currentTest]();
} else {
SimpleTest.finish();
}
}
info("About to run " + tests.length + " tests");
SpecialPowers.pushPermissions([
{type: "feature-detection", allow: 1, context: document}
], function() {
ok('getFeature' in navigator, "navigator.getFeature should exist");
ok('hasFeature' in navigator, "navigator.hasFeature should exist");
// B2G specific manifest features.
// Touching navigator before pushPermissions makes it fail.
if (!navigator.userAgent.includes("Android") &&
/Mobile|Tablet/.test(navigator.userAgent)) {
info("Adding B2G specific tests");
tests.push(createManifestTest("manifest.chrome.navigation"));
tests.push(createManifestTest("manifest.precompile"));
tests.push(createManifestTest("manifest.role.homescreen"));
}
runNextTest();
ok(true, "Test DONE");
});
SimpleTest.waitForExplicitFinish();
</script>
</body>
</html>