From db222ba461efa7f07bd535a209b2543893634b64 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Wed, 19 Jun 2013 13:29:05 -0400 Subject: [PATCH] Bug 882858 - Add a "showing" notification to PopupNotifications, r=jaws sr=gavin --- .../content/test/browser_CTP_drag_drop.js | 5 +++- .../test/browser_pluginnotification.js | 13 ++++++++-- .../test/browser_plugins_added_dynamically.js | 10 ++++++-- .../content/test/browser_popupNotification.js | 25 +++++++++++++++++++ toolkit/modules/PopupNotifications.jsm | 4 +++ 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/browser/base/content/test/browser_CTP_drag_drop.js b/browser/base/content/test/browser_CTP_drag_drop.js index 7d9be4fa818..c6f875973bf 100644 --- a/browser/base/content/test/browser_CTP_drag_drop.js +++ b/browser/base/content/test/browser_CTP_drag_drop.js @@ -132,7 +132,10 @@ function part11() { } catch (e) {} } -function part12() { +function part12(type) { + if (type != "shown") { + return; + } let notification = PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); notification.options.eventCallback = null; let centerAction = null; diff --git a/browser/base/content/test/browser_pluginnotification.js b/browser/base/content/test/browser_pluginnotification.js index 26685d018d8..6b2393d705f 100644 --- a/browser/base/content/test/browser_pluginnotification.js +++ b/browser/base/content/test/browser_pluginnotification.js @@ -718,6 +718,9 @@ function test18f() { var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); ok(!objLoadingContent.activated, "Test 18f, Plugin should not be activated"); + // XXXBAD: this code doesn't do what you think it does! it is actually + // observing the "removed" event of the old notification, since we create + // a *new* one when the plugin is clicked. notification.options.eventCallback = function() { executeSoon(test18g); }; EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow); } @@ -879,7 +882,10 @@ function test21a() { notification.reshow(); } -function test21b() { +function test21b(type) { + if (type != "shown") { + return; + } var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); notification.options.eventCallback = null; var centerAction = null; @@ -938,7 +944,10 @@ function test21c() { notification.reshow(); } -function test21d() { +function test21d(type) { + if (type != "shown") { + return; + } var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); notification.options.eventCallback = null; diff --git a/browser/base/content/test/browser_plugins_added_dynamically.js b/browser/base/content/test/browser_plugins_added_dynamically.js index b363a6239ea..9bca9eec41e 100644 --- a/browser/base/content/test/browser_plugins_added_dynamically.js +++ b/browser/base/content/test/browser_plugins_added_dynamically.js @@ -111,7 +111,10 @@ function testActivateAddSameTypePart2() { popupNotification.reshow(); } -function testActivateAddSameTypePart3() { +function testActivateAddSameTypePart3(type) { + if (type != "shown") { + return; + } let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); popupNotification.options.eventCallback = null; let centerAction = null; @@ -189,7 +192,10 @@ function testActivateAddDifferentTypePart2() { popupNotification.reshow(); } -function testActivateAddDifferentTypePart3() { +function testActivateAddDifferentTypePart3(type) { + if (type != "shown") { + return; + } let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); popupNotification.options.eventCallback = null; let centerAction = null; diff --git a/browser/base/content/test/browser_popupNotification.js b/browser/base/content/test/browser_popupNotification.js index 73ccff81e50..1146b5d7cbd 100644 --- a/browser/base/content/test/browser_popupNotification.js +++ b/browser/base/content/test/browser_popupNotification.js @@ -137,6 +137,9 @@ function basicNotification() { case "dismissed": self.dismissalCallbackTriggered = true; break; + case "showing": + self.showingCallbackTriggered = true; + break; case "shown": self.shownCallbackTriggered = true; break; @@ -858,6 +861,27 @@ var tests = [ this.notification1.remove(); this.notification2.remove(); } + }, + { // Test #30 - Showing should be able to modify the popup data + run: function() { + this.notifyObj = new basicNotification(); + var 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: function(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: function() { } } ]; @@ -874,6 +898,7 @@ function showNotification(notifyObj) { function checkPopup(popup, notificationObj) { info("[Test #" + gTestIndex + "] checking popup"); + ok(notificationObj.showingCallbackTriggered, "showing callback was triggered"); ok(notificationObj.shownCallbackTriggered, "shown callback was triggered"); let notifications = popup.childNodes; diff --git a/toolkit/modules/PopupNotifications.jsm b/toolkit/modules/PopupNotifications.jsm index a417accc9d5..7290c194abc 100644 --- a/toolkit/modules/PopupNotifications.jsm +++ b/toolkit/modules/PopupNotifications.jsm @@ -10,6 +10,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); const NOTIFICATION_EVENT_DISMISSED = "dismissed"; const NOTIFICATION_EVENT_REMOVED = "removed"; +const NOTIFICATION_EVENT_SHOWING = "showing"; const NOTIFICATION_EVENT_SHOWN = "shown"; const ICON_SELECTOR = ".notification-anchor-icon"; @@ -521,6 +522,9 @@ PopupNotifications.prototype = { _showPanel: function PopupNotifications_showPanel(notificationsToShow, anchorElement) { this.panel.hidden = false; + notificationsToShow.forEach(function (n) { + this._fireCallback(n, NOTIFICATION_EVENT_SHOWING); + }, this); this._refreshPanel(notificationsToShow); if (this.isPanelOpen && this._currentAnchorElement == anchorElement)