From 30c7362b5d382b95eb8185cd8621cb62a1ad1328 Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Thu, 8 Apr 2021 13:34:14 +0000 Subject: [PATCH] Bug 1702603, use command event for buttons in notificationbar, r=mstriemer Differential Revision: https://phabricator.services.mozilla.com/D110875 --- .../tests/chrome/test_notificationbox.xhtml | 43 +++++++++++++++++++ toolkit/content/widgets/notificationbox.js | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/toolkit/content/tests/chrome/test_notificationbox.xhtml b/toolkit/content/tests/chrome/test_notificationbox.xhtml index e5cf675584e6..32784c81daac 100644 --- a/toolkit/content/tests/chrome/test_notificationbox.xhtml +++ b/toolkit/content/tests/chrome/test_notificationbox.xhtml @@ -7,6 +7,7 @@ + @@ -32,6 +33,19 @@ var testtag_notificationbox_buttons = [ } ]; +var testtag_notificationbox_buttons_nopopup = [ + { + label: "Button 1 No Popup", + accesskey: "u", + callback: testtag_notificationbox_button1pressed, + }, + { + label: "Button 2 No Popup", + accesskey: "u", + callback: testtag_notificationbox_button2pressed, + } +]; + var testtag_notificationbox_links = [ { label: "Link 1", @@ -61,6 +75,10 @@ function testtag_notificationbox_buttonpressed(notification, button) return false; } +let buttonsPressedLog = ""; +function testtag_notificationbox_button1pressed(notification, button) { buttonsPressedLog += "button1"; return true; } +function testtag_notificationbox_button2pressed(notification, button) { buttonsPressedLog += "button2"; return true; } + function testtag_notificationbox(nb) { testtag_notificationbox_State(nb, "initial", null, 0); @@ -330,6 +348,31 @@ var tests = SimpleTest.is(nb.removeAllNotifications(false), undefined, "removeAllNotifications"); } }, + { + test(nb, ntf) { + // append a new notification + ntf = nb.appendNotification("Notification", "note", "happy.png", + nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons_nopopup); + return ntf; + }, + result(nb, ntf) { + let buttons = nb.currentNotification.buttonContainer.querySelectorAll("* button"); + + buttons[0].focus(); + synthesizeKey(" ", {}); + SimpleTest.is(buttonsPressedLog, "button1", "button 1 with keyboard"); + buttons[1].focus(); + synthesizeKey(" ", {}); + SimpleTest.is(buttonsPressedLog, "button1button2", "button 2 with keyboard"); + + synthesizeMouseAtCenter(buttons[0], {}); + SimpleTest.is(buttonsPressedLog, "button1button2button1", "button 1 with mouse"); + synthesizeMouseAtCenter(buttons[1], {}); + SimpleTest.is(buttonsPressedLog, "button1button2button1button2", "button 2 with mouse"); + + nb.removeAllNotifications(true); + } + }, { test(nb, ntf) { ntf = nb.appendNotification("Notification", "note", "happy.png", diff --git a/toolkit/content/widgets/notificationbox.js b/toolkit/content/widgets/notificationbox.js index 0d7cfdfdf79e..d9722e774395 100644 --- a/toolkit/content/widgets/notificationbox.js +++ b/toolkit/content/widgets/notificationbox.js @@ -587,7 +587,7 @@ this.messageImage = this.shadowRoot.querySelector(".icon"); messageContent.append(this.messageText, this.buttonContainer); - this.shadowRoot.addEventListener("click", this); + this.shadowRoot.addEventListener("command", this); } disconnectedCallback() {