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
~FakeMessageCenter()16 FakeMessageCenter::~FakeMessageCenter() {}
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
63 const NotificationList::Notifications&
GetVisibleNotifications()64 FakeMessageCenter::GetVisibleNotifications() {
65 return visible_notifications_;
66 }
67
68 NotificationList::PopupNotifications
GetPopupNotifications()69 FakeMessageCenter::GetPopupNotifications() {
70 return NotificationList::PopupNotifications();
71 }
72
AddNotification(std::unique_ptr<Notification> notification)73 void FakeMessageCenter::AddNotification(
74 std::unique_ptr<Notification> notification) {
75 std::string id = notification->id();
76 notifications_.AddNotification(std::move(notification));
77 visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
78 for (auto& observer : observers_)
79 observer.OnNotificationAdded(id);
80 }
81
UpdateNotification(const std::string & old_id,std::unique_ptr<Notification> new_notification)82 void FakeMessageCenter::UpdateNotification(
83 const std::string& old_id,
84 std::unique_ptr<Notification> new_notification) {
85 std::string new_id = new_notification->id();
86 notifications_.UpdateNotificationMessage(old_id, std::move(new_notification));
87 visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
88 for (auto& observer : observers_) {
89 if (old_id == new_id) {
90 observer.OnNotificationUpdated(old_id);
91 } else {
92 observer.OnNotificationRemoved(old_id, false /* by_user */);
93 observer.OnNotificationAdded(new_id);
94 }
95 }
96 }
97
RemoveNotification(const std::string & id,bool by_user)98 void FakeMessageCenter::RemoveNotification(const std::string& id,
99 bool by_user) {
100 notifications_.RemoveNotification(id);
101 visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
102 for (auto& observer : observers_)
103 observer.OnNotificationRemoved(id, by_user);
104 }
105
RemoveNotificationsForNotifierId(const NotifierId & notifier_id)106 void FakeMessageCenter::RemoveNotificationsForNotifierId(
107 const NotifierId& notifier_id) {}
108
RemoveAllNotifications(bool by_user,RemoveType type)109 void FakeMessageCenter::RemoveAllNotifications(bool by_user, RemoveType type) {}
110
SetNotificationIcon(const std::string & notification_id,const gfx::Image & image)111 void FakeMessageCenter::SetNotificationIcon(const std::string& notification_id,
112 const gfx::Image& image) {}
113
SetNotificationImage(const std::string & notification_id,const gfx::Image & image)114 void FakeMessageCenter::SetNotificationImage(const std::string& notification_id,
115 const gfx::Image& image) {}
116
ClickOnNotification(const std::string & id)117 void FakeMessageCenter::ClickOnNotification(const std::string& id) {}
118
ClickOnNotificationButton(const std::string & id,int button_index)119 void FakeMessageCenter::ClickOnNotificationButton(const std::string& id,
120 int button_index) {}
121
ClickOnNotificationButtonWithReply(const std::string & id,int button_index,const base::string16 & reply)122 void FakeMessageCenter::ClickOnNotificationButtonWithReply(
123 const std::string& id,
124 int button_index,
125 const base::string16& reply) {}
126
ClickOnSettingsButton(const std::string & id)127 void FakeMessageCenter::ClickOnSettingsButton(const std::string& id) {}
128
DisableNotification(const std::string & id)129 void FakeMessageCenter::DisableNotification(const std::string& id) {}
130
MarkSinglePopupAsShown(const std::string & id,bool mark_notification_as_read)131 void FakeMessageCenter::MarkSinglePopupAsShown(const std::string& id,
132 bool mark_notification_as_read) {
133 }
134
DisplayedNotification(const std::string & id,const DisplaySource source)135 void FakeMessageCenter::DisplayedNotification(const std::string& id,
136 const DisplaySource source) {}
137
SetQuietMode(bool in_quiet_mode)138 void FakeMessageCenter::SetQuietMode(bool in_quiet_mode) {}
139
SetSpokenFeedbackEnabled(bool enabled)140 void FakeMessageCenter::SetSpokenFeedbackEnabled(bool enabled) {}
141
EnterQuietModeWithExpire(const base::TimeDelta & expires_in)142 void FakeMessageCenter::EnterQuietModeWithExpire(
143 const base::TimeDelta& expires_in) {}
144
SetVisibility(Visibility visible)145 void FakeMessageCenter::SetVisibility(Visibility visible) {}
146
IsMessageCenterVisible() const147 bool FakeMessageCenter::IsMessageCenterVisible() const {
148 return false;
149 }
150
SetHasMessageCenterView(bool has_message_center_view)151 void FakeMessageCenter::SetHasMessageCenterView(bool has_message_center_view) {
152 has_message_center_view_ = has_message_center_view;
153 }
154
HasMessageCenterView() const155 bool FakeMessageCenter::HasMessageCenterView() const {
156 return has_message_center_view_;
157 }
158
RestartPopupTimers()159 void FakeMessageCenter::RestartPopupTimers() {}
160
PausePopupTimers()161 void FakeMessageCenter::PausePopupTimers() {}
162
GetSystemNotificationAppName() const163 const base::string16& FakeMessageCenter::GetSystemNotificationAppName() const {
164 return base::EmptyString16();
165 }
166
SetSystemNotificationAppName(const base::string16 & product_os_name)167 void FakeMessageCenter::SetSystemNotificationAppName(
168 const base::string16& product_os_name) {}
169
DisableTimersForTest()170 void FakeMessageCenter::DisableTimersForTest() {}
171
172 } // namespace message_center
173