| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_icon_image.h" | 5 #include "chrome/browser/extensions/extension_icon_image.h" |
| 6 | 6 |
| 7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "chrome/browser/extensions/image_loader.h" | 10 #include "chrome/browser/extensions/image_loader.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 : extension_(extension), | 75 : extension_(extension), |
| 76 waiting_(false), | 76 waiting_(false), |
| 77 image_loaded_(false) { | 77 image_loaded_(false) { |
| 78 } | 78 } |
| 79 virtual ~TestImageLoader() {} | 79 virtual ~TestImageLoader() {} |
| 80 | 80 |
| 81 void OnImageLoaded(const gfx::Image& image) { | 81 void OnImageLoaded(const gfx::Image& image) { |
| 82 image_ = image; | 82 image_ = image; |
| 83 image_loaded_ = true; | 83 image_loaded_ = true; |
| 84 if (waiting_) | 84 if (waiting_) |
| 85 MessageLoop::current()->Quit(); | 85 base::MessageLoop::current()->Quit(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 SkBitmap LoadBitmap(const std::string& path, | 88 SkBitmap LoadBitmap(const std::string& path, |
| 89 int size) { | 89 int size) { |
| 90 image_loaded_ = false; | 90 image_loaded_ = false; |
| 91 | 91 |
| 92 image_loader_.LoadImageAsync( | 92 image_loader_.LoadImageAsync( |
| 93 extension_, extension_->GetResource(path), gfx::Size(size, size), | 93 extension_, extension_->GetResource(path), gfx::Size(size, size), |
| 94 base::Bind(&TestImageLoader::OnImageLoaded, | 94 base::Bind(&TestImageLoader::OnImageLoaded, |
| 95 base::Unretained(this))); | 95 base::Unretained(this))); |
| 96 | 96 |
| 97 // If |image_| still hasn't been loaded (i.e. it is being loaded | 97 // If |image_| still hasn't been loaded (i.e. it is being loaded |
| 98 // asynchronously), wait for it. | 98 // asynchronously), wait for it. |
| 99 if (!image_loaded_) { | 99 if (!image_loaded_) { |
| 100 waiting_ = true; | 100 waiting_ = true; |
| 101 MessageLoop::current()->Run(); | 101 base::MessageLoop::current()->Run(); |
| 102 waiting_ = false; | 102 waiting_ = false; |
| 103 } | 103 } |
| 104 | 104 |
| 105 EXPECT_TRUE(image_loaded_); | 105 EXPECT_TRUE(image_loaded_); |
| 106 | 106 |
| 107 return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap(); | 107 return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 const Extension* extension_; | 111 const Extension* extension_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 125 quit_in_image_loaded_(false), | 125 quit_in_image_loaded_(false), |
| 126 ui_thread_(BrowserThread::UI, &ui_loop_), | 126 ui_thread_(BrowserThread::UI, &ui_loop_), |
| 127 file_thread_(BrowserThread::FILE), | 127 file_thread_(BrowserThread::FILE), |
| 128 io_thread_(BrowserThread::IO) { | 128 io_thread_(BrowserThread::IO) { |
| 129 } | 129 } |
| 130 | 130 |
| 131 virtual ~ExtensionIconImageTest() {} | 131 virtual ~ExtensionIconImageTest() {} |
| 132 | 132 |
| 133 void WaitForImageLoad() { | 133 void WaitForImageLoad() { |
| 134 quit_in_image_loaded_ = true; | 134 quit_in_image_loaded_ = true; |
| 135 MessageLoop::current()->Run(); | 135 base::MessageLoop::current()->Run(); |
| 136 quit_in_image_loaded_ = false; | 136 quit_in_image_loaded_ = false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 int ImageLoadedCount() { | 139 int ImageLoadedCount() { |
| 140 int result = image_loaded_count_; | 140 int result = image_loaded_count_; |
| 141 image_loaded_count_ = 0; | 141 image_loaded_count_ = 0; |
| 142 return result; | 142 return result; |
| 143 } | 143 } |
| 144 | 144 |
| 145 scoped_refptr<Extension> CreateExtension(const char* name, | 145 scoped_refptr<Extension> CreateExtension(const char* name, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 172 // testing::Test overrides: | 172 // testing::Test overrides: |
| 173 virtual void SetUp() OVERRIDE { | 173 virtual void SetUp() OVERRIDE { |
| 174 file_thread_.Start(); | 174 file_thread_.Start(); |
| 175 io_thread_.Start(); | 175 io_thread_.Start(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // IconImage::Delegate overrides: | 178 // IconImage::Delegate overrides: |
| 179 virtual void OnExtensionIconImageChanged(IconImage* image) OVERRIDE { | 179 virtual void OnExtensionIconImageChanged(IconImage* image) OVERRIDE { |
| 180 image_loaded_count_++; | 180 image_loaded_count_++; |
| 181 if (quit_in_image_loaded_) | 181 if (quit_in_image_loaded_) |
| 182 MessageLoop::current()->Quit(); | 182 base::MessageLoop::current()->Quit(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 gfx::ImageSkia GetDefaultIcon() { | 185 gfx::ImageSkia GetDefaultIcon() { |
| 186 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 186 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 187 IDR_EXTENSIONS_FAVICON); | 187 IDR_EXTENSIONS_FAVICON); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Loads an image to be used in test from the extension. | 190 // Loads an image to be used in test from the extension. |
| 191 // The image will be loaded from the relative path |path|. | 191 // The image will be loaded from the relative path |path|. |
| 192 SkBitmap GetTestBitmap(const Extension* extension, | 192 SkBitmap GetTestBitmap(const Extension* extension, |
| 193 const std::string& path, | 193 const std::string& path, |
| 194 int size) { | 194 int size) { |
| 195 TestImageLoader image_loader(extension); | 195 TestImageLoader image_loader(extension); |
| 196 return image_loader.LoadBitmap(path, size); | 196 return image_loader.LoadBitmap(path, size); |
| 197 } | 197 } |
| 198 | 198 |
| 199 private: | 199 private: |
| 200 int image_loaded_count_; | 200 int image_loaded_count_; |
| 201 bool quit_in_image_loaded_; | 201 bool quit_in_image_loaded_; |
| 202 MessageLoop ui_loop_; | 202 base::MessageLoop ui_loop_; |
| 203 content::TestBrowserThread ui_thread_; | 203 content::TestBrowserThread ui_thread_; |
| 204 content::TestBrowserThread file_thread_; | 204 content::TestBrowserThread file_thread_; |
| 205 content::TestBrowserThread io_thread_; | 205 content::TestBrowserThread io_thread_; |
| 206 | 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest); | 207 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest); |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 } // namespace | 210 } // namespace |
| 211 | 211 |
| 212 TEST_F(ExtensionIconImageTest, Basic) { | 212 TEST_F(ExtensionIconImageTest, Basic) { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 EXPECT_EQ(16, representation.pixel_width()); | 547 EXPECT_EQ(16, representation.pixel_width()); |
| 548 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); | 548 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); |
| 549 | 549 |
| 550 // When requesting another representation, we should get blank image. | 550 // When requesting another representation, we should get blank image. |
| 551 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); | 551 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); |
| 552 | 552 |
| 553 EXPECT_TRUE(gfx::BitmapsAreEqual( | 553 EXPECT_TRUE(gfx::BitmapsAreEqual( |
| 554 representation.sk_bitmap(), | 554 representation.sk_bitmap(), |
| 555 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); | 555 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); |
| 556 } | 556 } |
| OLD | NEW |