Skip to content

Commit e987260

Browse files
author
Anita Woodruff
committed
Add tests for notification inline reply idl properties
- Migrated existing html test to .any.js test + .idl interface to allow testing the new properties from a service worker scope. - See whatwg/notifications#132 for the spec change this tests. - See https://github.com/anitawoodruff/inline-notification-replies for an Explainer.
1 parent 31c2aeb commit e987260

File tree

3 files changed

+113
-36
lines changed

3 files changed

+113
-36
lines changed

notifications/interfaces.html renamed to interfaces/notifications.idl

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
1-
<!doctype html>
2-
<meta charset=utf-8>
3-
<title>Notification interface IDL tests</title>
4-
<div id=log></div>
5-
<script src=/resources/testharness.js></script>
6-
<script src=/resources/testharnessreport.js></script>
7-
<script src=/resources/WebIDLParser.js></script>
8-
<script src=/resources/idlharness.js></script>
9-
<script type=text/plain class=untested>
10-
interface EventTarget {
11-
void addEventListener(DOMString type, EventListener? callback, optional boolean capture /* = false */);
12-
void removeEventListener(DOMString type, EventListener? callback, optional boolean capture /* = false */);
13-
boolean dispatchEvent(Event event);
14-
};
15-
[TreatNonCallableAsNull]
16-
callback EventHandlerNonNull = any (Event event);
17-
typedef EventHandlerNonNull? EventHandler;
18-
</script>
19-
<script type=text/plain>
201
[Constructor(DOMString title, optional NotificationOptions options),
212
Exposed=(Window,Worker)]
223
interface Notification : EventTarget {
234
static readonly attribute NotificationPermission permission;
24-
[Exposed=Window] static Promise<NotificationPermission> requestPermission(optional NotificationPermissionCallback deprecatedCallback);
5+
[Exposed=Window] static Promise<NotificationPermission> requestPermission(
6+
optional NotificationPermissionCallback deprecatedCallback);
257

268
static readonly attribute unsigned long maxActions;
279

@@ -79,25 +61,39 @@
7961
};
8062

8163
dictionary NotificationAction {
64+
NotificationActionType type = "button";
8265
required DOMString action;
8366
required DOMString title;
8467
USVString icon;
68+
DOMString? placeholder = null;
8569
};
8670

8771
callback NotificationPermissionCallback = void (NotificationPermission permission);
88-
</script>
89-
<script>
90-
"use strict";
91-
var idlArray = new IdlArray();
92-
[].forEach.call(document.querySelectorAll("script[type=text\\/plain]"), function(node) {
93-
if (node.className == "untested") {
94-
idlArray.add_untested_idls(node.textContent);
95-
} else {
96-
idlArray.add_idls(node.textContent);
97-
}
98-
});
99-
idlArray.add_objects({
100-
Notification: ['new Notification("Running idlharness.")'],
101-
});
102-
idlArray.test();
103-
</script>
72+
73+
dictionary GetNotificationOptions {
74+
DOMString tag = "";
75+
};
76+
77+
partial interface ServiceWorkerRegistration {
78+
Promise<void> showNotification(DOMString title, optional NotificationOptions options);
79+
Promise<sequence<Notification>> getNotifications(optional GetNotificationOptions filter);
80+
};
81+
82+
[Constructor(DOMString type, NotificationEventInit eventInitDict),
83+
Exposed=ServiceWorker]
84+
interface NotificationEvent : ExtendableEvent {
85+
readonly attribute Notification notification;
86+
readonly attribute DOMString action;
87+
readonly attribute DOMString? reply;
88+
};
89+
90+
dictionary NotificationEventInit : ExtendableEventInit {
91+
required Notification notification;
92+
DOMString action = "";
93+
DOMString? reply = null;
94+
};
95+
96+
partial interface ServiceWorkerGlobalScope {
97+
attribute EventHandler onnotificationclick;
98+
attribute EventHandler onnotificationclose;
99+
};

notifications/interfaces.any.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// META: global=worker
2+
// META: script=/resources/WebIDLParser.js
3+
// META: script=/resources/idlharness.js
4+
5+
// See https://notifications.spec.whatwg.org/
6+
7+
// This file's contents are duplicated in notifications/interfaces.https.any.js
8+
// as a workaround for https://github.com/w3c/web-platform-tests/issues/11105
9+
10+
"use strict";
11+
12+
promise_test(async () => {
13+
const sw_idl = await fetch('/interfaces/ServiceWorker.idl').then(r => r.text());
14+
const dedicated_workers_idl = await fetch('/interfaces/dedicated-workers.idl').then(r => r.text());
15+
const dom_idl = await fetch('/interfaces/dom.idl').then(r => r.text());
16+
17+
const notifications_idl = await fetch('/interfaces/notifications.idl').then(r => r.text());
18+
19+
var idlArray = new IdlArray();
20+
21+
idlArray.add_untested_idls(sw_idl, { only: [
22+
'ServiceWorkerRegistration',
23+
'ServiceWorkerGlobalScope',
24+
'ExtendableEvent',
25+
'ExtendableEventInit',
26+
] });
27+
28+
idlArray.add_untested_idls(dedicated_workers_idl);
29+
idlArray.add_untested_idls(dom_idl, { only: [ 'Event', 'EventInit' ] });
30+
31+
idlArray.add_idls(notifications_idl);
32+
33+
if (!self.GLOBAL.isWorker()) {
34+
idlArray.add_objects({
35+
Notification: ['new Notification("Running idlharness.")'],
36+
});
37+
}
38+
39+
idlArray.test();
40+
done();
41+
}, 'notifications interfaces.');

notifications/interfaces.https.any.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// META: global=worker
2+
// META: script=/resources/WebIDLParser.js
3+
// META: script=/resources/idlharness.js
4+
5+
// See https://notifications.spec.whatwg.org/
6+
7+
// The contents of this file are duplicated in notifications/interfaces.any.js
8+
// as a workaround for https://github.com/w3c/web-platform-tests/issues/11105
9+
"use strict";
10+
11+
promise_test(async () => {
12+
const sw_idl = await fetch('/interfaces/ServiceWorker.idl').then(r => r.text());
13+
const dedicated_workers_idl = await fetch('/interfaces/dedicated-workers.idl').then(r => r.text());
14+
const dom_idl = await fetch('/interfaces/dom.idl').then(r => r.text());
15+
16+
const notifications_idl = await fetch('/interfaces/notifications.idl').then(r => r.text());
17+
18+
var idlArray = new IdlArray();
19+
20+
idlArray.add_untested_idls(sw_idl, { only: [
21+
'ServiceWorkerRegistration',
22+
'ServiceWorkerGlobalScope',
23+
'ExtendableEvent',
24+
'ExtendableEventInit',
25+
] });
26+
27+
idlArray.add_untested_idls(dedicated_workers_idl);
28+
idlArray.add_untested_idls(dom_idl, { only: [ 'Event', 'EventInit' ] });
29+
30+
idlArray.add_idls(notifications_idl);
31+
32+
if (!self.GLOBAL.isWorker()) {
33+
idlArray.add_objects({
34+
Notification: ['new Notification("Running idlharness.")'],
35+
});
36+
}
37+
38+
idlArray.test();
39+
done();
40+
}, 'notifications interfaces.');

0 commit comments

Comments
 (0)