File: shelf_test_base.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (87 lines) | stat: -rw-r--r-- 3,054 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/shelf/test/shelf_test_base.h"

#include "ash/shelf/scrollable_shelf_view.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_test_util.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/test/ash_test_util.h"
#include "base/strings/string_number_conversions.h"
#include "ui/gfx/image/image_unittest_util.h"

namespace ash {

ShelfTestBase::ShelfTestBase() = default;

ShelfTestBase::~ShelfTestBase() = default;

void ShelfTestBase::SetUp() {
  AshTestBase::SetUp();
  UpdateShelfRelatedMembers();
}

void ShelfTestBase::TearDown() {
  // When the test is completed, the page flip timer should be idle.
  EXPECT_FALSE(scrollable_shelf_view_->IsPageFlipTimerBusyForTest());

  AshTestBase::TearDown();
}

void ShelfTestBase::UpdateShelfRelatedMembers() {
  scrollable_shelf_view_ = GetPrimaryShelf()
                               ->shelf_widget()
                               ->hotseat_widget()
                               ->scrollable_shelf_view();
  shelf_view_ = scrollable_shelf_view_->shelf_view();
  test_api_ =
      std::make_unique<ShelfViewTestAPI>(scrollable_shelf_view_->shelf_view());
  test_api_->SetAnimationDuration(base::Milliseconds(1));
}

void ShelfTestBase::PopulateAppShortcut(int number,
                                        bool use_alternative_color) {
  for (int i = 0; i < number; i++)
    AddAppShortcutWithIconColor(
        TYPE_PINNED_APP, use_alternative_color
                             ? icon_color_generator_.GetAlternativeColor()
                             : icon_color_generator_.default_color());
}

void ShelfTestBase::AddAppShortcutsUntilOverflow(bool use_alternative_color) {
  while (scrollable_shelf_view_->layout_strategy_for_test() ==
         ScrollableShelfView::kNotShowArrowButtons) {
    AddAppShortcutWithIconColor(
        TYPE_PINNED_APP, use_alternative_color
                             ? icon_color_generator_.GetAlternativeColor()
                             : icon_color_generator_.default_color());
  }
}

ShelfItem ShelfTestBase::AddWebAppShortcut() {
  const int icon_dimension = 28;
  const int badge_icon_dimension = 18;
  ShelfItem item = ShelfTestUtil::AddWebAppShortcut(
      "shortcut_id", true,
      gfx::test::CreateImageSkia(icon_dimension, SK_ColorRED),
      gfx::test::CreateImageSkia(badge_icon_dimension, SK_ColorCYAN));
  return item;
}

ShelfID ShelfTestBase::AddAppShortcutWithIconColor(ShelfItemType item_type,
                                                   SkColor color) {
  ShelfItem item = ShelfTestUtil::AddAppShortcutWithIcon(
      base::NumberToString(id_++), item_type,
      CreateSolidColorTestImage(gfx::Size(1, 1), color));

  // Wait for shelf view's bounds animation to end. Otherwise the scrollable
  // shelf's bounds are not updated yet.
  test_api_->RunMessageLoopUntilAnimationsDone();

  return item.id;
}

}  // namespace ash