#include "extensions/browser/extension_icon_image.h"
+#include <vector>
+
#include "base/json/json_file_value_serializer.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
-#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread.h"
+#include "extensions/browser/extensions_test.h"
#include "extensions/browser/image_loader.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_paths.h"
#include "ui/gfx/skia_util.h"
using content::BrowserThread;
-using extensions::Extension;
-using extensions::IconImage;
-using extensions::Manifest;
+namespace extensions {
namespace {
SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) {
bool waiting_;
bool image_loaded_;
gfx::Image image_;
- extensions::ImageLoader image_loader_;
+ ImageLoader image_loader_;
DISALLOW_COPY_AND_ASSIGN(TestImageLoader);
};
-class ExtensionIconImageTest : public testing::Test,
+class ExtensionIconImageTest : public ExtensionsTest,
public IconImage::Observer {
public:
ExtensionIconImageTest()
quit_in_image_loaded_(false),
ui_thread_(BrowserThread::UI, &ui_loop_),
file_thread_(BrowserThread::FILE),
- io_thread_(BrowserThread::IO) {
- }
+ io_thread_(BrowserThread::IO),
+ notification_service_(content::NotificationService::Create()) {}
virtual ~ExtensionIconImageTest() {}
Manifest::Location location) {
// Create and load an extension.
base::FilePath test_file;
- if (!PathService::Get(extensions::DIR_TEST_DATA, &test_file)) {
+ if (!PathService::Get(DIR_TEST_DATA, &test_file)) {
EXPECT_FALSE(true);
return NULL;
}
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
content::TestBrowserThread io_thread_;
+ scoped_ptr<content::NotificationService> notification_service_;
DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest);
};
supported_factors.push_back(ui::SCALE_FACTOR_100P);
supported_factors.push_back(ui::SCALE_FACTOR_200P);
ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
GetTestBitmap(extension.get(), "48.png", 32);
ASSERT_FALSE(bitmap_48_resized_to_32.empty());
- IconImage image(profile.get(),
+ IconImage image(browser_context(),
extension.get(),
- extensions::IconsInfo::GetIcons(extension.get()),
+ IconsInfo::GetIcons(extension.get()),
16,
default_icon,
this);
supported_factors.push_back(ui::SCALE_FACTOR_100P);
supported_factors.push_back(ui::SCALE_FACTOR_200P);
ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
SkBitmap bitmap_48 = GetTestBitmap(extension.get(), "48.png", 48);
ASSERT_FALSE(bitmap_48.empty());
- IconImage image(profile.get(),
+ IconImage image(browser_context(),
extension.get(),
- extensions::IconsInfo::GetIcons(extension.get()),
+ IconsInfo::GetIcons(extension.get()),
32,
default_icon,
this);
}
// There is no resource with exact size, but there is a smaller and a bigger
-// one. Requested size is smaller than 32 though, so the smaller resource should
-// be loaded.
-TEST_F(ExtensionIconImageTest, FallbackToSmaller) {
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
+// one. The bigger resource should be loaded.
+TEST_F(ExtensionIconImageTest, FallbackToBigger) {
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
// Load images we expect to find as representations in icon_image, so we
// can later use them to validate icon_image.
- SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16);
- ASSERT_FALSE(bitmap_16.empty());
+ SkBitmap bitmap_24 = GetTestBitmap(extension.get(), "24.png", 24);
+ ASSERT_FALSE(bitmap_24.empty());
- IconImage image(profile.get(),
+ IconImage image(browser_context(),
extension.get(),
- extensions::IconsInfo::GetIcons(extension.get()),
+ IconsInfo::GetIcons(extension.get()),
17,
default_icon,
this);
representation = image.image_skia().GetRepresentation(1.0f);
- // We should have loaded smaller (resized) resource.
+ // We should have loaded the smallest bigger (resized) resource.
EXPECT_EQ(1.0f, representation.scale());
EXPECT_EQ(17, representation.pixel_width());
EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
- EnsureBitmapSize(bitmap_16, 17)));
+ EnsureBitmapSize(bitmap_24, 17)));
}
// If resource set is empty, |GetRepresentation| should synchronously return
// default icon, without notifying observer of image change.
TEST_F(ExtensionIconImageTest, NoResources) {
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
gfx::ImageSkia default_icon = GetDefaultIcon();
const int kRequestedSize = 24;
- IconImage image(profile.get(),
+ IconImage image(browser_context(),
extension.get(),
empty_icon_set,
kRequestedSize,
// the observer should be notified when it's done. |GetRepresentation| should
// return the default icon representation once image load is done.
TEST_F(ExtensionIconImageTest, InvalidResource) {
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
gfx::ImageSkia default_icon = GetDefaultIcon();
- IconImage image(profile.get(),
+ IconImage image(browser_context(),
extension.get(),
invalid_icon_set,
kInvalidIconSize,
// Test that IconImage works with lazily (but synchronously) created default
// icon when IconImage returns synchronously.
TEST_F(ExtensionIconImageTest, LazyDefaultIcon) {
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
ExtensionIconSet empty_icon_set;
const int kRequestedSize = 128;
- IconImage image(profile.get(),
+ IconImage image(browser_context(),
extension.get(),
empty_icon_set,
kRequestedSize,
// Test that IconImage works with lazily (but synchronously) created default
// icon when IconImage returns asynchronously.
TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) {
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
ExtensionIconSet invalid_icon_set;
invalid_icon_set.Add(kInvalidIconSize, "invalid.png");
- IconImage image(profile.get(),
+ IconImage image(browser_context(),
extension.get(),
invalid_icon_set,
kInvalidIconSize,
// representation was not loaded while IconImage host was around, transparent
// representations should be returned.
TEST_F(ExtensionIconImageTest, IconImageDestruction) {
- scoped_ptr<content::BrowserContext> profile(new TestingProfile());
scoped_refptr<Extension> extension(CreateExtension(
"extension_icon_image", Manifest::INVALID_LOCATION));
ASSERT_TRUE(extension.get() != NULL);
ASSERT_FALSE(bitmap_16.empty());
scoped_ptr<IconImage> image(
- new IconImage(profile.get(),
+ new IconImage(browser_context(),
extension.get(),
- extensions::IconsInfo::GetIcons(extension.get()),
+ IconsInfo::GetIcons(extension.get()),
16,
default_icon,
this));
EXPECT_EQ(16, representation.GetHeight());
EXPECT_EQ(2.0f, representation.scale());
}
+
+} // namespace extensions