Chromium Code Reviews| 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/shelf/shelf_widget.h" | 5 #include "ash/shelf/shelf_widget.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shelf/shelf_constants.h" | 8 #include "ash/shelf/shelf_constants.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_view.h" | 10 #include "ash/shelf/shelf_view.h" |
| 11 #include "ash/shelf/wm_shelf.h" | 11 #include "ash/shelf/wm_shelf.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_port.h" | 13 #include "ash/shell_port.h" |
| 14 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
| 15 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 16 #include "ash/test/ash_test_helper.h" | 16 #include "ash/test/ash_test_helper.h" |
| 17 #include "ash/test/shelf_view_test_api.h" | 17 #include "ash/test/shelf_view_test_api.h" |
| 18 #include "ash/test/test_shell_delegate.h" | |
| 18 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
| 19 #include "ash/wm_window.h" | 20 #include "ash/wm_window.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| 21 #include "ui/display/display.h" | 22 #include "ui/display/display.h" |
| 22 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
| 23 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 24 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 25 | 26 |
| 26 namespace ash { | 27 namespace ash { |
| 27 | |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 ShelfWidget* GetShelfWidget() { | 30 ShelfWidget* GetShelfWidget() { |
| 31 return test::AshTestBase::GetPrimaryShelf()->shelf_widget(); | 31 return test::AshTestBase::GetPrimaryShelf()->shelf_widget(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 ShelfLayoutManager* GetShelfLayoutManager() { | 34 ShelfLayoutManager* GetShelfLayoutManager() { |
| 35 return GetShelfWidget()->shelf_layout_manager(); | 35 return GetShelfWidget()->shelf_layout_manager(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | |
| 39 | |
| 40 using ShelfWidgetTest = test::AshTestBase; | |
| 41 | |
| 42 void TestLauncherAlignment(WmWindow* root, | 38 void TestLauncherAlignment(WmWindow* root, |
| 43 ShelfAlignment alignment, | 39 ShelfAlignment alignment, |
| 44 const gfx::Rect& expected) { | 40 const gfx::Rect& expected) { |
| 45 root->GetRootWindowController()->GetShelf()->SetAlignment(alignment); | 41 root->GetRootWindowController()->GetShelf()->SetAlignment(alignment); |
| 46 EXPECT_EQ(expected.ToString(), | 42 EXPECT_EQ(expected.ToString(), |
| 47 root->GetDisplayNearestWindow().work_area().ToString()); | 43 root->GetDisplayNearestWindow().work_area().ToString()); |
| 48 } | 44 } |
| 49 | 45 |
| 46 using ShelfWidgetTest = test::AshTestBase; | |
| 47 | |
| 50 TEST_F(ShelfWidgetTest, TestAlignment) { | 48 TEST_F(ShelfWidgetTest, TestAlignment) { |
| 51 UpdateDisplay("400x400"); | 49 UpdateDisplay("400x400"); |
| 52 { | 50 { |
| 53 SCOPED_TRACE("Single Bottom"); | 51 SCOPED_TRACE("Single Bottom"); |
| 54 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(), | 52 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(), |
| 55 SHELF_ALIGNMENT_BOTTOM, gfx::Rect(0, 0, 400, 352)); | 53 SHELF_ALIGNMENT_BOTTOM, gfx::Rect(0, 0, 400, 352)); |
| 56 } | 54 } |
| 57 { | 55 { |
| 58 SCOPED_TRACE("Single Locked"); | 56 SCOPED_TRACE("Single Locked"); |
| 59 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(), | 57 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(), |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 { | 314 { |
| 317 gfx::Point event_location(20, shelf_bounds.y() - 1); | 315 gfx::Point event_location(20, shelf_bounds.y() - 1); |
| 318 ui::TouchEvent touch( | 316 ui::TouchEvent touch( |
| 319 ui::ET_TOUCH_PRESSED, event_location, ui::EventTimeForNow(), | 317 ui::ET_TOUCH_PRESSED, event_location, ui::EventTimeForNow(), |
| 320 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); | 318 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); |
| 321 EXPECT_EQ(shelf_widget->GetNativeWindow(), | 319 EXPECT_EQ(shelf_widget->GetNativeWindow(), |
| 322 targeter->FindTargetForEvent(root, &touch)); | 320 targeter->FindTargetForEvent(root, &touch)); |
| 323 } | 321 } |
| 324 } | 322 } |
| 325 | 323 |
| 326 namespace { | 324 class ShelfWidgetAfterLoginTest : public test::AshTestBase { |
| 325 public: | |
| 326 ShelfWidgetAfterLoginTest() { set_start_session(false); } | |
| 327 ~ShelfWidgetAfterLoginTest() override = default; | |
| 327 | 328 |
| 328 // A ShellObserver that sets the shelf alignment and auto hide behavior when the | 329 void TestShelf(ShelfAlignment alignment, |
| 329 // shelf is created, to simulate ChromeLauncherController's behavior. | 330 ShelfAutoHideBehavior auto_hide_behavior, |
| 330 class ShelfInitializer : public ShellObserver { | 331 ShelfVisibilityState expected_shelf_visibility_state, |
| 331 public: | 332 ShelfAutoHideState expected_shelf_auto_hide_state) { |
| 332 ShelfInitializer(ShelfAlignment alignment, ShelfAutoHideBehavior auto_hide) | 333 // Simulate login. |
| 333 : alignment_(alignment), auto_hide_(auto_hide) { | 334 SetUserLoggedIn(true); |
| 334 Shell::Get()->AddShellObserver(this); | 335 SetSessionStarted(true); |
| 335 } | |
| 336 ~ShelfInitializer() override { Shell::Get()->RemoveShellObserver(this); } | |
| 337 | 336 |
| 338 // ShellObserver: | 337 // Simulate shelf settings being applied from profile prefs. |
| 339 void OnShelfCreatedForRootWindow(WmWindow* root_window) override { | 338 WmShelf* shelf = GetPrimaryShelf(); |
| 340 WmShelf* shelf = root_window->GetRootWindowController()->GetShelf(); | 339 ASSERT_NE(nullptr, shelf); |
| 341 shelf->SetAlignment(alignment_); | 340 shelf->SetAlignment(alignment); |
| 342 shelf->SetAutoHideBehavior(auto_hide_); | 341 shelf->SetAutoHideBehavior(auto_hide_behavior); |
| 343 shelf->UpdateVisibilityState(); | 342 shelf->UpdateVisibilityState(); |
| 343 | |
| 344 // Ensure settings are applied correctly. | |
| 345 EXPECT_EQ(alignment, shelf->alignment()); | |
| 346 EXPECT_EQ(auto_hide_behavior, shelf->auto_hide_behavior()); | |
| 347 EXPECT_EQ(expected_shelf_visibility_state, shelf->GetVisibilityState()); | |
| 348 EXPECT_EQ(expected_shelf_auto_hide_state, shelf->GetAutoHideState()); | |
| 344 } | 349 } |
| 345 | 350 |
| 346 private: | 351 private: |
| 347 ShelfAlignment alignment_; | 352 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetAfterLoginTest); |
| 348 ShelfAutoHideBehavior auto_hide_; | |
| 349 | |
| 350 DISALLOW_COPY_AND_ASSIGN(ShelfInitializer); | |
| 351 }; | 353 }; |
| 352 | 354 |
| 353 class ShelfWidgetTestWithInitializer : public ShelfWidgetTest { | 355 TEST_F(ShelfWidgetAfterLoginTest, InitialValues) { |
|
msw
2017/05/17 18:19:47
Great test!
| |
| 354 public: | 356 // Ensure shelf components are created. |
| 355 ShelfWidgetTestWithInitializer() { set_start_session(false); } | 357 WmShelf* shelf = GetPrimaryShelf(); |
| 356 ~ShelfWidgetTestWithInitializer() override {} | 358 ASSERT_NE(nullptr, shelf); |
| 359 ShelfWidget* shelf_widget = GetShelfWidget(); | |
| 360 ASSERT_NE(nullptr, shelf_widget); | |
| 361 ASSERT_NE(nullptr, shelf_widget->shelf_view_for_testing()); | |
| 362 ASSERT_NE(nullptr, shelf_widget->shelf_layout_manager()); | |
| 357 | 363 |
| 358 void TestCreateShelfWithInitialValues( | 364 // Ensure settings are correct before login. |
| 359 ShelfAlignment initial_alignment, | 365 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 360 ShelfAutoHideBehavior initial_auto_hide_behavior, | 366 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM_LOCKED, shelf->alignment()); |
| 361 ShelfVisibilityState expected_shelf_visibility_state, | 367 EXPECT_EQ(SHELF_AUTO_HIDE_ALWAYS_HIDDEN, shelf->auto_hide_behavior()); |
| 362 ShelfAutoHideState expected_shelf_auto_hide_state) { | 368 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 363 ShelfInitializer initializer(initial_alignment, initial_auto_hide_behavior); | |
| 364 SetUserLoggedIn(true); | |
| 365 SetSessionStarted(true); | |
| 366 | 369 |
| 367 ShelfWidget* shelf_widget = GetShelfWidget(); | 370 // Simulate login. |
| 368 ASSERT_NE(nullptr, shelf_widget); | 371 SetUserLoggedIn(true); |
| 369 WmShelf* shelf = GetPrimaryShelf(); | 372 SetSessionStarted(true); |
| 370 ASSERT_NE(nullptr, shelf); | |
| 371 ShelfLayoutManager* shelf_layout_manager = | |
| 372 shelf_widget->shelf_layout_manager(); | |
| 373 ASSERT_NE(nullptr, shelf_layout_manager); | |
| 374 | 373 |
| 375 EXPECT_EQ(initial_alignment, shelf->alignment()); | 374 // Ensure settings are correct after login. |
| 376 EXPECT_EQ(initial_auto_hide_behavior, shelf->auto_hide_behavior()); | 375 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 377 EXPECT_EQ(expected_shelf_visibility_state, | 376 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->alignment()); |
| 378 shelf_layout_manager->visibility_state()); | 377 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); |
| 379 EXPECT_EQ(expected_shelf_auto_hide_state, | 378 // "Hidden" is the default state when auto-hide is turned off. |
| 380 shelf_layout_manager->auto_hide_state()); | 379 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 381 } | 380 } |
| 382 | 381 |
| 383 private: | 382 TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysShelf) { |
| 384 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithInitializer); | 383 // The actual auto hide state is shown because there are no open windows. |
| 385 }; | 384 TestShelf(SHELF_ALIGNMENT_BOTTOM, SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, |
| 385 SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN); | |
| 386 } | |
| 387 | |
| 388 TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideNeverShelf) { | |
| 389 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | |
| 390 TestShelf(SHELF_ALIGNMENT_LEFT, SHELF_AUTO_HIDE_BEHAVIOR_NEVER, SHELF_VISIBLE, | |
| 391 SHELF_AUTO_HIDE_HIDDEN); | |
| 392 } | |
| 393 | |
| 394 TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysHideShelf) { | |
| 395 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | |
| 396 TestShelf(SHELF_ALIGNMENT_RIGHT, SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN, | |
| 397 SHELF_AUTO_HIDE_HIDDEN); | |
| 398 } | |
| 399 | |
| 400 TEST_F(ShelfWidgetAfterLoginTest, CreateLockedShelf) { | |
| 401 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | |
| 402 TestShelf(SHELF_ALIGNMENT_BOTTOM_LOCKED, SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | |
| 403 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | |
| 404 } | |
| 386 | 405 |
| 387 } // namespace | 406 } // namespace |
| 388 | |
| 389 TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysShelf) { | |
| 390 // The actual auto hide state is shown because there are no open windows. | |
| 391 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM, | |
| 392 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | |
| 393 SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN); | |
| 394 } | |
| 395 | |
| 396 TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideNeverShelf) { | |
| 397 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | |
| 398 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_LEFT, | |
| 399 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | |
| 400 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | |
| 401 } | |
| 402 | |
| 403 TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysHideShelf) { | |
| 404 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | |
| 405 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_RIGHT, | |
| 406 SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN, | |
| 407 SHELF_AUTO_HIDE_HIDDEN); | |
| 408 } | |
| 409 | |
| 410 TEST_F(ShelfWidgetTestWithInitializer, CreateLockedShelf) { | |
| 411 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | |
| 412 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED, | |
| 413 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | |
| 414 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | |
| 415 } | |
| 416 | |
| 417 } // namespace ash | 407 } // namespace ash |
| OLD | NEW |