class WebNotificationTrayTest : public InProcessBrowserTest {
public:
WebNotificationTrayTest() {}
- virtual ~WebNotificationTrayTest() {}
+ ~WebNotificationTrayTest() override {}
- virtual void TearDownOnMainThread() OVERRIDE {
+ void TearDownOnMainThread() override {
message_center::MessageCenter::Get()->RemoveAllNotifications(false);
}
class TestNotificationDelegate : public ::NotificationDelegate {
public:
explicit TestNotificationDelegate(std::string id) : id_(id) {}
- virtual void Display() OVERRIDE {}
- virtual void Error() OVERRIDE {}
- virtual void Close(bool by_user) OVERRIDE {}
- virtual void Click() OVERRIDE {}
- virtual std::string id() const OVERRIDE { return id_; }
- virtual content::WebContents* GetWebContents() const OVERRIDE {
- return NULL;
- }
+ std::string id() const override { return id_; }
private:
- virtual ~TestNotificationDelegate() {}
+ ~TestNotificationDelegate() override {}
std::string id_;
};
- void AddNotification(const std::string& id, const std::string& replace_id) {
- ::Notification notification(GURL("chrome-extension://abbccedd"),
- GURL(),
- base::ASCIIToUTF16("Test Web Notification"),
- base::ASCIIToUTF16(
- "Notification message body."),
- blink::WebTextDirectionDefault,
- base::string16(),
- base::ASCIIToUTF16(replace_id),
- new TestNotificationDelegate(id));
+ void AddNotification(const std::string& delegate_id,
+ const std::string& replace_id) {
+ ::Notification notification(
+ GURL("chrome-extension://abbccedd"),
+ base::ASCIIToUTF16("Test Web Notification"),
+ base::ASCIIToUTF16("Notification message body."),
+ gfx::Image(),
+ base::string16(),
+ base::ASCIIToUTF16(replace_id),
+ new TestNotificationDelegate(delegate_id));
+
+ g_browser_process->notification_ui_manager()->Add(notification,
+ browser()->profile());
+ }
- g_browser_process->notification_ui_manager()->Add(
- notification, browser()->profile());
+ std::string FindNotificationIdByDelegateId(const std::string& delegate_id) {
+ const ::Notification* notification =
+ g_browser_process->notification_ui_manager()->FindById(
+ delegate_id,
+ NotificationUIManager::GetProfileID(browser()->profile()));
+ EXPECT_TRUE(notification);
+ return notification->id();
}
void UpdateNotification(const std::string& replace_id,
const std::string& new_id) {
::Notification notification(GURL("chrome-extension://abbccedd"),
- GURL(""),
base::ASCIIToUTF16("Updated Web Notification"),
base::ASCIIToUTF16("Updated message body."),
- blink::WebTextDirectionDefault,
+ gfx::Image(),
base::string16(),
base::ASCIIToUTF16(replace_id),
new TestNotificationDelegate(new_id));
- g_browser_process->notification_ui_manager()->Add(
- notification, browser()->profile());
+ g_browser_process->notification_ui_manager()->Add(notification,
+ browser()->profile());
}
void RemoveNotification(const std::string& id) {
- g_browser_process->notification_ui_manager()->CancelById(id);
+ g_browser_process->notification_ui_manager()->CancelById(
+ id, NotificationUIManager::GetProfileID(browser()->profile()));
}
bool HasNotification(message_center::MessageCenter* message_center,
// Add a notification.
AddNotification("test_id1", "replace_id1");
EXPECT_EQ(1u, message_center->NotificationCount());
- EXPECT_TRUE(HasNotification(message_center, "test_id1"));
+ EXPECT_TRUE(HasNotification(message_center,
+ FindNotificationIdByDelegateId("test_id1")));
EXPECT_FALSE(HasNotification(message_center, "test_id2"));
AddNotification("test_id2", "replace_id2");
AddNotification("test_id2", "replace_id2");
EXPECT_EQ(2u, message_center->NotificationCount());
- EXPECT_TRUE(HasNotification(message_center, "test_id1"));
+ EXPECT_TRUE(HasNotification(message_center,
+ FindNotificationIdByDelegateId("test_id1")));
// Ensure that updating a notification does not affect the count.
UpdateNotification("replace_id2", "test_id3");