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

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

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 "chrome/browser/extensions/image_loader.h" 5 #include "chrome/browser/extensions/image_loader.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/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_constants.h" 13 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/extension_icon_set.h" 14 #include "chrome/common/extensions/extension_icon_set.h"
15 #include "chrome/common/extensions/extension_resource.h" 15 #include "chrome/common/extensions/extension_resource.h"
16 #include "chrome/common/extensions/manifest.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
18 #include "grit/component_extension_resources.h" 19 #include "grit/component_extension_resources.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
22 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
23 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
24 25
25 using content::BrowserThread; 26 using content::BrowserThread;
26 using extensions::Extension; 27 using extensions::Extension;
27 using extensions::ImageLoader; 28 using extensions::ImageLoader;
29 using extensions::Manifest;
28 30
29 class ImageLoaderTest : public testing::Test { 31 class ImageLoaderTest : public testing::Test {
30 public: 32 public:
31 ImageLoaderTest() 33 ImageLoaderTest()
32 : image_loaded_count_(0), 34 : image_loaded_count_(0),
33 quit_in_image_loaded_(false), 35 quit_in_image_loaded_(false),
34 ui_thread_(BrowserThread::UI, &ui_loop_), 36 ui_thread_(BrowserThread::UI, &ui_loop_),
35 file_thread_(BrowserThread::FILE), 37 file_thread_(BrowserThread::FILE),
36 io_thread_(BrowserThread::IO) { 38 io_thread_(BrowserThread::IO) {
37 } 39 }
(...skipping 11 matching lines...) Expand all
49 quit_in_image_loaded_ = false; 51 quit_in_image_loaded_ = false;
50 } 52 }
51 53
52 int image_loaded_count() { 54 int image_loaded_count() {
53 int result = image_loaded_count_; 55 int result = image_loaded_count_;
54 image_loaded_count_ = 0; 56 image_loaded_count_ = 0;
55 return result; 57 return result;
56 } 58 }
57 59
58 scoped_refptr<Extension> CreateExtension(const char* name, 60 scoped_refptr<Extension> CreateExtension(const char* name,
59 Extension::Location location) { 61 Manifest::Location location) {
60 // Create and load an extension. 62 // Create and load an extension.
61 FilePath test_file; 63 FilePath test_file;
62 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) { 64 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) {
63 EXPECT_FALSE(true); 65 EXPECT_FALSE(true);
64 return NULL; 66 return NULL;
65 } 67 }
66 test_file = test_file.AppendASCII("extensions") 68 test_file = test_file.AppendASCII("extensions")
67 .AppendASCII(name); 69 .AppendASCII(name);
68 int error_code = 0; 70 int error_code = 0;
69 std::string error; 71 std::string error;
70 JSONFileValueSerializer serializer(test_file.AppendASCII("app.json")); 72 JSONFileValueSerializer serializer(test_file.AppendASCII("app.json"));
71 scoped_ptr<DictionaryValue> valid_value( 73 scoped_ptr<DictionaryValue> valid_value(
72 static_cast<DictionaryValue*>(serializer.Deserialize(&error_code, 74 static_cast<DictionaryValue*>(serializer.Deserialize(&error_code,
73 &error))); 75 &error)));
74 EXPECT_EQ(0, error_code) << error; 76 EXPECT_EQ(0, error_code) << error;
75 if (error_code != 0) 77 if (error_code != 0)
76 return NULL; 78 return NULL;
77 79
78 EXPECT_TRUE(valid_value.get()); 80 EXPECT_TRUE(valid_value.get());
79 if (!valid_value.get()) 81 if (!valid_value.get())
80 return NULL; 82 return NULL;
81 83
82 if (location == Extension::COMPONENT) { 84 if (location == Manifest::COMPONENT) {
83 if (!PathService::Get(chrome::DIR_RESOURCES, &test_file)) { 85 if (!PathService::Get(chrome::DIR_RESOURCES, &test_file)) {
84 EXPECT_FALSE(true); 86 EXPECT_FALSE(true);
85 return NULL; 87 return NULL;
86 } 88 }
87 test_file = test_file.AppendASCII(name); 89 test_file = test_file.AppendASCII(name);
88 } 90 }
89 return Extension::Create(test_file, location, *valid_value, 91 return Extension::Create(test_file, location, *valid_value,
90 Extension::NO_FLAGS, &error); 92 Extension::NO_FLAGS, &error);
91 } 93 }
92 94
93 gfx::Image image_; 95 gfx::Image image_;
94 96
95 private: 97 private:
96 virtual void SetUp() { 98 virtual void SetUp() {
97 file_thread_.Start(); 99 file_thread_.Start();
98 io_thread_.Start(); 100 io_thread_.Start();
99 } 101 }
100 102
101 int image_loaded_count_; 103 int image_loaded_count_;
102 bool quit_in_image_loaded_; 104 bool quit_in_image_loaded_;
103 MessageLoop ui_loop_; 105 MessageLoop ui_loop_;
104 content::TestBrowserThread ui_thread_; 106 content::TestBrowserThread ui_thread_;
105 content::TestBrowserThread file_thread_; 107 content::TestBrowserThread file_thread_;
106 content::TestBrowserThread io_thread_; 108 content::TestBrowserThread io_thread_;
107 }; 109 };
108 110
109 // Tests loading an image works correctly. 111 // Tests loading an image works correctly.
110 TEST_F(ImageLoaderTest, LoadImage) { 112 TEST_F(ImageLoaderTest, LoadImage) {
111 scoped_refptr<Extension> extension(CreateExtension( 113 scoped_refptr<Extension> extension(CreateExtension(
112 "image_loading_tracker", Extension::INVALID)); 114 "image_loading_tracker", Manifest::INVALID_LOCATION));
113 ASSERT_TRUE(extension.get() != NULL); 115 ASSERT_TRUE(extension.get() != NULL);
114 116
115 ExtensionResource image_resource = 117 ExtensionResource image_resource =
116 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH, 118 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH,
117 ExtensionIconSet::MATCH_EXACTLY); 119 ExtensionIconSet::MATCH_EXACTLY);
118 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, 120 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH,
119 extension_misc::EXTENSION_ICON_SMALLISH); 121 extension_misc::EXTENSION_ICON_SMALLISH);
120 ImageLoader loader; 122 ImageLoader loader;
121 loader.LoadImageAsync(extension.get(), 123 loader.LoadImageAsync(extension.get(),
122 image_resource, 124 image_resource,
(...skipping 11 matching lines...) Expand all
134 136
135 // Check that the image was loaded. 137 // Check that the image was loaded.
136 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, 138 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
137 image_.ToSkBitmap()->width()); 139 image_.ToSkBitmap()->width());
138 } 140 }
139 141
140 // Tests deleting an extension while waiting for the image to load doesn't cause 142 // Tests deleting an extension while waiting for the image to load doesn't cause
141 // problems. 143 // problems.
142 TEST_F(ImageLoaderTest, DeleteExtensionWhileWaitingForCache) { 144 TEST_F(ImageLoaderTest, DeleteExtensionWhileWaitingForCache) {
143 scoped_refptr<Extension> extension(CreateExtension( 145 scoped_refptr<Extension> extension(CreateExtension(
144 "image_loading_tracker", Extension::INVALID)); 146 "image_loading_tracker", Manifest::INVALID_LOCATION));
145 ASSERT_TRUE(extension.get() != NULL); 147 ASSERT_TRUE(extension.get() != NULL);
146 148
147 ExtensionResource image_resource = 149 ExtensionResource image_resource =
148 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH, 150 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH,
149 ExtensionIconSet::MATCH_EXACTLY); 151 ExtensionIconSet::MATCH_EXACTLY);
150 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, 152 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH,
151 extension_misc::EXTENSION_ICON_SMALLISH); 153 extension_misc::EXTENSION_ICON_SMALLISH);
152 ImageLoader loader; 154 ImageLoader loader;
153 std::set<int> sizes; 155 std::set<int> sizes;
154 sizes.insert(extension_misc::EXTENSION_ICON_SMALLISH); 156 sizes.insert(extension_misc::EXTENSION_ICON_SMALLISH);
(...skipping 25 matching lines...) Expand all
180 EXPECT_EQ(1, image_loaded_count()); 182 EXPECT_EQ(1, image_loaded_count());
181 183
182 // Check that the image was loaded. 184 // Check that the image was loaded.
183 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, 185 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
184 image_.ToSkBitmap()->width()); 186 image_.ToSkBitmap()->width());
185 } 187 }
186 188
187 // Tests loading multiple dimensions of the same image. 189 // Tests loading multiple dimensions of the same image.
188 TEST_F(ImageLoaderTest, MultipleImages) { 190 TEST_F(ImageLoaderTest, MultipleImages) {
189 scoped_refptr<Extension> extension(CreateExtension( 191 scoped_refptr<Extension> extension(CreateExtension(
190 "image_loading_tracker", Extension::INVALID)); 192 "image_loading_tracker", Manifest::INVALID_LOCATION));
191 ASSERT_TRUE(extension.get() != NULL); 193 ASSERT_TRUE(extension.get() != NULL);
192 194
193 std::vector<ImageLoader::ImageRepresentation> info_list; 195 std::vector<ImageLoader::ImageRepresentation> info_list;
194 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH, 196 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH,
195 extension_misc::EXTENSION_ICON_BITTY}; 197 extension_misc::EXTENSION_ICON_BITTY};
196 for (size_t i = 0; i < arraysize(sizes); ++i) { 198 for (size_t i = 0; i < arraysize(sizes); ++i) {
197 ExtensionResource resource = 199 ExtensionResource resource =
198 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); 200 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY);
199 info_list.push_back(ImageLoader::ImageRepresentation( 201 info_list.push_back(ImageLoader::ImageRepresentation(
200 resource, 202 resource,
(...skipping 26 matching lines...) Expand all
227 } 229 }
228 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, 230 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY,
229 img_rep1->pixel_width()); 231 img_rep1->pixel_width());
230 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, 232 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
231 img_rep2->pixel_width()); 233 img_rep2->pixel_width());
232 } 234 }
233 235
234 // Tests IsComponentExtensionResource function. 236 // Tests IsComponentExtensionResource function.
235 TEST_F(ImageLoaderTest, IsComponentExtensionResource) { 237 TEST_F(ImageLoaderTest, IsComponentExtensionResource) {
236 scoped_refptr<Extension> extension(CreateExtension( 238 scoped_refptr<Extension> extension(CreateExtension(
237 "file_manager", Extension::COMPONENT)); 239 "file_manager", Manifest::COMPONENT));
238 ASSERT_TRUE(extension.get() != NULL); 240 ASSERT_TRUE(extension.get() != NULL);
239 241
240 ExtensionResource resource = 242 ExtensionResource resource =
241 extension->GetIconResource(extension_misc::EXTENSION_ICON_BITTY, 243 extension->GetIconResource(extension_misc::EXTENSION_ICON_BITTY,
242 ExtensionIconSet::MATCH_EXACTLY); 244 ExtensionIconSet::MATCH_EXACTLY);
243 245
244 #if defined(FILE_MANAGER_EXTENSION) 246 #if defined(FILE_MANAGER_EXTENSION)
245 int resource_id; 247 int resource_id;
246 ASSERT_EQ(true, 248 ASSERT_EQ(true,
247 ImageLoader::IsComponentExtensionResource(extension->path(), 249 ImageLoader::IsComponentExtensionResource(extension->path(),
248 resource.relative_path(), 250 resource.relative_path(),
249 &resource_id)); 251 &resource_id));
250 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); 252 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id);
251 #endif 253 #endif
252 } 254 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/image_loader.cc ('k') | chrome/browser/extensions/image_loading_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698