blob: cb1751a1d15ab1ea6e4b76b1f3ca9f43c01a72de [file] [log] [blame]
<!doctype html>
<html>
<head>
<title>Notifications: The Notification.permission property reflects the permission status.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script>
// Tests that the Notification.permission property reflects the current
// permission level of notifications for the current origin. This test
// requires the TestRunner.
// This test is doing some hacks to make sure the internal representation
// is correctly updated before calling Notification.permission because
// testRunner.setPermission() and Notification.permission might end up
// in a race given the synchronous aspect of the latter.
var notificationsPermissionsTest = async_test("Notification.permission reflects th actual permission.");
var testIndex = 0;
var tests = [
function() {
testRunner.setPermission('notifications', 'prompt', location.origin, location.origin);
navigator.permissions.query({name:'notifications'}).then(function() {
// "default" indicates that no permission request has been answered.
assert_equals(Notification.permission, 'default');
notificationsPermissionsTest.step(tests[++testIndex]);
});
},
function() {
testRunner.setPermission('notifications', 'denied', location.origin, location.origin);
navigator.permissions.query({name:'notifications'}).then(function() {
// "default" indicates that no permission request has been answered.
assert_equals(Notification.permission, 'denied');
notificationsPermissionsTest.step(tests[++testIndex]);
});
},
function () {
testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
navigator.permissions.query({name:'notifications'}).then(function() {
// "default" indicates that no permission request has been answered.
assert_equals(Notification.permission, 'granted');
notificationsPermissionsTest.step(tests[++testIndex]);
});
},
function () {
notificationsPermissionsTest.done();
}
];
notificationsPermissionsTest.step(function() {
if (!window.testRunner) {
assert_unreached('This test requires the TestRunner for working correctly.');
return;
}
notificationsPermissionsTest.step(tests[testIndex]);
});
</script>
</body>
</html>