1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/fake_notifier_settings_provider.h"
#include "ui/message_center/views/notifier_settings_view.h"
namespace message_center {
namespace {
Notifier* NewNotifier(const std::string& id,
const std::string& title,
bool enabled) {
NotifierId notifier_id(NotifierId::APPLICATION, id);
return new Notifier(notifier_id, base::UTF8ToUTF16(title), enabled);
}
// A class used by NotifierSettingsView to integrate with a setting system
// for the clients of this module.
class TestingNotifierSettingsProvider
: public FakeNotifierSettingsProvider {
public:
TestingNotifierSettingsProvider(const std::vector<Notifier*>& notifiers,
const NotifierId& settings_handler_id)
: FakeNotifierSettingsProvider(notifiers),
settings_handler_id_(settings_handler_id),
request_count_(0u) {}
~TestingNotifierSettingsProvider() override {}
bool NotifierHasAdvancedSettings(
const NotifierId& notifier_id) const override {
return notifier_id == settings_handler_id_;
}
void OnNotifierAdvancedSettingsRequested(
const NotifierId& notifier_id,
const std::string* notification_id) override {
request_count_++;
last_notifier_id_settings_requested_.reset(new NotifierId(notifier_id));
}
size_t request_count() const { return request_count_; }
const NotifierId* last_requested_notifier_id() const {
return last_notifier_id_settings_requested_.get();
}
private:
NotifierId settings_handler_id_;
size_t request_count_;
scoped_ptr<NotifierId> last_notifier_id_settings_requested_;
};
} // namespace
class NotifierSettingsViewTest : public testing::Test {
public:
NotifierSettingsViewTest();
~NotifierSettingsViewTest() override;
void SetUp() override;
void TearDown() override;
NotifierSettingsView* GetView() const;
TestingNotifierSettingsProvider* settings_provider() const {
return settings_provider_.get();
}
private:
scoped_ptr<TestingNotifierSettingsProvider> settings_provider_;
scoped_ptr<NotifierSettingsView> notifier_settings_view_;
DISALLOW_COPY_AND_ASSIGN(NotifierSettingsViewTest);
};
NotifierSettingsViewTest::NotifierSettingsViewTest() {}
NotifierSettingsViewTest::~NotifierSettingsViewTest() {}
void NotifierSettingsViewTest::SetUp() {
std::vector<Notifier*> notifiers;
notifiers.push_back(NewNotifier("id", "title", /*enabled=*/true));
notifiers.push_back(NewNotifier("id2", "other title", /*enabled=*/false));
settings_provider_.reset(new TestingNotifierSettingsProvider(
notifiers, NotifierId(NotifierId::APPLICATION, "id")));
notifier_settings_view_.reset(
new NotifierSettingsView(settings_provider_.get()));
}
void NotifierSettingsViewTest::TearDown() {
notifier_settings_view_.reset();
settings_provider_.reset();
}
NotifierSettingsView* NotifierSettingsViewTest::GetView() const {
return notifier_settings_view_.get();
}
TEST_F(NotifierSettingsViewTest, TestLearnMoreButton) {
const std::set<NotifierSettingsView::NotifierButton*> buttons =
GetView()->buttons_;
EXPECT_EQ(2u, buttons.size());
size_t number_of_settings_buttons = 0;
std::set<NotifierSettingsView::NotifierButton*>::iterator iter =
buttons.begin();
for (; iter != buttons.end(); ++iter) {
if ((*iter)->has_learn_more()) {
++number_of_settings_buttons;
(*iter)->SendLearnMorePressedForTest();
}
}
EXPECT_EQ(1u, number_of_settings_buttons);
EXPECT_EQ(1u, settings_provider()->request_count());
const NotifierId* last_settings_button_id =
settings_provider()->last_requested_notifier_id();
ASSERT_FALSE(last_settings_button_id == NULL);
EXPECT_EQ(NotifierId(NotifierId::APPLICATION, "id"),
*last_settings_button_id);
}
} // namespace message_center
|