scrollable_shelf_test_base.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/test/scrollable_shelf_test_base.h"
  5. #include "ash/shelf/scrollable_shelf_view.h"
  6. #include "ash/shelf/shelf.h"
  7. #include "ash/shelf/shelf_test_util.h"
  8. #include "ash/shelf/shelf_view_test_api.h"
  9. #include "ash/shelf/shelf_widget.h"
  10. #include "ash/test/ash_test_util.h"
  11. namespace ash {
  12. ScrollableShelfTestBase::ScrollableShelfTestBase() = default;
  13. ScrollableShelfTestBase::~ScrollableShelfTestBase() = default;
  14. void ScrollableShelfTestBase::SetUp() {
  15. AshTestBase::SetUp();
  16. scrollable_shelf_view_ = GetPrimaryShelf()
  17. ->shelf_widget()
  18. ->hotseat_widget()
  19. ->scrollable_shelf_view();
  20. shelf_view_ = scrollable_shelf_view_->shelf_view();
  21. test_api_ =
  22. std::make_unique<ShelfViewTestAPI>(scrollable_shelf_view_->shelf_view());
  23. test_api_->SetAnimationDuration(base::Milliseconds(1));
  24. }
  25. void ScrollableShelfTestBase::TearDown() {
  26. // When the test is completed, the page flip timer should be idle.
  27. EXPECT_FALSE(scrollable_shelf_view_->IsPageFlipTimerBusyForTest());
  28. AshTestBase::TearDown();
  29. }
  30. void ScrollableShelfTestBase::PopulateAppShortcut(int number,
  31. bool use_alternative_color) {
  32. for (int i = 0; i < number; i++)
  33. AddAppShortcutWithIconColor(
  34. TYPE_PINNED_APP, use_alternative_color
  35. ? icon_color_generator_.GetAlternativeColor()
  36. : icon_color_generator_.default_color());
  37. }
  38. void ScrollableShelfTestBase::AddAppShortcutsUntilOverflow(
  39. bool use_alternative_color) {
  40. while (scrollable_shelf_view_->layout_strategy_for_test() ==
  41. ScrollableShelfView::kNotShowArrowButtons) {
  42. AddAppShortcutWithIconColor(
  43. TYPE_PINNED_APP, use_alternative_color
  44. ? icon_color_generator_.GetAlternativeColor()
  45. : icon_color_generator_.default_color());
  46. }
  47. }
  48. ShelfID ScrollableShelfTestBase::AddAppShortcutWithIconColor(
  49. ShelfItemType item_type,
  50. SkColor color) {
  51. ShelfItem item = ShelfTestUtil::AddAppShortcutWithIcon(
  52. base::NumberToString(id_++), item_type,
  53. CreateSolidColorTestImage(gfx::Size(1, 1), color));
  54. // Wait for shelf view's bounds animation to end. Otherwise the scrollable
  55. // shelf's bounds are not updated yet.
  56. test_api_->RunMessageLoopUntilAnimationsDone();
  57. return item.id;
  58. }
  59. } // namespace ash