scrollable_shelf_view_pixeltest.cc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (c) 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/shelf/scrollable_shelf_view.h"
  5. #include "ash/shelf/test/scrollable_shelf_test_base.h"
  6. #include "ash/test/ash_pixel_diff_test_helper.h"
  7. #include "ash/test/ash_pixel_test_init_params.h"
  8. namespace ash {
  9. class ScrollableShelfViewPixelRTLTest
  10. : public ScrollableShelfTestBase,
  11. public testing::WithParamInterface<bool /*is_rtl=*/> {
  12. public:
  13. ScrollableShelfViewPixelRTLTest() {
  14. PrepareForPixelDiffTest();
  15. if (GetParam()) {
  16. pixel_test::InitParams init_params;
  17. init_params.under_rtl = true;
  18. SetPixelTestInitParam(init_params);
  19. }
  20. }
  21. ScrollableShelfViewPixelRTLTest(const ScrollableShelfViewPixelRTLTest&) =
  22. delete;
  23. ScrollableShelfViewPixelRTLTest& operator=(
  24. const ScrollableShelfViewPixelRTLTest&) = delete;
  25. ~ScrollableShelfViewPixelRTLTest() override = default;
  26. // ScrollableShelfTestBase:
  27. void SetUp() override {
  28. ScrollableShelfTestBase::SetUp();
  29. pixel_test_helper_.InitSkiaGoldPixelDiff("scrollable_shelf_view_pixel");
  30. AddAppShortcutsUntilOverflow(/*use_alternative_color=*/true);
  31. }
  32. AshPixelDiffTestHelper pixel_test_helper_;
  33. };
  34. INSTANTIATE_TEST_SUITE_P(RTL, ScrollableShelfViewPixelRTLTest, testing::Bool());
  35. // Verifies the scrollable shelf under overflow.
  36. TEST_P(ScrollableShelfViewPixelRTLTest, Basics) {
  37. EXPECT_TRUE(pixel_test_helper_.CompareUiComponentScreenshot(
  38. GetParam() ? "overflow_rtl" : "overflow",
  39. AshPixelDiffTestHelper::UiComponent::kShelfWidget));
  40. }
  41. class ScrollableShelfViewWithGuestModePixelTest
  42. : public ScrollableShelfTestBase,
  43. public testing::WithParamInterface<bool /*use_guest_mode=*/> {
  44. public:
  45. ScrollableShelfViewWithGuestModePixelTest() {
  46. set_start_session(false);
  47. PrepareForPixelDiffTest();
  48. }
  49. ScrollableShelfViewWithGuestModePixelTest(
  50. const ScrollableShelfViewWithGuestModePixelTest&) = delete;
  51. ScrollableShelfViewWithGuestModePixelTest& operator=(
  52. const ScrollableShelfViewWithGuestModePixelTest&) = delete;
  53. ~ScrollableShelfViewWithGuestModePixelTest() override = default;
  54. // ScrollableShelfTestBase:
  55. void SetUp() override {
  56. ScrollableShelfTestBase::SetUp();
  57. pixel_test_helper_.InitSkiaGoldPixelDiff(
  58. "scrollable_shelf_view_with_guest_mode_pixel");
  59. if (GetParam())
  60. SimulateGuestLogin();
  61. else
  62. SimulateUserLogin("user@gmail.com");
  63. StabilizeUIForPixelTest();
  64. }
  65. AshPixelDiffTestHelper pixel_test_helper_;
  66. };
  67. INSTANTIATE_TEST_SUITE_P(EnableGuestMode,
  68. ScrollableShelfViewWithGuestModePixelTest,
  69. testing::Bool());
  70. // Verifies the shelf context menu.
  71. TEST_P(ScrollableShelfViewWithGuestModePixelTest, VerifyShelfContextMenu) {
  72. // Move the mouse to the shelf center then right-click.
  73. const gfx::Point shelf_center =
  74. scrollable_shelf_view_->GetBoundsInScreen().CenterPoint();
  75. GetEventGenerator()->MoveMouseTo(shelf_center);
  76. GetEventGenerator()->PressRightButton();
  77. EXPECT_TRUE(pixel_test_helper_.ComparePrimaryFullScreen(
  78. GetParam() ? "shelf_context_menu_in_guest_mode" : "shelf_context_menu"));
  79. }
  80. } // namespace ash