Commit 6f43982d authored by Jaeyong Bae's avatar Jaeyong Bae Committed by Commit Bot

Add processing for missing fields in ImageResource

If any of sizes or purpose are missing in ImageResource,
provide default values for 'purpose' and 'sizes'.

Bug: 868875
Change-Id: I2e88144e1d098a18c740ffeaf9a2fb474db031a1
Reviewed-on: https://chromium-review.googlesource.com/c/1244176
Commit-Queue: Jaeyong Bae <jdragon.bae@gmail.com>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarMugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597175}
parent 739f7f62
...@@ -114,10 +114,18 @@ KURL BackgroundFetchIconLoader::PickBestIconForDisplay( ...@@ -114,10 +114,18 @@ KURL BackgroundFetchIconLoader::PickBestIconForDisplay(
// Update the src of |icon| to include the base URL in case relative paths // Update the src of |icon| to include the base URL in case relative paths
// were used. // were used.
icon.setSrc(execution_context->CompleteURL(icon.src())); icon.setSrc(execution_context->CompleteURL(icon.src()));
icons.emplace_back(blink::ConvertManifestImageResource(icon)); Manifest::ImageResource candidate_icon =
blink::ConvertManifestImageResource(icon);
// Provide default values for 'purpose' and 'sizes' if they are missing.
if (candidate_icon.sizes.empty())
candidate_icon.sizes.emplace_back(gfx::Size(0, 0));
if (candidate_icon.purpose.empty()) {
candidate_icon.purpose.emplace_back(
Manifest::ImageResource::Purpose::ANY);
}
icons.emplace_back(candidate_icon);
} }
// TODO(crbug.com/868875): Handle cases where `sizes` or `purpose` is empty.
return KURL(ManifestIconSelector::FindBestMatchingIcon( return KURL(ManifestIconSelector::FindBestMatchingIcon(
std::move(icons), icon_display_size_pixels_.height, kMinimumIconSizeInPx, std::move(icons), icon_display_size_pixels_.height, kMinimumIconSizeInPx,
Manifest::ImageResource::Purpose::ANY)); Manifest::ImageResource::Purpose::ANY));
......
...@@ -97,12 +97,14 @@ class BackgroundFetchIconLoaderTest : public PageTestBase { ...@@ -97,12 +97,14 @@ class BackgroundFetchIconLoaderTest : public PageTestBase {
void LoadIcon(const KURL& url, void LoadIcon(const KURL& url,
const WebSize& maximum_size, const WebSize& maximum_size,
base::OnceClosure quit_closure) { base::OnceClosure quit_closure,
const String& sizes = "500x500",
const String& purpose = "ANY") {
ManifestImageResource icon; ManifestImageResource icon;
icon.setSrc(url.GetString()); icon.setSrc(url.GetString());
icon.setType("image/png"); icon.setType("image/png");
icon.setSizes("500x500"); icon.setSizes(sizes);
icon.setPurpose("ANY"); icon.setPurpose(purpose);
HeapVector<ManifestImageResource> icons(1, icon); HeapVector<ManifestImageResource> icons(1, icon);
loader_->icons_ = std::move(icons); loader_->icons_ = std::move(icons);
loader_->DidGetIconDisplaySizeIfSoLoadIcon( loader_->DidGetIconDisplaySizeIfSoLoadIcon(
...@@ -183,4 +185,34 @@ TEST_F(BackgroundFetchIconLoaderTest, PickRightIcon) { ...@@ -183,4 +185,34 @@ TEST_F(BackgroundFetchIconLoaderTest, PickRightIcon) {
kBackgroundFetchImageLoaderIcon48x48)); kBackgroundFetchImageLoaderIcon48x48));
} }
TEST_F(BackgroundFetchIconLoaderTest, EmptySizes) {
base::RunLoop run_loop;
WebSize maximum_size{192, 168};
LoadIcon(KURL(kBackgroundFetchImageLoaderIcon500x500FullPath), maximum_size,
run_loop.QuitClosure(), "", "ANY");
platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
run_loop.Run();
ASSERT_EQ(BackgroundFetchLoadState::kLoadSuccessful, loaded_);
ASSERT_FALSE(bitmap_.drawsNothing());
}
TEST_F(BackgroundFetchIconLoaderTest, EmptyPurpose) {
base::RunLoop run_loop;
WebSize maximum_size{192, 168};
LoadIcon(KURL(kBackgroundFetchImageLoaderIcon500x500FullPath), maximum_size,
run_loop.QuitClosure(), "500X500", "");
platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
run_loop.Run();
ASSERT_EQ(BackgroundFetchLoadState::kLoadSuccessful, loaded_);
ASSERT_FALSE(bitmap_.drawsNothing());
}
} // namespace blink } // namespace blink
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