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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
ash / system / notification_center / views / notifier_settings_view_unittest.cc [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/notification_center/views/notifier_settings_view.h"
#include <stddef.h>
#include <memory>
#include "ash/constants/ash_features.h"
#include "ash/public/cpp/notifier_metadata.h"
#include "ash/public/cpp/notifier_settings_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/notification_center/test_notifier_settings_controller.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/accessibility/view_accessibility.h"
namespace ash {
using message_center::NotifierId;
class NotifierSettingsViewTest : public AshTestBase {
public:
NotifierSettingsViewTest();
NotifierSettingsViewTest(const NotifierSettingsViewTest&) = delete;
NotifierSettingsViewTest& operator=(const NotifierSettingsViewTest&) = delete;
~NotifierSettingsViewTest() override;
void SetNoNotifiers(bool no_notifiers) {
ash_test_helper()->notifier_settings_controller()->set_no_notifiers(
no_notifiers);
}
std::vector<NotifierMetadata> GetNotifiersMetadata() {
return ash_test_helper()
->notifier_settings_controller()
->GetTestNotifiersMetadata();
}
};
NotifierSettingsViewTest::NotifierSettingsViewTest() = default;
NotifierSettingsViewTest::~NotifierSettingsViewTest() = default;
TEST_F(NotifierSettingsViewTest, TestEmptyNotifierView) {
SetNoNotifiers(false);
auto notifier_settings_view = std::make_unique<NotifierSettingsView>();
// Wait for mojo.
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(notifier_settings_view->no_notifiers_view_->GetVisible());
EXPECT_TRUE(notifier_settings_view->top_label_->GetVisible());
SetNoNotifiers(true);
notifier_settings_view = std::make_unique<NotifierSettingsView>();
// Wait for mojo.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(notifier_settings_view->no_notifiers_view_->GetVisible());
EXPECT_FALSE(notifier_settings_view->top_label_->GetVisible());
}
TEST_F(NotifierSettingsViewTest, NotifierButtonsAccessibleProperties) {
SetNoNotifiers(false);
auto notifier_settings_view = std::make_unique<NotifierSettingsView>();
std::vector<NotifierMetadata> notifiers = GetNotifiersMetadata();
// Wait for mojo.
base::RunLoop().RunUntilIdle();
size_t index = 0;
ASSERT_EQ(notifiers.size(), notifier_settings_view->buttons_.size());
for (auto button : notifier_settings_view->buttons_) {
ui::AXNodeData data;
ui::AXNodeData checkbox_data;
button->checkbox_->GetViewAccessibility().GetAccessibleNodeData(
&checkbox_data);
button->GetViewAccessibility().GetAccessibleNodeData(&data);
EXPECT_EQ(data.role, ax::mojom::Role::kCheckBox);
EXPECT_EQ(data.GetString16Attribute(ax::mojom::StringAttribute::kName),
notifiers[index].name);
ax::mojom::CheckedState checked = notifiers[index].enabled
? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse;
EXPECT_EQ(data.GetCheckedState(), checked);
EXPECT_EQ(data.GetRestriction(), checkbox_data.GetRestriction());
EXPECT_EQ(data.HasState(ax::mojom::State::kHovered),
checkbox_data.HasState(ax::mojom::State::kHovered));
EXPECT_EQ(data.HasState(ax::mojom::State::kDefault),
checkbox_data.HasState(ax::mojom::State::kDefault));
EXPECT_EQ(data.GetDefaultActionVerb(),
checkbox_data.GetDefaultActionVerb());
++index;
}
}
TEST_F(NotifierSettingsViewTest, AccessibleProperties) {
auto notifier_settings_view = std::make_unique<NotifierSettingsView>();
ui::AXNodeData data;
notifier_settings_view->GetViewAccessibility().GetAccessibleNodeData(&data);
EXPECT_EQ(data.role, ax::mojom::Role::kList);
EXPECT_EQ(data.GetString16Attribute(ax::mojom::StringAttribute::kName),
l10n_util::GetStringUTF16(
IDS_ASH_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION));
}
// Tests the notifier settings view with kSettingsAppNotificationSettings
// enabled/disabled.
class NotifierSettingsViewSettingsAppNotificationTest
: public NotifierSettingsViewTest,
public testing::WithParamInterface<bool> {
public:
NotifierSettingsViewSettingsAppNotificationTest() = default;
NotifierSettingsViewSettingsAppNotificationTest(
const NotifierSettingsViewSettingsAppNotificationTest&) = delete;
NotifierSettingsViewSettingsAppNotificationTest& operator=(
const NotifierSettingsViewSettingsAppNotificationTest&) = delete;
~NotifierSettingsViewSettingsAppNotificationTest() = default;
void SetUp() override {
feature_list_.InitWithFeatureState(
features::kSettingsAppNotificationSettings, GetParam());
NotifierSettingsViewTest::SetUp();
}
bool IsSettingsAppNotificationSettingsEnabled() { return GetParam(); }
private:
base::test::ScopedFeatureList feature_list_;
};
INSTANTIATE_TEST_SUITE_P(All,
NotifierSettingsViewSettingsAppNotificationTest,
testing::Bool());
TEST_P(NotifierSettingsViewSettingsAppNotificationTest,
NotificationSettingsLabelTest) {
auto notifier_settings_view = std::make_unique<NotifierSettingsView>();
EXPECT_TRUE(notifier_settings_view->get_quiet_mode_icon_view_for_test());
EXPECT_TRUE(notifier_settings_view->get_quiet_mode_toggle_for_test());
EXPECT_EQ(
IsSettingsAppNotificationSettingsEnabled(),
!!notifier_settings_view->get_notification_settings_lable_for_test());
EXPECT_NE(IsSettingsAppNotificationSettingsEnabled(),
!!notifier_settings_view->get_scroller_view_for_test());
}
} // namespace ash