1 // Copyright (c) 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_notifier_settings_provider.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/gfx/image/image.h"
9
10 namespace message_center {
11
NotifierGroupItem()12 FakeNotifierSettingsProvider::NotifierGroupItem::NotifierGroupItem() {
13 }
14
~NotifierGroupItem()15 FakeNotifierSettingsProvider::NotifierGroupItem::~NotifierGroupItem() {
16 }
17
FakeNotifierSettingsProvider()18 FakeNotifierSettingsProvider::FakeNotifierSettingsProvider()
19 : closed_called_count_(0),
20 active_item_index_(0),
21 notifier_settings_requested_count_(0u) { }
22
FakeNotifierSettingsProvider(const std::vector<Notifier * > & notifiers)23 FakeNotifierSettingsProvider::FakeNotifierSettingsProvider(
24 const std::vector<Notifier*>& notifiers)
25 : closed_called_count_(0),
26 active_item_index_(0),
27 notifier_settings_requested_count_(0u) {
28 NotifierGroupItem item;
29 item.group = new NotifierGroup(gfx::Image(),
30 base::UTF8ToUTF16("Fake name"),
31 base::UTF8ToUTF16("fake@email.com"),
32 true);
33 item.notifiers = notifiers;
34 items_.push_back(item);
35 }
36
~FakeNotifierSettingsProvider()37 FakeNotifierSettingsProvider::~FakeNotifierSettingsProvider() {
38 for (size_t i = 0; i < items_.size(); ++i) {
39 delete items_[i].group;
40 }
41 }
42
GetNotifierGroupCount() const43 size_t FakeNotifierSettingsProvider::GetNotifierGroupCount() const {
44 return items_.size();
45 }
46
47 const message_center::NotifierGroup&
GetNotifierGroupAt(size_t index) const48 FakeNotifierSettingsProvider::GetNotifierGroupAt(size_t index) const {
49 return *(items_[index].group);
50 }
51
IsNotifierGroupActiveAt(size_t index) const52 bool FakeNotifierSettingsProvider::IsNotifierGroupActiveAt(
53 size_t index) const {
54 return active_item_index_ == index;
55 }
56
SwitchToNotifierGroup(size_t index)57 void FakeNotifierSettingsProvider::SwitchToNotifierGroup(size_t index) {
58 active_item_index_ = index;
59 }
60
61 const message_center::NotifierGroup&
GetActiveNotifierGroup() const62 FakeNotifierSettingsProvider::GetActiveNotifierGroup() const {
63 return *(items_[active_item_index_].group);
64 }
65
GetNotifierList(std::vector<Notifier * > * notifiers)66 void FakeNotifierSettingsProvider::GetNotifierList(
67 std::vector<Notifier*>* notifiers) {
68 notifiers->clear();
69 for (size_t i = 0; i < items_[active_item_index_].notifiers.size(); ++i)
70 notifiers->push_back(items_[active_item_index_].notifiers[i]);
71 }
72
SetNotifierEnabled(const Notifier & notifier,bool enabled)73 void FakeNotifierSettingsProvider::SetNotifierEnabled(const Notifier& notifier,
74 bool enabled) {
75 enabled_[¬ifier] = enabled;
76 }
77
OnNotifierSettingsClosing()78 void FakeNotifierSettingsProvider::OnNotifierSettingsClosing() {
79 closed_called_count_++;
80 }
81
NotifierHasAdvancedSettings(const message_center::NotifierId & notifier_id) const82 bool FakeNotifierSettingsProvider::NotifierHasAdvancedSettings(
83 const message_center::NotifierId& notifier_id) const {
84 if (!notifier_id_with_settings_handler_)
85 return false;
86 return *notifier_id_with_settings_handler_ == notifier_id;
87 }
88
OnNotifierAdvancedSettingsRequested(const NotifierId & notifier_id,const std::string * notification_id)89 void FakeNotifierSettingsProvider::OnNotifierAdvancedSettingsRequested(
90 const NotifierId& notifier_id,
91 const std::string* notification_id) {
92 notifier_settings_requested_count_++;
93 }
94
AddObserver(NotifierSettingsObserver * observer)95 void FakeNotifierSettingsProvider::AddObserver(
96 NotifierSettingsObserver* observer) {
97 }
98
RemoveObserver(NotifierSettingsObserver * observer)99 void FakeNotifierSettingsProvider::RemoveObserver(
100 NotifierSettingsObserver* observer) {
101 }
102
WasEnabled(const Notifier & notifier)103 bool FakeNotifierSettingsProvider::WasEnabled(const Notifier& notifier) {
104 return enabled_[¬ifier];
105 }
106
AddGroup(NotifierGroup * group,const std::vector<Notifier * > & notifiers)107 void FakeNotifierSettingsProvider::AddGroup(
108 NotifierGroup* group, const std::vector<Notifier*>& notifiers) {
109 NotifierGroupItem item;
110 item.group = group;
111 item.notifiers = notifiers;
112 items_.push_back(item);
113 }
114
SetNotifierHasAdvancedSettings(const NotifierId & notifier_id)115 void FakeNotifierSettingsProvider::SetNotifierHasAdvancedSettings(
116 const NotifierId& notifier_id) {
117 notifier_id_with_settings_handler_.reset(new NotifierId(notifier_id));
118 }
119
closed_called_count()120 int FakeNotifierSettingsProvider::closed_called_count() {
121 return closed_called_count_;
122 }
123
settings_requested_count() const124 size_t FakeNotifierSettingsProvider::settings_requested_count() const {
125 return notifier_settings_requested_count_;
126 }
127
128 } // namespace message_center
129