OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/system/tray/tray_details_view.h" | 5 #include "ash/common/system/tray/tray_details_view.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | |
8 #include "ash/common/system/tray/hover_highlight_view.h" | 7 #include "ash/common/system/tray/hover_highlight_view.h" |
9 #include "ash/common/system/tray/special_popup_row.h" | 8 #include "ash/common/system/tray/special_popup_row.h" |
10 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
11 #include "ash/common/system/tray/system_tray_item.h" | 10 #include "ash/common/system/tray/system_tray_item.h" |
12 #include "ash/common/system/tray/tray_popup_header_button.h" | 11 #include "ash/common/system/tray/tray_popup_header_button.h" |
13 #include "ash/common/system/tray/view_click_listener.h" | 12 #include "ash/common/system/tray/view_click_listener.h" |
14 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
16 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
17 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
18 #include "ui/events/test/event_generator.h" | 17 #include "ui/events/test/event_generator.h" |
19 #include "ui/views/controls/button/button.h" | 18 #include "ui/views/controls/button/button.h" |
20 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
21 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
22 | 21 |
23 namespace ash { | 22 namespace ash { |
24 namespace test { | 23 namespace test { |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 class TestDetailsView : public TrayDetailsView { | 27 class TestDetailsView : public TrayDetailsView, |
| 28 public ViewClickListener, |
| 29 public views::ButtonListener { |
29 public: | 30 public: |
30 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { | 31 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) { |
31 // Uses bluetooth label for testing purpose. It can be changed to any | 32 // Uses bluetooth label for testing purpose. It can be changed to any |
32 // string_id. | 33 // string_id. |
33 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); | 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_); |
34 } | 42 } |
35 | 43 |
36 ~TestDetailsView() override {} | 44 ~TestDetailsView() override {} |
37 | 45 |
38 TrayPopupHeaderButton* tray_popup_header_button() { | 46 TrayPopupHeaderButton* tray_popup_header_button() { |
39 return tray_popup_header_button_; | 47 return tray_popup_header_button_; |
40 } | 48 } |
41 | 49 |
42 void FocusTitleRow() { title_row()->content()->RequestFocus(); } | 50 void FocusFooter() { footer()->content()->RequestFocus(); } |
43 | 51 |
44 // TrayDetailsView: | 52 // ViewClickListener: |
45 void CreateExtraTitleRowButtons() override { | 53 void OnViewClicked(views::View* sender) override {} |
46 // TODO(tdanderson): Add test coverage for material design buttons in the | |
47 // title row once they are implemented. | |
48 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
49 return; | |
50 | 54 |
51 tray_popup_header_button_ = | 55 // views::ButtonListener: |
52 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, | 56 void ButtonPressed(views::Button* sender, const ui::Event& event) override {} |
53 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, | |
54 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, | |
55 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, | |
56 IDS_ASH_STATUS_TRAY_BLUETOOTH); | |
57 title_row()->AddButton(tray_popup_header_button_); | |
58 } | |
59 | 57 |
60 private: | 58 private: |
61 TrayPopupHeaderButton* tray_popup_header_button_; | 59 TrayPopupHeaderButton* tray_popup_header_button_; |
62 | 60 |
63 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); | 61 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); |
64 }; | 62 }; |
65 | 63 |
66 // Trivial item implementation that tracks its views for testing. | 64 // Trivial item implementation that tracks its views for testing. |
67 class TestItem : public SystemTrayItem { | 65 class TestItem : public SystemTrayItem { |
68 public: | 66 public: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 HoverHighlightView* CreateAndShowHoverHighlightView() { | 110 HoverHighlightView* CreateAndShowHoverHighlightView() { |
113 SystemTray* tray = GetPrimarySystemTray(); | 111 SystemTray* tray = GetPrimarySystemTray(); |
114 TestItem* test_item = new TestItem; | 112 TestItem* test_item = new TestItem; |
115 tray->AddTrayItem(test_item); | 113 tray->AddTrayItem(test_item); |
116 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 114 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
117 RunAllPendingInMessageLoop(); | 115 RunAllPendingInMessageLoop(); |
118 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 116 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
119 RunAllPendingInMessageLoop(); | 117 RunAllPendingInMessageLoop(); |
120 | 118 |
121 return static_cast<HoverHighlightView*>( | 119 return static_cast<HoverHighlightView*>( |
122 test_item->detailed_view()->title_row()->content()); | 120 test_item->detailed_view()->footer()->content()); |
123 } | 121 } |
124 | 122 |
125 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() { | 123 TrayPopupHeaderButton* CreateAndShowTrayPopupHeaderButton() { |
126 SystemTray* tray = GetPrimarySystemTray(); | 124 SystemTray* tray = GetPrimarySystemTray(); |
127 TestItem* test_item = new TestItem; | 125 TestItem* test_item = new TestItem; |
128 tray->AddTrayItem(test_item); | 126 tray->AddTrayItem(test_item); |
129 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 127 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
130 RunAllPendingInMessageLoop(); | 128 RunAllPendingInMessageLoop(); |
131 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 129 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
132 RunAllPendingInMessageLoop(); | 130 RunAllPendingInMessageLoop(); |
133 | 131 |
134 return test_item->detailed_view()->tray_popup_header_button(); | 132 return test_item->detailed_view()->tray_popup_header_button(); |
135 } | 133 } |
136 | 134 |
137 void TransitionFromDetailedToDefaultView(TestDetailsView* detailed) { | |
138 detailed->TransitionToDefaultView(); | |
139 } | |
140 | |
141 private: | 135 private: |
142 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); | 136 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest); |
143 }; | 137 }; |
144 | 138 |
145 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { | 139 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { |
146 SystemTray* tray = GetPrimarySystemTray(); | 140 SystemTray* tray = GetPrimarySystemTray(); |
147 ASSERT_TRUE(tray->GetWidget()); | 141 ASSERT_TRUE(tray->GetWidget()); |
148 | 142 |
149 TestItem* test_item_1 = new TestItem; | 143 TestItem* test_item_1 = new TestItem; |
150 TestItem* test_item_2 = new TestItem; | 144 TestItem* test_item_2 = new TestItem; |
151 tray->AddTrayItem(test_item_1); | 145 tray->AddTrayItem(test_item_1); |
152 tray->AddTrayItem(test_item_2); | 146 tray->AddTrayItem(test_item_2); |
153 | 147 |
154 // Ensure the tray views are created. | 148 // Ensure the tray views are created. |
155 ASSERT_TRUE(test_item_1->tray_view() != NULL); | 149 ASSERT_TRUE(test_item_1->tray_view() != NULL); |
156 ASSERT_TRUE(test_item_2->tray_view() != NULL); | 150 ASSERT_TRUE(test_item_2->tray_view() != NULL); |
157 | 151 |
158 // Show the default view. | 152 // Show the default view. |
159 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 153 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
160 RunAllPendingInMessageLoop(); | 154 RunAllPendingInMessageLoop(); |
161 | 155 |
162 // Show the detailed view of item 2. | 156 // Show the detailed view of item 2. |
163 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 157 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
164 EXPECT_TRUE(test_item_2->detailed_view()); | 158 EXPECT_TRUE(test_item_2->detailed_view()); |
165 RunAllPendingInMessageLoop(); | 159 RunAllPendingInMessageLoop(); |
166 EXPECT_FALSE(test_item_2->default_view()); | 160 EXPECT_FALSE(test_item_2->default_view()); |
167 | 161 |
168 // Transition back to default view, the default view of item 2 should have | 162 // Transition back to default view, the default view of item 2 should have |
169 // focus. | 163 // focus. |
170 test_item_2->detailed_view()->FocusTitleRow(); | 164 test_item_2->detailed_view()->FocusFooter(); |
171 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); | 165 test_item_2->detailed_view()->TransitionToDefaultView(); |
172 RunAllPendingInMessageLoop(); | 166 RunAllPendingInMessageLoop(); |
173 | 167 |
174 EXPECT_TRUE(test_item_2->default_view()); | 168 EXPECT_TRUE(test_item_2->default_view()); |
175 EXPECT_FALSE(test_item_2->detailed_view()); | 169 EXPECT_FALSE(test_item_2->detailed_view()); |
176 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); | 170 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); |
177 | 171 |
178 // Show the detailed view of item 2 again. | 172 // Show the detailed view of item 2 again. |
179 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 173 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
180 EXPECT_TRUE(test_item_2->detailed_view()); | 174 EXPECT_TRUE(test_item_2->detailed_view()); |
181 RunAllPendingInMessageLoop(); | 175 RunAllPendingInMessageLoop(); |
182 EXPECT_FALSE(test_item_2->default_view()); | 176 EXPECT_FALSE(test_item_2->default_view()); |
183 | 177 |
184 // Transition back to default view, the default view of item 2 should NOT have | 178 // Transition back to default view, the default view of item 2 should NOT have |
185 // focus. | 179 // focus. |
186 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); | 180 test_item_2->detailed_view()->TransitionToDefaultView(); |
187 RunAllPendingInMessageLoop(); | 181 RunAllPendingInMessageLoop(); |
188 | 182 |
189 EXPECT_TRUE(test_item_2->default_view()); | 183 EXPECT_TRUE(test_item_2->default_view()); |
190 EXPECT_FALSE(test_item_2->detailed_view()); | 184 EXPECT_FALSE(test_item_2->detailed_view()); |
191 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); | 185 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); |
192 } | 186 } |
193 | 187 |
194 // Tests that HoverHighlightView enters hover state in response to touch. | 188 // Tests that HoverHighlightView enters hover state in response to touch. |
195 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) { | 189 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) { |
196 HoverHighlightView* view = CreateAndShowHoverHighlightView(); | 190 HoverHighlightView* view = CreateAndShowHoverHighlightView(); |
(...skipping 23 matching lines...) Expand all Loading... |
220 generator.MoveTouch(move_point); | 214 generator.MoveTouch(move_point); |
221 EXPECT_FALSE(view->hover()); | 215 EXPECT_FALSE(view->hover()); |
222 | 216 |
223 generator.set_current_location(move_point); | 217 generator.set_current_location(move_point); |
224 generator.ReleaseTouch(); | 218 generator.ReleaseTouch(); |
225 EXPECT_FALSE(view->hover()); | 219 EXPECT_FALSE(view->hover()); |
226 } | 220 } |
227 | 221 |
228 // Tests that TrayPopupHeaderButton renders a background in response to touch. | 222 // Tests that TrayPopupHeaderButton renders a background in response to touch. |
229 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) { | 223 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) { |
230 // Material design detailed views will not use TrayPopupHeaderButton. | |
231 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
232 return; | |
233 | |
234 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | 224 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
235 EXPECT_FALSE(button->background()); | 225 EXPECT_FALSE(button->background()); |
236 | 226 |
237 ui::test::EventGenerator& generator = GetEventGenerator(); | 227 ui::test::EventGenerator& generator = GetEventGenerator(); |
238 generator.set_current_location(button->GetBoundsInScreen().CenterPoint()); | 228 generator.set_current_location(button->GetBoundsInScreen().CenterPoint()); |
239 generator.PressTouch(); | 229 generator.PressTouch(); |
240 EXPECT_TRUE(button->background()); | 230 EXPECT_TRUE(button->background()); |
241 | 231 |
242 generator.ReleaseTouch(); | 232 generator.ReleaseTouch(); |
243 EXPECT_FALSE(button->background()); | 233 EXPECT_FALSE(button->background()); |
244 } | 234 } |
245 | 235 |
246 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch | 236 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch |
247 // feedback background. | 237 // feedback background. |
248 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) { | 238 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) { |
249 // Material design detailed views will not use TrayPopupHeaderButton. | |
250 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
251 return; | |
252 | |
253 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | 239 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
254 EXPECT_FALSE(button->background()); | 240 EXPECT_FALSE(button->background()); |
255 | 241 |
256 gfx::Rect view_bounds = button->GetBoundsInScreen(); | 242 gfx::Rect view_bounds = button->GetBoundsInScreen(); |
257 ui::test::EventGenerator& generator = GetEventGenerator(); | 243 ui::test::EventGenerator& generator = GetEventGenerator(); |
258 generator.set_current_location(view_bounds.CenterPoint()); | 244 generator.set_current_location(view_bounds.CenterPoint()); |
259 generator.PressTouch(); | 245 generator.PressTouch(); |
260 EXPECT_TRUE(button->background()); | 246 EXPECT_TRUE(button->background()); |
261 | 247 |
262 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | 248 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); |
263 generator.MoveTouch(move_point); | 249 generator.MoveTouch(move_point); |
264 EXPECT_FALSE(button->background()); | 250 EXPECT_FALSE(button->background()); |
265 | 251 |
266 generator.set_current_location(move_point); | 252 generator.set_current_location(move_point); |
267 generator.ReleaseTouch(); | 253 generator.ReleaseTouch(); |
268 EXPECT_FALSE(button->background()); | 254 EXPECT_FALSE(button->background()); |
269 } | 255 } |
270 | 256 |
271 // Tests that a mouse entering TrayPopupHeaderButton renders a background as | 257 // Tests that a mouse entering TrayPopupHeaderButton renders a background as |
272 // visual feedback. | 258 // visual feedback. |
273 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) { | 259 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) { |
274 // Material design detailed views will not use TrayPopupHeaderButton. | |
275 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
276 return; | |
277 | |
278 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | 260 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); |
279 EXPECT_FALSE(button->background()); | 261 EXPECT_FALSE(button->background()); |
280 | 262 |
281 ui::test::EventGenerator& generator = GetEventGenerator(); | 263 ui::test::EventGenerator& generator = GetEventGenerator(); |
282 gfx::Rect bounds = button->GetBoundsInScreen(); | 264 gfx::Rect bounds = button->GetBoundsInScreen(); |
283 gfx::Point initial_point(bounds.x() - 1, bounds.y()); | 265 gfx::Point initial_point(bounds.x() - 1, bounds.y()); |
284 generator.set_current_location(initial_point); | 266 generator.set_current_location(initial_point); |
285 generator.MoveMouseBy(1, 0); | 267 generator.MoveMouseBy(1, 0); |
286 RunAllPendingInMessageLoop(); | 268 RunAllPendingInMessageLoop(); |
287 EXPECT_TRUE(button->background()); | 269 EXPECT_TRUE(button->background()); |
288 } | 270 } |
289 | 271 |
290 } // namespace test | 272 } // namespace test |
291 } // namespace ash | 273 } // namespace ash |
OLD | NEW |