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