-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Pixel Diff Ash] Add a helper class to fetch icon colors
This CL adds a test helper class that returns different colors in several consecutive color fetches. This helper class is useful in pixel tests where we would like to add several items of different icon colors to verify the item order. This CL should not bring any noticeable changes. Bug: 1351444 Change-Id: I3971780f2e73908be31ea41d45d5b1898f7c9aae Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3829656 Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Commit-Queue: Andrew Xu <andrewxu@chromium.org> Cr-Commit-Position: refs/heads/main@{#1035146}
- Loading branch information
Andrew Xu
authored and
Chromium LUCI CQ
committed
Aug 15, 2022
1 parent
0d34fe2
commit a27dc46
Showing
5 changed files
with
73 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/test/ash_test_color_generator.h" | ||
|
||
namespace ash { | ||
|
||
namespace { | ||
|
||
// The array of the candidate colors for app icons. | ||
constexpr std::array<SkColor, 7> kColorArray = { | ||
SK_ColorWHITE, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, | ||
SK_ColorYELLOW, SK_ColorCYAN, SK_ColorMAGENTA}; | ||
|
||
} // namespace | ||
|
||
AshTestColorGenerator::AshTestColorGenerator(SkColor default_color) | ||
: default_color_(default_color) {} | ||
|
||
AshTestColorGenerator::~AshTestColorGenerator() = default; | ||
|
||
SkColor AshTestColorGenerator::GetAlternativeColor() { | ||
const SkColor color = kColorArray[next_color_index_]; | ||
next_color_index_ = (next_color_index_ + 1) % kColorArray.size(); | ||
return color; | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_TEST_ASH_TEST_COLOR_GENERATOR_H_ | ||
#define ASH_TEST_ASH_TEST_COLOR_GENERATOR_H_ | ||
|
||
#include "third_party/skia/include/core/SkColor.h" | ||
|
||
namespace ash { | ||
|
||
// A helper class to return a color. Usually used for solid-colored icons. | ||
class AshTestColorGenerator { | ||
public: | ||
explicit AshTestColorGenerator(SkColor default_color); | ||
AshTestColorGenerator(const AshTestColorGenerator&) = delete; | ||
AshTestColorGenerator& operator=(const AshTestColorGenerator&) = delete; | ||
~AshTestColorGenerator(); | ||
|
||
SkColor default_color() const { return default_color_; } | ||
|
||
// This method guarantees that two consequent callings get different colors. | ||
SkColor GetAlternativeColor(); | ||
|
||
private: | ||
const SkColor default_color_; | ||
|
||
// The next color to be returned by `GetAlternativeColor()`. | ||
size_t next_color_index_ = 0; | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_TEST_ASH_TEST_COLOR_GENERATOR_H_ |