OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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" | 7 #include "base/run_loop.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/notifications/message_center_notification_manager.h" | 10 #include "chrome/browser/notifications/message_center_notification_manager.h" |
11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
12 #include "chrome/browser/notifications/notification_prefs_manager.h" | 12 #include "chrome/browser/notifications/notification_prefs_manager.h" |
13 #include "chrome/browser/notifications/notification_test_util.h" | 13 #include "chrome/browser/notifications/notification_test_util.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/scoped_testing_local_state.h" | 15 #include "chrome/test/base/scoped_testing_local_state.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/message_center/fake_notifier_settings_provider.h" |
20 #include "ui/message_center/message_center_impl.h" | 21 #include "ui/message_center/message_center_impl.h" |
21 #include "ui/message_center/message_center_tray.h" | 22 #include "ui/message_center/message_center_tray.h" |
22 #include "ui/message_center/message_center_tray_delegate.h" | 23 #include "ui/message_center/message_center_tray_delegate.h" |
| 24 #include "ui/message_center/notifier_settings.h" |
23 | 25 |
24 namespace message_center { | 26 namespace message_center { |
25 class FakeMessageCenterTrayDelegate : public MessageCenterTrayDelegate { | 27 class FakeMessageCenterTrayDelegate : public MessageCenterTrayDelegate { |
26 public: | 28 public: |
27 FakeMessageCenterTrayDelegate(MessageCenter* message_center, | 29 FakeMessageCenterTrayDelegate(MessageCenter* message_center, |
28 base::Closure quit_closure) | 30 base::Closure quit_closure) |
29 : tray_(this, message_center), | 31 : tray_(this, message_center), |
30 quit_closure_(quit_closure), | 32 quit_closure_(quit_closure), |
31 displayed_first_run_balloon_(false) {} | 33 displayed_first_run_balloon_(false) {} |
32 | 34 |
(...skipping 29 matching lines...) Expand all Loading... |
62 local_state_.ClearPref(prefs::kMessageCenterShowedFirstRunBalloon); | 64 local_state_.ClearPref(prefs::kMessageCenterShowedFirstRunBalloon); |
63 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, | 65 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, |
64 &local_state_); | 66 &local_state_); |
65 | 67 |
66 // Get ourselves a run loop. | 68 // Get ourselves a run loop. |
67 run_loop_.reset(new base::RunLoop()); | 69 run_loop_.reset(new base::RunLoop()); |
68 | 70 |
69 // Initialize message center infrastructure with mock tray delegate. | 71 // Initialize message center infrastructure with mock tray delegate. |
70 MessageCenter::Initialize(); | 72 MessageCenter::Initialize(); |
71 message_center_ = MessageCenter::Get(); | 73 message_center_ = MessageCenter::Get(); |
72 notification_manager_.reset( | 74 scoped_ptr<NotifierSettingsProvider> settings_provider( |
73 new MessageCenterNotificationManager(message_center_, &local_state_)); | 75 new FakeNotifierSettingsProvider(notifiers_)); |
| 76 notification_manager_.reset(new MessageCenterNotificationManager( |
| 77 message_center_, &local_state_, settings_provider.Pass())); |
74 delegate_ = new FakeMessageCenterTrayDelegate(message_center_, | 78 delegate_ = new FakeMessageCenterTrayDelegate(message_center_, |
75 run_loop_->QuitClosure()); | 79 run_loop_->QuitClosure()); |
76 notification_manager_->SetMessageCenterTrayDelegateForTest(delegate_); | 80 notification_manager_->SetMessageCenterTrayDelegateForTest(delegate_); |
77 notification_manager_->SetFirstRunTimeoutForTest( | 81 notification_manager_->SetFirstRunTimeoutForTest( |
78 TestTimeouts::tiny_timeout()); | 82 TestTimeouts::tiny_timeout()); |
79 } | 83 } |
80 | 84 |
81 virtual void TearDown() { | 85 virtual void TearDown() { |
82 run_loop_.reset(); | 86 run_loop_.reset(); |
83 notification_manager_.reset(); | 87 notification_manager_.reset(); |
(...skipping 17 matching lines...) Expand all Loading... |
101 } | 105 } |
102 | 106 |
103 base::RunLoop* run_loop() { return run_loop_.get(); } | 107 base::RunLoop* run_loop() { return run_loop_.get(); } |
104 const TestingPrefServiceSimple& local_state() { return local_state_; } | 108 const TestingPrefServiceSimple& local_state() { return local_state_; } |
105 bool DidFirstRunPref() { return first_run_pref_.GetValue(); } | 109 bool DidFirstRunPref() { return first_run_pref_.GetValue(); } |
106 | 110 |
107 private: | 111 private: |
108 scoped_ptr<base::RunLoop> run_loop_; | 112 scoped_ptr<base::RunLoop> run_loop_; |
109 TestingPrefServiceSimple local_state_; | 113 TestingPrefServiceSimple local_state_; |
110 MessageCenter* message_center_; | 114 MessageCenter* message_center_; |
| 115 std::vector<Notifier*> notifiers_; |
111 scoped_ptr<MessageCenterNotificationManager> notification_manager_; | 116 scoped_ptr<MessageCenterNotificationManager> notification_manager_; |
112 FakeMessageCenterTrayDelegate* delegate_; | 117 FakeMessageCenterTrayDelegate* delegate_; |
113 content::TestBrowserThreadBundle thread_bundle_; | 118 content::TestBrowserThreadBundle thread_bundle_; |
114 BooleanPrefMember first_run_pref_; | 119 BooleanPrefMember first_run_pref_; |
115 }; | 120 }; |
116 | 121 |
117 TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) { | 122 TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) { |
118 TestingProfile profile; | 123 TestingProfile profile; |
119 notification_manager()->Add(GetANotification("test"), &profile); | 124 notification_manager()->Add(GetANotification("test"), &profile); |
120 EXPECT_FALSE(DidFirstRunPref()); | 125 EXPECT_FALSE(DidFirstRunPref()); |
(...skipping 28 matching lines...) Expand all Loading... |
149 TEST_F(MessageCenterNotificationManagerTest, | 154 TEST_F(MessageCenterNotificationManagerTest, |
150 FirstRunNotShownWithMessageCenter) { | 155 FirstRunNotShownWithMessageCenter) { |
151 TestingProfile profile; | 156 TestingProfile profile; |
152 notification_manager()->Add(GetANotification("test"), &profile); | 157 notification_manager()->Add(GetANotification("test"), &profile); |
153 message_center()->SetMessageCenterVisible(true); | 158 message_center()->SetMessageCenterVisible(true); |
154 run_loop()->RunUntilIdle(); | 159 run_loop()->RunUntilIdle(); |
155 EXPECT_FALSE(notification_manager()->FirstRunTimerIsActive()); | 160 EXPECT_FALSE(notification_manager()->FirstRunTimerIsActive()); |
156 EXPECT_FALSE(DidFirstRunPref()); | 161 EXPECT_FALSE(DidFirstRunPref()); |
157 } | 162 } |
158 } // namespace message_center | 163 } // namespace message_center |
OLD | NEW |