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

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: fix2 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
« no previous file with comments | « ui/message_center/message_center_tray_delegate.h ('k') | ui/message_center/views/group_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base/models/menu_model.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 base::string16 display_source = ASCIIToUTF16("www.test.org");
256 NotifierId notifier_id = DummyNotifierId();
257
258 NotifierId notifier_id2(NotifierId::APPLICATION, "sample-app");
259 scoped_ptr<Notification> notification(
260 new Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
261 id2,
262 ASCIIToUTF16("Test Web Notification"),
263 ASCIIToUTF16("Notification message body."),
264 gfx::Image(),
265 base::string16() /* empty display source */,
266 notifier_id2,
267 message_center::RichNotificationData(),
268 NULL /* delegate */));
269 message_center_->AddNotification(notification.Pass());
270
271 AddNotification(id3);
272
273 scoped_ptr<ui::MenuModel> model(
274 message_center_tray_->CreateNotificationMenuModel(
275 notifier_id, display_source));
276 EXPECT_EQ(2, model->GetItemCount());
277 const int second_command = model->GetCommandIdAt(1);
278
279 // The second item is to open the settings.
280 EXPECT_TRUE(model->IsEnabledAt(0));
281 EXPECT_TRUE(model->IsEnabledAt(1));
282 model->ActivatedAt(1);
283 EXPECT_TRUE(message_center_tray_->message_center_visible());
284
285 message_center_tray_->HideMessageCenterBubble();
286
287 // The first item is to disable notifications from the notifier id. It also
288 // removes all notifications from the same notifier, i.e. id1 and id3.
289 model->ActivatedAt(0);
290 NotificationList::Notifications notifications =
291 message_center_->GetVisibleNotifications();
292 EXPECT_EQ(1u, notifications.size());
293 EXPECT_EQ(id2, (*notifications.begin())->id());
294
295 // Disables the context menu.
296 delegate_->enable_context_menu_ = false;
297
298 // id2 doesn't have the display source, so it don't have the menu item for
299 // disabling notifications.
300 model = message_center_tray_->CreateNotificationMenuModel(
301 notifier_id2, base::string16());
302 EXPECT_EQ(1, model->GetItemCount());
303 EXPECT_EQ(second_command, model->GetCommandIdAt(0));
304
305 // The command itself is disabled because delegate disables context menu.
306 EXPECT_FALSE(model->IsEnabledAt(0));
307 }
308
243 } // namespace message_center 309 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_tray_delegate.h ('k') | ui/message_center/views/group_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698