Home | History | Annotate | Download | only in message_center
      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 
     12 FakeNotifierSettingsProvider::NotifierGroupItem::NotifierGroupItem() {
     13 }
     14 
     15 FakeNotifierSettingsProvider::NotifierGroupItem::~NotifierGroupItem() {
     16 }
     17 
     18 FakeNotifierSettingsProvider::FakeNotifierSettingsProvider()
     19     : closed_called_count_(0),
     20       active_item_index_(0),
     21       notifier_settings_requested_count_(0u) { }
     22 
     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                                  UTF8ToUTF16("Fake name"),
     31                                  UTF8ToUTF16("fake (at) email.com"),
     32                                  true);
     33   item.notifiers = notifiers;
     34   items_.push_back(item);
     35 }
     36 
     37 FakeNotifierSettingsProvider::~FakeNotifierSettingsProvider() {
     38   for (size_t i = 0; i < items_.size(); ++i) {
     39     delete items_[i].group;
     40   }
     41 }
     42 
     43 size_t FakeNotifierSettingsProvider::GetNotifierGroupCount() const {
     44   return items_.size();
     45 }
     46 
     47 const message_center::NotifierGroup&
     48 FakeNotifierSettingsProvider::GetNotifierGroupAt(size_t index) const {
     49   return *(items_[index].group);
     50 }
     51 
     52 bool FakeNotifierSettingsProvider::IsNotifierGroupActiveAt(
     53     size_t index) const {
     54   return active_item_index_ == index;
     55 }
     56 
     57 void FakeNotifierSettingsProvider::SwitchToNotifierGroup(size_t index) {
     58   active_item_index_ = index;
     59 }
     60 
     61 const message_center::NotifierGroup&
     62 FakeNotifierSettingsProvider::GetActiveNotifierGroup() const {
     63   return *(items_[active_item_index_].group);
     64 }
     65 
     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 
     73 void FakeNotifierSettingsProvider::SetNotifierEnabled(const Notifier& notifier,
     74                                                       bool enabled) {
     75   enabled_[&notifier] = enabled;
     76 }
     77 
     78 void FakeNotifierSettingsProvider::OnNotifierSettingsClosing() {
     79   closed_called_count_++;
     80 }
     81 
     82 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 
     89 void FakeNotifierSettingsProvider::OnNotifierAdvancedSettingsRequested(
     90     const NotifierId& notifier_id,
     91     const std::string* notification_id) {
     92   notifier_settings_requested_count_++;
     93 }
     94 
     95 void FakeNotifierSettingsProvider::AddObserver(
     96     NotifierSettingsObserver* observer) {
     97 }
     98 
     99 void FakeNotifierSettingsProvider::RemoveObserver(
    100     NotifierSettingsObserver* observer) {
    101 }
    102 
    103 bool FakeNotifierSettingsProvider::WasEnabled(const Notifier& notifier) {
    104   return enabled_[&notifier];
    105 }
    106 
    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 
    115 void FakeNotifierSettingsProvider::SetNotifierHasAdvancedSettings(
    116     const NotifierId& notifier_id) {
    117   notifier_id_with_settings_handler_.reset(new NotifierId(notifier_id));
    118 }
    119 
    120 int FakeNotifierSettingsProvider::closed_called_count() {
    121   return closed_called_count_;
    122 }
    123 
    124 size_t FakeNotifierSettingsProvider::settings_requested_count() const {
    125   return notifier_settings_requested_count_;
    126 }
    127 
    128 }  // namespace message_center
    129