blob: f510251e8acc6b58082abb9f3f31ddb4cd94992f [file] [log] [blame]
<!doctype html>
<html>
<head>
<title>Notifications: ServiceWorkerRegistration.showNotification().</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
</head>
<body>
<script>
// Tests that the showNotification() function rejects the returned promise with a
// TypeError when no permission has been granted for Web Notifications.
async_test(function(test) {
var scope = 'resources/scope/service-worker-show-notification-no-permission',
workerUrl = 'resources/empty-worker.js';
if (window.testRunner)
testRunner.setPermission('notifications', 'denied', location.origin, location.origin);
var registration = null;
service_worker_unregister_and_register(test, workerUrl, scope).then(function(swRegistration) {
registration = swRegistration;
return wait_for_state(test, registration.installing, 'activated');
}).then(function() {
assert_inherits(registration, 'showNotification', 'showNotification() must be exposed.');
registration.showNotification('Title', {
body: 'Hello, world!',
icon: '/icon.png'
}).then(function() {
assert_unreached('showNotification() is expected to reject.');
}).catch(function(error) {
assert_equals(error.name, 'TypeError');
assert_equals(error.message, 'No notification permission has been granted for this origin.');
test.done();
});
}).catch(unreached_rejection(test));
}, 'showNotification() must reject if no Web Notification permission has been granted.');
</script>
</body>
</html>