Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<html>
<head>
<title>Notification Basics</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="NotificationTest.js"></script>
<script src="GleanTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script>
var info = NotificationTest.info;
var options;
SimpleTest.requestFlakyTimeout("untriaged");
var steps = [
async function() {
info("Test notification spec");
ok(Notification, "Notification constructor exists");
ok(Notification.permission, "Notification.permission exists");
ok(Notification.requestPermission, "Notification.requestPermission exists");
},
function() {
info("Test requestPermission without callback");
Notification.requestPermission();
},
async function() {
info("Test Glean telemetry");
await GleanTest.testResetFOG();
await Notification.requestPermission();
const requestCount = await GleanTest.webNotification.requestPermissionOrigin.first_party.testGetValue();
is(requestCount, 1, "Notification first party request permission counter should increment once.");
Notification.permission;
const permissionCount = await GleanTest.webNotification.permissionOrigin.first_party.testGetValue();
is(permissionCount, 1, "Notification first party request permission counter should increment once.");
await new Promise(r => new Notification("first party").onerror = r);
const showCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue();
is(showCount, 1, "Notification first party show attempt counter should increment once.");
},
async function(done) {
info("Test requestPermission deny");
function assertPermissionDenied(perm) {
is(perm, "denied", "Permission should be denied.");
is(Notification.permission, "denied", "Permission should be denied.");
}
await NotificationTest.denyNotifications();
Notification.requestPermission()
.then(assertPermissionDenied)
.then(_ => Notification.requestPermission(assertPermissionDenied))
.catch(err => {
ok(!err, "requestPermission should not reject promise");
})
.then(done);
},
async function(done) {
info("Test requestPermission grant");
function assertPermissionGranted(perm) {
is(perm, "granted", "Permission should be granted.");
is(Notification.permission, "granted", "Permission should be granted");
}
await NotificationTest.allowNotifications();
Notification.requestPermission()
.then(assertPermissionGranted)
.then(_ => Notification.requestPermission(assertPermissionGranted))
.catch(err => {
ok(!err, "requestPermission should not reject promise");
})
.then(done);
},
function(done) {
info("Test invalid requestPermission");
Notification.requestPermission({})
.then(_ => {
ok(false, "Non callable arg to requestPermission should reject promise");
}, () => {
ok(true, "Non callable arg to requestPermission should reject promise");
})
.then(done);
},
function(done) {
info("Test create notification");
options = NotificationTest.payload;
var notification = new Notification("This is a title", options);
ok(notification, "Notification exists");
is(notification.onclick, null, "onclick() should be null");
is(notification.onshow, null, "onshow() should be null");
is(notification.onerror, null, "onerror() should be null");
is(notification.onclose, null, "onclose() should be null");
is(typeof notification.close, "function", "close() should exist");
is(notification.dir, options.dir, "auto should get set");
is(notification.lang, options.lang, "lang should get set");
is(notification.body, options.body, "body should get set");
is(notification.tag, options.tag, "tag should get set");
is(
notification.icon,
new URL(options.icon, location.href).toString(),
"icon should get set"
);
// store notification in test context
this.notification = notification;
notification.onshow = function() {
ok(true, "onshow handler should be called");
done();
};
},
function(done) {
info("Test closing a notification");
var notification = this.notification;
notification.onclose = function() {
ok(true, "onclose handler should be called");
done();
};
notification.close();
},
];
NotificationTest.run(steps);
</script>
</body>
</html>