Commit 79681532 authored by Peter Beverloo's avatar Peter Beverloo Committed by Commit Bot

Improve clarity of the notification permission test for detached contexts

Rename variables to be clearer in their intention, use a switch
statement instead of an if/else if/else blocks and wrap the whole thing
as a step function to properly catch failing asserts.

Bug: 
Change-Id: I89c92d7a5071728bfdd8c9827f08ae3af94377db
Reviewed-on: https://chromium-review.googlesource.com/809425Reviewed-by: default avatarAnita Woodruff <awdf@chromium.org>
Commit-Queue: Anita Woodruff <awdf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522076}
parent 017ed391
......@@ -15,26 +15,36 @@
testRunner.setCanOpenWindows();
}
async_test(function (test) {
var win = window.open('resources/window-permission-detached-context.html'),
notificationObj = null;
window.addEventListener('message', function (event) {
if (event.data == 'opened') {
assert_own_property(win, 'Notification');
notificationObj = win.Notification;
win.close();
} else if (event.data == 'closed') {
assert_equals(notificationObj.permission, 'denied');
notificationObj.requestPermission(function () {});
test.done();
} else {
assert_unreached('Unrecognized message from the opened window.');
}
});
async_test(test => {
const remoteWindow = window.open('resources/window-permission-detached-context.html');
let remoteNotificationObj = null;
window.addEventListener('message', test.step_func(event => {
switch (event.data) {
case 'opened':
assert_equals(remoteNotificationObj, null);
remoteNotificationObj = remoteWindow.Notification;
remoteWindow.close();
break;
case 'closed':
assert_not_equals(remoteNotificationObj, null);
// Permission is always set to denied for detached objects.
assert_equals(remoteNotificationObj.permission, 'denied');
// The following call should not throw an exception.
remoteNotificationObj.requestPermission(function () {});
test.done();
break;
default:
assert_unreached('Unrecognized message from the opened window.');
break;
}
}));
}, 'Requesting notification permission in a detached context should not crash.');
</script>
</body>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment