Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: ui/message_center/message_center_tray_unittest.cc

Issue 114323002: Fixes the context menu for a notification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/events/event_constants.h"
9 #include "ui/message_center/message_center.h" 10 #include "ui/message_center/message_center.h"
10 #include "ui/message_center/notification_types.h" 11 #include "ui/message_center/notification_types.h"
11 12
12 namespace message_center { 13 namespace message_center {
13 namespace { 14 namespace {
14 15
15 class MockDelegate : public MessageCenterTrayDelegate { 16 class MockDelegate : public MessageCenterTrayDelegate {
16 public: 17 public:
17 MockDelegate() 18 MockDelegate()
18 : show_popups_success_(true), 19 : show_popups_success_(true),
19 show_message_center_success_(true) {} 20 show_message_center_success_(true),
21 enable_context_menu_(true) {}
20 virtual ~MockDelegate() {} 22 virtual ~MockDelegate() {}
21 virtual void OnMessageCenterTrayChanged() OVERRIDE {} 23 virtual void OnMessageCenterTrayChanged() OVERRIDE {}
22 virtual bool ShowPopups() OVERRIDE { 24 virtual bool ShowPopups() OVERRIDE {
23 return show_message_center_success_; 25 return show_message_center_success_;
24 } 26 }
25 virtual void HidePopups() OVERRIDE {} 27 virtual void HidePopups() OVERRIDE {}
26 virtual bool ShowMessageCenter() OVERRIDE { 28 virtual bool ShowMessageCenter() OVERRIDE {
27 return show_popups_success_; 29 return show_popups_success_;
28 } 30 }
29 virtual void HideMessageCenter() OVERRIDE {} 31 virtual void HideMessageCenter() OVERRIDE {}
30 virtual bool ShowNotifierSettings() OVERRIDE { 32 virtual bool ShowNotifierSettings() OVERRIDE {
31 return false; 33 return true;
34 }
35 virtual bool IsContextMenuEnabled() const OVERRIDE {
36 return enable_context_menu_;
32 } 37 }
33 38
34 virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE { 39 virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE {
35 return NULL; 40 return NULL;
36 } 41 }
37 42
38 bool show_popups_success_; 43 bool show_popups_success_;
39 bool show_message_center_success_; 44 bool show_message_center_success_;
45 bool enable_context_menu_;
40 46
41 private: 47 private:
42 DISALLOW_COPY_AND_ASSIGN(MockDelegate); 48 DISALLOW_COPY_AND_ASSIGN(MockDelegate);
43 }; 49 };
44 50
45 } // namespace 51 } // namespace
46 52
47 class MessageCenterTrayTest : public testing::Test { 53 class MessageCenterTrayTest : public testing::Test {
48 public: 54 public:
49 MessageCenterTrayTest() {} 55 MessageCenterTrayTest() {}
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 239
234 ASSERT_FALSE(message_center_tray_->popups_visible()); 240 ASSERT_FALSE(message_center_tray_->popups_visible());
235 ASSERT_FALSE(message_center_tray_->message_center_visible()); 241 ASSERT_FALSE(message_center_tray_->message_center_visible());
236 242
237 message_center_tray_->HidePopupBubble(); 243 message_center_tray_->HidePopupBubble();
238 244
239 ASSERT_FALSE(message_center_tray_->popups_visible()); 245 ASSERT_FALSE(message_center_tray_->popups_visible());
240 ASSERT_FALSE(message_center_tray_->message_center_visible()); 246 ASSERT_FALSE(message_center_tray_->message_center_visible());
241 } 247 }
242 248
249 TEST_F(MessageCenterTrayTest, ContextMenuTest) {
250 const std::string id1 = "id1";
251 const std::string id2 = "id2";
252 const std::string id3 = "id3";
253 AddNotification(id1);
254
255 scoped_ptr<Notification> notification(
256 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
257 id2,
258 ASCIIToUTF16("Test Web Notification"),
259 ASCIIToUTF16("Notification message body."),
260 gfx::Image(),
261 base::string16() /* empty display source */,
262 NotifierId(NotifierId::APPLICATION, "sample-app"),
263 message_center::RichNotificationData(),
264 NULL /* delegate */));
265 message_center_->AddNotification(notification.Pass());
266
267 AddNotification(id3);
268
269 scoped_ptr<ui::MenuModel> model(
270 message_center_tray_->CreateMenuModelForNotification(id1));
271 EXPECT_EQ(2, model->GetItemCount());
272 const int first_command = model->GetCommandIdAt(0);
273 const int second_command = model->GetCommandIdAt(1);
274
275 // The second item is to open the settings.
276 EXPECT_TRUE(message_center_tray_->IsCommandIdEnabled(second_command));
277 message_center_tray_->ExecuteCommand(second_command, ui::EF_NONE);
278 EXPECT_TRUE(message_center_tray_->message_center_visible());
279
280 message_center_tray_->HideMessageCenterBubble();
281
282 // The first item is to disable notifications from the notifier id. It also
283 // removes all notifications from the same notifier, i.e. id1 and id3.
284 EXPECT_TRUE(message_center_tray_->IsCommandIdEnabled(first_command));
285 message_center_tray_->ExecuteCommand(first_command, ui::EF_NONE);
286 NotificationList::Notifications notifications =
287 message_center_->GetVisibleNotifications();
288 EXPECT_EQ(1u, notifications.size());
289 EXPECT_EQ(id2, (*notifications.begin())->id());
290
291 // Disables the context menu.
292 delegate_->enable_context_menu_ = false;
293
294 // id2 doesn't have the display source, so it don't have the menu item for
295 // disabling notifications.
296 model = message_center_tray_->CreateMenuModelForNotification(id2);
297 EXPECT_EQ(1, model->GetItemCount());
298 EXPECT_EQ(second_command, model->GetCommandIdAt(0));
299
300 // The command itself is disabled because delegate disables context menu.
301 EXPECT_FALSE(
302 message_center_tray_->IsCommandIdEnabled(model->GetCommandIdAt(0)));
303
304 model = message_center_tray_->CreateMenuModelForNotification("no-such-id");
305 EXPECT_EQ(0, model->GetItemCount());
306 }
307
243 } // namespace message_center 308 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698