OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/message_center/message_center_tray.h" | 5 #include "ui/message_center/message_center_tray.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/base/models/menu_model.h" | 9 #include "ui/base/models/menu_model.h" |
10 #include "ui/message_center/message_center.h" | 10 #include "ui/message_center/message_center.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 message_center_ = NULL; | 62 message_center_ = NULL; |
63 MessageCenter::Shutdown(); | 63 MessageCenter::Shutdown(); |
64 } | 64 } |
65 | 65 |
66 protected: | 66 protected: |
67 NotifierId DummyNotifierId() { | 67 NotifierId DummyNotifierId() { |
68 return NotifierId(); | 68 return NotifierId(); |
69 } | 69 } |
70 | 70 |
71 void AddNotification(const std::string& id) { | 71 void AddNotification(const std::string& id) { |
72 AddNotification(id, DummyNotifierId()); | |
73 } | |
74 | |
75 void AddNotification(const std::string& id, NotifierId notifier_id) { | |
72 scoped_ptr<Notification> notification(new Notification( | 76 scoped_ptr<Notification> notification(new Notification( |
73 message_center::NOTIFICATION_TYPE_SIMPLE, id, | 77 message_center::NOTIFICATION_TYPE_SIMPLE, id, |
74 ASCIIToUTF16("Test Web Notification"), | 78 ASCIIToUTF16("Test Web Notification"), |
75 ASCIIToUTF16("Notification message body."), gfx::Image(), | 79 ASCIIToUTF16("Notification message body."), gfx::Image(), |
76 ASCIIToUTF16("www.test.org"), GURL(), DummyNotifierId(), | 80 ASCIIToUTF16("www.test.org"), GURL(), notifier_id, |
77 message_center::RichNotificationData(), NULL /* delegate */)); | 81 message_center::RichNotificationData(), NULL /* delegate */)); |
78 message_center_->AddNotification(notification.Pass()); | 82 message_center_->AddNotification(notification.Pass()); |
79 } | 83 } |
80 scoped_ptr<MockDelegate> delegate_; | 84 scoped_ptr<MockDelegate> delegate_; |
81 scoped_ptr<MessageCenterTray> message_center_tray_; | 85 scoped_ptr<MessageCenterTray> message_center_tray_; |
82 MessageCenter* message_center_; | 86 MessageCenter* message_center_; |
83 | 87 |
84 private: | 88 private: |
85 DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayTest); | 89 DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayTest); |
86 }; | 90 }; |
87 | 91 |
88 TEST_F(MessageCenterTrayTest, BasicMessageCenter) { | 92 TEST_F(MessageCenterTrayTest, BasicMessageCenter) { |
89 ASSERT_FALSE(message_center_tray_->popups_visible()); | 93 ASSERT_FALSE(message_center_tray_->popups_visible()); |
90 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 94 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
91 | 95 |
92 bool shown = message_center_tray_->ShowMessageCenterBubble(); | 96 bool shown = message_center_tray_->ShowMessageCenterBubble(); |
93 EXPECT_TRUE(shown); | 97 EXPECT_TRUE(shown); |
94 | 98 |
95 ASSERT_FALSE(message_center_tray_->popups_visible()); | 99 ASSERT_FALSE(message_center_tray_->popups_visible()); |
96 ASSERT_TRUE(message_center_tray_->message_center_visible()); | 100 ASSERT_TRUE(message_center_tray_->message_center_visible()); |
97 | 101 |
98 message_center_tray_->HideMessageCenterBubble(); | 102 message_center_tray_->HideMessageCenterBubble(); |
99 | 103 |
100 ASSERT_FALSE(message_center_tray_->popups_visible()); | 104 ASSERT_FALSE(message_center_tray_->popups_visible()); |
101 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 105 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
102 | 106 |
103 message_center_tray_->ToggleMessageCenterBubble(); | 107 message_center_tray_->ShowMessageCenterBubble(); |
104 | 108 |
105 ASSERT_FALSE(message_center_tray_->popups_visible()); | 109 ASSERT_FALSE(message_center_tray_->popups_visible()); |
106 ASSERT_TRUE(message_center_tray_->message_center_visible()); | 110 ASSERT_TRUE(message_center_tray_->message_center_visible()); |
107 | 111 |
108 message_center_tray_->ToggleMessageCenterBubble(); | 112 message_center_tray_->HideMessageCenterBubble(); |
109 | 113 |
110 ASSERT_FALSE(message_center_tray_->popups_visible()); | 114 ASSERT_FALSE(message_center_tray_->popups_visible()); |
111 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 115 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
112 } | 116 } |
113 | 117 |
114 TEST_F(MessageCenterTrayTest, BasicPopup) { | 118 TEST_F(MessageCenterTrayTest, BasicPopup) { |
115 ASSERT_FALSE(message_center_tray_->popups_visible()); | 119 ASSERT_FALSE(message_center_tray_->popups_visible()); |
116 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 120 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
117 | 121 |
118 message_center_tray_->ShowPopupBubble(); | 122 message_center_tray_->ShowPopupBubble(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 EXPECT_FALSE(shown); | 218 EXPECT_FALSE(shown); |
215 | 219 |
216 ASSERT_FALSE(message_center_tray_->popups_visible()); | 220 ASSERT_FALSE(message_center_tray_->popups_visible()); |
217 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 221 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
218 | 222 |
219 message_center_tray_->HideMessageCenterBubble(); | 223 message_center_tray_->HideMessageCenterBubble(); |
220 | 224 |
221 ASSERT_FALSE(message_center_tray_->popups_visible()); | 225 ASSERT_FALSE(message_center_tray_->popups_visible()); |
222 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 226 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
223 | 227 |
224 message_center_tray_->ToggleMessageCenterBubble(); | 228 message_center_tray_->ShowMessageCenterBubble(); |
225 | 229 |
226 ASSERT_FALSE(message_center_tray_->popups_visible()); | 230 ASSERT_FALSE(message_center_tray_->popups_visible()); |
227 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 231 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
228 | 232 |
229 message_center_tray_->HidePopupBubble(); | 233 message_center_tray_->HidePopupBubble(); |
230 | 234 |
231 ASSERT_FALSE(message_center_tray_->popups_visible()); | 235 ASSERT_FALSE(message_center_tray_->popups_visible()); |
232 ASSERT_FALSE(message_center_tray_->message_center_visible()); | 236 ASSERT_FALSE(message_center_tray_->message_center_visible()); |
233 } | 237 } |
234 | 238 |
235 TEST_F(MessageCenterTrayTest, ContextMenuTest) { | 239 #ifdef OS_CHROMEOS |
240 TEST_F(MessageCenterTrayTest, ContextMenuTestWithMessageCenter) { | |
236 const std::string id1 = "id1"; | 241 const std::string id1 = "id1"; |
237 const std::string id2 = "id2"; | 242 const std::string id2 = "id2"; |
238 const std::string id3 = "id3"; | 243 const std::string id3 = "id3"; |
239 AddNotification(id1); | 244 AddNotification(id1); |
240 | 245 |
241 base::string16 display_source = ASCIIToUTF16("www.test.org"); | 246 base::string16 display_source = ASCIIToUTF16("www.test.org"); |
242 NotifierId notifier_id = DummyNotifierId(); | 247 NotifierId notifier_id = DummyNotifierId(); |
243 | 248 |
244 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app"); | 249 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app"); |
245 scoped_ptr<Notification> notification(new Notification( | 250 scoped_ptr<Notification> notification(new Notification( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 // disabling notifications. | 286 // disabling notifications. |
282 model = message_center_tray_->CreateNotificationMenuModel( | 287 model = message_center_tray_->CreateNotificationMenuModel( |
283 notifier_id2, base::string16()); | 288 notifier_id2, base::string16()); |
284 EXPECT_EQ(1, model->GetItemCount()); | 289 EXPECT_EQ(1, model->GetItemCount()); |
285 EXPECT_EQ(second_command, model->GetCommandIdAt(0)); | 290 EXPECT_EQ(second_command, model->GetCommandIdAt(0)); |
286 | 291 |
287 // The command itself is disabled because delegate disables context menu. | 292 // The command itself is disabled because delegate disables context menu. |
288 EXPECT_FALSE(model->IsEnabledAt(0)); | 293 EXPECT_FALSE(model->IsEnabledAt(0)); |
289 } | 294 } |
290 | 295 |
296 #else | |
297 TEST_F(MessageCenterTrayTest, ContextMenuTestPopupsOnly) { | |
298 const std::string id1 = "id1"; | |
299 const std::string id2 = "id2"; | |
300 const std::string id3 = "id3"; | |
301 | |
302 base::string16 display_source = ASCIIToUTF16("www.test.org"); | |
303 NotifierId notifier_id(GURL("www.test.org")); | |
Peter Beverloo
2015/09/16 10:34:20
micro nit: protocol?
dewittj
2015/09/16 18:23:49
Done.
| |
304 | |
305 AddNotification(id1, notifier_id); | |
306 | |
307 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app"); | |
308 scoped_ptr<Notification> notification(new Notification( | |
309 message_center::NOTIFICATION_TYPE_SIMPLE, id2, | |
310 ASCIIToUTF16("Test Web Notification"), | |
311 ASCIIToUTF16("Notification message body."), gfx::Image(), | |
312 base::string16() /* empty display source */, GURL(), notifier_id2, | |
313 message_center::RichNotificationData(), NULL /* delegate */)); | |
314 message_center_->AddNotification(notification.Pass()); | |
315 | |
316 AddNotification(id3, notifier_id); | |
317 | |
318 // The dummy notifier is SYSTEM_COMPONENT so no context menu is visible. | |
319 scoped_ptr<ui::MenuModel> model( | |
320 message_center_tray_->CreateNotificationMenuModel(DummyNotifierId(), | |
321 display_source)); | |
322 EXPECT_EQ(nullptr, model.get()); | |
323 | |
324 model = message_center_tray_->CreateNotificationMenuModel(notifier_id, | |
325 display_source); | |
326 EXPECT_EQ(1, model->GetItemCount()); | |
327 | |
328 // The first item is to disable notifications from the notifier id. It also | |
329 // removes all notifications from the same notifier, i.e. id1 and id3. | |
330 EXPECT_TRUE(model->IsEnabledAt(0)); | |
331 model->ActivatedAt(0); | |
332 | |
333 NotificationList::Notifications notifications = | |
334 message_center_->GetVisibleNotifications(); | |
335 EXPECT_EQ(1u, notifications.size()); | |
336 EXPECT_EQ(id2, (*notifications.begin())->id()); | |
337 | |
338 // Disables the context menu. | |
339 delegate_->enable_context_menu_ = false; | |
340 | |
341 // id2 doesn't have the display source, so it don't have the menu item for | |
342 // disabling notifications. | |
343 EXPECT_EQ(nullptr, message_center_tray_->CreateNotificationMenuModel( | |
344 notifier_id2, base::string16())); | |
345 } | |
346 #endif | |
347 | |
348 TEST_F(MessageCenterTrayTest, DelegateDisabledContextMenu) { | |
349 const std::string id1 = "id1"; | |
350 base::string16 display_source = ASCIIToUTF16("www.test.org"); | |
351 AddNotification(id1); | |
352 NotifierId notifier_id(GURL("www.test.org")); | |
353 | |
354 delegate_->enable_context_menu_ = false; | |
355 // id2 doesn't have the display source, so it don't have the menu item for | |
356 // disabling notifications. | |
357 scoped_ptr<ui::MenuModel> model( | |
358 message_center_tray_->CreateNotificationMenuModel(notifier_id, | |
359 display_source)); | |
360 | |
361 // The commands are disabled because delegate disables context menu. | |
362 #ifndef OS_CHROMEOS | |
363 EXPECT_EQ(1, model->GetItemCount()); | |
364 #else | |
365 EXPECT_EQ(2, model->GetItemCount()); | |
366 EXPECT_FALSE(model->IsEnabledAt(1)); | |
367 #endif | |
368 | |
369 EXPECT_FALSE(model->IsEnabledAt(0)); | |
370 } | |
371 | |
291 } // namespace message_center | 372 } // namespace message_center |
OLD | NEW |