| 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/message_loop.h" | 8 #include "base/message_loop/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 image_ = image; | 81 image_ = image; |
| 82 image_loaded_ = true; | 82 image_loaded_ = true; |
| 83 if (waiting_) | 83 if (waiting_) |
| 84 base::MessageLoop::current()->Quit(); | 84 base::MessageLoop::current()->Quit(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 SkBitmap LoadBitmap(const std::string& path, | 87 SkBitmap LoadBitmap(const std::string& path, |
| 88 int size) { | 88 int size) { |
| 89 image_loaded_ = false; | 89 image_loaded_ = false; |
| 90 | 90 |
| 91 image_loader_.LoadImageAsync( | 91 image_loader_.reset(new extensions::ImageLoader(NULL)); |
| 92 image_loader_->LoadImageAsync( |
| 92 extension_, extension_->GetResource(path), gfx::Size(size, size), | 93 extension_, extension_->GetResource(path), gfx::Size(size, size), |
| 93 base::Bind(&TestImageLoader::OnImageLoaded, | 94 base::Bind(&TestImageLoader::OnImageLoaded, |
| 94 base::Unretained(this))); | 95 base::Unretained(this))); |
| 95 | 96 |
| 96 // 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 |
| 97 // asynchronously), wait for it. | 98 // asynchronously), wait for it. |
| 98 if (!image_loaded_) { | 99 if (!image_loaded_) { |
| 99 waiting_ = true; | 100 waiting_ = true; |
| 100 base::MessageLoop::current()->Run(); | 101 base::MessageLoop::current()->Run(); |
| 101 waiting_ = false; | 102 waiting_ = false; |
| 102 } | 103 } |
| 103 | 104 |
| 104 EXPECT_TRUE(image_loaded_); | 105 EXPECT_TRUE(image_loaded_); |
| 105 | 106 |
| 106 return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap(); | 107 return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 private: | 110 private: |
| 110 const Extension* extension_; | 111 const Extension* extension_; |
| 111 bool waiting_; | 112 bool waiting_; |
| 112 bool image_loaded_; | 113 bool image_loaded_; |
| 113 gfx::Image image_; | 114 gfx::Image image_; |
| 114 extensions::ImageLoader image_loader_; | 115 scoped_ptr<extensions::ImageLoader> image_loader_; |
| 115 | 116 |
| 116 DISALLOW_COPY_AND_ASSIGN(TestImageLoader); | 117 DISALLOW_COPY_AND_ASSIGN(TestImageLoader); |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 class ExtensionIconImageTest : public testing::Test, | 120 class ExtensionIconImageTest : public testing::Test, |
| 120 public IconImage::Observer { | 121 public IconImage::Observer { |
| 121 public: | 122 public: |
| 122 ExtensionIconImageTest() | 123 ExtensionIconImageTest() |
| 123 : image_loaded_count_(0), | 124 : image_loaded_count_(0), |
| 124 quit_in_image_loaded_(false), | 125 quit_in_image_loaded_(false), |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 EXPECT_EQ(16, representation.pixel_width()); | 564 EXPECT_EQ(16, representation.pixel_width()); |
| 564 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); | 565 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); |
| 565 | 566 |
| 566 // When requesting another representation, we should get blank image. | 567 // When requesting another representation, we should get blank image. |
| 567 representation = image_skia.GetRepresentation(2.0f); | 568 representation = image_skia.GetRepresentation(2.0f); |
| 568 | 569 |
| 569 EXPECT_TRUE(gfx::BitmapsAreEqual( | 570 EXPECT_TRUE(gfx::BitmapsAreEqual( |
| 570 representation.sk_bitmap(), | 571 representation.sk_bitmap(), |
| 571 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); | 572 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); |
| 572 } | 573 } |
| OLD | NEW |