Chromium Code Reviews| Index: chrome/browser/extensions/image_loader_unittest.cc |
| diff --git a/chrome/browser/extensions/image_loader_unittest.cc b/chrome/browser/extensions/image_loader_unittest.cc |
| index 05cea06db4661170d1b80a0ae35488fb1421e6fb..793cc265947f141b025d4ca2aa4af073ec8a594d 100644 |
| --- a/chrome/browser/extensions/image_loader_unittest.cc |
| +++ b/chrome/browser/extensions/image_loader_unittest.cc |
| @@ -47,6 +47,13 @@ class ImageLoaderTest : public testing::Test { |
| image_ = image; |
| } |
| + void OnImageURLLoaded(const GURL& url) { |
| + image_loaded_count_++; |
| + if (quit_in_image_loaded_) |
| + base::MessageLoop::current()->Quit(); |
| + url_ = url; |
| + } |
| + |
| void WaitForImageLoad() { |
| quit_in_image_loaded_ = true; |
| base::MessageLoop::current()->Run(); |
| @@ -95,6 +102,7 @@ class ImageLoaderTest : public testing::Test { |
| } |
| gfx::Image image_; |
| + GURL url_; |
|
Finnur
2013/10/02 09:52:15
Document:
// Holds the image loaded by the test.
a
dvh-g
2013/10/02 15:08:13
Done.
dvh-g
2013/10/02 15:08:13
Done.
|
| private: |
| virtual void SetUp() OVERRIDE { |
| @@ -123,7 +131,7 @@ TEST_F(ImageLoaderTest, LoadImage) { |
| ExtensionIconSet::MATCH_EXACTLY); |
| gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, |
| extension_misc::EXTENSION_ICON_SMALLISH); |
| - ImageLoader loader; |
| + ImageLoader loader(NULL); |
| loader.LoadImageAsync(extension.get(), |
| image_resource, |
| max_size, |
| @@ -156,7 +164,7 @@ TEST_F(ImageLoaderTest, DeleteExtensionWhileWaitingForCache) { |
| ExtensionIconSet::MATCH_EXACTLY); |
| gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, |
| extension_misc::EXTENSION_ICON_SMALLISH); |
| - ImageLoader loader; |
| + ImageLoader loader(NULL); |
| std::set<int> sizes; |
| sizes.insert(extension_misc::EXTENSION_ICON_SMALLISH); |
| loader.LoadImageAsync(extension.get(), |
| @@ -210,7 +218,7 @@ TEST_F(ImageLoaderTest, MultipleImages) { |
| ui::SCALE_FACTOR_NONE)); |
| } |
| - ImageLoader loader; |
| + ImageLoader loader(NULL); |
| loader.LoadImagesAsync(extension.get(), info_list, |
| base::Bind(&ImageLoaderTest::OnImageLoaded, |
| base::Unretained(this))); |
| @@ -258,3 +266,121 @@ TEST_F(ImageLoaderTest, IsComponentExtensionResource) { |
| ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); |
| #endif |
| } |
| + |
| +// Tests loading an image works correctly. |
| +TEST_F(ImageLoaderTest, LoadIcon) { |
| + scoped_refptr<Extension> extension(CreateExtension( |
| + "image_loading_tracker", Manifest::INVALID_LOCATION)); |
| + ASSERT_TRUE(extension.get() != NULL); |
| + |
| + ImageLoader loader(NULL); |
| + loader.LoadExtensionIconAsync(extension.get(), |
| + extension_misc::EXTENSION_ICON_SMALLISH, |
| + false, |
| + base::Bind(&ImageLoaderTest::OnImageLoaded, |
| + base::Unretained(this))); |
| + |
| + // The image isn't cached, so we should not have received notification. |
| + EXPECT_EQ(0, image_loaded_count()); |
| + |
| + WaitForImageLoad(); |
| + |
| + // We should have gotten the image. |
| + EXPECT_EQ(1, image_loaded_count()); |
| + |
| + // Check that the image was loaded. |
| + EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
| + image_.ToSkBitmap()->width()); |
| +} |
| + |
| +// Tests loading an icon in grayscale works correctly. |
| +TEST_F(ImageLoaderTest, LoadIconGrayscale) { |
| + scoped_refptr<Extension> extension(CreateExtension( |
| + "image_loading_tracker", Manifest::INVALID_LOCATION)); |
| + ASSERT_TRUE(extension.get() != NULL); |
| + |
| + ImageLoader loader(NULL); |
| + loader.LoadExtensionIconAsync(extension.get(), |
| + extension_misc::EXTENSION_ICON_SMALLISH, |
| + true, |
| + base::Bind(&ImageLoaderTest::OnImageLoaded, |
| + base::Unretained(this))); |
| + |
| + // The image isn't cached, so we should not have received notification. |
| + EXPECT_EQ(0, image_loaded_count()); |
| + |
| + WaitForImageLoad(); |
| + |
| + // We should have gotten the image. |
| + EXPECT_EQ(1, image_loaded_count()); |
| + |
| + // Check that the image was loaded. |
| + EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
| + image_.ToSkBitmap()->width()); |
| +} |
| + |
| +// Tests loading an icon URL works correctly. |
| +TEST_F(ImageLoaderTest, LoadIconURL) { |
| + scoped_refptr<Extension> extension(CreateExtension( |
| + "image_loading_tracker", Manifest::INVALID_LOCATION)); |
| + ASSERT_TRUE(extension.get() != NULL); |
| + |
| + ImageLoader loader(NULL); |
| + loader.LoadExtensionIconDataURLAsync( |
| + extension.get(), |
| + extension_misc::EXTENSION_ICON_SMALLISH, |
| + true, |
| + base::Bind(&ImageLoaderTest::OnImageURLLoaded, base::Unretained(this))); |
| + |
| + // The image isn't cached, so we should not have received notification. |
| + EXPECT_EQ(0, image_loaded_count()); |
| + |
| + WaitForImageLoad(); |
| + |
| + // We should have gotten the image. |
| + EXPECT_EQ(1, image_loaded_count()); |
|
Finnur
2013/10/02 09:52:15
We could test against an actual data URL. Or is th
dvh-g
2013/10/02 15:08:13
Even though lossless, I think that PNG compression
Finnur
2013/10/02 15:19:27
Fair enough.
|
| +} |
| + |
| +// Tests loading the default icon works correctly. |
| +TEST_F(ImageLoaderTest, LoadDefaultIcon) { |
| + ImageLoader loader(NULL); |
| + loader.LoadExtensionIconAsync( |
| + NULL, |
| + -1, |
| + false, |
| + base::Bind(&ImageLoaderTest::OnImageLoaded, base::Unretained(this))); |
| + |
| + // The image isn't cached, so we should not have received notification. |
| + EXPECT_EQ(0, image_loaded_count()); |
| + |
| + WaitForImageLoad(); |
| + |
| + // We should have gotten the image. |
| + EXPECT_EQ(1, image_loaded_count()); |
| +} |
| + |
| +// Tests loading the icon of an extension without icon works correctly. |
| +TEST_F(ImageLoaderTest, LoadExtensionWithoutIcon) { |
| + scoped_refptr<Extension> extension(CreateExtension( |
| + "default_image_loading_tracker", Manifest::INVALID_LOCATION)); |
| + ASSERT_TRUE(extension.get() != NULL); |
| + |
| + ImageLoader loader(NULL); |
| + loader.LoadExtensionIconAsync(extension.get(), |
| + extension_misc::EXTENSION_ICON_SMALLISH, |
| + false, |
| + base::Bind(&ImageLoaderTest::OnImageLoaded, |
| + base::Unretained(this))); |
| + |
| + // The image isn't cached, so we should not have received notification. |
| + EXPECT_EQ(0, image_loaded_count()); |
| + |
| + WaitForImageLoad(); |
| + |
| + // We should have gotten the image. |
| + EXPECT_EQ(1, image_loaded_count()); |
| + |
| + // Check that the image was loaded. |
| + EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
| + image_.ToSkBitmap()->width()); |
| +} |