blob: e7d2a649d6db62c60ce95c56ed2a9a387d765f5e [file] [log] [blame]
<!doctype html>
<html>
<head>
<title>Notifications: Should be able to focus window in onclick event.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/permissions-helper.js"></script>
</head>
<body>
<script>
// Tests that Document-bound notifications are able to focus a window in
// their onclick event. When the test is being run manually, grant
// Notification permission and click on the notification.
if (window.testRunner) {
testRunner.setCanOpenWindows();
testRunner.setCloseRemainingWindowsWhenComplete();
}
async_test(function(test) {
PermissionsHelper.setPermission('notifications', 'granted').then(test.step_func(function() {
if (Notification.permission != 'granted') {
assert_unreached('No permission has been granted for displaying notifications.');
return;
}
window.addEventListener('focus', test.step_func(function() {
test.done();
}));
var childWindow = window.open('about:blank');
childWindow.focus();
var notification = new Notification('My Notification');
notification.addEventListener('show', test.step_func(function() {
if (window.testRunner)
testRunner.simulateWebNotificationClick('My Notification');
}));
notification.addEventListener('click', test.step_func(function() {
window.focus();
}));
notification.addEventListener('error', test.step_func(function() {
assert_unreached('The error event should not be thrown.');
}));
}));
}, 'Clicking on a notification enables it to focus the window it was created from.');
</script>
<script src="resources/click-focus-test.js"></script>
</body>
</html>