Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ash/system/tray/tray_details_view_unittest.cc

Issue 2084733002: mash: Move tray accessibility and keyboard to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@typenamespace
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/tray/tray_details_view.cc ('k') | ash/system/tray_accessibility.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ash/system/tray/tray_details_view.h"
6
7 #include "ash/common/system/tray/hover_highlight_view.h"
8 #include "ash/common/system/tray/special_popup_row.h"
9 #include "ash/common/system/tray/system_tray_item.h"
10 #include "ash/common/system/tray/tray_popup_header_button.h"
11 #include "ash/common/system/tray/view_click_listener.h"
12 #include "ash/system/tray/system_tray.h"
13 #include "ash/test/ash_test_base.h"
14 #include "base/run_loop.h"
15 #include "grit/ash_resources.h"
16 #include "grit/ash_strings.h"
17 #include "ui/events/test/event_generator.h"
18 #include "ui/views/controls/button/button.h"
19 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h"
21
22 namespace ash {
23 namespace test {
24
25 namespace {
26
27 class TestDetailsView : public TrayDetailsView,
28 public ViewClickListener,
29 public views::ButtonListener {
30 public:
31 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) {
32 // Uses bluetooth label for testing purpose. It can be changed to any
33 // string_id.
34 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this);
35 tray_popup_header_button_ =
36 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
37 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
38 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
39 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER,
40 IDS_ASH_STATUS_TRAY_BLUETOOTH);
41 footer()->AddButton(tray_popup_header_button_);
42 }
43
44 ~TestDetailsView() override {}
45
46 TrayPopupHeaderButton* tray_popup_header_button() {
47 return tray_popup_header_button_;
48 }
49
50 void FocusFooter() {
51 footer()->content()->RequestFocus();
52 }
53
54 // ViewClickListener:
55 void OnViewClicked(views::View* sender) override {}
56
57 // views::ButtonListener:
58 void ButtonPressed(views::Button* sender, const ui::Event& event) override {}
59
60 private:
61 TrayPopupHeaderButton* tray_popup_header_button_;
62
63 DISALLOW_COPY_AND_ASSIGN(TestDetailsView);
64 };
65
66 // Trivial item implementation that tracks its views for testing.
67 class TestItem : public SystemTrayItem {
68 public:
69 TestItem()
70 : SystemTrayItem(AshTestBase::GetPrimarySystemTray()),
71 tray_view_(nullptr),
72 default_view_(nullptr),
73 detailed_view_(nullptr) {}
74
75 // Overridden from SystemTrayItem:
76 views::View* CreateTrayView(LoginStatus status) override {
77 tray_view_ = new views::View;
78 return tray_view_;
79 }
80 views::View* CreateDefaultView(LoginStatus status) override {
81 default_view_ = new views::View;
82 default_view_->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
83 return default_view_;
84 }
85 views::View* CreateDetailedView(LoginStatus status) override {
86 detailed_view_ = new TestDetailsView(this);
87 return detailed_view_;
88 }
89 void DestroyTrayView() override { tray_view_ = NULL; }
90 void DestroyDefaultView() override { default_view_ = NULL; }
91 void DestroyDetailedView() override { detailed_view_ = NULL; }
92
93 views::View* tray_view() const { return tray_view_; }
94 views::View* default_view() const { return default_view_; }
95 TestDetailsView* detailed_view() const { return detailed_view_; }
96
97 private:
98 views::View* tray_view_;
99 views::View* default_view_;
100 TestDetailsView* detailed_view_;
101
102 DISALLOW_COPY_AND_ASSIGN(TestItem);
103 };
104
105 } // namespace
106
107 class TrayDetailsViewTest : public AshTestBase {
108 public:
109 TrayDetailsViewTest() {}
110 ~TrayDetailsViewTest() override {}
111
112 HoverHighlightView* CreateAndShowHoverHighlightView() {
113 SystemTray* tray = GetPrimarySystemTray();
114 TestItem* test_item = new TestItem;
115 tray->AddTrayItem(test_item);
116 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
117 RunAllPendingInMessageLoop();
118 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING);
119 RunAllPendingInMessageLoop();
120
121 return static_cast<HoverHighlightView*>(test_item->detailed_view()->
122 footer()->content());
123 }
124
125 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() {
126 SystemTray* tray = GetPrimarySystemTray();
127 TestItem* test_item = new TestItem;
128 tray->AddTrayItem(test_item);
129 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
130 RunAllPendingInMessageLoop();
131 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING);
132 RunAllPendingInMessageLoop();
133
134 return test_item->detailed_view()->tray_popup_header_button();
135 }
136
137 private:
138 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest);
139 };
140
141 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) {
142 SystemTray* tray = GetPrimarySystemTray();
143 ASSERT_TRUE(tray->GetWidget());
144
145 TestItem* test_item_1 = new TestItem;
146 TestItem* test_item_2 = new TestItem;
147 tray->AddTrayItem(test_item_1);
148 tray->AddTrayItem(test_item_2);
149
150 // Ensure the tray views are created.
151 ASSERT_TRUE(test_item_1->tray_view() != NULL);
152 ASSERT_TRUE(test_item_2->tray_view() != NULL);
153
154 // Show the default view.
155 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
156 RunAllPendingInMessageLoop();
157
158 // Show the detailed view of item 2.
159 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING);
160 EXPECT_TRUE(test_item_2->detailed_view());
161 RunAllPendingInMessageLoop();
162 EXPECT_FALSE(test_item_2->default_view());
163
164 // Transition back to default view, the default view of item 2 should have
165 // focus.
166 test_item_2->detailed_view()->FocusFooter();
167 test_item_2->detailed_view()->TransitionToDefaultView();
168 RunAllPendingInMessageLoop();
169
170 EXPECT_TRUE(test_item_2->default_view());
171 EXPECT_FALSE(test_item_2->detailed_view());
172 EXPECT_TRUE(test_item_2->default_view()->HasFocus());
173
174 // Show the detailed view of item 2 again.
175 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING);
176 EXPECT_TRUE(test_item_2->detailed_view());
177 RunAllPendingInMessageLoop();
178 EXPECT_FALSE(test_item_2->default_view());
179
180 // Transition back to default view, the default view of item 2 should NOT have
181 // focus.
182 test_item_2->detailed_view()->TransitionToDefaultView();
183 RunAllPendingInMessageLoop();
184
185 EXPECT_TRUE(test_item_2->default_view());
186 EXPECT_FALSE(test_item_2->detailed_view());
187 EXPECT_FALSE(test_item_2->default_view()->HasFocus());
188 }
189
190 // Tests that HoverHighlightView enters hover state in response to touch.
191 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) {
192 HoverHighlightView* view = CreateAndShowHoverHighlightView();
193 EXPECT_FALSE(view->hover());
194
195 ui::test::EventGenerator& generator = GetEventGenerator();
196 generator.set_current_location(view->GetBoundsInScreen().CenterPoint());
197 generator.PressTouch();
198 EXPECT_TRUE(view->hover());
199
200 generator.ReleaseTouch();
201 EXPECT_FALSE(view->hover());
202 }
203
204 // Tests that touch events leaving HoverHighlightView cancel the hover state.
205 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) {
206 HoverHighlightView* view = CreateAndShowHoverHighlightView();
207 EXPECT_FALSE(view->hover());
208
209 gfx::Rect view_bounds = view->GetBoundsInScreen();
210 ui::test::EventGenerator& generator = GetEventGenerator();
211 generator.set_current_location(view_bounds.CenterPoint());
212 generator.PressTouch();
213 EXPECT_TRUE(view->hover());
214
215 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y());
216 generator.MoveTouch(move_point);
217 EXPECT_FALSE(view->hover());
218
219 generator.set_current_location(move_point);
220 generator.ReleaseTouch();
221 EXPECT_FALSE(view->hover());
222 }
223
224 // Tests that TrayPopupHeaderButton renders a background in response to touch.
225 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) {
226 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton();
227 EXPECT_FALSE(button->background());
228
229 ui::test::EventGenerator& generator = GetEventGenerator();
230 generator.set_current_location(button->GetBoundsInScreen().CenterPoint());
231 generator.PressTouch();
232 EXPECT_TRUE(button->background());
233
234 generator.ReleaseTouch();
235 EXPECT_FALSE(button->background());
236 }
237
238 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch
239 // feedback background.
240 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) {
241 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton();
242 EXPECT_FALSE(button->background());
243
244 gfx::Rect view_bounds = button->GetBoundsInScreen();
245 ui::test::EventGenerator& generator = GetEventGenerator();
246 generator.set_current_location(view_bounds.CenterPoint());
247 generator.PressTouch();
248 EXPECT_TRUE(button->background());
249
250 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y());
251 generator.MoveTouch(move_point);
252 EXPECT_FALSE(button->background());
253
254 generator.set_current_location(move_point);
255 generator.ReleaseTouch();
256 EXPECT_FALSE(button->background());
257 }
258
259 // Tests that a mouse entering TrayPopupHeaderButton renders a background as
260 // visual feedback.
261 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) {
262 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton();
263 EXPECT_FALSE(button->background());
264
265 ui::test::EventGenerator& generator = GetEventGenerator();
266 gfx::Rect bounds = button->GetBoundsInScreen();
267 gfx::Point initial_point(bounds.x() - 1, bounds.y());
268 generator.set_current_location(initial_point);
269 generator.MoveMouseBy(1, 0);
270 RunAllPendingInMessageLoop();
271 EXPECT_TRUE(button->background());
272 }
273
274 } // namespace test
275 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_details_view.cc ('k') | ash/system/tray_accessibility.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698