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.
5 #include "base/strings/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/message_center/fake_notifier_settings_provider.h"
8 #include "ui/message_center/views/notifier_settings_view.h"
10 namespace message_center
{
14 Notifier
* NewNotifier(const std::string
& id
,
15 const std::string
& title
,
17 NotifierId
notifier_id(NotifierId::APPLICATION
, id
);
18 return new Notifier(notifier_id
, base::UTF8ToUTF16(title
), enabled
);
21 // A class used by NotifierSettingsView to integrate with a setting system
22 // for the clients of this module.
23 class TestingNotifierSettingsProvider
24 : public FakeNotifierSettingsProvider
{
26 TestingNotifierSettingsProvider(const std::vector
<Notifier
*>& notifiers
,
27 const NotifierId
& settings_handler_id
)
28 : FakeNotifierSettingsProvider(notifiers
),
29 settings_handler_id_(settings_handler_id
),
31 ~TestingNotifierSettingsProvider() override
{}
33 bool NotifierHasAdvancedSettings(
34 const NotifierId
& notifier_id
) const override
{
35 return notifier_id
== settings_handler_id_
;
38 void OnNotifierAdvancedSettingsRequested(
39 const NotifierId
& notifier_id
,
40 const std::string
* notification_id
) override
{
42 last_notifier_id_settings_requested_
.reset(new NotifierId(notifier_id
));
45 size_t request_count() const { return request_count_
; }
46 const NotifierId
* last_requested_notifier_id() const {
47 return last_notifier_id_settings_requested_
.get();
51 NotifierId settings_handler_id_
;
52 size_t request_count_
;
53 scoped_ptr
<NotifierId
> last_notifier_id_settings_requested_
;
58 class NotifierSettingsViewTest
: public testing::Test
{
60 NotifierSettingsViewTest();
61 ~NotifierSettingsViewTest() override
;
63 void SetUp() override
;
64 void TearDown() override
;
66 NotifierSettingsView
* GetView() const;
67 TestingNotifierSettingsProvider
* settings_provider() const {
68 return settings_provider_
.get();
72 scoped_ptr
<TestingNotifierSettingsProvider
> settings_provider_
;
73 scoped_ptr
<NotifierSettingsView
> notifier_settings_view_
;
75 DISALLOW_COPY_AND_ASSIGN(NotifierSettingsViewTest
);
78 NotifierSettingsViewTest::NotifierSettingsViewTest() {}
80 NotifierSettingsViewTest::~NotifierSettingsViewTest() {}
82 void NotifierSettingsViewTest::SetUp() {
83 std::vector
<Notifier
*> notifiers
;
84 notifiers
.push_back(NewNotifier("id", "title", /*enabled=*/true));
85 notifiers
.push_back(NewNotifier("id2", "other title", /*enabled=*/false));
86 settings_provider_
.reset(new TestingNotifierSettingsProvider(
87 notifiers
, NotifierId(NotifierId::APPLICATION
, "id")));
88 notifier_settings_view_
.reset(
89 new NotifierSettingsView(settings_provider_
.get()));
92 void NotifierSettingsViewTest::TearDown() {
93 notifier_settings_view_
.reset();
94 settings_provider_
.reset();
97 NotifierSettingsView
* NotifierSettingsViewTest::GetView() const {
98 return notifier_settings_view_
.get();
101 TEST_F(NotifierSettingsViewTest
, TestLearnMoreButton
) {
102 const std::set
<NotifierSettingsView::NotifierButton
*> buttons
=
104 EXPECT_EQ(2u, buttons
.size());
105 size_t number_of_settings_buttons
= 0;
106 std::set
<NotifierSettingsView::NotifierButton
*>::iterator iter
=
108 for (; iter
!= buttons
.end(); ++iter
) {
109 if ((*iter
)->has_learn_more()) {
110 ++number_of_settings_buttons
;
111 (*iter
)->SendLearnMorePressedForTest();
115 EXPECT_EQ(1u, number_of_settings_buttons
);
116 EXPECT_EQ(1u, settings_provider()->request_count());
117 const NotifierId
* last_settings_button_id
=
118 settings_provider()->last_requested_notifier_id();
119 ASSERT_FALSE(last_settings_button_id
== NULL
);
120 EXPECT_EQ(NotifierId(NotifierId::APPLICATION
, "id"),
121 *last_settings_button_id
);
124 } // namespace message_center