Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/extensions/image_loading_tracker_unittest.cc

Issue 10083006: Revert 132196 - Attempt to load component extension favicon from the resources first. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/json/json_file_value_serializer.h" 5 #include "base/json/json_file_value_serializer.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/browser/extensions/image_loading_tracker.h" 8 #include "chrome/browser/extensions/image_loading_tracker.h"
9 #include "chrome/common/chrome_notification_types.h" 9 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_icon_set.h" 12 #include "chrome/common/extensions/extension_icon_set.h"
13 #include "chrome/common/extensions/extension_resource.h" 13 #include "chrome/common/extensions/extension_resource.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "content/test/test_browser_thread.h" 15 #include "content/test/test_browser_thread.h"
16 #include "grit/component_extension_resources.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
20 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
21 20
22 using content::BrowserThread; 21 using content::BrowserThread;
23 22
24 class ImageLoadingTrackerTest : public testing::Test, 23 class ImageLoadingTrackerTest : public testing::Test,
25 public ImageLoadingTracker::Observer { 24 public ImageLoadingTracker::Observer {
26 public: 25 public:
(...skipping 19 matching lines...) Expand all
46 MessageLoop::current()->Run(); 45 MessageLoop::current()->Run();
47 quit_in_image_loaded_ = false; 46 quit_in_image_loaded_ = false;
48 } 47 }
49 48
50 int image_loaded_count() { 49 int image_loaded_count() {
51 int result = image_loaded_count_; 50 int result = image_loaded_count_;
52 image_loaded_count_ = 0; 51 image_loaded_count_ = 0;
53 return result; 52 return result;
54 } 53 }
55 54
56 scoped_refptr<Extension> CreateExtension(const char* name, 55 scoped_refptr<Extension> CreateExtension() {
57 Extension::Location location) {
58 // Create and load an extension. 56 // Create and load an extension.
59 FilePath test_file; 57 FilePath test_file;
60 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) { 58 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) {
61 EXPECT_FALSE(true); 59 EXPECT_FALSE(true);
62 return NULL; 60 return NULL;
63 } 61 }
64 test_file = test_file.AppendASCII("extensions") 62 test_file = test_file.AppendASCII("extensions")
65 .AppendASCII(name); 63 .AppendASCII("image_loading_tracker");
66 int error_code = 0; 64 int error_code = 0;
67 std::string error; 65 std::string error;
68 JSONFileValueSerializer serializer(test_file.AppendASCII("app.json")); 66 JSONFileValueSerializer serializer(test_file.AppendASCII("app.json"));
69 scoped_ptr<DictionaryValue> valid_value( 67 scoped_ptr<DictionaryValue> valid_value(
70 static_cast<DictionaryValue*>(serializer.Deserialize(&error_code, 68 static_cast<DictionaryValue*>(serializer.Deserialize(&error_code,
71 &error))); 69 &error)));
72 EXPECT_EQ(0, error_code) << error; 70 EXPECT_EQ(0, error_code) << error;
73 if (error_code != 0) 71 if (error_code != 0)
74 return NULL; 72 return NULL;
75 73
76 EXPECT_TRUE(valid_value.get()); 74 EXPECT_TRUE(valid_value.get());
77 if (!valid_value.get()) 75 if (!valid_value.get())
78 return NULL; 76 return NULL;
79 77
80 return Extension::Create(test_file, location, *valid_value, 78 return Extension::Create(test_file, Extension::INVALID, *valid_value,
81 Extension::STRICT_ERROR_CHECKS, &error); 79 Extension::STRICT_ERROR_CHECKS, &error);
82 } 80 }
83 81
84 gfx::Image image_; 82 gfx::Image image_;
85 83
86 private: 84 private:
87 virtual void SetUp() { 85 virtual void SetUp() {
88 file_thread_.Start(); 86 file_thread_.Start();
89 io_thread_.Start(); 87 io_thread_.Start();
90 } 88 }
91 89
92 int image_loaded_count_; 90 int image_loaded_count_;
93 bool quit_in_image_loaded_; 91 bool quit_in_image_loaded_;
94 MessageLoop ui_loop_; 92 MessageLoop ui_loop_;
95 content::TestBrowserThread ui_thread_; 93 content::TestBrowserThread ui_thread_;
96 content::TestBrowserThread file_thread_; 94 content::TestBrowserThread file_thread_;
97 content::TestBrowserThread io_thread_; 95 content::TestBrowserThread io_thread_;
98 }; 96 };
99 97
100 // Tests asking ImageLoadingTracker to cache pushes the result to the Extension. 98 // Tests asking ImageLoadingTracker to cache pushes the result to the Extension.
101 TEST_F(ImageLoadingTrackerTest, Cache) { 99 TEST_F(ImageLoadingTrackerTest, Cache) {
102 scoped_refptr<Extension> extension(CreateExtension( 100 scoped_refptr<Extension> extension(CreateExtension());
103 "image_loading_tracker", Extension::INVALID));
104 ASSERT_TRUE(extension.get() != NULL); 101 ASSERT_TRUE(extension.get() != NULL);
105 102
106 ExtensionResource image_resource = 103 ExtensionResource image_resource =
107 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH, 104 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
108 ExtensionIconSet::MATCH_EXACTLY); 105 ExtensionIconSet::MATCH_EXACTLY);
109 gfx::Size max_size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, 106 gfx::Size max_size(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
110 ExtensionIconSet::EXTENSION_ICON_SMALLISH); 107 ExtensionIconSet::EXTENSION_ICON_SMALLISH);
111 ImageLoadingTracker loader(this); 108 ImageLoadingTracker loader(this);
112 loader.LoadImage(extension.get(), 109 loader.LoadImage(extension.get(),
113 image_resource, 110 image_resource,
(...skipping 28 matching lines...) Expand all
142 EXPECT_EQ(1, image_loaded_count()); 139 EXPECT_EQ(1, image_loaded_count());
143 140
144 // Check that the image was loaded. 141 // Check that the image was loaded.
145 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, 142 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
146 image_.ToSkBitmap()->width()); 143 image_.ToSkBitmap()->width());
147 } 144 }
148 145
149 // Tests deleting an extension while waiting for the image to load doesn't cause 146 // Tests deleting an extension while waiting for the image to load doesn't cause
150 // problems. 147 // problems.
151 TEST_F(ImageLoadingTrackerTest, DeleteExtensionWhileWaitingForCache) { 148 TEST_F(ImageLoadingTrackerTest, DeleteExtensionWhileWaitingForCache) {
152 scoped_refptr<Extension> extension(CreateExtension( 149 scoped_refptr<Extension> extension(CreateExtension());
153 "image_loading_tracker", Extension::INVALID));
154 ASSERT_TRUE(extension.get() != NULL); 150 ASSERT_TRUE(extension.get() != NULL);
155 151
156 ExtensionResource image_resource = 152 ExtensionResource image_resource =
157 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH, 153 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
158 ExtensionIconSet::MATCH_EXACTLY); 154 ExtensionIconSet::MATCH_EXACTLY);
159 ImageLoadingTracker loader(this); 155 ImageLoadingTracker loader(this);
160 loader.LoadImage(extension.get(), 156 loader.LoadImage(extension.get(),
161 image_resource, 157 image_resource,
162 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, 158 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
163 ExtensionIconSet::EXTENSION_ICON_SMALLISH), 159 ExtensionIconSet::EXTENSION_ICON_SMALLISH),
(...skipping 20 matching lines...) Expand all
184 // We should still have gotten the image. 180 // We should still have gotten the image.
185 EXPECT_EQ(1, image_loaded_count()); 181 EXPECT_EQ(1, image_loaded_count());
186 182
187 // Check that the image was loaded. 183 // Check that the image was loaded.
188 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, 184 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
189 image_.ToSkBitmap()->width()); 185 image_.ToSkBitmap()->width());
190 } 186 }
191 187
192 // Tests loading multiple dimensions of the same image. 188 // Tests loading multiple dimensions of the same image.
193 TEST_F(ImageLoadingTrackerTest, MultipleImages) { 189 TEST_F(ImageLoadingTrackerTest, MultipleImages) {
194 scoped_refptr<Extension> extension(CreateExtension( 190 scoped_refptr<Extension> extension(CreateExtension());
195 "image_loading_tracker", Extension::INVALID));
196 ASSERT_TRUE(extension.get() != NULL); 191 ASSERT_TRUE(extension.get() != NULL);
197 192
198 std::vector<ImageLoadingTracker::ImageInfo> info_list; 193 std::vector<ImageLoadingTracker::ImageInfo> info_list;
199 int sizes[] = {ExtensionIconSet::EXTENSION_ICON_SMALLISH, 194 int sizes[] = {ExtensionIconSet::EXTENSION_ICON_SMALLISH,
200 ExtensionIconSet::EXTENSION_ICON_BITTY}; 195 ExtensionIconSet::EXTENSION_ICON_BITTY};
201 for (size_t i = 0; i < arraysize(sizes); ++i) { 196 for (size_t i = 0; i < arraysize(sizes); ++i) {
202 ExtensionResource resource = 197 ExtensionResource resource =
203 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); 198 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY);
204 info_list.push_back(ImageLoadingTracker::ImageInfo( 199 info_list.push_back(ImageLoadingTracker::ImageInfo(
205 resource, gfx::Size(sizes[i], sizes[i]))); 200 resource, gfx::Size(sizes[i], sizes[i])));
(...skipping 13 matching lines...) Expand all
219 // Check that all images were loaded. 214 // Check that all images were loaded.
220 ASSERT_EQ(2u, image_.GetNumberOfSkBitmaps()); 215 ASSERT_EQ(2u, image_.GetNumberOfSkBitmaps());
221 const SkBitmap* bmp1 = image_.GetSkBitmapAtIndex(0); 216 const SkBitmap* bmp1 = image_.GetSkBitmapAtIndex(0);
222 const SkBitmap* bmp2 = image_.GetSkBitmapAtIndex(1); 217 const SkBitmap* bmp2 = image_.GetSkBitmapAtIndex(1);
223 if (bmp1->width() > bmp2->width()) { 218 if (bmp1->width() > bmp2->width()) {
224 std::swap(bmp1, bmp2); 219 std::swap(bmp1, bmp2);
225 } 220 }
226 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_BITTY, bmp1->width()); 221 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_BITTY, bmp1->width());
227 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, bmp2->width()); 222 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, bmp2->width());
228 } 223 }
229
230 // Tests loading multiple dimensions of the same image.
231 TEST_F(ImageLoadingTrackerTest, IsComponentExtensionResource) {
232 scoped_refptr<Extension> extension(CreateExtension(
233 "file_manager", Extension::COMPONENT));
234 ASSERT_TRUE(extension.get() != NULL);
235
236 ExtensionResource resource =
237 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_BITTY,
238 ExtensionIconSet::MATCH_EXACTLY);
239
240 ImageLoadingTracker loader(this);
241 int resource_id;
242 ASSERT_EQ(true,
243 loader.IsComponentExtensionResource(extension.get(),
244 resource,
245 resource_id));
246 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id);
247 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/image_loading_tracker.cc ('k') | chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698