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

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

Issue 1334363002: [Eraser] First pass at removing the notification center panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: peter comments Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/prefs/testing_pref_service.h" 6 #include "base/prefs/testing_pref_service.h"
7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
9 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
10 #include "base/values.h" 9 #include "base/values.h"
11 #include "chrome/browser/notifications/message_center_notification_manager.h" 10 #include "chrome/browser/notifications/message_center_notification_manager.h"
12 #include "chrome/browser/notifications/notification.h" 11 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_test_util.h" 12 #include "chrome/browser/notifications/notification_test_util.h"
14 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/browser_with_test_window_test.h" 14 #include "chrome/test/base/browser_with_test_window_test.h"
16 #include "chrome/test/base/scoped_testing_local_state.h" 15 #include "chrome/test/base/scoped_testing_local_state.h"
17 #include "chrome/test/base/testing_browser_process.h" 16 #include "chrome/test/base/testing_browser_process.h"
18 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
19 #include "chrome/test/base/testing_profile_manager.h" 18 #include "chrome/test/base/testing_profile_manager.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/message_center/fake_message_center_tray_delegate.h" 21 #include "ui/message_center/fake_message_center_tray_delegate.h"
23 #include "ui/message_center/fake_notifier_settings_provider.h"
24 #include "ui/message_center/message_center_impl.h" 22 #include "ui/message_center/message_center_impl.h"
25 #include "ui/message_center/message_center_tray.h" 23 #include "ui/message_center/message_center_tray.h"
26 #include "ui/message_center/message_center_types.h" 24 #include "ui/message_center/message_center_types.h"
27 #include "ui/message_center/notifier_settings.h" 25 #include "ui/message_center/notifier_settings.h"
28 26
29 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
30 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chrom eos.h" 28 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chrom eos.h"
31 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 29 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
32 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 30 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
33 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 31 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
34 #endif 32 #endif
35 33
36 namespace message_center { 34 namespace message_center {
37 35
38 class MessageCenterNotificationManagerTest : public BrowserWithTestWindowTest { 36 class MessageCenterNotificationManagerTest : public BrowserWithTestWindowTest {
39 public: 37 public:
40 MessageCenterNotificationManagerTest() {} 38 MessageCenterNotificationManagerTest() {}
41 39
42 protected: 40 protected:
43 void SetUp() override { 41 void SetUp() override {
44 BrowserWithTestWindowTest::SetUp(); 42 BrowserWithTestWindowTest::SetUp();
45 #if !defined(OS_CHROMEOS) 43 #if !defined(OS_CHROMEOS)
46 // BrowserWithTestWindowTest owns an AshTestHelper on OS_CHROMEOS, which 44 // BrowserWithTestWindowTest owns an AshTestHelper on OS_CHROMEOS, which
47 // in turn initializes the message center. On other platforms, we need to 45 // in turn initializes the message center. On other platforms, we need to
48 // initialize it here. 46 // initialize it here.
49 MessageCenter::Initialize(); 47 MessageCenter::Initialize();
50 #endif 48 #endif
51 49
52 50
53 // Clear the preference and initialize.
54 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); 51 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal();
55 profile_manager_.reset(new TestingProfileManager(browser_process)); 52 profile_manager_.reset(new TestingProfileManager(browser_process));
56 ASSERT_TRUE(profile_manager_->SetUp()); 53 ASSERT_TRUE(profile_manager_->SetUp());
57 local_state()->ClearPref(prefs::kMessageCenterShowedFirstRunBalloon);
58 first_run_pref_.reset(new BooleanPrefMember);
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 54
65 message_center_ = MessageCenter::Get(); 55 message_center_ = MessageCenter::Get();
66 scoped_ptr<NotifierSettingsProvider> settings_provider( 56 delegate_ = new FakeMessageCenterTrayDelegate(message_center_);
67 new FakeNotifierSettingsProvider(notifiers_));
68 delegate_ = new FakeMessageCenterTrayDelegate(message_center_,
69 run_loop_->QuitClosure());
70 notification_manager()->SetMessageCenterTrayDelegateForTest(delegate_); 57 notification_manager()->SetMessageCenterTrayDelegateForTest(delegate_);
71 #if defined(OS_WIN)
72 // First run features are only implemented on Windows, where the
73 // notification center is hard to find.
74 notification_manager()->SetFirstRunTimeoutForTest(
75 TestTimeouts::tiny_timeout());
76 #endif
77 } 58 }
78 59
79 void TearDown() override { 60 void TearDown() override {
80 run_loop_.reset();
81 first_run_pref_.reset();
82 profile_manager_.reset(); 61 profile_manager_.reset();
83 62
84 #if !defined(OS_CHROMEOS) 63 #if !defined(OS_CHROMEOS)
85 // Shutdown the message center if we initialized it manually. 64 // Shutdown the message center if we initialized it manually.
86 MessageCenter::Shutdown(); 65 MessageCenter::Shutdown();
87 #endif 66 #endif
88 67
89 BrowserWithTestWindowTest::TearDown(); 68 BrowserWithTestWindowTest::TearDown();
90 } 69 }
91 70
92 MessageCenterNotificationManager* notification_manager() { 71 MessageCenterNotificationManager* notification_manager() {
93 return (MessageCenterNotificationManager*) 72 return (MessageCenterNotificationManager*)
94 g_browser_process->notification_ui_manager(); 73 g_browser_process->notification_ui_manager();
95 } 74 }
96 75
97 FakeMessageCenterTrayDelegate* delegate() { return delegate_; }
98
99 MessageCenter* message_center() { return message_center_; } 76 MessageCenter* message_center() { return message_center_; }
100 77
101 const ::Notification GetANotification(const std::string& id) { 78 const ::Notification GetANotification(const std::string& id) {
102 return ::Notification( 79 return ::Notification(
103 GURL("chrome-extension://adflkjsdflkdsfdsflkjdsflkdjfs"), 80 GURL("chrome-extension://adflkjsdflkdsfdsflkjdsflkdjfs"),
104 base::string16(), 81 base::string16(),
105 base::string16(), 82 base::string16(),
106 gfx::Image(), 83 gfx::Image(),
107 base::string16(), 84 base::string16(),
108 id, 85 id,
109 new MockNotificationDelegate(id)); 86 new MockNotificationDelegate(id));
110 } 87 }
111 88
112 base::RunLoop* run_loop() { return run_loop_.get(); }
113 PrefService* local_state() {
114 return TestingBrowserProcess::GetGlobal()->local_state();
115 }
116 bool DidFirstRunPref() { return first_run_pref_->GetValue(); }
117
118 private: 89 private:
119 scoped_ptr<TestingProfileManager> profile_manager_; 90 scoped_ptr<TestingProfileManager> profile_manager_;
120 scoped_ptr<base::RunLoop> run_loop_;
121 MessageCenter* message_center_; 91 MessageCenter* message_center_;
122 std::vector<Notifier*> notifiers_;
123 FakeMessageCenterTrayDelegate* delegate_; 92 FakeMessageCenterTrayDelegate* delegate_;
124 scoped_ptr<BooleanPrefMember> first_run_pref_;
125 }; 93 };
126 94
127 TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) { 95 TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) {
128 TestingProfile profile; 96 TestingProfile profile;
129 notification_manager()->Add(GetANotification("test"), &profile); 97 notification_manager()->Add(GetANotification("test"), &profile);
130 EXPECT_FALSE(DidFirstRunPref());
131 } 98 }
132 99
133 TEST_F(MessageCenterNotificationManagerTest, UpdateNotification) { 100 TEST_F(MessageCenterNotificationManagerTest, UpdateNotification) {
134 TestingProfile profile; 101 TestingProfile profile;
135 EXPECT_TRUE(message_center()->NotificationCount() == 0); 102 EXPECT_TRUE(message_center()->NotificationCount() == 0);
136 notification_manager()->Add(GetANotification("test"), &profile); 103 notification_manager()->Add(GetANotification("test"), &profile);
137 EXPECT_TRUE(message_center()->NotificationCount() == 1); 104 EXPECT_TRUE(message_center()->NotificationCount() == 1);
138 ASSERT_TRUE( 105 ASSERT_TRUE(
139 notification_manager()->Update(GetANotification("test"), &profile)); 106 notification_manager()->Update(GetANotification("test"), &profile));
140 EXPECT_TRUE(message_center()->NotificationCount() == 1); 107 EXPECT_TRUE(message_center()->NotificationCount() == 1);
(...skipping 15 matching lines...) Expand all
156 active_user_id)); 123 active_user_id));
157 EXPECT_EQ(0u, message_center()->NotificationCount()); 124 EXPECT_EQ(0u, message_center()->NotificationCount());
158 notification_manager()->Add(GetANotification("test"), &profile); 125 notification_manager()->Add(GetANotification("test"), &profile);
159 EXPECT_EQ(1u, message_center()->NotificationCount()); 126 EXPECT_EQ(1u, message_center()->NotificationCount());
160 notification_manager()->Update(GetANotification("test"), &profile); 127 notification_manager()->Update(GetANotification("test"), &profile);
161 EXPECT_EQ(1u, message_center()->NotificationCount()); 128 EXPECT_EQ(1u, message_center()->NotificationCount());
162 chrome::MultiUserWindowManager::DeleteInstance(); 129 chrome::MultiUserWindowManager::DeleteInstance();
163 } 130 }
164 #endif 131 #endif
165 132
166 #if defined(OS_WIN)
167 // The following tests test the first run balloon, which is only implemented for
168 // Windows.
169 TEST_F(MessageCenterNotificationManagerTest, FirstRunShown) {
170 TestingProfile profile;
171 notification_manager()->Add(GetANotification("test"), &profile);
172 std::string notification_id =
173 notification_manager()
174 ->FindById("test", NotificationUIManager::GetProfileID(&profile))
175 ->id();
176 message_center()->DisplayedNotification(
177 notification_id, message_center::DISPLAY_SOURCE_MESSAGE_CENTER);
178 message_center()->MarkSinglePopupAsShown(notification_id, false);
179
180 run_loop()->Run();
181 base::RunLoop run_loop_2;
182 run_loop_2.RunUntilIdle();
183 EXPECT_TRUE(delegate()->displayed_first_run_balloon());
184 EXPECT_TRUE(DidFirstRunPref());
185 }
186
187 TEST_F(MessageCenterNotificationManagerTest,
188 FirstRunNotShownWithPopupsVisible) {
189 TestingProfile profile;
190 notification_manager()->Add(GetANotification("test"), &profile);
191 std::string notification_id =
192 notification_manager()
193 ->FindById("test", NotificationUIManager::GetProfileID(&profile))
194 ->id();
195 message_center()->DisplayedNotification(
196 notification_id, message_center::DISPLAY_SOURCE_MESSAGE_CENTER);
197 run_loop()->RunUntilIdle();
198 EXPECT_FALSE(delegate()->displayed_first_run_balloon());
199 EXPECT_FALSE(notification_manager()->FirstRunTimerIsActive());
200 EXPECT_FALSE(DidFirstRunPref());
201 }
202
203 TEST_F(MessageCenterNotificationManagerTest,
204 FirstRunNotShownWithMessageCenter) {
205 TestingProfile profile;
206 notification_manager()->Add(GetANotification("test"), &profile);
207 message_center()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
208 run_loop()->RunUntilIdle();
209 EXPECT_FALSE(notification_manager()->FirstRunTimerIsActive());
210 EXPECT_FALSE(DidFirstRunPref());
211 }
212
213 #endif
214 } // namespace message_center 133 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698