Commit d32dda5b authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Desktop PWAs: Support webp icons for PWA promotability

InstallableManager now supports webp icons for desktop PWA installs,
in addition to png and svg icons.

TBR=mmenke@chromium.org

Bug: 466958
Change-Id: I47fe3ae5c4d96fabba7dbc2d839d8e299df47355
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1942904
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Commit-Queue: Dominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721884}
parent bad8a05f
...@@ -270,6 +270,14 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerSvgIcon) { ...@@ -270,6 +270,14 @@ IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerSvgIcon) {
base::nullopt); base::nullopt);
} }
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, WebAppBannerWebPIcon) {
std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser()));
RunBannerTest(browser(), manager.get(),
GetBannerURLWithManifest("/banners/manifest_webp_icon.json"),
base::nullopt);
}
IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) { IN_PROC_BROWSER_TEST_F(AppBannerManagerBrowserTest, NoManifest) {
std::unique_ptr<AppBannerManagerTest> manager( std::unique_ptr<AppBannerManagerTest> manager(
CreateAppBannerManager(browser())); CreateAppBannerManager(browser()));
......
...@@ -28,15 +28,15 @@ static const char kManifestDisplayNotSupportedMessage[] = ...@@ -28,15 +28,15 @@ static const char kManifestDisplayNotSupportedMessage[] =
"Manifest 'display' property must be one of 'standalone', 'fullscreen', or " "Manifest 'display' property must be one of 'standalone', 'fullscreen', or "
"'minimal-ui'"; "'minimal-ui'";
static const char kManifestMissingSuitableIconMessage[] = static const char kManifestMissingSuitableIconMessage[] =
"Manifest does not contain a suitable icon - PNG or SVG format of at least " "Manifest does not contain a suitable icon - PNG, SVG or WebP format of at "
"%dpx is required, the sizes attribute must be set, and the purpose " "least %dpx is required, the sizes attribute must be set, and the purpose "
"attribute, if set, must include \"any\" or \"maskable\"."; "attribute, if set, must include \"any\" or \"maskable\".";
static const char kNoMatchingServiceWorkerMessage[] = static const char kNoMatchingServiceWorkerMessage[] =
"No matching service worker detected. You may need to reload the page, or " "No matching service worker detected. You may need to reload the page, or "
"check that the service worker for the current page also controls the " "check that the service worker for the current page also controls the "
"start URL from the manifest"; "start URL from the manifest";
static const char kNoAcceptableIconMessage[] = static const char kNoAcceptableIconMessage[] =
"No supplied icon is at least %dpx square in PNG or SVG format"; "No supplied icon is at least %dpx square in PNG, SVG or WebP format";
static const char kCannotDownloadIconMessage[] = static const char kCannotDownloadIconMessage[] =
"Could not download a required icon from the manifest"; "Could not download a required icon from the manifest";
static const char kNoIconAvailableMessage[] = static const char kNoIconAvailableMessage[] =
......
...@@ -103,8 +103,10 @@ struct ImageTypeDetails { ...@@ -103,8 +103,10 @@ struct ImageTypeDetails {
constexpr ImageTypeDetails kSupportedImageTypes[] = { constexpr ImageTypeDetails kSupportedImageTypes[] = {
{".png", "image/png"}, {".png", "image/png"},
// TODO(https://crbug.com/578122): Add SVG support for Android. // TODO(https://crbug.com/578122): Add SVG support for Android.
// TODO(https://crbug.com/466958): Add WebP support for Android.
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
{".svg", "image/svg+xml"}, {".svg", "image/svg+xml"},
{".webp", "image/webp"},
#endif #endif
}; };
......
...@@ -173,6 +173,34 @@ TEST_F(InstallableManagerUnitTest, ManifestSupportsImageSVG) { ...@@ -173,6 +173,34 @@ TEST_F(InstallableManagerUnitTest, ManifestSupportsImageSVG) {
#endif #endif
} }
TEST_F(InstallableManagerUnitTest, ManifestSupportsImageWebP) {
blink::Manifest manifest = GetValidManifest();
manifest.icons[0].type = base::ASCIIToUTF16("image/webp");
manifest.icons[0].src = GURL("http://example.com/");
// TODO(https://crbug.com/466958): Add WebP support for Android.
#if defined(OS_ANDROID)
EXPECT_FALSE(IsManifestValid(manifest));
EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
#else
EXPECT_TRUE(IsManifestValid(manifest));
EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
#endif
// If the type is null, the icon src is checked instead.
// Case is ignored.
manifest.icons[0].type.clear();
manifest.icons[0].src = GURL("http://example.com/icon.wEBp");
// TODO(https://crbug.com/466958): Add WebP support for Android.
#if defined(OS_ANDROID)
EXPECT_FALSE(IsManifestValid(manifest));
EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
#else
EXPECT_TRUE(IsManifestValid(manifest));
EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
#endif
}
TEST_F(InstallableManagerUnitTest, ManifestRequiresPurposeAny) { TEST_F(InstallableManagerUnitTest, ManifestRequiresPurposeAny) {
blink::Manifest manifest = GetValidManifest(); blink::Manifest manifest = GetValidManifest();
......
{
"name": "WebP test app",
"icons": [
{
"src": "webp-icon.webp",
"sizes": "192x192",
"type": "image/webp"
}
],
"start_url": "manifest_test_page.html",
"display": "standalone",
"orientation": "landscape"
}
...@@ -58,6 +58,8 @@ std::string GetContentType(const base::FilePath& path) { ...@@ -58,6 +58,8 @@ std::string GetContentType(const base::FilePath& path) {
return "text/plain"; return "text/plain";
if (path.MatchesExtension(FILE_PATH_LITERAL(".wav"))) if (path.MatchesExtension(FILE_PATH_LITERAL(".wav")))
return "audio/wav"; return "audio/wav";
if (path.MatchesExtension(FILE_PATH_LITERAL(".webp")))
return "image/webp";
if (path.MatchesExtension(FILE_PATH_LITERAL(".xml"))) if (path.MatchesExtension(FILE_PATH_LITERAL(".xml")))
return "text/xml"; return "text/xml";
if (path.MatchesExtension(FILE_PATH_LITERAL(".mhtml"))) if (path.MatchesExtension(FILE_PATH_LITERAL(".mhtml")))
......
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