| 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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/test/test_browser_context.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 15 #include "extensions/browser/extension_registry.h" |
| 14 #include "extensions/browser/extensions_browser_client.h" | 16 #include "extensions/browser/extensions_browser_client.h" |
| 15 #include "extensions/browser/notification_types.h" | 17 #include "extensions/browser/extensions_test.h" |
| 16 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 17 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 18 #include "extensions/common/extension_icon_set.h" | 20 #include "extensions/common/extension_icon_set.h" |
| 19 #include "extensions/common/extension_paths.h" | 21 #include "extensions/common/extension_paths.h" |
| 20 #include "extensions/common/extension_resource.h" | 22 #include "extensions/common/extension_resource.h" |
| 21 #include "extensions/common/manifest.h" | 23 #include "extensions/common/manifest.h" |
| 22 #include "extensions/common/manifest_handlers/icons_handler.h" | 24 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
| 26 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 27 #include "ui/gfx/image/image_family.h" | 29 #include "ui/gfx/image/image_family.h" |
| 28 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 29 | 31 |
| 30 using content::BrowserThread; | 32 using content::BrowserThread; |
| 31 using content::NotificationService; | 33 using content::NotificationService; |
| 32 | 34 |
| 33 namespace extensions { | 35 namespace extensions { |
| 34 | 36 |
| 35 class ImageLoaderTest : public testing::Test { | 37 class ImageLoaderTest : public ExtensionsTest { |
| 36 public: | 38 public: |
| 37 ImageLoaderTest() | 39 ImageLoaderTest() |
| 38 : image_loaded_count_(0), | 40 : image_loaded_count_(0), |
| 39 quit_in_image_loaded_(false), | 41 quit_in_image_loaded_(false), |
| 40 ui_thread_(BrowserThread::UI, &ui_loop_), | 42 ui_thread_(BrowserThread::UI, &ui_loop_), |
| 41 file_thread_(BrowserThread::FILE), | 43 file_thread_(BrowserThread::FILE), |
| 42 io_thread_(BrowserThread::IO), | 44 io_thread_(BrowserThread::IO), |
| 43 notification_service_(NotificationService::Create()) {} | 45 notification_service_(NotificationService::Create()) {} |
| 44 | 46 |
| 45 void OnImageLoaded(const gfx::Image& image) { | 47 void OnImageLoaded(const gfx::Image& image) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 loader.LoadImageAsync(extension.get(), | 169 loader.LoadImageAsync(extension.get(), |
| 168 image_resource, | 170 image_resource, |
| 169 max_size, | 171 max_size, |
| 170 base::Bind(&ImageLoaderTest::OnImageLoaded, | 172 base::Bind(&ImageLoaderTest::OnImageLoaded, |
| 171 base::Unretained(this))); | 173 base::Unretained(this))); |
| 172 | 174 |
| 173 // The image isn't cached, so we should not have received notification. | 175 // The image isn't cached, so we should not have received notification. |
| 174 EXPECT_EQ(0, image_loaded_count()); | 176 EXPECT_EQ(0, image_loaded_count()); |
| 175 | 177 |
| 176 // Send out notification the extension was uninstalled. | 178 // Send out notification the extension was uninstalled. |
| 177 UnloadedExtensionInfo details(extension.get(), | 179 ExtensionRegistry::Get(browser_context())->TriggerOnUnloaded( |
| 178 UnloadedExtensionInfo::REASON_UNINSTALL); | 180 extension.get(), UnloadedExtensionInfo::REASON_UNINSTALL); |
| 179 content::NotificationService::current()->Notify( | |
| 180 NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 181 content::NotificationService::AllSources(), | |
| 182 content::Details<UnloadedExtensionInfo>(&details)); | |
| 183 | 181 |
| 184 // Chuck the extension, that way if anyone tries to access it we should crash | 182 // Chuck the extension, that way if anyone tries to access it we should crash |
| 185 // or get valgrind errors. | 183 // or get valgrind errors. |
| 186 extension = NULL; | 184 extension = NULL; |
| 187 | 185 |
| 188 WaitForImageLoad(); | 186 WaitForImageLoad(); |
| 189 | 187 |
| 190 // Even though we deleted the extension, we should still get the image. | 188 // Even though we deleted the extension, we should still get the image. |
| 191 // We should still have gotten the image. | 189 // We should still have gotten the image. |
| 192 EXPECT_EQ(1, image_loaded_count()); | 190 EXPECT_EQ(1, image_loaded_count()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 302 |
| 305 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; | 303 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; |
| 306 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; | 304 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; |
| 307 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, img_rep1->pixel_width()); | 305 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, img_rep1->pixel_width()); |
| 308 EXPECT_EQ(1.0f, img_rep1->scale()); | 306 EXPECT_EQ(1.0f, img_rep1->scale()); |
| 309 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, img_rep2->pixel_width()); | 307 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, img_rep2->pixel_width()); |
| 310 EXPECT_EQ(2.0f, img_rep2->scale()); | 308 EXPECT_EQ(2.0f, img_rep2->scale()); |
| 311 } | 309 } |
| 312 | 310 |
| 313 } // namespace extensions | 311 } // namespace extensions |
| OLD | NEW |