Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 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: | 48 // TrayDetailsView: |
| 50 void CreateExtraTitleRowButtons() override { | 49 void CreateExtraTitleRowButtons() override { |
|
tdanderson
2017/02/08 23:20:16
nit: just remove this function completely. I will
mohsen
2017/02/09 02:43:10
Done.
| |
| 51 // TODO(tdanderson): Add test coverage for material design buttons in the | 50 // TODO(tdanderson): Add test coverage for material design buttons in the |
| 52 // title row once they are implemented. | 51 // 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 } | 52 } |
| 64 | 53 |
| 65 void CreateScrollerViews() { CreateScrollableList(); } | 54 void CreateScrollerViews() { CreateScrollableList(); } |
| 66 | 55 |
| 67 private: | 56 private: |
| 68 TrayPopupHeaderButton* tray_popup_header_button_; | 57 TrayPopupHeaderButton* tray_popup_header_button_; |
| 69 | 58 |
| 70 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); | 59 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); |
| 71 }; | 60 }; |
| 72 | 61 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 | 166 |
| 178 // Show the detailed view of item 2. | 167 // Show the detailed view of item 2. |
| 179 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 168 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
| 180 EXPECT_TRUE(test_item_2->detailed_view()); | 169 EXPECT_TRUE(test_item_2->detailed_view()); |
| 181 RunAllPendingInMessageLoop(); | 170 RunAllPendingInMessageLoop(); |
| 182 EXPECT_FALSE(test_item_2->default_view()); | 171 EXPECT_FALSE(test_item_2->default_view()); |
| 183 | 172 |
| 184 // Transition back to default view, the default view of item 2 should have | 173 // Transition back to default view, the default view of item 2 should have |
| 185 // focus. | 174 // focus. |
| 186 tray->GetSystemBubble()->bubble_view()->set_can_activate(true); | 175 tray->GetSystemBubble()->bubble_view()->set_can_activate(true); |
| 187 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | 176 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()); | 177 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); |
| 192 RunAllPendingInMessageLoop(); | 178 RunAllPendingInMessageLoop(); |
| 193 | 179 |
| 194 EXPECT_TRUE(test_item_2->default_view()); | 180 EXPECT_TRUE(test_item_2->default_view()); |
| 195 EXPECT_FALSE(test_item_2->detailed_view()); | 181 EXPECT_FALSE(test_item_2->detailed_view()); |
| 196 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); | 182 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); |
| 197 | 183 |
| 198 // Show the detailed view of item 2 again. | 184 // Show the detailed view of item 2 again. |
| 199 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); | 185 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); |
| 200 EXPECT_TRUE(test_item_2->detailed_view()); | 186 EXPECT_TRUE(test_item_2->detailed_view()); |
| 201 RunAllPendingInMessageLoop(); | 187 RunAllPendingInMessageLoop(); |
| 202 EXPECT_FALSE(test_item_2->default_view()); | 188 EXPECT_FALSE(test_item_2->default_view()); |
| 203 | 189 |
| 204 // Transition back to default view, the default view of item 2 should NOT have | 190 // Transition back to default view, the default view of item 2 should NOT have |
| 205 // focus. | 191 // focus. |
| 206 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); | 192 TransitionFromDetailedToDefaultView(test_item_2->detailed_view()); |
| 207 RunAllPendingInMessageLoop(); | 193 RunAllPendingInMessageLoop(); |
| 208 | 194 |
| 209 EXPECT_TRUE(test_item_2->default_view()); | 195 EXPECT_TRUE(test_item_2->default_view()); |
| 210 EXPECT_FALSE(test_item_2->detailed_view()); | 196 EXPECT_FALSE(test_item_2->detailed_view()); |
| 211 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); | 197 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); |
| 212 } | 198 } |
| 213 | 199 |
| 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) { | 200 TEST_F(TrayDetailsViewTest, ScrollContentsTest) { |
| 320 SystemTray* tray = GetPrimarySystemTray(); | 201 SystemTray* tray = GetPrimarySystemTray(); |
| 321 TestItem* test_item = new TestItem; | 202 TestItem* test_item = new TestItem; |
| 322 tray->AddTrayItem(base::WrapUnique(test_item)); | 203 tray->AddTrayItem(base::WrapUnique(test_item)); |
| 323 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 204 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 324 RunAllPendingInMessageLoop(); | 205 RunAllPendingInMessageLoop(); |
| 325 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | 206 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); |
| 326 RunAllPendingInMessageLoop(); | 207 RunAllPendingInMessageLoop(); |
| 327 test_item->detailed_view()->CreateScrollerViews(); | 208 test_item->detailed_view()->CreateScrollerViews(); |
| 328 | 209 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 351 | 232 |
| 352 // Sticky header layer should be above the last child's layer. | 233 // Sticky header layer should be above the last child's layer. |
| 353 EXPECT_EQ(3u, layers.size()); | 234 EXPECT_EQ(3u, layers.size()); |
| 354 EXPECT_EQ(view3->layer(), layers[0]); | 235 EXPECT_EQ(view3->layer(), layers[0]); |
| 355 EXPECT_EQ(view4->layer(), layers[1]); | 236 EXPECT_EQ(view4->layer(), layers[1]); |
| 356 EXPECT_EQ(view2->layer(), layers[2]); | 237 EXPECT_EQ(view2->layer(), layers[2]); |
| 357 } | 238 } |
| 358 | 239 |
| 359 } // namespace test | 240 } // namespace test |
| 360 } // namespace ash | 241 } // namespace ash |
| OLD | NEW |