login_shelf_view_pixeltest.cc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/focus_cycler.h"
  5. #include "ash/login/ui/login_test_base.h"
  6. #include "ash/shelf/login_shelf_view.h"
  7. #include "ash/shelf/shelf.h"
  8. #include "ash/shelf/shelf_widget.h"
  9. #include "ash/test/ash_pixel_diff_test_helper.h"
  10. namespace ash {
  11. class LoginShelfViewPixelTest : public LoginTestBase {
  12. public:
  13. LoginShelfViewPixelTest() { PrepareForPixelDiffTest(); }
  14. LoginShelfViewPixelTest(const LoginShelfViewPixelTest&) = delete;
  15. LoginShelfViewPixelTest& operator=(const LoginShelfViewPixelTest&) = delete;
  16. ~LoginShelfViewPixelTest() override = default;
  17. // Focuses on the login shelf's shutdown button.
  18. void FocusOnShutdownButton() {
  19. views::View* shutdown_button =
  20. GetPrimaryShelf()->shelf_widget()->GetLoginShelfView()->GetViewByID(
  21. LoginShelfView::kShutdown);
  22. views::Widget* shutdown_button_widget = shutdown_button->GetWidget();
  23. Shell::Get()->focus_cycler()->FocusWidget(shutdown_button_widget);
  24. shutdown_button_widget->Activate();
  25. shutdown_button_widget->GetFocusManager()->SetFocusedView(shutdown_button);
  26. }
  27. // Returns the screenshot name prefix.
  28. virtual const char* GetScreenshotPrefix() const {
  29. return "login_shelf_view_pixel";
  30. }
  31. // LoginTestBase:
  32. void SetUp() override {
  33. LoginTestBase::SetUp();
  34. pixel_test_helper_.InitSkiaGoldPixelDiff(GetScreenshotPrefix());
  35. // The wallpaper has been set when the pixel test is set up.
  36. ShowLoginScreen(/*set_wallpaper=*/false);
  37. SetUserCount(1);
  38. }
  39. AshPixelDiffTestHelper pixel_test_helper_;
  40. };
  41. // Verifies that moving the focus by the tab key from the lock contents view
  42. // to the login shelf works as expected.
  43. TEST_F(LoginShelfViewPixelTest, FocusTraversalFromLockContents) {
  44. // Trigger the tab key. Verify that the login user expand button is focused.
  45. PressAndReleaseKey(ui::VKEY_TAB);
  46. EXPECT_TRUE(pixel_test_helper_.ComparePrimaryFullScreen(
  47. "focus_on_login_user_expand_button"));
  48. // Trigger the tab key. Check that the login shelf shutdown button is focused.
  49. PressAndReleaseKey(ui::VKEY_TAB);
  50. EXPECT_TRUE(
  51. pixel_test_helper_.ComparePrimaryFullScreen("focus_on_shutdown_button"));
  52. // Trigger the tab key. Check that the browser as guest button is focused.
  53. PressAndReleaseKey(ui::VKEY_TAB);
  54. EXPECT_TRUE(pixel_test_helper_.ComparePrimaryFullScreen(
  55. "focus_on_browser_as_guest_button"));
  56. // Trigger the tab key. Check that the add person button is focused.
  57. PressAndReleaseKey(ui::VKEY_TAB);
  58. EXPECT_TRUE(pixel_test_helper_.ComparePrimaryFullScreen(
  59. "focus_on_add_person_button"));
  60. }
  61. // Used to verify the login shelf features with a policy wallpaper.
  62. TEST_F(LoginShelfViewPixelTest, FocusTraversalWithinShelf) {
  63. // Focus on the calendar view.
  64. FocusOnShutdownButton();
  65. PressAndReleaseKey(ui::VKEY_TAB);
  66. PressAndReleaseKey(ui::VKEY_TAB);
  67. PressAndReleaseKey(ui::VKEY_TAB);
  68. EXPECT_TRUE(pixel_test_helper_.CompareUiComponentScreenshot(
  69. "focus_on_calendar_view",
  70. AshPixelDiffTestHelper::UiComponent::kShelfWidget));
  71. // Focus on the time view.
  72. PressAndReleaseKey(ui::VKEY_TAB);
  73. EXPECT_TRUE(pixel_test_helper_.CompareUiComponentScreenshot(
  74. "focus_on_time_view", AshPixelDiffTestHelper::UiComponent::kShelfWidget));
  75. PressAndReleaseKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN);
  76. PressAndReleaseKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN);
  77. // Move the focus back to the add person button.
  78. EXPECT_TRUE(pixel_test_helper_.CompareUiComponentScreenshot(
  79. "refocus_on_login_shelf",
  80. AshPixelDiffTestHelper::UiComponent::kShelfWidget));
  81. }
  82. class LoginShelfWithPolicyWallpaperPixelTestWithRTL
  83. : public LoginShelfViewPixelTest,
  84. public testing::WithParamInterface<bool /*is_rtl=*/> {
  85. public:
  86. LoginShelfWithPolicyWallpaperPixelTestWithRTL() {
  87. pixel_test::InitParams init_params;
  88. init_params.wallpaper_init_type = pixel_test::WallpaperInitType::kPolicy;
  89. if (GetParam())
  90. init_params.under_rtl = true;
  91. SetPixelTestInitParam(init_params);
  92. }
  93. LoginShelfWithPolicyWallpaperPixelTestWithRTL(
  94. const LoginShelfWithPolicyWallpaperPixelTestWithRTL&) = delete;
  95. LoginShelfWithPolicyWallpaperPixelTestWithRTL& operator=(
  96. const LoginShelfWithPolicyWallpaperPixelTestWithRTL&) = delete;
  97. ~LoginShelfWithPolicyWallpaperPixelTestWithRTL() override = default;
  98. // LoginShelfViewPixelTest:
  99. const char* GetScreenshotPrefix() const override {
  100. return "login_shelf_view_policy_wallpaper_pixel";
  101. }
  102. };
  103. INSTANTIATE_TEST_SUITE_P(RTL,
  104. LoginShelfWithPolicyWallpaperPixelTestWithRTL,
  105. testing::Bool());
  106. // Verifies that focusing on the login shelf widget with a policy wallpaper
  107. // works as expected (see https://crbug.com/1197052).
  108. TEST_P(LoginShelfWithPolicyWallpaperPixelTestWithRTL, FocusOnShutdownButton) {
  109. FocusOnShutdownButton();
  110. EXPECT_TRUE(pixel_test_helper_.ComparePrimaryFullScreen(
  111. GetParam() ? "focus_on_shutdown_button_rtl"
  112. : "focus_on_shutdown_button"));
  113. }
  114. } // namespace ash