gecko/dom/tests/mochitest/general/test_idleapi_permissions.html

53 lines
1.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for idle api permissions</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">
</div>
<pre id="test">
<script type="application/javascript">
var idleObserver = {
onidle: null,
onactive: null
};
function doAddIdleObserver(obs) {
var i = document.createElement("iframe");
document.body.appendChild(i);
var added = false;
try {
i.contentWindow.navigator.addIdleObserver(obs);
added = true;
} catch (e) { }
i.remove();
return added;
}
function run_test() {
// addIdleObserver checks whether time is > 0.
this.idleObserver.time = 100;
var added = doAddIdleObserver(this.idleObserver, false);
ok(!added, "Should not be able to add idle observer without permission");
SpecialPowers.addPermission("idle", true, document);
added = doAddIdleObserver(this.idleObserver, true);
ok(added, "Should be able to add idle observer with permission.");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(run_test);
</script>
</pre>
</body>
</html>