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 "ui/message_center/fake_message_center.h"
6
7 #include <utility>
8
9 #include "base/strings/string_util.h"
10 #include "ui/message_center/notification_list.h"
11
12 namespace message_center {
13
FakeMessageCenter()14 FakeMessageCenter::FakeMessageCenter() : notifications_(this) {}
15
16 FakeMessageCenter::~FakeMessageCenter() = default;
17
AddObserver(MessageCenterObserver * observer)18 void FakeMessageCenter::AddObserver(MessageCenterObserver* observer) {
19 observers_.AddObserver(observer);
20 }
21
RemoveObserver(MessageCenterObserver * observer)22 void FakeMessageCenter::RemoveObserver(MessageCenterObserver* observer) {
23 observers_.RemoveObserver(observer);
24 }
25
AddNotificationBlocker(NotificationBlocker * blocker)26 void FakeMessageCenter::AddNotificationBlocker(NotificationBlocker* blocker) {}
27
RemoveNotificationBlocker(NotificationBlocker * blocker)28 void FakeMessageCenter::RemoveNotificationBlocker(
29 NotificationBlocker* blocker) {}
30
NotificationCount() const31 size_t FakeMessageCenter::NotificationCount() const {
32 return 0u;
33 }
34
HasPopupNotifications() const35 bool FakeMessageCenter::HasPopupNotifications() const {
36 return false;
37 }
38
IsQuietMode() const39 bool FakeMessageCenter::IsQuietMode() const {
40 return false;
41 }
42
IsSpokenFeedbackEnabled() const43 bool FakeMessageCenter::IsSpokenFeedbackEnabled() const {
44 return false;
45 }
46
FindVisibleNotificationById(const std::string & id)47 Notification* FakeMessageCenter::FindVisibleNotificationById(
48 const std::string& id) {
49 const auto& notifications = GetVisibleNotifications();
50 for (auto* notification : notifications) {
51 if (notification->id() == id)
52 return notification;
53 }
54
55 return nullptr;
56 }
57
FindNotificationsByAppId(const std::string & app_id)58 NotificationList::Notifications FakeMessageCenter::FindNotificationsByAppId(
59 const std::string& app_id) {
60 return notifications_.GetNotificationsByAppId(app_id);
61 }
62
GetNotifications()63 NotificationList::Notifications FakeMessageCenter::GetNotifications() {
64 return notifications_.GetNotifications();
65 }
66
67 const NotificationList::Notifications&
GetVisibleNotifications()68 FakeMessageCenter::GetVisibleNotifications() {
69 return visible_notifications_;
70 }
71
72 NotificationList::PopupNotifications
GetPopupNotifications()73 FakeMessageCenter::GetPopupNotifications() {
74 return NotificationList::PopupNotifications();
75 }
76
AddNotification(std::unique_ptr<Notification> notification)77 void FakeMessageCenter::AddNotification(
78 std::unique_ptr<Notification> notification) {
79 std::string id = notification->id();
80 notifications_.AddNotification(std::move(notification));
81 visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
82 for (auto& observer : observers_)
83 observer.OnNotificationAdded(id);
84 }
85
UpdateNotification(const std::string & old_id,std::unique_ptr<Notification> new_notification)86 void FakeMessageCenter::UpdateNotification(
87 const std::string& old_id,
88 std::unique_ptr<Notification> new_notification) {
89 std::string new_id = new_notification->id();
90 notifications_.UpdateNotificationMessage(old_id, std::move(new_notification));
91 visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
92 for (auto& observer : observers_) {
93 if (old_id == new_id) {
94 observer.OnNotificationUpdated(old_id);
95 } else {
96 observer.OnNotificationRemoved(old_id, false /* by_user */);
97 observer.OnNotificationAdded(new_id);
98 }
99 }
100 }
101
RemoveNotification(const std::string & id,bool by_user)102 void FakeMessageCenter::RemoveNotification(const std::string& id,
103 bool by_user) {
104 notifications_.RemoveNotification(id);
105 visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
106 for (auto& observer : observers_)
107 observer.OnNotificationRemoved(id, by_user);
108 }
109
RemoveNotificationsForNotifierId(const NotifierId & notifier_id)110 void FakeMessageCenter::RemoveNotificationsForNotifierId(
111 const NotifierId& notifier_id) {}
112
RemoveAllNotifications(bool by_user,RemoveType type)113 void FakeMessageCenter::RemoveAllNotifications(bool by_user, RemoveType type) {}
114
SetNotificationIcon(const std::string & notification_id,const gfx::Image & image)115 void FakeMessageCenter::SetNotificationIcon(const std::string& notification_id,
116 const gfx::Image& image) {}
117
SetNotificationImage(const std::string & notification_id,const gfx::Image & image)118 void FakeMessageCenter::SetNotificationImage(const std::string& notification_id,
119 const gfx::Image& image) {}
120
ClickOnNotification(const std::string & id)121 void FakeMessageCenter::ClickOnNotification(const std::string& id) {}
122
ClickOnNotificationButton(const std::string & id,int button_index)123 void FakeMessageCenter::ClickOnNotificationButton(const std::string& id,
124 int button_index) {}
125
ClickOnNotificationButtonWithReply(const std::string & id,int button_index,const base::string16 & reply)126 void FakeMessageCenter::ClickOnNotificationButtonWithReply(
127 const std::string& id,
128 int button_index,
129 const base::string16& reply) {}
130
ClickOnSettingsButton(const std::string & id)131 void FakeMessageCenter::ClickOnSettingsButton(const std::string& id) {}
132
DisableNotification(const std::string & id)133 void FakeMessageCenter::DisableNotification(const std::string& id) {}
134
MarkSinglePopupAsShown(const std::string & id,bool mark_notification_as_read)135 void FakeMessageCenter::MarkSinglePopupAsShown(const std::string& id,
136 bool mark_notification_as_read) {
137 }
138
DisplayedNotification(const std::string & id,const DisplaySource source)139 void FakeMessageCenter::DisplayedNotification(const std::string& id,
140 const DisplaySource source) {}
141
SetQuietMode(bool in_quiet_mode)142 void FakeMessageCenter::SetQuietMode(bool in_quiet_mode) {}
143
SetSpokenFeedbackEnabled(bool enabled)144 void FakeMessageCenter::SetSpokenFeedbackEnabled(bool enabled) {}
145
EnterQuietModeWithExpire(const base::TimeDelta & expires_in)146 void FakeMessageCenter::EnterQuietModeWithExpire(
147 const base::TimeDelta& expires_in) {}
148
SetVisibility(Visibility visible)149 void FakeMessageCenter::SetVisibility(Visibility visible) {}
150
IsMessageCenterVisible() const151 bool FakeMessageCenter::IsMessageCenterVisible() const {
152 return false;
153 }
154
SetHasMessageCenterView(bool has_message_center_view)155 void FakeMessageCenter::SetHasMessageCenterView(bool has_message_center_view) {
156 has_message_center_view_ = has_message_center_view;
157 }
158
HasMessageCenterView() const159 bool FakeMessageCenter::HasMessageCenterView() const {
160 return has_message_center_view_;
161 }
162
RestartPopupTimers()163 void FakeMessageCenter::RestartPopupTimers() {}
164
PausePopupTimers()165 void FakeMessageCenter::PausePopupTimers() {}
166
GetSystemNotificationAppName() const167 const base::string16& FakeMessageCenter::GetSystemNotificationAppName() const {
168 return base::EmptyString16();
169 }
170
SetSystemNotificationAppName(const base::string16 & product_os_name)171 void FakeMessageCenter::SetSystemNotificationAppName(
172 const base::string16& product_os_name) {}
173
DisableTimersForTest()174 void FakeMessageCenter::DisableTimersForTest() {}
175
176 } // namespace message_center
177