OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h" | 5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 new TestNotificationDelegate(new_id)); | 89 new TestNotificationDelegate(new_id)); |
90 | 90 |
91 g_browser_process->notification_ui_manager()->Add( | 91 g_browser_process->notification_ui_manager()->Add( |
92 notification, browser()->profile()); | 92 notification, browser()->profile()); |
93 } | 93 } |
94 | 94 |
95 void RemoveNotification(const std::string& id) { | 95 void RemoveNotification(const std::string& id) { |
96 g_browser_process->notification_ui_manager()->CancelById(id); | 96 g_browser_process->notification_ui_manager()->CancelById(id); |
97 } | 97 } |
98 | 98 |
| 99 bool HasNotification(message_center::MessageCenter* message_center, |
| 100 const std::string& id) { |
| 101 return message_center->FindVisibleNotificationById(id) != NULL; |
| 102 } |
| 103 |
99 private: | 104 private: |
100 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); | 105 DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); |
101 }; | 106 }; |
102 | 107 |
103 } // namespace | 108 } // namespace |
104 | 109 |
105 | 110 |
106 // TODO(dewittj): More exhaustive testing. | 111 // TODO(dewittj): More exhaustive testing. |
107 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, WebNotifications) { | 112 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, WebNotifications) { |
108 message_center::MessageCenter* message_center = | 113 message_center::MessageCenter* message_center = |
109 message_center::MessageCenter::Get(); | 114 message_center::MessageCenter::Get(); |
110 | 115 |
111 // Add a notification. | 116 // Add a notification. |
112 AddNotification("test_id1", "replace_id1"); | 117 AddNotification("test_id1", "replace_id1"); |
113 EXPECT_EQ(1u, message_center->NotificationCount()); | 118 EXPECT_EQ(1u, message_center->NotificationCount()); |
114 EXPECT_TRUE(message_center->HasNotification("test_id1")); | 119 EXPECT_TRUE(HasNotification(message_center, "test_id1")); |
115 EXPECT_FALSE(message_center->HasNotification("test_id2")); | 120 EXPECT_FALSE(HasNotification(message_center, "test_id2")); |
116 AddNotification("test_id2", "replace_id2"); | 121 AddNotification("test_id2", "replace_id2"); |
117 AddNotification("test_id2", "replace_id2"); | 122 AddNotification("test_id2", "replace_id2"); |
118 EXPECT_EQ(2u, message_center->NotificationCount()); | 123 EXPECT_EQ(2u, message_center->NotificationCount()); |
119 EXPECT_TRUE(message_center->HasNotification("test_id2")); | 124 EXPECT_TRUE(HasNotification(message_center, "test_id1")); |
120 | 125 |
121 // Ensure that updating a notification does not affect the count. | 126 // Ensure that updating a notification does not affect the count. |
122 UpdateNotification("replace_id2", "test_id3"); | 127 UpdateNotification("replace_id2", "test_id3"); |
123 UpdateNotification("replace_id2", "test_id3"); | 128 UpdateNotification("replace_id2", "test_id3"); |
124 EXPECT_EQ(2u, message_center->NotificationCount()); | 129 EXPECT_EQ(2u, message_center->NotificationCount()); |
125 EXPECT_FALSE(message_center->HasNotification("test_id2")); | 130 EXPECT_FALSE(HasNotification(message_center, "test_id2")); |
126 | 131 |
127 // Ensure that Removing the first notification removes it from the tray. | 132 // Ensure that Removing the first notification removes it from the tray. |
128 RemoveNotification("test_id1"); | 133 RemoveNotification("test_id1"); |
129 EXPECT_FALSE(message_center->HasNotification("test_id1")); | 134 EXPECT_FALSE(HasNotification(message_center, "test_id1")); |
130 EXPECT_EQ(1u, message_center->NotificationCount()); | 135 EXPECT_EQ(1u, message_center->NotificationCount()); |
131 | 136 |
132 // Remove the remaining notification. | 137 // Remove the remaining notification. |
133 RemoveNotification("test_id3"); | 138 RemoveNotification("test_id3"); |
134 EXPECT_EQ(0u, message_center->NotificationCount()); | 139 EXPECT_EQ(0u, message_center->NotificationCount()); |
135 EXPECT_FALSE(message_center->HasNotification("test_id3")); | 140 EXPECT_FALSE(HasNotification(message_center, "test_id1")); |
136 } | 141 } |
137 | 142 |
138 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, WebNotificationPopupBubble) { | 143 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, WebNotificationPopupBubble) { |
139 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray(NULL)); | 144 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray(NULL)); |
140 tray->message_center(); | 145 tray->message_center(); |
141 | 146 |
142 // Adding a notification should show the popup bubble. | 147 // Adding a notification should show the popup bubble. |
143 AddNotification("test_id1", "replace_id1"); | 148 AddNotification("test_id1", "replace_id1"); |
144 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); | 149 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); |
145 | 150 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 base::RunLoop().RunUntilIdle(); | 245 base::RunLoop().RunUntilIdle(); |
241 EXPECT_TRUE(tray->status_icon_ == NULL); | 246 EXPECT_TRUE(tray->status_icon_ == NULL); |
242 AddNotification("test_id", "replace_id"); | 247 AddNotification("test_id", "replace_id"); |
243 base::RunLoop().RunUntilIdle(); | 248 base::RunLoop().RunUntilIdle(); |
244 EXPECT_TRUE(tray->status_icon_ != NULL); | 249 EXPECT_TRUE(tray->status_icon_ != NULL); |
245 RemoveNotification("test_id"); | 250 RemoveNotification("test_id"); |
246 base::RunLoop().RunUntilIdle(); | 251 base::RunLoop().RunUntilIdle(); |
247 EXPECT_TRUE(tray->status_icon_ != NULL); | 252 EXPECT_TRUE(tray->status_icon_ != NULL); |
248 } | 253 } |
249 } // namespace message_center | 254 } // namespace message_center |
OLD | NEW |