OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/shelf/shelf_widget.h" | 5 #include "ash/common/shelf/shelf_widget.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/shelf/shelf_constants.h" | 8 #include "ash/common/shelf/shelf_constants.h" |
9 #include "ash/common/shelf/shelf_delegate.h" | |
10 #include "ash/common/shelf/shelf_layout_manager.h" | 9 #include "ash/common/shelf/shelf_layout_manager.h" |
11 #include "ash/common/shelf/shelf_view.h" | 10 #include "ash/common/shelf/shelf_view.h" |
12 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
13 #include "ash/common/system/status_area_widget.h" | 12 #include "ash/common/system/status_area_widget.h" |
14 #include "ash/common/wm_root_window_controller.h" | 13 #include "ash/common/wm_root_window_controller.h" |
15 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
16 #include "ash/common/wm_window.h" | 15 #include "ash/common/wm_window.h" |
17 #include "ash/root_window_controller.h" | 16 #include "ash/root_window_controller.h" |
18 #include "ash/shell.h" | 17 #include "ash/shell.h" |
19 #include "ash/test/ash_md_test_base.h" | 18 #include "ash/test/ash_md_test_base.h" |
20 #include "ash/test/ash_test_helper.h" | 19 #include "ash/test/ash_test_helper.h" |
21 #include "ash/test/shelf_view_test_api.h" | 20 #include "ash/test/shelf_view_test_api.h" |
22 #include "ash/test/test_shell_delegate.h" | |
23 #include "ash/wm/window_util.h" | 21 #include "ash/wm/window_util.h" |
24 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
25 #include "ui/display/display.h" | 23 #include "ui/display/display.h" |
26 #include "ui/events/event_utils.h" | 24 #include "ui/events/event_utils.h" |
27 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
28 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
29 | 27 |
30 namespace ash { | 28 namespace ash { |
31 | 29 |
32 namespace { | 30 namespace { |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 gfx::Point event_location(20, shelf_bounds.y() - 1); | 339 gfx::Point event_location(20, shelf_bounds.y() - 1); |
342 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0, | 340 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0, |
343 ui::EventTimeForNow()); | 341 ui::EventTimeForNow()); |
344 EXPECT_EQ(shelf_widget->GetNativeWindow(), | 342 EXPECT_EQ(shelf_widget->GetNativeWindow(), |
345 targeter->FindTargetForEvent(root, &touch)); | 343 targeter->FindTargetForEvent(root, &touch)); |
346 } | 344 } |
347 } | 345 } |
348 | 346 |
349 namespace { | 347 namespace { |
350 | 348 |
351 // A TestShelfDelegate that sets the shelf alignment and auto hide behavior in | 349 // A ShellObserver that sets the shelf alignment and auto hide behavior when the |
352 // OnShelfCreated, to simulate ChromeLauncherController's behavior. | 350 // shelf is created, to simulate ChromeLauncherController's behavior. |
353 class TestShelfDelegate : public ShelfDelegate { | 351 class ShelfInitializer : public ShellObserver { |
354 public: | 352 public: |
355 TestShelfDelegate(ShelfAlignment initial_alignment, | 353 ShelfInitializer(ShelfAlignment alignment, ShelfAutoHideBehavior auto_hide) |
356 ShelfAutoHideBehavior initial_auto_hide_behavior) | 354 : alignment_(alignment), auto_hide_(auto_hide) { |
357 : initial_alignment_(initial_alignment), | 355 WmShell::Get()->AddShellObserver(this); |
358 initial_auto_hide_behavior_(initial_auto_hide_behavior) {} | 356 } |
359 ~TestShelfDelegate() override {} | 357 ~ShelfInitializer() override { WmShell::Get()->RemoveShellObserver(this); } |
360 | 358 |
361 // ShelfDelegate implementation. | 359 // ShellObserver: |
362 void OnShelfCreated(WmShelf* shelf) override { | 360 void OnShelfCreatedForRootWindow(WmWindow* root_window) override { |
363 shelf->SetAlignment(initial_alignment_); | 361 WmShelf* shelf = root_window->GetRootWindowController()->GetShelf(); |
364 shelf->SetAutoHideBehavior(initial_auto_hide_behavior_); | 362 shelf->SetAlignment(alignment_); |
365 } | 363 shelf->SetAutoHideBehavior(auto_hide_); |
366 void OnShelfDestroyed(WmShelf* shelf) override {} | |
367 void OnShelfAlignmentChanged(WmShelf* shelf) override {} | |
368 void OnShelfAutoHideBehaviorChanged(WmShelf* shelf) override {} | |
369 void OnShelfAutoHideStateChanged(WmShelf* shelf) override {} | |
370 void OnShelfVisibilityStateChanged(WmShelf* shelf) override {} | |
371 ShelfID GetShelfIDForAppID(const std::string& app_id) override { return 0; } | |
372 ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id, | |
373 const std::string& launch_id) override { | |
374 return 0; | |
375 } | |
376 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return false; } | |
377 const std::string& GetAppIDForShelfID(ShelfID id) override { | |
378 return base::EmptyString(); | |
379 } | |
380 void PinAppWithID(const std::string& app_id) override {} | |
381 bool IsAppPinned(const std::string& app_id) override { return false; } | |
382 void UnpinAppWithID(const std::string& app_id) override {} | |
383 | |
384 private: | |
385 ShelfAlignment initial_alignment_; | |
386 ShelfAutoHideBehavior initial_auto_hide_behavior_; | |
387 | |
388 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegate); | |
389 }; | |
390 | |
391 // A TestShellDelegate that creates a TestShelfDelegate with initial values. | |
392 class ShelfWidgetTestShellDelegate : public test::TestShellDelegate { | |
393 public: | |
394 ShelfWidgetTestShellDelegate() {} | |
395 ~ShelfWidgetTestShellDelegate() override {} | |
396 | |
397 // test::TestShellDelegate | |
398 ShelfDelegate* CreateShelfDelegate(ShelfModel* model) override { | |
399 return new TestShelfDelegate(initial_alignment_, | |
400 initial_auto_hide_behavior_); | |
401 } | |
402 | |
403 void set_initial_alignment(ShelfAlignment alignment) { | |
404 initial_alignment_ = alignment; | |
405 } | |
406 | |
407 void set_initial_auto_hide_behavior(ShelfAutoHideBehavior behavior) { | |
408 initial_auto_hide_behavior_ = behavior; | |
409 } | 364 } |
410 | 365 |
411 private: | 366 private: |
412 ShelfAlignment initial_alignment_ = SHELF_ALIGNMENT_BOTTOM; | 367 ShelfAlignment alignment_; |
413 ShelfAutoHideBehavior initial_auto_hide_behavior_ = | 368 ShelfAutoHideBehavior auto_hide_; |
414 SHELF_AUTO_HIDE_BEHAVIOR_NEVER; | 369 |
415 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestShellDelegate); | 370 DISALLOW_COPY_AND_ASSIGN(ShelfInitializer); |
416 }; | 371 }; |
417 | 372 |
418 class ShelfWidgetTestWithDelegate : public ShelfWidgetTest { | 373 class ShelfWidgetTestWithInitializer : public ShelfWidgetTest { |
419 public: | 374 public: |
420 ShelfWidgetTestWithDelegate() { set_start_session(false); } | 375 ShelfWidgetTestWithInitializer() { set_start_session(false); } |
421 ~ShelfWidgetTestWithDelegate() override {} | 376 ~ShelfWidgetTestWithInitializer() override {} |
422 | |
423 // ShelfWidgetTest: | |
424 void SetUp() override { | |
425 shelf_widget_test_shell_delegate_ = new ShelfWidgetTestShellDelegate; | |
426 ash_test_helper()->set_test_shell_delegate( | |
427 shelf_widget_test_shell_delegate_); | |
428 ShelfWidgetTest::SetUp(); | |
429 } | |
430 | 377 |
431 void TestCreateShelfWithInitialValues( | 378 void TestCreateShelfWithInitialValues( |
432 ShelfAlignment initial_alignment, | 379 ShelfAlignment initial_alignment, |
433 ShelfAutoHideBehavior initial_auto_hide_behavior, | 380 ShelfAutoHideBehavior initial_auto_hide_behavior, |
434 ShelfVisibilityState expected_shelf_visibility_state, | 381 ShelfVisibilityState expected_shelf_visibility_state, |
435 ShelfAutoHideState expected_shelf_auto_hide_state) { | 382 ShelfAutoHideState expected_shelf_auto_hide_state) { |
436 shelf_widget_test_shell_delegate_->set_initial_alignment(initial_alignment); | 383 ShelfInitializer initializer(initial_alignment, initial_auto_hide_behavior); |
437 shelf_widget_test_shell_delegate_->set_initial_auto_hide_behavior( | |
438 initial_auto_hide_behavior); | |
439 SetUserLoggedIn(true); | 384 SetUserLoggedIn(true); |
440 SetSessionStarted(true); | 385 SetSessionStarted(true); |
441 | 386 |
442 ShelfWidget* shelf_widget = GetShelfWidget(); | 387 ShelfWidget* shelf_widget = GetShelfWidget(); |
443 ASSERT_NE(nullptr, shelf_widget); | 388 ASSERT_NE(nullptr, shelf_widget); |
444 WmShelf* shelf = GetPrimaryShelf(); | 389 WmShelf* shelf = GetPrimaryShelf(); |
445 ASSERT_NE(nullptr, shelf); | 390 ASSERT_NE(nullptr, shelf); |
446 ShelfLayoutManager* shelf_layout_manager = | 391 ShelfLayoutManager* shelf_layout_manager = |
447 shelf_widget->shelf_layout_manager(); | 392 shelf_widget->shelf_layout_manager(); |
448 ASSERT_NE(nullptr, shelf_layout_manager); | 393 ASSERT_NE(nullptr, shelf_layout_manager); |
449 | 394 |
450 EXPECT_EQ(initial_alignment, shelf->alignment()); | 395 EXPECT_EQ(initial_alignment, shelf->alignment()); |
451 EXPECT_EQ(initial_auto_hide_behavior, shelf->auto_hide_behavior()); | 396 EXPECT_EQ(initial_auto_hide_behavior, shelf->auto_hide_behavior()); |
452 EXPECT_EQ(expected_shelf_visibility_state, | 397 EXPECT_EQ(expected_shelf_visibility_state, |
453 shelf_layout_manager->visibility_state()); | 398 shelf_layout_manager->visibility_state()); |
454 EXPECT_EQ(expected_shelf_auto_hide_state, | 399 EXPECT_EQ(expected_shelf_auto_hide_state, |
455 shelf_layout_manager->auto_hide_state()); | 400 shelf_layout_manager->auto_hide_state()); |
456 } | 401 } |
457 | 402 |
458 private: | 403 private: |
459 ShelfWidgetTestShellDelegate* shelf_widget_test_shell_delegate_; | 404 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithInitializer); |
460 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithDelegate); | |
461 }; | 405 }; |
462 | 406 |
463 } // namespace | 407 } // namespace |
464 | 408 |
465 INSTANTIATE_TEST_CASE_P( | 409 INSTANTIATE_TEST_CASE_P( |
466 /* prefix intentionally left blank due to only one parameterization */, | 410 /* prefix intentionally left blank due to only one parameterization */, |
467 ShelfWidgetTestWithDelegate, | 411 ShelfWidgetTestWithInitializer, |
468 testing::Values(MaterialDesignController::NON_MATERIAL, | 412 testing::Values(MaterialDesignController::NON_MATERIAL, |
469 MaterialDesignController::MATERIAL_NORMAL, | 413 MaterialDesignController::MATERIAL_NORMAL, |
470 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | 414 MaterialDesignController::MATERIAL_EXPERIMENTAL)); |
471 | 415 |
472 TEST_P(ShelfWidgetTestWithDelegate, CreateAutoHideAlwaysShelf) { | 416 TEST_P(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysShelf) { |
473 // The actual auto hide state is shown because there are no open windows. | 417 // The actual auto hide state is shown because there are no open windows. |
474 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM, | 418 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM, |
475 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | 419 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, |
476 SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN); | 420 SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN); |
477 } | 421 } |
478 | 422 |
479 TEST_P(ShelfWidgetTestWithDelegate, CreateAutoHideNeverShelf) { | 423 TEST_P(ShelfWidgetTestWithInitializer, CreateAutoHideNeverShelf) { |
480 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | 424 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. |
481 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_LEFT, | 425 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_LEFT, |
482 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | 426 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, |
483 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | 427 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); |
484 } | 428 } |
485 | 429 |
486 TEST_P(ShelfWidgetTestWithDelegate, CreateAutoHideAlwaysHideShelf) { | 430 TEST_P(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysHideShelf) { |
487 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | 431 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. |
488 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_RIGHT, | 432 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_RIGHT, |
489 SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN, | 433 SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN, |
490 SHELF_AUTO_HIDE_HIDDEN); | 434 SHELF_AUTO_HIDE_HIDDEN); |
491 } | 435 } |
492 | 436 |
493 TEST_P(ShelfWidgetTestWithDelegate, CreateLockedShelf) { | 437 TEST_P(ShelfWidgetTestWithInitializer, CreateLockedShelf) { |
494 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | 438 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. |
495 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED, | 439 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED, |
496 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | 440 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, |
497 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | 441 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); |
498 } | 442 } |
499 | 443 |
500 } // namespace ash | 444 } // namespace ash |
OLD | NEW |