| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/image_loader.h" | 5 #include "extensions/browser/image_loader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); | 200 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); |
| 201 ASSERT_TRUE(extension.get() != NULL); | 201 ASSERT_TRUE(extension.get() != NULL); |
| 202 | 202 |
| 203 std::vector<ImageLoader::ImageRepresentation> info_list; | 203 std::vector<ImageLoader::ImageRepresentation> info_list; |
| 204 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, | 204 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, |
| 205 extension_misc::EXTENSION_ICON_SMALLISH, }; | 205 extension_misc::EXTENSION_ICON_SMALLISH, }; |
| 206 for (size_t i = 0; i < arraysize(sizes); ++i) { | 206 for (size_t i = 0; i < arraysize(sizes); ++i) { |
| 207 ExtensionResource resource = IconsInfo::GetIconResource( | 207 ExtensionResource resource = IconsInfo::GetIconResource( |
| 208 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); | 208 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); |
| 209 info_list.push_back(ImageLoader::ImageRepresentation( | 209 info_list.push_back(ImageLoader::ImageRepresentation( |
| 210 resource, | 210 resource, ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER, |
| 211 ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER, | 211 gfx::Size(sizes[i], sizes[i]), 1.f)); |
| 212 gfx::Size(sizes[i], sizes[i]), | |
| 213 ui::SCALE_FACTOR_NONE)); | |
| 214 } | 212 } |
| 215 | 213 |
| 216 ImageLoader loader; | 214 ImageLoader loader; |
| 217 loader.LoadImagesAsync(extension.get(), info_list, | 215 loader.LoadImagesAsync(extension.get(), info_list, |
| 218 base::Bind(&ImageLoaderTest::OnImageLoaded, | 216 base::Bind(&ImageLoaderTest::OnImageLoaded, |
| 219 base::Unretained(this))); | 217 base::Unretained(this))); |
| 220 | 218 |
| 221 // The image isn't cached, so we should not have received notification. | 219 // The image isn't cached, so we should not have received notification. |
| 222 EXPECT_EQ(0, image_loaded_count()); | 220 EXPECT_EQ(0, image_loaded_count()); |
| 223 | 221 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 245 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); | 243 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); |
| 246 ASSERT_TRUE(extension.get() != NULL); | 244 ASSERT_TRUE(extension.get() != NULL); |
| 247 | 245 |
| 248 std::vector<ImageLoader::ImageRepresentation> info_list; | 246 std::vector<ImageLoader::ImageRepresentation> info_list; |
| 249 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, | 247 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, |
| 250 extension_misc::EXTENSION_ICON_SMALLISH, }; | 248 extension_misc::EXTENSION_ICON_SMALLISH, }; |
| 251 for (size_t i = 0; i < arraysize(sizes); ++i) { | 249 for (size_t i = 0; i < arraysize(sizes); ++i) { |
| 252 ExtensionResource resource = IconsInfo::GetIconResource( | 250 ExtensionResource resource = IconsInfo::GetIconResource( |
| 253 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); | 251 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); |
| 254 info_list.push_back(ImageLoader::ImageRepresentation( | 252 info_list.push_back(ImageLoader::ImageRepresentation( |
| 255 resource, | 253 resource, ImageLoader::ImageRepresentation::NEVER_RESIZE, |
| 256 ImageLoader::ImageRepresentation::NEVER_RESIZE, | 254 gfx::Size(sizes[i], sizes[i]), 1.f)); |
| 257 gfx::Size(sizes[i], sizes[i]), | |
| 258 ui::SCALE_FACTOR_100P)); | |
| 259 } | 255 } |
| 260 | 256 |
| 261 // Add a second icon of 200P which should get grouped with the smaller icon's | 257 // Add a second icon of 200P which should get grouped with the smaller icon's |
| 262 // ImageSkia. | 258 // ImageSkia. |
| 263 ExtensionResource resource = | 259 ExtensionResource resource = |
| 264 IconsInfo::GetIconResource(extension.get(), | 260 IconsInfo::GetIconResource(extension.get(), |
| 265 extension_misc::EXTENSION_ICON_SMALLISH, | 261 extension_misc::EXTENSION_ICON_SMALLISH, |
| 266 ExtensionIconSet::MATCH_EXACTLY); | 262 ExtensionIconSet::MATCH_EXACTLY); |
| 267 info_list.push_back(ImageLoader::ImageRepresentation( | 263 info_list.push_back(ImageLoader::ImageRepresentation( |
| 268 resource, | 264 resource, ImageLoader::ImageRepresentation::NEVER_RESIZE, |
| 269 ImageLoader::ImageRepresentation::NEVER_RESIZE, | |
| 270 gfx::Size(extension_misc::EXTENSION_ICON_BITTY, | 265 gfx::Size(extension_misc::EXTENSION_ICON_BITTY, |
| 271 extension_misc::EXTENSION_ICON_BITTY), | 266 extension_misc::EXTENSION_ICON_BITTY), |
| 272 ui::SCALE_FACTOR_200P)); | 267 2.f)); |
| 273 | 268 |
| 274 ImageLoader loader; | 269 ImageLoader loader; |
| 275 loader.LoadImageFamilyAsync(extension.get(), | 270 loader.LoadImageFamilyAsync(extension.get(), |
| 276 info_list, | 271 info_list, |
| 277 base::Bind(&ImageLoaderTest::OnImageFamilyLoaded, | 272 base::Bind(&ImageLoaderTest::OnImageFamilyLoaded, |
| 278 base::Unretained(this))); | 273 base::Unretained(this))); |
| 279 | 274 |
| 280 // The image isn't cached, so we should not have received notification. | 275 // The image isn't cached, so we should not have received notification. |
| 281 EXPECT_EQ(0, image_loaded_count()); | 276 EXPECT_EQ(0, image_loaded_count()); |
| 282 | 277 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 302 | 297 |
| 303 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; | 298 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; |
| 304 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; | 299 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; |
| 305 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, img_rep1->pixel_width()); | 300 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, img_rep1->pixel_width()); |
| 306 EXPECT_EQ(1.0f, img_rep1->scale()); | 301 EXPECT_EQ(1.0f, img_rep1->scale()); |
| 307 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, img_rep2->pixel_width()); | 302 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, img_rep2->pixel_width()); |
| 308 EXPECT_EQ(2.0f, img_rep2->scale()); | 303 EXPECT_EQ(2.0f, img_rep2->scale()); |
| 309 } | 304 } |
| 310 | 305 |
| 311 } // namespace extensions | 306 } // namespace extensions |
| OLD | NEW |