mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-13 03:24:26 +00:00
Bug 1928702 - Part 12: Add extra coverage for Glean metrics r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D227853
This commit is contained in:
parent
e558ae71bd
commit
abf63ced1d
@ -13,6 +13,11 @@ const GleanTest = new Proxy(
|
||||
Services.fog.testResetFOG();
|
||||
});
|
||||
},
|
||||
async flush() {
|
||||
return SpecialPowers.spawnChrome([], async () => {
|
||||
await Services.fog.testFlushAllChildren();
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
get(gleanTestObj, gleanTestProp) {
|
||||
|
@ -69,6 +69,12 @@ support-files = [
|
||||
]
|
||||
tags = "openwindow"
|
||||
|
||||
["test_notification_serviceworker_show.html"]
|
||||
skip-if = ["xorigin"] # Bug 1792790
|
||||
support-files = [
|
||||
"notification_show_sw.js",
|
||||
]
|
||||
|
||||
["test_notification_worker_child.html"]
|
||||
skip-if = [
|
||||
"os == 'android'", # Bug 1816427, Notification.onshow/close are broken on Android
|
||||
|
13
dom/notification/test/mochitest/notification_show_sw.js
Normal file
13
dom/notification/test/mochitest/notification_show_sw.js
Normal file
@ -0,0 +1,13 @@
|
||||
onmessage = async ev => {
|
||||
if (ev.data !== "show") {
|
||||
return;
|
||||
}
|
||||
const shown = await self.registration.showNotification("title").then(
|
||||
() => true,
|
||||
() => false
|
||||
);
|
||||
const clients = await self.clients.matchAll({ includeUncontrolled: true });
|
||||
for (let client of clients) {
|
||||
client.postMessage({ shown });
|
||||
}
|
||||
};
|
@ -45,7 +45,7 @@
|
||||
|
||||
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 request permission counter should increment once.");
|
||||
is(showCount, 1, "Notification first party show attempt counter should increment once.");
|
||||
},
|
||||
|
||||
async function(done) {
|
||||
|
@ -49,7 +49,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1560741
|
||||
});
|
||||
|
||||
const requestCount = await GleanTest.webNotification.requestPermissionOrigin.nested_first_party.testGetValue();
|
||||
is(requestCount, 1, "Notification third party request permission counter should increment once.");
|
||||
is(requestCount, 1, "Notification nested first party request permission counter should increment once.");
|
||||
|
||||
await SpecialPowers.spawn(iframe, [], async () => {
|
||||
const nested = this.content.document.querySelector("iframe");
|
||||
@ -59,7 +59,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1560741
|
||||
});
|
||||
|
||||
const permissionCount = await GleanTest.webNotification.permissionOrigin.nested_first_party.testGetValue();
|
||||
is(permissionCount, 1, "Notification third party permission read counter should increment once.");
|
||||
is(permissionCount, 1, "Notification nested first party permission read counter should increment once.");
|
||||
|
||||
await SpecialPowers.spawn(iframe, [], async () => {
|
||||
const nested = this.content.document.querySelector("iframe");
|
||||
@ -69,7 +69,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1560741
|
||||
});
|
||||
|
||||
const showCount = await GleanTest.webNotification.showOrigin.nested_first_party.testGetValue();
|
||||
is(showCount, 1, "Notification third party show attempt counter should increment once.");
|
||||
is(showCount, 1, "Notification nested first party show attempt counter should increment once.");
|
||||
|
||||
SimpleTest.finish();
|
||||
})();
|
||||
|
@ -3,9 +3,10 @@
|
||||
<head>
|
||||
<title>ServiceWorkerRegistration.getNotifications() on main thread and worker thread.</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/dom/notification/test/mochitest/MockAlertsService.js"></script>
|
||||
<script type="text/javascript" src="/tests/dom/notification/test/mochitest/NotificationTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<script src="MockAlertsService.js"></script>
|
||||
<script src="NotificationTest.js"></script>
|
||||
<script src="GleanTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
@ -43,10 +44,15 @@
|
||||
}
|
||||
|
||||
async function testDismiss() {
|
||||
await GleanTest.testResetFOG();
|
||||
|
||||
// Dismissed persistent notifications should be removed from the
|
||||
// notification list.
|
||||
const reg = await navigator.serviceWorker.getRegistration("./notification/");
|
||||
await reg.showNotification("This is a notification that will be closed", { tag: "dismiss" });
|
||||
const showCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue();
|
||||
is(showCount, 1, "Notification first party show attempt counter should increment once.");
|
||||
|
||||
const notifications = await reg.getNotifications();
|
||||
is(notifications.length, 1, "There should be one visible notification");
|
||||
is(notifications[0].tag, "dismiss", "Tag should match");
|
||||
|
@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Test showNotification called within service worker</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" />
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
<script>
|
||||
add_task(async function test() {
|
||||
await GleanTest.testResetFOG();
|
||||
|
||||
info("Registering service worker");
|
||||
let swr = await navigator.serviceWorker.register("notification_show_sw.js");
|
||||
await navigator.serviceWorker.ready;
|
||||
|
||||
SimpleTest.registerCleanupFunction(async () => {
|
||||
await swr.unregister();
|
||||
navigator.serviceWorker.onmessage = null;
|
||||
});
|
||||
|
||||
info("Showing notification");
|
||||
await NotificationTest.allowNotifications();
|
||||
let messagePromise = new Promise(r => navigator.serviceWorker.addEventListener("message", r, { once: true }));
|
||||
swr.active.postMessage("show");
|
||||
ok((await messagePromise).data.shown);
|
||||
|
||||
await GleanTest.flush();
|
||||
let permissionCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue();
|
||||
is(permissionCount, 1, "Notification first party show attempt counter should increment once.");
|
||||
|
||||
info("Denying notification");
|
||||
await NotificationTest.denyNotifications();
|
||||
messagePromise = new Promise(r => navigator.serviceWorker.addEventListener("message", r, { once: true }));
|
||||
swr.active.postMessage("show");
|
||||
ok(!(await messagePromise).data.shown);
|
||||
|
||||
await GleanTest.flush();
|
||||
permissionCount = await GleanTest.webNotification.showOrigin.first_party.testGetValue();
|
||||
is(permissionCount, 2, "Notification first party show attempt counter should increment once more.");
|
||||
});
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user