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

Side by Side Diff: chrome/browser/notifications/message_center_notifications_browsertest.cc

Issue 11896085: Adding implementation for MessageCenter::Delegate on MessageCeneterNotificationManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable on win7_aura Created 7 years, 10 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/command_line.h"
8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/notifications/message_center_notification_manager.h"
13 #include "chrome/browser/notifications/notification.h"
14 #include "chrome/browser/notifications/notification_ui_manager.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "ui/message_center/message_center.h"
20
21 class MessageCenterNotificationsTest : public InProcessBrowserTest {
22 public:
23 MessageCenterNotificationsTest() {}
24
25 virtual void SetUpCommandLine(CommandLine* command_line) {
26 // This switch enables the new piping of Notifications through Message
27 // Center.
28 command_line->AppendSwitch(switches::kEnableRichNotifications);
29 }
30
31 MessageCenterNotificationManager* manager() {
32 return static_cast<MessageCenterNotificationManager*>(
33 g_browser_process->notification_ui_manager());
34 }
35
36 message_center::MessageCenter* message_center() {
37 return g_browser_process->message_center();
38 }
39
40 Profile* profile() { return browser()->profile(); }
41
42 class TestDelegate : public NotificationDelegate {
43 public:
44 explicit TestDelegate(const std::string& id) : id_(id) {}
45
46 void Display() OVERRIDE { log_ += "Display_"; }
47 void Error() OVERRIDE { log_ += "Error_"; }
48 void Close(bool by_user) OVERRIDE {
49 log_ += "Close_";
50 log_ += ( by_user ? "by_user_" : "programmatically_");
51 }
52 void Click() OVERRIDE { log_ += "Click_"; }
53 void ButtonClick(int button_index) OVERRIDE {
54 log_ += "ButtonClick_";
55 log_ += base::IntToString(button_index) + "_";
56 }
57 std::string id() const OVERRIDE { return id_; }
58 content::RenderViewHost* GetRenderViewHost() const OVERRIDE { return NULL; }
59
60 const std::string& log() { return log_; }
61
62 private:
63 virtual ~TestDelegate() {}
64 std::string id_;
65 std::string log_;
66
67 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
68 };
69
70 Notification CreateTestNotification(const std::string& id,
71 TestDelegate** delegate = NULL) {
72 TestDelegate* new_delegate = new TestDelegate(id);
73 if (delegate) {
74 *delegate = new_delegate;
75 new_delegate->AddRef();
76 }
77
78 return Notification(GURL(),
79 GURL(),
80 ASCIIToUTF16("title"),
81 ASCIIToUTF16("message"),
82 WebKit::WebTextDirectionDefault,
83 EmptyString16(),
84 EmptyString16(),
85 new_delegate);
86 }
87 };
88
89 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, RetrieveBaseParts) {
90 // Make sure comamnd-line switch has an effect.
91 EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter());
92 EXPECT_TRUE(manager());
93 EXPECT_TRUE(message_center());
94 }
95
96 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicAddCancel) {
97 manager()->Add(CreateTestNotification("hey"), profile());
98 EXPECT_EQ(1u, message_center()->NotificationCount());
99 manager()->CancelById("hey");
100 EXPECT_EQ(0u, message_center()->NotificationCount());
101 }
102
103 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicDelegate) {
104 TestDelegate* delegate;
105 manager()->Add(CreateTestNotification("hey", &delegate), profile());
106 // Verify that delegate accumulated correct log of events.
107 EXPECT_EQ("Display_", delegate->log());
108 manager()->CancelById("hey");
109 // Verify that delegate accumulated correct log of events.
110 EXPECT_EQ("Display_Close_programmatically_", delegate->log());
111 delegate->Release();
112 }
113
114 IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, ButtonClickedDelegate) {
115 TestDelegate* delegate;
116 manager()->Add(CreateTestNotification("n", &delegate), profile());
117 message_center()->OnButtonClicked("n", 1);
118 // Verify that delegate accumulated correct log of events.
119 EXPECT_EQ("Display_ButtonClick_1_", delegate->log());
120 delegate->Release();
121 }
122
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698