-
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.
Add unit test for WebappIcon.GetIdealSizeInPx
Bug: 1444216 Change-Id: If491edba150d040553811e9d6841ca455fdc905a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4573881 Commit-Queue: Ella Ge <eirage@chromium.org> Commit-Queue: Glenn Hartmann <hartmanng@chromium.org> Auto-Submit: Ella Ge <eirage@chromium.org> Reviewed-by: Glenn Hartmann <hartmanng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1150326}
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 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
86 changes: 86 additions & 0 deletions
86
components/webapps/browser/android/webapp_icon_unittest.cc
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,86 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/webapps/browser/android/webapp_icon.h" | ||
|
||
#include "components/webapps/browser/android/webapps_icon_utils.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "url/gurl.h" | ||
|
||
namespace webapps { | ||
|
||
namespace { | ||
|
||
const int kIdealHomescreenIconSize = 96; | ||
const int kMinimumHomescreenIconSize = 48; | ||
const int kIdealSplashImageSize = 256; | ||
const int kMinimumSplashImageSize = 32; | ||
const int kIdealMonochromeIconSize = 48; | ||
const int kIdealAdaptiveLauncherIconSize = 166; | ||
const int kIdealShortcutIconSize = 72; | ||
|
||
} // namespace | ||
|
||
class WebappIconTest : public testing::Test { | ||
public: | ||
WebappIconTest() = default; | ||
|
||
WebappIconTest(const WebappIconTest&) = delete; | ||
WebappIconTest& operator=(const WebappIconTest&) = delete; | ||
|
||
protected: | ||
void SetUp() override { | ||
WebappsIconUtils::SetIconSizesForTesting({ | ||
kIdealHomescreenIconSize, | ||
kMinimumHomescreenIconSize, | ||
kIdealSplashImageSize, | ||
kMinimumSplashImageSize, | ||
kIdealMonochromeIconSize, | ||
kIdealAdaptiveLauncherIconSize, | ||
kIdealShortcutIconSize, | ||
}); | ||
} | ||
|
||
const GURL kIconUrl = GURL("http://example.com"); | ||
}; | ||
|
||
TEST_F(WebappIconTest, GetIdealIconSizes) { | ||
WebappIcon primary_icon(kIconUrl, false /* is_maskable*/, | ||
webapk::Image::PRIMARY_ICON); | ||
EXPECT_EQ(primary_icon.GetIdealSizeInPx(), kIdealHomescreenIconSize); | ||
|
||
WebappIcon maskable_primary_icon(kIconUrl, true /* is_maskable*/, | ||
webapk::Image::PRIMARY_ICON); | ||
EXPECT_EQ(maskable_primary_icon.GetIdealSizeInPx(), | ||
kIdealAdaptiveLauncherIconSize); | ||
|
||
WebappIcon splash_icon(kIconUrl, false /* is_maskable*/, | ||
webapk::Image::SPLASH_ICON); | ||
EXPECT_EQ(splash_icon.GetIdealSizeInPx(), kIdealSplashImageSize); | ||
|
||
WebappIcon shortcut_icon(kIconUrl, false /* is_maskable*/, | ||
webapk::Image::SHORTCUT_ICON); | ||
EXPECT_EQ(shortcut_icon.GetIdealSizeInPx(), kIdealShortcutIconSize); | ||
} | ||
|
||
// Test that icon with multiple usages have ideal size of the largest usage. | ||
TEST_F(WebappIconTest, GetIdealSizeForMultiplePurpose) { | ||
WebappIcon icon(kIconUrl); | ||
icon.AddUsage(webapk::Image::PRIMARY_ICON); | ||
icon.AddUsage(webapk::Image::SPLASH_ICON); | ||
EXPECT_EQ(icon.GetIdealSizeInPx(), kIdealSplashImageSize); | ||
|
||
WebappIcon icon2(kIconUrl); | ||
icon2.AddUsage(webapk::Image::PRIMARY_ICON); | ||
icon2.AddUsage(webapk::Image::SHORTCUT_ICON); | ||
EXPECT_EQ(icon2.GetIdealSizeInPx(), kIdealHomescreenIconSize); | ||
|
||
WebappIcon icon3(kIconUrl); | ||
icon3.AddUsage(webapk::Image::PRIMARY_ICON); | ||
icon3.AddUsage(webapk::Image::SPLASH_ICON); | ||
icon3.AddUsage(webapk::Image::SHORTCUT_ICON); | ||
EXPECT_EQ(icon3.GetIdealSizeInPx(), kIdealSplashImageSize); | ||
} | ||
|
||
} // namespace webapps |
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