Bug 1841841 - Add notification tag WPT test and replace old ones r=hsingh

Differential Revision: https://phabricator.services.mozilla.com/D207179
This commit is contained in:
Kagami Sascha Rosylight 2024-04-15 18:03:46 +00:00
parent 1e447389e4
commit 8da18dbcfc
6 changed files with 57 additions and 144 deletions

View file

@ -19,10 +19,6 @@ skip-if = ["os == 'win'"] # Bug 1411118
https_first_disabled = true
skip-if = ["os == 'win'"] # Bug 1411118
["browser_notification_replace.js"]
https_first_disabled = true
skip-if = ["os == 'win'"] # Bug 1422928
["browser_notification_tab_switching.js"]
https_first_disabled = true
skip-if = ["os == 'win'"] # Bug 1243263

View file

@ -1,66 +0,0 @@
"use strict";
let notificationURL =
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
add_task(async function test_notificationReplace() {
await addNotificationPermission(notificationURL);
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: notificationURL,
},
async function dummyTabTask(aBrowser) {
await SpecialPowers.spawn(aBrowser, [], async function () {
let win = content.window.wrappedJSObject;
let notification = win.showNotification1();
let promiseCloseEvent = ContentTaskUtils.waitForEvent(
notification,
"close"
);
let showEvent = await ContentTaskUtils.waitForEvent(
notification,
"show"
);
Assert.equal(
showEvent.target.body,
"Test body 1",
"Showed tagged notification"
);
let newNotification = win.showNotification2();
let newShowEvent = await ContentTaskUtils.waitForEvent(
newNotification,
"show"
);
Assert.equal(
newShowEvent.target.body,
"Test body 2",
"Showed new notification with same tag"
);
let closeEvent = await promiseCloseEvent;
Assert.equal(
closeEvent.target.body,
"Test body 1",
"Closed previous tagged notification"
);
let promiseNewCloseEvent = ContentTaskUtils.waitForEvent(
newNotification,
"close"
);
newNotification.close();
let newCloseEvent = await promiseNewCloseEvent;
Assert.equal(
newCloseEvent.target.body,
"Test body 2",
"Closed new notification"
);
});
}
);
});

View file

@ -0,0 +1,10 @@
prefs: [notification.prompt.testing:true,marionette.setpermission.enabled:true]
[tag.https.html]
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1891536
expected:
if (os == "android"): TIMEOUT
[Opening two notifications with the same tag should close the first one]
expected:
if (os == "android"): TIMEOUT

View file

@ -1,37 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Notification.tag (two tags with different values)</title>
<link rel="author" title="Intel" href="http://www.intel.com/">
<link rel="author" title="Xin Liu" href="mailto:xinx.liu@intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
<div id=passfail></div>
<script>
setup({ explicit_timeout: true })
if (hasNotificationPermission()) {
async_test(function (t) {
t.step(function () {
var notification1 = null,
notification2 = null,
notifications = [],
text1 = "This is the body: Room 101",
text2 = "This is the body: Room 202"
createPassFail("If two notifications appear: First one with the"
+ " text \"" + text1 + "\", followed by one with the text \""
+ text2 + "\"",
t, closeNotifications, notifications)
notification1 = new Notification("New Email Received", {
body: text1,
tag: "Tom"
})
notification2 = new Notification("New Email Received", {
body: text2,
tag: "Rose"
})
notifications.push(notification1)
notifications.push(notification2)
})
})
}
</script>

View file

@ -1,37 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Notification.tag (two tags with same value)</title>
<link rel="author" title="Intel" href="http://www.intel.com/">
<link rel="author" title="Xin Liu" href="mailto:xinx.liu@intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
<div id=passfail></div>
<script>
setup({ explicit_timeout: true })
if (hasNotificationPermission()) {
async_test(function (t) {
t.step(function () {
var notification1 = null,
notification2 = null,
notifications = [],
text1 = "This is the body: Room 101",
text2 = "This is the body: Room 202"
createPassFail("If a notification with the text \""
+ text2 + "\", replaces the notification with the text \""
+ text1 + "\" in the same position",
t, closeNotifications, notifications)
notification1 = new Notification("New Email Received", {
body: text1,
tag: "Tom"
})
notification2 = new Notification("New Email Received", {
body: text2,
tag: "Tom"
})
notifications.push(notification1)
notifications.push(notification2)
})
})
}
</script>

View file

@ -0,0 +1,47 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Notification.tag (two tags with same or different value)</title>
<link rel="author" title="Intel" href="http://www.intel.com/">
<link rel="author" title="Xin Liu" href="mailto:xinx.liu@intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script>
function promiseEvent(target, eventName, syncListener) {
return new Promise(resolve => {
target.addEventListener(eventName, ev => {
syncListener?.();
resolve(ev);
}, { once: true });
});
}
promise_setup(async () => {
await trySettingPermission("granted");
});
promise_test(async t => {
const tom1 = new Notification("New Email to tom", {
tag: "Tom"
});
t.add_cleanup(() => tom1.close());
let closed = false;
const promiseCloseEvent = promiseEvent(tom1, "close", () => closed = true);
await promiseEvent(tom1, "show");
const rose = new Notification("New Email to Rose", {
tag: "Rose"
});
t.add_cleanup(() => rose.close());
await promiseEvent(rose, "show");
assert_false(closed, "Different tag should not close the first notification");
const tom2 = new Notification("New Email to tom", {
tag: "Tom"
});
t.add_cleanup(() => tom2.close());
await promiseCloseEvent; // This should not timeout
}, "Opening two notifications with the same tag should close the first one");
</script>