Commit 594ca47b authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

Reland "WebApp: Check pixel at the center of the generated icon."

This is a reland of 5a0adcbe

Looks like some platforms don't support sophisticated fonts to render fancy
unicode characters. Let's use simple "+" ASCII character.

Original change's description:
> WebApp: Check pixel at the center of the generated icon.
>
> We generate an icon placeholder using a letter with some solid
> background color.
>
> Let the test check if letter_color is actually presented in the icon.
>
> This is a follow up test enhancement for the previous CL:
> https://chromium-review.googlesource.com/c/chromium/src/+/1888234
>
> Bug: 1019102
> Change-Id: I10e196926dff78032dcd8f00e93e24715d1be913
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891816
> Commit-Queue: Alexey Baskakov <loyso@chromium.org>
> Reviewed-by: Alan Cutter <alancutter@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#711143}

Bug: 1019102
Change-Id: I25f09ff941b8256d7fae9a7121aa439dc2ef2b1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893596Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711591}
parent 21e819b5
......@@ -9,6 +9,7 @@
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "chrome/browser/web_applications/test/web_app_icon_test_utils.h"
#include "chrome/common/web_application_info.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -370,13 +371,10 @@ TEST_F(WebAppIconGeneratorTest, GenerateIcons) {
std::set<int> sizes = SizesToGenerate();
const SkColor bg_color = SK_ColorCYAN;
// This is Unicode "Black Large Circle" U+2B24 character encoded as UTF8.
// Guarantees that there is some letter_color area at the center of the
// generated icon.
const char black_circle[] = "\u2B24";
// The |+| character guarantees that there is some letter_color area at the
// center of the generated icon.
const std::vector<WebApplicationIconInfo> icon_infos =
GenerateIcons(black_circle, bg_color);
GenerateIcons("+", bg_color);
EXPECT_EQ(sizes.size(), icon_infos.size());
for (const auto& icon_info : icon_infos) {
......@@ -393,8 +391,19 @@ TEST_F(WebAppIconGeneratorTest, GenerateIcons) {
// We don't check corner colors here: the icon is rounded by border_radius.
EXPECT_EQ(bg_color, icon_info.data.getColor(border_radius * 2, center_y));
EXPECT_EQ(bg_color, icon_info.data.getColor(center_x, border_radius * 2));
// TODO(loyso): Peek a pixel at the center of icon and check the color.
// Only for large icons with a sharp letter: Peek a pixel at the center of
// icon. This is tested on Linux and ChromeOS only because different OSes
// use different text shaping engines.
#if defined(OS_LINUX)
const SkColor letter_color = color_utils::GetColorWithMaxContrast(bg_color);
if (icon_info.width >= icon_size::k256) {
SkColor center_color = icon_info.data.getColor(center_x, center_y);
SCOPED_TRACE(letter_color);
SCOPED_TRACE(center_color);
EXPECT_TRUE(AreColorsEqual(letter_color, center_color, /*threshold=*/50));
}
#endif // defined(OS_LINUX)
sizes.erase(icon_info.width);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment