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 "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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 : image_loaded_count_(0), | 37 : image_loaded_count_(0), |
38 quit_in_image_loaded_(false), | 38 quit_in_image_loaded_(false), |
39 ui_thread_(BrowserThread::UI, &ui_loop_), | 39 ui_thread_(BrowserThread::UI, &ui_loop_), |
40 file_thread_(BrowserThread::FILE), | 40 file_thread_(BrowserThread::FILE), |
41 io_thread_(BrowserThread::IO) { | 41 io_thread_(BrowserThread::IO) { |
42 } | 42 } |
43 | 43 |
44 void OnImageLoaded(const gfx::Image& image) { | 44 void OnImageLoaded(const gfx::Image& image) { |
45 image_loaded_count_++; | 45 image_loaded_count_++; |
46 if (quit_in_image_loaded_) | 46 if (quit_in_image_loaded_) |
47 MessageLoop::current()->Quit(); | 47 base::MessageLoop::current()->Quit(); |
48 image_ = image; | 48 image_ = image; |
49 } | 49 } |
50 | 50 |
51 void WaitForImageLoad() { | 51 void WaitForImageLoad() { |
52 quit_in_image_loaded_ = true; | 52 quit_in_image_loaded_ = true; |
53 MessageLoop::current()->Run(); | 53 base::MessageLoop::current()->Run(); |
54 quit_in_image_loaded_ = false; | 54 quit_in_image_loaded_ = false; |
55 } | 55 } |
56 | 56 |
57 int image_loaded_count() { | 57 int image_loaded_count() { |
58 int result = image_loaded_count_; | 58 int result = image_loaded_count_; |
59 image_loaded_count_ = 0; | 59 image_loaded_count_ = 0; |
60 return result; | 60 return result; |
61 } | 61 } |
62 | 62 |
63 scoped_refptr<Extension> CreateExtension(const char* name, | 63 scoped_refptr<Extension> CreateExtension(const char* name, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 file_thread_.Start(); | 105 file_thread_.Start(); |
106 io_thread_.Start(); | 106 io_thread_.Start(); |
107 } | 107 } |
108 | 108 |
109 virtual void TearDown() OVERRIDE { | 109 virtual void TearDown() OVERRIDE { |
110 extensions::ManifestHandler::ClearRegistryForTesting(); | 110 extensions::ManifestHandler::ClearRegistryForTesting(); |
111 } | 111 } |
112 | 112 |
113 int image_loaded_count_; | 113 int image_loaded_count_; |
114 bool quit_in_image_loaded_; | 114 bool quit_in_image_loaded_; |
115 MessageLoop ui_loop_; | 115 base::MessageLoop ui_loop_; |
116 content::TestBrowserThread ui_thread_; | 116 content::TestBrowserThread ui_thread_; |
117 content::TestBrowserThread file_thread_; | 117 content::TestBrowserThread file_thread_; |
118 content::TestBrowserThread io_thread_; | 118 content::TestBrowserThread io_thread_; |
119 }; | 119 }; |
120 | 120 |
121 // Tests loading an image works correctly. | 121 // Tests loading an image works correctly. |
122 TEST_F(ImageLoaderTest, LoadImage) { | 122 TEST_F(ImageLoaderTest, LoadImage) { |
123 scoped_refptr<Extension> extension(CreateExtension( | 123 scoped_refptr<Extension> extension(CreateExtension( |
124 "image_loading_tracker", Manifest::INVALID_LOCATION)); | 124 "image_loading_tracker", Manifest::INVALID_LOCATION)); |
125 ASSERT_TRUE(extension.get() != NULL); | 125 ASSERT_TRUE(extension.get() != NULL); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 #if defined(FILE_MANAGER_EXTENSION) | 259 #if defined(FILE_MANAGER_EXTENSION) |
260 int resource_id; | 260 int resource_id; |
261 ASSERT_EQ(true, | 261 ASSERT_EQ(true, |
262 ImageLoader::IsComponentExtensionResource(extension->path(), | 262 ImageLoader::IsComponentExtensionResource(extension->path(), |
263 resource.relative_path(), | 263 resource.relative_path(), |
264 &resource_id)); | 264 &resource_id)); |
265 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); | 265 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); |
266 #endif | 266 #endif |
267 } | 267 } |
OLD | NEW |