| 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 "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" | 16 #include "grit/component_extension_resources.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 20 #include "ui/gfx/image/image_skia.h" | 20 #include "ui/gfx/image/image_skia.h" |
| 21 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 using extensions::Extension; |
| 24 | 25 |
| 25 class ImageLoadingTrackerTest : public testing::Test, | 26 class ImageLoadingTrackerTest : public testing::Test, |
| 26 public ImageLoadingTracker::Observer { | 27 public ImageLoadingTracker::Observer { |
| 27 public: | 28 public: |
| 28 ImageLoadingTrackerTest() | 29 ImageLoadingTrackerTest() |
| 29 : image_loaded_count_(0), | 30 : image_loaded_count_(0), |
| 30 quit_in_image_loaded_(false), | 31 quit_in_image_loaded_(false), |
| 31 ui_thread_(BrowserThread::UI, &ui_loop_), | 32 ui_thread_(BrowserThread::UI, &ui_loop_), |
| 32 file_thread_(BrowserThread::FILE), | 33 file_thread_(BrowserThread::FILE), |
| 33 io_thread_(BrowserThread::IO) { | 34 io_thread_(BrowserThread::IO) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 loader.LoadImage(extension.get(), | 162 loader.LoadImage(extension.get(), |
| 162 image_resource, | 163 image_resource, |
| 163 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, | 164 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
| 164 ExtensionIconSet::EXTENSION_ICON_SMALLISH), | 165 ExtensionIconSet::EXTENSION_ICON_SMALLISH), |
| 165 ImageLoadingTracker::CACHE); | 166 ImageLoadingTracker::CACHE); |
| 166 | 167 |
| 167 // The image isn't cached, so we should not have received notification. | 168 // The image isn't cached, so we should not have received notification. |
| 168 EXPECT_EQ(0, image_loaded_count()); | 169 EXPECT_EQ(0, image_loaded_count()); |
| 169 | 170 |
| 170 // Send out notification the extension was uninstalled. | 171 // Send out notification the extension was uninstalled. |
| 171 UnloadedExtensionInfo details(extension.get(), | 172 extensions::UnloadedExtensionInfo details(extension.get(), |
| 172 extension_misc::UNLOAD_REASON_UNINSTALL); | 173 extension_misc::UNLOAD_REASON_UNINSTALL); |
| 173 content::NotificationService::current()->Notify( | 174 content::NotificationService::current()->Notify( |
| 174 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 175 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 175 content::NotificationService::AllSources(), | 176 content::NotificationService::AllSources(), |
| 176 content::Details<UnloadedExtensionInfo>(&details)); | 177 content::Details<extensions::UnloadedExtensionInfo>(&details)); |
| 177 | 178 |
| 178 // Chuck the extension, that way if anyone tries to access it we should crash | 179 // Chuck the extension, that way if anyone tries to access it we should crash |
| 179 // or get valgrind errors. | 180 // or get valgrind errors. |
| 180 extension = NULL; | 181 extension = NULL; |
| 181 | 182 |
| 182 WaitForImageLoad(); | 183 WaitForImageLoad(); |
| 183 | 184 |
| 184 // Even though we deleted the extension, we should still get the image. | 185 // Even though we deleted the extension, we should still get the image. |
| 185 // We should still have gotten the image. | 186 // We should still have gotten the image. |
| 186 EXPECT_EQ(1, image_loaded_count()); | 187 EXPECT_EQ(1, image_loaded_count()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 #if defined(FILE_MANAGER_EXTENSION) | 243 #if defined(FILE_MANAGER_EXTENSION) |
| 243 ImageLoadingTracker loader(this); | 244 ImageLoadingTracker loader(this); |
| 244 int resource_id; | 245 int resource_id; |
| 245 ASSERT_EQ(true, | 246 ASSERT_EQ(true, |
| 246 loader.IsComponentExtensionResource(extension.get(), | 247 loader.IsComponentExtensionResource(extension.get(), |
| 247 resource, | 248 resource, |
| 248 resource_id)); | 249 resource_id)); |
| 249 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); | 250 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); |
| 250 #endif | 251 #endif |
| 251 } | 252 } |
| OLD | NEW |