| Index: chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader_unittest.cc
|
| diff --git a/chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image_unittest.cc b/chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader_unittest.cc
|
| similarity index 59%
|
| rename from chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image_unittest.cc
|
| rename to chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader_unittest.cc
|
| index 46e8f474780a3ca93dc2a007ec23387a5332cc33..c0f69a3e62c483c51254e473aafb5140fcb94729 100644
|
| --- a/chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image_unittest.cc
|
| +++ b/chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader_unittest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/ui/app_list/search/launcher_search/extension_badged_icon_image.h"
|
| +#include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader.h"
|
|
|
| #include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h"
|
| #include "extensions/common/manifest_constants.h"
|
| @@ -24,55 +24,33 @@ namespace {
|
| const char kTestExtensionId[] = "foo";
|
| const char kTestCustomIconURL[] = "chrome-extension://foo/bar";
|
|
|
| -// This image source generates following image:
|
| -//
|
| -// ###
|
| -// #**
|
| -// #**
|
| -//
|
| -// where # is the primary fill color, and * is the secondary fill color.
|
| -class BadgedImageSource : public gfx::CanvasImageSource {
|
| +// Generates an image source which is filled with |fill_color|.
|
| +class FillColorImageSource : public gfx::CanvasImageSource {
|
| public:
|
| - BadgedImageSource(const gfx::Size& image_size,
|
| - const SkColor primary_fill_color)
|
| - : CanvasImageSource(image_size, false),
|
| - primary_fill_color_(primary_fill_color),
|
| - secondary_fill_color_(SK_ColorTRANSPARENT) {}
|
| -
|
| - BadgedImageSource(const gfx::Size& image_size,
|
| - const SkColor primary_fill_color,
|
| - const SkColor secondary_fill_color)
|
| - : CanvasImageSource(image_size, false),
|
| - primary_fill_color_(primary_fill_color),
|
| - secondary_fill_color_(secondary_fill_color) {}
|
| + FillColorImageSource(const gfx::Size& image_size, const SkColor fill_color)
|
| + : CanvasImageSource(image_size, false), fill_color_(fill_color) {}
|
|
|
| void Draw(gfx::Canvas* canvas) override {
|
| - canvas->FillRect(gfx::Rect(size()), primary_fill_color_);
|
| -
|
| - const int badge_dimension = size().width() * 2 / 3;
|
| - const int offset = size().width() - badge_dimension;
|
| - canvas->FillRect(
|
| - gfx::Rect(offset, offset, badge_dimension, badge_dimension),
|
| - secondary_fill_color_);
|
| + canvas->FillRect(gfx::Rect(size()), fill_color_);
|
| }
|
|
|
| private:
|
| - const SkColor primary_fill_color_;
|
| - const SkColor secondary_fill_color_;
|
| + const SkColor fill_color_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(BadgedImageSource);
|
| + DISALLOW_COPY_AND_ASSIGN(FillColorImageSource);
|
| };
|
|
|
| -// Test implementation of ExtensionBadgedIconImage.
|
| -class ExtensionBadgedIconImageTestImpl : public ExtensionBadgedIconImage {
|
| +// Test implementation of LauncherSearchIconImageLoader.
|
| +class LauncherSearchIconImageLoaderTestImpl
|
| + : public LauncherSearchIconImageLoader {
|
| public:
|
| // Use base class constructor.
|
| - using ExtensionBadgedIconImage::ExtensionBadgedIconImage;
|
| + using LauncherSearchIconImageLoader::LauncherSearchIconImageLoader;
|
|
|
| const gfx::ImageSkia& LoadExtensionIcon() override {
|
| // Returns 32x32 black image.
|
| extension_icon_ = gfx::ImageSkia(
|
| - new BadgedImageSource(icon_size_, SK_ColorBLACK), icon_size_);
|
| + new FillColorImageSource(icon_size_, SK_ColorBLACK), icon_size_);
|
| return extension_icon_;
|
| }
|
|
|
| @@ -141,17 +119,16 @@ scoped_refptr<extensions::Extension> CreateTestExtension(
|
| extensions::Extension::NO_FLAGS, extension_id, &error);
|
| }
|
|
|
| -// Returns true if icon image of |badged_icon_image| equals to |expected_image|.
|
| +// Returns true if icon image of |result_image| equals to |expected_image|.
|
| bool IsEqual(const gfx::ImageSkia& expected_image,
|
| - const ExtensionBadgedIconImage& badged_icon_image) {
|
| - return gfx::test::IsEqual(
|
| - expected_image.GetRepresentation(1.0).sk_bitmap(),
|
| - badged_icon_image.GetIconImage().GetRepresentation(1.0).sk_bitmap());
|
| + const gfx::ImageSkia& result_image) {
|
| + return gfx::test::IsEqual(expected_image.GetRepresentation(1.0).sk_bitmap(),
|
| + result_image.GetRepresentation(1.0).sk_bitmap());
|
| }
|
|
|
| } // namespace
|
|
|
| -class ExtensionBadgedIconImageTest : public testing::Test {
|
| +class LauncherSearchIconImageLoaderTest : public testing::Test {
|
| protected:
|
| void SetUp() override { extension_ = CreateTestExtension(kTestExtensionId); }
|
|
|
| @@ -162,59 +139,71 @@ class ExtensionBadgedIconImageTest : public testing::Test {
|
| scoped_refptr<extensions::Extension> extension_;
|
| };
|
|
|
| -TEST_F(ExtensionBadgedIconImageTest, WithoutCustomIconSuccessCase) {
|
| +TEST_F(LauncherSearchIconImageLoaderTest, WithoutCustomIconSuccessCase) {
|
| GURL icon_url; // No custom icon.
|
| - ExtensionBadgedIconImageTestImpl impl(icon_url, nullptr, nullptr, 32,
|
| - GetFakeErrorReporter());
|
| + LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr, nullptr, 32,
|
| + GetFakeErrorReporter());
|
| impl.LoadResources();
|
|
|
| - // Icon should be black image.
|
| + // Assert that extension icon image is set to icon image and badge icon image
|
| + // is null.
|
| gfx::Size icon_size(32, 32);
|
| - gfx::ImageSkia expected_image(new BadgedImageSource(icon_size, SK_ColorBLACK),
|
| - icon_size);
|
| - ASSERT_TRUE(IsEqual(expected_image, impl));
|
| + gfx::ImageSkia expected_image(
|
| + new FillColorImageSource(icon_size, SK_ColorBLACK), icon_size);
|
| + ASSERT_TRUE(IsEqual(expected_image, impl.GetIconImage()));
|
| +
|
| + ASSERT_TRUE(impl.GetBadgeIconImage().isNull());
|
| }
|
|
|
| -TEST_F(ExtensionBadgedIconImageTest, ExtensionIconAsyncLoadSuccessCase) {
|
| +TEST_F(LauncherSearchIconImageLoaderTest, ExtensionIconAsyncLoadSuccessCase) {
|
| GURL icon_url; // No custom icon.
|
| - ExtensionBadgedIconImageTestImpl impl(icon_url, nullptr, nullptr, 32,
|
| - GetFakeErrorReporter());
|
| + LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr, nullptr, 32,
|
| + GetFakeErrorReporter());
|
| impl.LoadResources();
|
|
|
| // Extension icon is loaded as async.
|
| gfx::Size icon_size(32, 32);
|
| - gfx::ImageSkia extension_icon(new BadgedImageSource(icon_size, SK_ColorGREEN),
|
| - icon_size);
|
| + gfx::ImageSkia extension_icon(
|
| + new FillColorImageSource(icon_size, SK_ColorGREEN), icon_size);
|
| impl.LoadExtensionIconAsync(extension_icon);
|
|
|
| - gfx::ImageSkia expected_image(new BadgedImageSource(icon_size, SK_ColorGREEN),
|
| - icon_size);
|
| - ASSERT_TRUE(IsEqual(expected_image, impl));
|
| + // Assert that the asynchronously loaded image is set to icon image and badge
|
| + // icon image is null.
|
| + gfx::ImageSkia expected_image(
|
| + new FillColorImageSource(icon_size, SK_ColorGREEN), icon_size);
|
| + ASSERT_TRUE(IsEqual(expected_image, impl.GetIconImage()));
|
| +
|
| + ASSERT_TRUE(impl.GetBadgeIconImage().isNull());
|
| }
|
|
|
| -TEST_F(ExtensionBadgedIconImageTest, WithCustomIconSuccessCase) {
|
| +TEST_F(LauncherSearchIconImageLoaderTest, WithCustomIconSuccessCase) {
|
| GURL icon_url(kTestCustomIconURL);
|
| - ExtensionBadgedIconImageTestImpl impl(icon_url, nullptr, extension_.get(), 32,
|
| - GetFakeErrorReporter());
|
| + LauncherSearchIconImageLoaderTestImpl impl(
|
| + icon_url, nullptr, extension_.get(), 32, GetFakeErrorReporter());
|
| ASSERT_FALSE(impl.IsLoadExtensionIconResourceCalled());
|
| impl.LoadResources();
|
|
|
| - // Asserts that LoadExtensionIconResource is called.
|
| + // Assert that LoadExtensionIconResource is called.
|
| ASSERT_TRUE(impl.IsLoadExtensionIconResourceCalled());
|
|
|
| // Load custom icon as async.
|
| gfx::Size icon_size(32, 32);
|
| - gfx::ImageSkia custom_icon(new BadgedImageSource(icon_size, SK_ColorGREEN),
|
| + gfx::ImageSkia custom_icon(new FillColorImageSource(icon_size, SK_ColorGREEN),
|
| icon_size);
|
| impl.CallOnCustomIconLoaded(custom_icon);
|
|
|
| + // Assert that custom icon image is set to icon image and extension icon image
|
| + // is set to badge icon image.
|
| gfx::ImageSkia expected_image(
|
| - new BadgedImageSource(icon_size, SK_ColorGREEN, SK_ColorBLACK),
|
| - icon_size);
|
| - ASSERT_TRUE(IsEqual(expected_image, impl));
|
| + new FillColorImageSource(icon_size, SK_ColorGREEN), icon_size);
|
| + ASSERT_TRUE(IsEqual(expected_image, impl.GetIconImage()));
|
| +
|
| + gfx::ImageSkia expected_badge_icon_image(
|
| + new FillColorImageSource(icon_size, SK_ColorBLACK), icon_size);
|
| + ASSERT_TRUE(IsEqual(expected_badge_icon_image, impl.GetBadgeIconImage()));
|
| }
|
|
|
| -TEST_F(ExtensionBadgedIconImageTest, InvalidCustomIconUrl) {
|
| +TEST_F(LauncherSearchIconImageLoaderTest, InvalidCustomIconUrl) {
|
| // Use a really long URL (for testing the string truncation).
|
| // The URL is from the wrong extension (foo2), so should be rejected.
|
| std::string invalid_url =
|
| @@ -225,8 +214,9 @@ TEST_F(ExtensionBadgedIconImageTest, InvalidCustomIconUrl) {
|
|
|
| scoped_ptr<FakeErrorReporter> fake_error_reporter = GetFakeErrorReporter();
|
| GURL icon_url(invalid_url);
|
| - ExtensionBadgedIconImageTestImpl impl(icon_url, nullptr, extension_.get(), 32,
|
| - fake_error_reporter->Duplicate());
|
| + LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr,
|
| + extension_.get(), 32,
|
| + fake_error_reporter->Duplicate());
|
| impl.LoadResources();
|
|
|
| // Warning message should be provided.
|
| @@ -241,11 +231,12 @@ TEST_F(ExtensionBadgedIconImageTest, InvalidCustomIconUrl) {
|
| ASSERT_FALSE(impl.IsLoadExtensionIconResourceCalled());
|
| }
|
|
|
| -TEST_F(ExtensionBadgedIconImageTest, FailedToLoadCustomIcon) {
|
| +TEST_F(LauncherSearchIconImageLoaderTest, FailedToLoadCustomIcon) {
|
| scoped_ptr<FakeErrorReporter> fake_error_reporter = GetFakeErrorReporter();
|
| GURL icon_url(kTestCustomIconURL);
|
| - ExtensionBadgedIconImageTestImpl impl(icon_url, nullptr, extension_.get(), 32,
|
| - fake_error_reporter->Duplicate());
|
| + LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr,
|
| + extension_.get(), 32,
|
| + fake_error_reporter->Duplicate());
|
| impl.LoadResources();
|
| ASSERT_TRUE(impl.IsLoadExtensionIconResourceCalled());
|
|
|
| @@ -259,11 +250,14 @@ TEST_F(ExtensionBadgedIconImageTest, FailedToLoadCustomIcon) {
|
| "URL: chrome-extension://foo/bar",
|
| fake_error_reporter->GetLastWarningMessage());
|
|
|
| - // Icon should be extension icon.
|
| + // Assert that extension icon image is set to icon image and badge icon image
|
| + // is null.
|
| gfx::Size icon_size(32, 32);
|
| - gfx::ImageSkia expected_image(new BadgedImageSource(icon_size, SK_ColorBLACK),
|
| - icon_size);
|
| - ASSERT_TRUE(IsEqual(expected_image, impl));
|
| + gfx::ImageSkia expected_image(
|
| + new FillColorImageSource(icon_size, SK_ColorBLACK), icon_size);
|
| + ASSERT_TRUE(IsEqual(expected_image, impl.GetIconImage()));
|
| +
|
| + ASSERT_TRUE(impl.GetBadgeIconImage().isNull());
|
| }
|
|
|
| } // namespace app_list
|
|
|