mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 20:47:44 +00:00
121 lines
3.2 KiB
HTML
121 lines
3.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1081873
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 1081873</title>
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
<script type="text/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=1081873">Mozilla Bug 1081873</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
"use strict";
|
|
|
|
SpecialPowers.addPermission("contacts-write", false, document);
|
|
SpecialPowers.addPermission("contacts-read", false, document);
|
|
SpecialPowers.addPermission("contacts-create", false, document);
|
|
|
|
function onUnexpectedSuccess() {
|
|
ok(false, "Unexpected success");
|
|
next();
|
|
}
|
|
|
|
function onExpectedError(event) {
|
|
is(event.target.error.name, PERMISSION_DENIED, "Expected PERMISSION_DENIED");
|
|
next();
|
|
}
|
|
|
|
const PERMISSION_DENIED = "PERMISSION_DENIED";
|
|
|
|
var index = 0;
|
|
|
|
function next() {
|
|
info("Step " + index);
|
|
if (index >= steps.length) {
|
|
ok(false, "Shouldn't get here!");
|
|
return;
|
|
}
|
|
try {
|
|
var i = index++;
|
|
steps[i]();
|
|
} catch(ex) {
|
|
ok(false, "Caught exception", ex);
|
|
}
|
|
}
|
|
|
|
var steps = [
|
|
function() {
|
|
ok(true, "Add contact without permission");
|
|
var req = navigator.mozContacts.save(new mozContact({}));
|
|
req.onsuccess = onUnexpectedSuccess;
|
|
req.onerror = onExpectedError;
|
|
},
|
|
function() {
|
|
ok(true, "Find contact without permission");
|
|
var req = navigator.mozContacts.find({});
|
|
req.onsuccess = onUnexpectedSuccess;
|
|
req.onerror = onExpectedError;
|
|
},
|
|
function() {
|
|
ok(true, "Get all contacts without permission");
|
|
var req = navigator.mozContacts.getAll();
|
|
req.onsuccess = onUnexpectedSuccess;
|
|
req.onerror = onExpectedError;
|
|
},
|
|
function() {
|
|
ok(true, "Remove contact without permission");
|
|
var req = navigator.mozContacts.remove("aId");
|
|
req.onsuccess = onUnexpectedSuccess;
|
|
req.onerror = onExpectedError;
|
|
},
|
|
function() {
|
|
ok(true, "Clear contacts without permission");
|
|
var req = navigator.mozContacts.clear();
|
|
req.onsuccess = onUnexpectedSuccess;
|
|
req.onerror = onExpectedError;
|
|
},
|
|
function() {
|
|
ok(true, "Get revision without permission");
|
|
var req = navigator.mozContacts.getRevision();
|
|
req.onsuccess = onUnexpectedSuccess;
|
|
req.onerror = onExpectedError;
|
|
},
|
|
function() {
|
|
ok(true, "Get count without permission");
|
|
var req = navigator.mozContacts.getCount();
|
|
req.onsuccess = onUnexpectedSuccess;
|
|
req.onerror = function() {
|
|
is(req.error.name, PERMISSION_DENIED, "Expected PERMISSION_DENIED");
|
|
SimpleTest.finish();
|
|
};
|
|
}
|
|
];
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
const DENY = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION;
|
|
var interval = setInterval(function() {
|
|
if (!SpecialPowers.testPermission("contacts-read", DENY, document) ||
|
|
!SpecialPowers.testPermission("contacts-write", DENY, document) ||
|
|
!SpecialPowers.testPermission("contacts-create", DENY, document)) {
|
|
return;
|
|
}
|
|
clearInterval(interval);
|
|
next();
|
|
}, 1000);
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|