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

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

Issue 17286015: Adds a first-run balloon to the Windows notification center. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added some tests. Created 7 years, 6 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 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 "base/memory/scoped_ptr.h"
6 #include "base/prefs/testing_pref_service.h"
7 #include "base/run_loop.h"
8 #include "base/test/test_timeouts.h"
9 #include "base/values.h"
10 #include "chrome/browser/notifications/message_center_notification_manager.h"
11 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/notifications/notification_prefs_manager.h"
13 #include "chrome/browser/notifications/notification_test_util.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/scoped_testing_local_state.h"
16 #include "chrome/test/base/testing_browser_process.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/message_center/message_center_impl.h"
22 #include "ui/message_center/message_center_tray.h"
23 #include "ui/message_center/message_center_tray_delegate.h"
24
25 namespace message_center {
26 class MockMessageCenterTrayDelegate : public MessageCenterTrayDelegate {
27 public:
28 MockMessageCenterTrayDelegate(MessageCenter* message_center,
29 base::Closure quit_closure)
30 : tray_(this, message_center), quit_closure_(quit_closure) {}
31
32 virtual void DisplayFirstRunBalloon() {
33 DidDisplayFirstRunBalloon();
34 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
35 }
36
37 virtual void OnMessageCenterTrayChanged() {}
38 virtual bool ShowPopups() { return true; }
39 virtual void HidePopups() {}
40 MOCK_METHOD0(UpdatePopups, void());
41 MOCK_METHOD0(ShowMessageCenter, bool());
42 MOCK_METHOD0(HideMessageCenter, void());
43 MOCK_METHOD0(DidDisplayFirstRunBalloon, void());
44
45 private:
46 MessageCenterTray tray_;
47 base::Closure quit_closure_;
48 };
49
50 class MessageCenterNotificationManagerTest : public testing::Test {
51 protected:
52 MessageCenterNotificationManagerTest() {
53 NotificationPrefsManager::RegisterPrefs(local_state_.registry());
54 }
55
56 virtual void SetUp() {
57 // Clear the preference and initialize.
58 local_state_.ClearPref(prefs::kMessageCenterShowedFirstRunBalloon);
59 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon,
60 &local_state_);
61
62 // Get ourselves a run loop.
63 run_loop_.reset(new base::RunLoop());
64
65 // Initialize message center infrastructure with mock tray delegate.
66 MessageCenter::Initialize();
67 message_center_ = MessageCenter::Get();
68 notification_manager_.reset(
69 new MessageCenterNotificationManager(message_center_, &local_state_));
70 delegate_ = new MockMessageCenterTrayDelegate(message_center_,
71 run_loop_->QuitClosure());
72 notification_manager_->SetMessageCenterTrayDelegateForTest(delegate_);
73 notification_manager_->SetFirstRunTimeoutForTest(
74 TestTimeouts::tiny_timeout());
75 }
76
77 virtual void TearDown() {
78 run_loop_.reset();
79 notification_manager_.reset();
80 MessageCenter::Shutdown();
81 }
82
83 MessageCenterNotificationManager* notification_manager() {
84 return notification_manager_.get();
85 }
86
87 MockMessageCenterTrayDelegate* delegate() { return delegate_; }
88
89 MessageCenter* message_center() { return message_center_; }
90
91 const ::Notification GetANotification(const std::string& id) {
92 return ::Notification(GURL(),
93 GURL(),
94 string16(),
95 string16(),
96 new MockNotificationDelegate(id));
97 }
98
99 base::RunLoop* run_loop() { return run_loop_.get(); }
100 const TestingPrefServiceSimple& local_state() { return local_state_; }
101 bool DidFirstRunPref() { return first_run_pref_.GetValue(); }
102
103 private:
104 scoped_ptr<base::RunLoop> run_loop_;
105 TestingPrefServiceSimple local_state_;
106 MessageCenter* message_center_;
107 scoped_ptr<MessageCenterNotificationManager> notification_manager_;
108 MockMessageCenterTrayDelegate* delegate_;
109 content::TestBrowserThreadBundle thread_bundle_;
110 BooleanPrefMember first_run_pref_;
111 };
112
113 TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) {
114 TestingProfile profile;
115 notification_manager()->Add(GetANotification("test"), &profile);
116 EXPECT_FALSE(DidFirstRunPref());
117 }
118
119 TEST_F(MessageCenterNotificationManagerTest, FirstRunShown) {
120 TestingProfile profile;
121 EXPECT_CALL(*delegate(), DidDisplayFirstRunBalloon());
122 notification_manager()->Add(GetANotification("test"), &profile);
123 message_center()->DisplayedNotification("test");
124 message_center()->MarkSinglePopupAsShown("test", false);
125
126 run_loop()->Run();
127 base::RunLoop run_loop_2;
128 run_loop_2.RunUntilIdle();
129 EXPECT_TRUE(DidFirstRunPref());
130 }
131
132 TEST_F(MessageCenterNotificationManagerTest,
133 FirstRunNotShownWithPopupsVisible) {
134 TestingProfile profile;
135 EXPECT_CALL(*delegate(), DidDisplayFirstRunBalloon()).Times(0);
136 notification_manager()->Add(GetANotification("test"), &profile);
137 message_center()->DisplayedNotification("test");
138
139 base::MessageLoop::current()->PostDelayedTask(
140 FROM_HERE,
141 run_loop()->QuitClosure(),
142 TestTimeouts::tiny_timeout() + base::TimeDelta::FromMilliseconds(10));
143 run_loop()->Run();
144 EXPECT_FALSE(DidFirstRunPref());
145 }
146
147 TEST_F(MessageCenterNotificationManagerTest,
148 FirstRunNotShownWithMessageCenter) {
149 TestingProfile profile;
150 EXPECT_CALL(*delegate(), DidDisplayFirstRunBalloon()).Times(0);
151 notification_manager()->Add(GetANotification("test"), &profile);
152 message_center()->SetMessageCenterVisible(true);
153
154 base::MessageLoop::current()->PostDelayedTask(
155 FROM_HERE,
156 run_loop()->QuitClosure(),
157 TestTimeouts::tiny_timeout() + base::TimeDelta::FromMilliseconds(10));
158 run_loop()->Run();
159 EXPECT_FALSE(DidFirstRunPref());
160 }
161
162 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698