| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "chrome/browser/chrome_thread.h" | 7 #include "chrome/browser/chrome_thread.h" |
| 8 #include "chrome/browser/extensions/image_loading_tracker.h" | 8 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 9 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 ChromeThread io_thread_; | 95 ChromeThread io_thread_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 // Tests asking ImageLoadingTracker to cache pushes the result to the Extension. | 98 // Tests asking ImageLoadingTracker to cache pushes the result to the Extension. |
| 99 TEST_F(ImageLoadingTrackerTest, Cache) { | 99 TEST_F(ImageLoadingTrackerTest, Cache) { |
| 100 scoped_ptr<Extension> extension(CreateExtension()); | 100 scoped_ptr<Extension> extension(CreateExtension()); |
| 101 ASSERT_TRUE(extension.get() != NULL); | 101 ASSERT_TRUE(extension.get() != NULL); |
| 102 | 102 |
| 103 ExtensionResource image_resource = | 103 ExtensionResource image_resource = |
| 104 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH); | 104 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH); |
| 105 gfx::Size max_size(Extension::EXTENSION_ICON_SMALLISH, |
| 106 Extension::EXTENSION_ICON_SMALLISH); |
| 105 ImageLoadingTracker loader(static_cast<ImageLoadingTracker::Observer*>(this)); | 107 ImageLoadingTracker loader(static_cast<ImageLoadingTracker::Observer*>(this)); |
| 106 loader.LoadImage(extension.get(), | 108 loader.LoadImage(extension.get(), |
| 107 image_resource, | 109 image_resource, |
| 108 gfx::Size(Extension::EXTENSION_ICON_SMALLISH, | 110 max_size, |
| 109 Extension::EXTENSION_ICON_SMALLISH), | |
| 110 ImageLoadingTracker::CACHE); | 111 ImageLoadingTracker::CACHE); |
| 111 | 112 |
| 112 // The image isn't cached, so we should not have received notification. | 113 // The image isn't cached, so we should not have received notification. |
| 113 EXPECT_EQ(0, image_loaded_count()); | 114 EXPECT_EQ(0, image_loaded_count()); |
| 114 | 115 |
| 115 WaitForImageLoad(); | 116 WaitForImageLoad(); |
| 116 | 117 |
| 117 // We should have gotten the image. | 118 // We should have gotten the image. |
| 118 EXPECT_EQ(1, image_loaded_count()); | 119 EXPECT_EQ(1, image_loaded_count()); |
| 119 | 120 |
| 120 // Check that the image was loaded. | 121 // Check that the image was loaded. |
| 121 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); | 122 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); |
| 122 | 123 |
| 123 // The image should be cached in the Extension. | 124 // The image should be cached in the Extension. |
| 124 EXPECT_TRUE(extension->HasCachedImage(image_resource)); | 125 EXPECT_TRUE(extension->HasCachedImage(image_resource, max_size)); |
| 125 | 126 |
| 126 // Make sure the image is in the extension. | 127 // Make sure the image is in the extension. |
| 127 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, | 128 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, |
| 128 extension->GetCachedImage(image_resource).width()); | 129 extension->GetCachedImage(image_resource, max_size).width()); |
| 129 | 130 |
| 130 // Ask the tracker for the image again, this should call us back immediately. | 131 // Ask the tracker for the image again, this should call us back immediately. |
| 131 loader.LoadImage(extension.get(), | 132 loader.LoadImage(extension.get(), |
| 132 image_resource, | 133 image_resource, |
| 133 gfx::Size(Extension::EXTENSION_ICON_SMALLISH, | 134 max_size, |
| 134 Extension::EXTENSION_ICON_SMALLISH), | |
| 135 ImageLoadingTracker::CACHE); | 135 ImageLoadingTracker::CACHE); |
| 136 // We should have gotten the image. | 136 // We should have gotten the image. |
| 137 EXPECT_EQ(1, image_loaded_count()); | 137 EXPECT_EQ(1, image_loaded_count()); |
| 138 | 138 |
| 139 // Check that the image was loaded. | 139 // Check that the image was loaded. |
| 140 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); | 140 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Tests deleting an extension while waiting for the image to load doesn't cause | 143 // Tests deleting an extension while waiting for the image to load doesn't cause |
| 144 // problems. | 144 // problems. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 170 | 170 |
| 171 WaitForImageLoad(); | 171 WaitForImageLoad(); |
| 172 | 172 |
| 173 // Even though we deleted the extension, we should still get the image. | 173 // Even though we deleted the extension, we should still get the image. |
| 174 // We should still have gotten the image. | 174 // We should still have gotten the image. |
| 175 EXPECT_EQ(1, image_loaded_count()); | 175 EXPECT_EQ(1, image_loaded_count()); |
| 176 | 176 |
| 177 // Check that the image was loaded. | 177 // Check that the image was loaded. |
| 178 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); | 178 EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); |
| 179 } | 179 } |
| OLD | NEW |