| 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/ash_view_ids.h" | 7 #include "ash/common/ash_view_ids.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | |
| 9 #include "ash/common/system/tray/hover_highlight_view.h" | 8 #include "ash/common/system/tray/hover_highlight_view.h" |
| 10 #include "ash/common/system/tray/special_popup_row.h" | 9 #include "ash/common/system/tray/special_popup_row.h" |
| 11 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/system/tray/system_tray_item.h" | 11 #include "ash/common/system/tray/system_tray_item.h" |
| 13 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
| 14 #include "ash/common/system/tray/tray_popup_header_button.h" | 13 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 15 #include "ash/common/system/tray/view_click_listener.h" | 14 #include "ash/common/system/tray/view_click_listener.h" |
| 16 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 17 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 18 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 39 } | 38 } |
| 40 | 39 |
| 41 ~TestDetailsView() override {} | 40 ~TestDetailsView() override {} |
| 42 | 41 |
| 43 TrayPopupHeaderButton* tray_popup_header_button() { | 42 TrayPopupHeaderButton* tray_popup_header_button() { |
| 44 return tray_popup_header_button_; | 43 return tray_popup_header_button_; |
| 45 } | 44 } |
| 46 | 45 |
| 47 void FocusTitleRow() { title_row()->content()->RequestFocus(); } | 46 void FocusTitleRow() { title_row()->content()->RequestFocus(); } |
| 48 | 47 |
| 49 // TrayDetailsView: | |
| 50 void CreateExtraTitleRowButtons() override { | |
| 51 // TODO(tdanderson): Add test coverage for material design buttons in the | |
| 52 // title row once they are implemented. | |
| 53 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 54 return; | |
| 55 | |
| 56 tray_popup_header_button_ = | |
| 57 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, | |
| 58 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, | |
| 59 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, | |
| 60 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, | |
| 61 IDS_ASH_STATUS_TRAY_BLUETOOTH); | |
| 62 title_row()->AddViewToRowNonMd(tray_popup_header_button_, true); | |
| 63 } | |
| 64 | |
| 65 void CreateScrollerViews() { CreateScrollableList(); } | 48 void CreateScrollerViews() { CreateScrollableList(); } |
| 66 | 49 |
| 67 private: | 50 private: |
| 68 TrayPopupHeaderButton* tray_popup_header_button_; | 51 TrayPopupHeaderButton* tray_popup_header_button_; |
| 69 | 52 |
| 70 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); | 53 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); |
| 71 }; | 54 }; |
| 72 | 55 |
| 73 // Trivial item implementation that tracks its views for testing. | 56 // Trivial item implementation that tracks its views for testing. |
| 74 class TestItem : public SystemTrayItem { | 57 class TestItem : public SystemTrayItem { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 160 |
| 178 // Show the detailed view of item 2. | 161 // Show the detailed view of item 2. |
| 179 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 162 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
| 180 EXPECT_TRUE(test_item_2->detailed_view()); | 163 EXPECT_TRUE(test_item_2->detailed_view()); |
| 181 RunAllPendingInMessageLoop(); | 164 RunAllPendingInMessageLoop(); |
| 182 EXPECT_FALSE(test_item_2->default_view()); | 165 EXPECT_FALSE(test_item_2->default_view()); |
| 183 | 166 |
| 184 // Transition back to default view, the default view of item 2 should have | 167 // Transition back to default view, the default view of item 2 should have |
| 185 // focus. | 168 // focus. |
| 186 tray->GetSystemBubble()->bubble_view()->set_can_activate(true); | 169 tray->GetSystemBubble()->bubble_view()->set_can_activate(true); |
| 187 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | 170 FocusBackButton(test_item_2->detailed_view()); |
| 188 FocusBackButton(test_item_2->detailed_view()); | |
| 189 else | |
| 190 test_item_2->detailed_view()->FocusTitleRow(); | |
| 191 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); | 171 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); |
| 192 RunAllPendingInMessageLoop(); | 172 RunAllPendingInMessageLoop(); |
| 193 | 173 |
| 194 EXPECT_TRUE(test_item_2->default_view()); | 174 EXPECT_TRUE(test_item_2->default_view()); |
| 195 EXPECT_FALSE(test_item_2->detailed_view()); | 175 EXPECT_FALSE(test_item_2->detailed_view()); |
| 196 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); | 176 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); |
| 197 | 177 |
| 198 // Show the detailed view of item 2 again. | 178 // Show the detailed view of item 2 again. |
| 199 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 179 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
| 200 EXPECT_TRUE(test_item_2->detailed_view()); | 180 EXPECT_TRUE(test_item_2->detailed_view()); |
| 201 RunAllPendingInMessageLoop(); | 181 RunAllPendingInMessageLoop(); |
| 202 EXPECT_FALSE(test_item_2->default_view()); | 182 EXPECT_FALSE(test_item_2->default_view()); |
| 203 | 183 |
| 204 // Transition back to default view, the default view of item 2 should NOT have | 184 // Transition back to default view, the default view of item 2 should NOT have |
| 205 // focus. | 185 // focus. |
| 206 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); | 186 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); |
| 207 RunAllPendingInMessageLoop(); | 187 RunAllPendingInMessageLoop(); |
| 208 | 188 |
| 209 EXPECT_TRUE(test_item_2->default_view()); | 189 EXPECT_TRUE(test_item_2->default_view()); |
| 210 EXPECT_FALSE(test_item_2->detailed_view()); | 190 EXPECT_FALSE(test_item_2->detailed_view()); |
| 211 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); | 191 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); |
| 212 } | 192 } |
| 213 | 193 |
| 214 // Tests that HoverHighlightView enters hover state in response to touch. | |
| 215 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) { | |
| 216 // Material design detailed views will not use the visual feedback from | |
| 217 // HoverHighlightView. | |
| 218 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 219 return; | |
| 220 | |
| 221 HoverHighlightView* view = CreateAndShowHoverHighlightView(); | |
| 222 EXPECT_FALSE(view->hover()); | |
| 223 | |
| 224 ui::test::EventGenerator& generator = GetEventGenerator(); | |
| 225 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); | |
| 226 generator.PressTouch(); | |
| 227 EXPECT_TRUE(view->hover()); | |
| 228 | |
| 229 generator.ReleaseTouch(); | |
| 230 } | |
| 231 | |
| 232 // Tests that touch events leaving HoverHighlightView cancel the hover state. | |
| 233 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) { | |
| 234 // Material design detailed views will not use the visual feedback from | |
| 235 // HoverHighlightView. | |
| 236 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 237 return; | |
| 238 | |
| 239 HoverHighlightView* view = CreateAndShowHoverHighlightView(); | |
| 240 EXPECT_FALSE(view->hover()); | |
| 241 | |
| 242 gfx::Rect view_bounds = view->GetBoundsInScreen(); | |
| 243 ui::test::EventGenerator& generator = GetEventGenerator(); | |
| 244 generator.set_current_location(view_bounds.CenterPoint()); | |
| 245 generator.PressTouch(); | |
| 246 EXPECT_TRUE(view->hover()); | |
| 247 | |
| 248 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | |
| 249 generator.MoveTouch(move_point); | |
| 250 EXPECT_FALSE(view->hover()); | |
| 251 | |
| 252 generator.set_current_location(move_point); | |
| 253 generator.ReleaseTouch(); | |
| 254 EXPECT_FALSE(view->hover()); | |
| 255 } | |
| 256 | |
| 257 // Tests that TrayPopupHeaderButton renders a background in response to touch. | |
| 258 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedback) { | |
| 259 // Material design detailed views will not use TrayPopupHeaderButton. | |
| 260 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 261 return; | |
| 262 | |
| 263 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | |
| 264 EXPECT_FALSE(button->background()); | |
| 265 | |
| 266 ui::test::EventGenerator& generator = GetEventGenerator(); | |
| 267 generator.set_current_location(button->GetBoundsInScreen().CenterPoint()); | |
| 268 generator.PressTouch(); | |
| 269 EXPECT_TRUE(button->background()); | |
| 270 | |
| 271 generator.ReleaseTouch(); | |
| 272 EXPECT_FALSE(button->background()); | |
| 273 } | |
| 274 | |
| 275 // Tests that touch events leaving TrayPopupHeaderButton cancel the touch | |
| 276 // feedback background. | |
| 277 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonTouchFeedbackCancellation) { | |
| 278 // Material design detailed views will not use TrayPopupHeaderButton. | |
| 279 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 280 return; | |
| 281 | |
| 282 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | |
| 283 EXPECT_FALSE(button->background()); | |
| 284 | |
| 285 gfx::Rect view_bounds = button->GetBoundsInScreen(); | |
| 286 ui::test::EventGenerator& generator = GetEventGenerator(); | |
| 287 generator.set_current_location(view_bounds.CenterPoint()); | |
| 288 generator.PressTouch(); | |
| 289 EXPECT_TRUE(button->background()); | |
| 290 | |
| 291 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | |
| 292 generator.MoveTouch(move_point); | |
| 293 EXPECT_FALSE(button->background()); | |
| 294 | |
| 295 generator.set_current_location(move_point); | |
| 296 generator.ReleaseTouch(); | |
| 297 EXPECT_FALSE(button->background()); | |
| 298 } | |
| 299 | |
| 300 // Tests that a mouse entering TrayPopupHeaderButton renders a background as | |
| 301 // visual feedback. | |
| 302 TEST_F(TrayDetailsViewTest, TrayPopupHeaderButtonMouseHoverFeedback) { | |
| 303 // Material design detailed views will not use TrayPopupHeaderButton. | |
| 304 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 305 return; | |
| 306 | |
| 307 TrayPopupHeaderButton* button = CreateAndShowTrayPopupHeaderButton(); | |
| 308 EXPECT_FALSE(button->background()); | |
| 309 | |
| 310 ui::test::EventGenerator& generator = GetEventGenerator(); | |
| 311 gfx::Rect bounds = button->GetBoundsInScreen(); | |
| 312 gfx::Point initial_point(bounds.x() - 1, bounds.y()); | |
| 313 generator.set_current_location(initial_point); | |
| 314 generator.MoveMouseBy(1, 0); | |
| 315 RunAllPendingInMessageLoop(); | |
| 316 EXPECT_TRUE(button->background()); | |
| 317 } | |
| 318 | |
| 319 TEST_F(TrayDetailsViewTest, ScrollContentsTest) { | 194 TEST_F(TrayDetailsViewTest, ScrollContentsTest) { |
| 320 SystemTray* tray = GetPrimarySystemTray(); | 195 SystemTray* tray = GetPrimarySystemTray(); |
| 321 TestItem* test_item = new TestItem; | 196 TestItem* test_item = new TestItem; |
| 322 tray->AddTrayItem(base::WrapUnique(test_item)); | 197 tray->AddTrayItem(base::WrapUnique(test_item)); |
| 323 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 198 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 324 RunAllPendingInMessageLoop(); | 199 RunAllPendingInMessageLoop(); |
| 325 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 200 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
| 326 RunAllPendingInMessageLoop(); | 201 RunAllPendingInMessageLoop(); |
| 327 test_item->detailed_view()->CreateScrollerViews(); | 202 test_item->detailed_view()->CreateScrollerViews(); |
| 328 | 203 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 351 | 226 |
| 352 // Sticky header layer should be above the last child's layer. | 227 // Sticky header layer should be above the last child's layer. |
| 353 EXPECT_EQ(3u, layers.size()); | 228 EXPECT_EQ(3u, layers.size()); |
| 354 EXPECT_EQ(view3->layer(), layers[0]); | 229 EXPECT_EQ(view3->layer(), layers[0]); |
| 355 EXPECT_EQ(view4->layer(), layers[1]); | 230 EXPECT_EQ(view4->layer(), layers[1]); |
| 356 EXPECT_EQ(view2->layer(), layers[2]); | 231 EXPECT_EQ(view2->layer(), layers[2]); |
| 357 } | 232 } |
| 358 | 233 |
| 359 } // namespace test | 234 } // namespace test |
| 360 } // namespace ash | 235 } // namespace ash |
| OLD | NEW |