1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function test() {
waitForExplicitFinish();
ok(PopupNotifications, "PopupNotifications object exists");
ok(PopupNotifications.panel, "PopupNotifications panel exists");
setup();
}
var tests = [
// Popup Notifications main actions should catch exceptions from callbacks
{
id: "Test#1",
run() {
this.testNotif = new ErrorNotification(this.id);
showNotification(this.testNotif);
},
onShown(popup) {
checkPopup(popup, this.testNotif);
triggerMainCommand(popup);
},
onHidden() {
ok(this.testNotif.mainActionClicked, "main action has been triggered");
},
},
// Popup Notifications secondary actions should catch exceptions from callbacks
{
id: "Test#2",
run() {
this.testNotif = new ErrorNotification(this.id);
showNotification(this.testNotif);
},
onShown(popup) {
checkPopup(popup, this.testNotif);
triggerSecondaryCommand(popup, 0);
},
onHidden() {
ok(
this.testNotif.secondaryActionClicked,
"secondary action has been triggered"
);
},
},
// Existing popup notification shouldn't disappear when adding a dismissed notification
{
id: "Test#3",
run() {
this.notifyObj1 = new BasicNotification(this.id);
this.notifyObj1.id += "_1";
this.notifyObj1.anchorID = "default-notification-icon";
this.notification1 = showNotification(this.notifyObj1);
},
onShown(popup) {
// Now show a dismissed notification, and check that it doesn't clobber
// the showing one.
this.notifyObj2 = new BasicNotification(this.id);
this.notifyObj2.id += "_2";
this.notifyObj2.anchorID = "geo-notification-icon";
this.notifyObj2.options.dismissed = true;
this.notification2 = showNotification(this.notifyObj2);
checkPopup(popup, this.notifyObj1);
// check that both anchor icons are showing
is(
document
.getElementById("default-notification-icon")
.getAttribute("showing"),
"true",
"notification1 anchor should be visible"
);
is(
document
.getElementById("geo-notification-icon")
.getAttribute("showing"),
"true",
"notification2 anchor should be visible"
);
dismissNotification(popup);
},
onHidden() {
this.notification1.remove();
this.notification2.remove();
},
},
// Showing should be able to modify the popup data
{
id: "Test#4",
run() {
this.notifyObj = new BasicNotification(this.id);
let normalCallback = this.notifyObj.options.eventCallback;
this.notifyObj.options.eventCallback = function (eventName) {
if (eventName == "showing") {
this.mainAction.label = "Alternate Label";
}
normalCallback.call(this, eventName);
};
showNotification(this.notifyObj);
},
onShown(popup) {
// checkPopup checks for the matching label. Note that this assumes that
// this.notifyObj.mainAction is the same as notification.mainAction,
// which could be a problem if we ever decided to deep-copy.
checkPopup(popup, this.notifyObj);
triggerMainCommand(popup);
},
onHidden() {},
},
// Moving a tab to a new window should remove non-swappable notifications.
{
id: "Test#5",
async run() {
await BrowserTestUtils.openNewForegroundTab(
gBrowser,
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://example.com/"
);
let notifyObj = new BasicNotification(this.id);
let shown = waitForNotificationPanel();
showNotification(notifyObj);
await shown;
let promiseWin = BrowserTestUtils.waitForNewWindow();
gBrowser.replaceTabWithWindow(gBrowser.selectedTab);
let win = await promiseWin;
let anchor = win.document.getElementById("default-notification-icon");
win.PopupNotifications._reshowNotifications(anchor);
ok(
!win.PopupNotifications.panel.children.length,
"no notification displayed in new window"
);
ok(
notifyObj.swappingCallbackTriggered,
"the swapping callback was triggered"
);
ok(
notifyObj.removedCallbackTriggered,
"the removed callback was triggered"
);
await BrowserTestUtils.closeWindow(win);
await waitForWindowReadyForPopupNotifications(window);
goNext();
},
},
// Moving a tab to a new window should preserve swappable notifications.
{
id: "Test#6",
async run() {
await BrowserTestUtils.openNewForegroundTab(
gBrowser,
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://example.com/"
);
let notifyObj = new BasicNotification(this.id);
let originalCallback = notifyObj.options.eventCallback;
notifyObj.options.eventCallback = function (eventName) {
originalCallback(eventName);
return eventName == "swapping";
};
let shown = waitForNotificationPanel();
let notification = showNotification(notifyObj);
await shown;
let promiseWin = BrowserTestUtils.waitForNewWindow();
gBrowser.replaceTabWithWindow(gBrowser.selectedTab);
let win = await promiseWin;
await waitForWindowReadyForPopupNotifications(win);
await new Promise(resolve => {
let callback = notification.options.eventCallback;
notification.options.eventCallback = function (eventName) {
callback(eventName);
if (eventName == "shown") {
resolve();
}
};
info("Showing the notification again");
notification.reshow();
});
checkPopup(win.PopupNotifications.panel, notifyObj);
ok(
notifyObj.swappingCallbackTriggered,
"the swapping callback was triggered"
);
await BrowserTestUtils.closeWindow(win);
await waitForWindowReadyForPopupNotifications(window);
goNext();
},
},
// the main action callback can keep the notification.
{
id: "Test#8",
run() {
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.mainAction.dismiss = true;
this.notification = showNotification(this.notifyObj);
},
onShown(popup) {
checkPopup(popup, this.notifyObj);
triggerMainCommand(popup);
},
onHidden() {
ok(
this.notifyObj.dismissalCallbackTriggered,
"dismissal callback was triggered"
);
ok(
!this.notifyObj.removedCallbackTriggered,
"removed callback wasn't triggered"
);
this.notification.remove();
},
},
// a secondary action callback can keep the notification.
{
id: "Test#9",
run() {
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.secondaryActions[0].dismiss = true;
this.notification = showNotification(this.notifyObj);
},
onShown(popup) {
checkPopup(popup, this.notifyObj);
triggerSecondaryCommand(popup, 0);
},
onHidden() {
ok(
this.notifyObj.dismissalCallbackTriggered,
"dismissal callback was triggered"
);
ok(
!this.notifyObj.removedCallbackTriggered,
"removed callback wasn't triggered"
);
this.notification.remove();
},
},
// returning true in the showing callback should dismiss the notification.
{
id: "Test#10",
run() {
let notifyObj = new BasicNotification(this.id);
let originalCallback = notifyObj.options.eventCallback;
notifyObj.options.eventCallback = function (eventName) {
originalCallback(eventName);
return eventName == "showing";
};
let notification = showNotification(notifyObj);
ok(
notifyObj.showingCallbackTriggered,
"the showing callback was triggered"
);
ok(
!notifyObj.shownCallbackTriggered,
"the shown callback wasn't triggered"
);
notification.remove();
goNext();
},
},
// the main action button should apply non-default(no highlight) style.
{
id: "Test#11",
run() {
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.secondaryActions = undefined;
this.notification = showNotification(this.notifyObj);
},
onShown(popup) {
checkPopup(popup, this.notifyObj);
dismissNotification(popup);
},
onHidden() {},
},
];
|