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 "ui/message_center/message_center_impl.h" | 5 #include "ui/message_center/message_center_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
14 #include "ui/message_center/message_center.h" | 14 #include "ui/message_center/message_center.h" |
15 #include "ui/message_center/message_center_types.h" | 15 #include "ui/message_center/message_center_types.h" |
16 #include "ui/message_center/notification_blocker.h" | 16 #include "ui/message_center/notification_blocker.h" |
17 #include "ui/message_center/notification_types.h" | 17 #include "ui/message_center/notification_types.h" |
18 #include "ui/message_center/notifier_settings.h" | 18 #include "ui/message_center/notifier_settings.h" |
19 | 19 |
20 using base::UTF8ToUTF16; | 20 using base::UTF8ToUTF16; |
21 | 21 |
22 namespace message_center { | 22 namespace message_center { |
23 namespace { | 23 namespace { |
24 | 24 |
25 class MessageCenterImplTest : public testing::Test, | 25 class MessageCenterImplTest : public testing::Test, |
26 public MessageCenterObserver { | 26 public MessageCenterObserver { |
27 public: | 27 public: |
28 MessageCenterImplTest() {} | 28 MessageCenterImplTest() {} |
29 | 29 |
30 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() override { |
31 MessageCenter::Initialize(); | 31 MessageCenter::Initialize(); |
32 message_center_ = MessageCenter::Get(); | 32 message_center_ = MessageCenter::Get(); |
33 loop_.reset(new base::MessageLoop); | 33 loop_.reset(new base::MessageLoop); |
34 run_loop_.reset(new base::RunLoop()); | 34 run_loop_.reset(new base::RunLoop()); |
35 closure_ = run_loop_->QuitClosure(); | 35 closure_ = run_loop_->QuitClosure(); |
36 } | 36 } |
37 | 37 |
38 virtual void TearDown() OVERRIDE { | 38 virtual void TearDown() override { |
39 run_loop_.reset(); | 39 run_loop_.reset(); |
40 loop_.reset(); | 40 loop_.reset(); |
41 message_center_ = NULL; | 41 message_center_ = NULL; |
42 MessageCenter::Shutdown(); | 42 MessageCenter::Shutdown(); |
43 } | 43 } |
44 | 44 |
45 MessageCenter* message_center() const { return message_center_; } | 45 MessageCenter* message_center() const { return message_center_; } |
46 NotifierSettingsObserver* notifier_settings_observer() const { | 46 NotifierSettingsObserver* notifier_settings_observer() const { |
47 return static_cast<NotifierSettingsObserver*>(message_center_impl()); | 47 return static_cast<NotifierSettingsObserver*>(message_center_impl()); |
48 } | 48 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 void SetNotificationsEnabled(bool enabled) { | 112 void SetNotificationsEnabled(bool enabled) { |
113 if (notifications_enabled_ != enabled) { | 113 if (notifications_enabled_ != enabled) { |
114 notifications_enabled_ = enabled; | 114 notifications_enabled_ = enabled; |
115 NotifyBlockingStateChanged(); | 115 NotifyBlockingStateChanged(); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 // NotificationBlocker overrides: | 119 // NotificationBlocker overrides: |
120 virtual bool ShouldShowNotificationAsPopup( | 120 virtual bool ShouldShowNotificationAsPopup( |
121 const message_center::NotifierId& notifier_id) const OVERRIDE { | 121 const message_center::NotifierId& notifier_id) const override { |
122 return notifications_enabled_; | 122 return notifications_enabled_; |
123 } | 123 } |
124 | 124 |
125 private: | 125 private: |
126 bool notifications_enabled_; | 126 bool notifications_enabled_; |
127 | 127 |
128 DISALLOW_COPY_AND_ASSIGN(ToggledNotificationBlocker); | 128 DISALLOW_COPY_AND_ASSIGN(ToggledNotificationBlocker); |
129 }; | 129 }; |
130 | 130 |
131 class PopupNotificationBlocker : public ToggledNotificationBlocker { | 131 class PopupNotificationBlocker : public ToggledNotificationBlocker { |
132 public: | 132 public: |
133 PopupNotificationBlocker(MessageCenter* message_center, | 133 PopupNotificationBlocker(MessageCenter* message_center, |
134 const NotifierId& allowed_notifier) | 134 const NotifierId& allowed_notifier) |
135 : ToggledNotificationBlocker(message_center), | 135 : ToggledNotificationBlocker(message_center), |
136 allowed_notifier_(allowed_notifier) {} | 136 allowed_notifier_(allowed_notifier) {} |
137 virtual ~PopupNotificationBlocker() {} | 137 virtual ~PopupNotificationBlocker() {} |
138 | 138 |
139 // NotificationBlocker overrides: | 139 // NotificationBlocker overrides: |
140 virtual bool ShouldShowNotificationAsPopup( | 140 virtual bool ShouldShowNotificationAsPopup( |
141 const NotifierId& notifier_id) const OVERRIDE { | 141 const NotifierId& notifier_id) const override { |
142 return (notifier_id == allowed_notifier_) || | 142 return (notifier_id == allowed_notifier_) || |
143 ToggledNotificationBlocker::ShouldShowNotificationAsPopup(notifier_id); | 143 ToggledNotificationBlocker::ShouldShowNotificationAsPopup(notifier_id); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 NotifierId allowed_notifier_; | 147 NotifierId allowed_notifier_; |
148 | 148 |
149 DISALLOW_COPY_AND_ASSIGN(PopupNotificationBlocker); | 149 DISALLOW_COPY_AND_ASSIGN(PopupNotificationBlocker); |
150 }; | 150 }; |
151 | 151 |
152 class TotalNotificationBlocker : public PopupNotificationBlocker { | 152 class TotalNotificationBlocker : public PopupNotificationBlocker { |
153 public: | 153 public: |
154 TotalNotificationBlocker(MessageCenter* message_center, | 154 TotalNotificationBlocker(MessageCenter* message_center, |
155 const NotifierId& allowed_notifier) | 155 const NotifierId& allowed_notifier) |
156 : PopupNotificationBlocker(message_center, allowed_notifier) {} | 156 : PopupNotificationBlocker(message_center, allowed_notifier) {} |
157 virtual ~TotalNotificationBlocker() {} | 157 virtual ~TotalNotificationBlocker() {} |
158 | 158 |
159 // NotificationBlocker overrides: | 159 // NotificationBlocker overrides: |
160 virtual bool ShouldShowNotification( | 160 virtual bool ShouldShowNotification( |
161 const NotifierId& notifier_id) const OVERRIDE { | 161 const NotifierId& notifier_id) const override { |
162 return ShouldShowNotificationAsPopup(notifier_id); | 162 return ShouldShowNotificationAsPopup(notifier_id); |
163 } | 163 } |
164 | 164 |
165 private: | 165 private: |
166 DISALLOW_COPY_AND_ASSIGN(TotalNotificationBlocker); | 166 DISALLOW_COPY_AND_ASSIGN(TotalNotificationBlocker); |
167 }; | 167 }; |
168 | 168 |
169 bool PopupNotificationsContain( | 169 bool PopupNotificationsContain( |
170 const NotificationList::PopupNotifications& popups, | 170 const NotificationList::PopupNotifications& popups, |
171 const std::string& id) { | 171 const std::string& id) { |
(...skipping 23 matching lines...) Expand all Loading... |
195 | 195 |
196 class MockPopupTimersController : public PopupTimersController { | 196 class MockPopupTimersController : public PopupTimersController { |
197 public: | 197 public: |
198 MockPopupTimersController(MessageCenter* message_center, | 198 MockPopupTimersController(MessageCenter* message_center, |
199 base::Closure quit_closure) | 199 base::Closure quit_closure) |
200 : PopupTimersController(message_center), | 200 : PopupTimersController(message_center), |
201 timer_finished_(false), | 201 timer_finished_(false), |
202 quit_closure_(quit_closure) {} | 202 quit_closure_(quit_closure) {} |
203 virtual ~MockPopupTimersController() {} | 203 virtual ~MockPopupTimersController() {} |
204 | 204 |
205 virtual void TimerFinished(const std::string& id) OVERRIDE { | 205 virtual void TimerFinished(const std::string& id) override { |
206 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); | 206 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); |
207 timer_finished_ = true; | 207 timer_finished_ = true; |
208 last_id_ = id; | 208 last_id_ = id; |
209 } | 209 } |
210 | 210 |
211 bool timer_finished() const { return timer_finished_; } | 211 bool timer_finished() const { return timer_finished_; } |
212 const std::string& last_id() const { return last_id_; } | 212 const std::string& last_id() const { return last_id_; } |
213 | 213 |
214 private: | 214 private: |
215 bool timer_finished_; | 215 bool timer_finished_; |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 ASSERT_EQ(3u, message_center()->NotificationCount()); | 862 ASSERT_EQ(3u, message_center()->NotificationCount()); |
863 | 863 |
864 // Now we remove the remaining notifications. | 864 // Now we remove the remaining notifications. |
865 notifier_settings_observer()->NotifierEnabledChanged( | 865 notifier_settings_observer()->NotifierEnabledChanged( |
866 NotifierId(NotifierId::APPLICATION, "app1"), false); | 866 NotifierId(NotifierId::APPLICATION, "app1"), false); |
867 ASSERT_EQ(0u, message_center()->NotificationCount()); | 867 ASSERT_EQ(0u, message_center()->NotificationCount()); |
868 } | 868 } |
869 | 869 |
870 } // namespace internal | 870 } // namespace internal |
871 } // namespace message_center | 871 } // namespace message_center |
OLD | NEW |