Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/extensions/extension_icon_manager_unittest.cc

Issue 13814009: Fix failing ExtensionIconManagerTest.LoadComponentExtensionResource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: inherit ExtensionTest Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_icon_manager.h" 9 #include "chrome/browser/extensions/extension_icon_manager.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_unittest.h"
12 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
14 #include "extensions/common/id_util.h" 15 #include "extensions/common/id_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/skia_util.h" 17 #include "ui/gfx/skia_util.h"
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 using extensions::Extension; 20 using extensions::Extension;
20 using extensions::Manifest; 21 using extensions::Manifest;
21 22
22 // Our test class that takes care of managing the necessary threads for loading 23 // Our test class that takes care of managing the necessary threads for loading
23 // extension icons, and waiting for those loads to happen. 24 // extension icons, and waiting for those loads to happen.
24 class ExtensionIconManagerTest : public testing::Test { 25 class ExtensionIconManagerTest : public extensions::ExtensionTest {
25 public: 26 public:
26 ExtensionIconManagerTest() : 27 ExtensionIconManagerTest() :
27 unwaited_image_loads_(0), 28 unwaited_image_loads_(0),
28 waiting_(false), 29 waiting_(false),
29 ui_thread_(BrowserThread::UI, &ui_loop_), 30 ui_thread_(BrowserThread::UI, &ui_loop_),
30 file_thread_(BrowserThread::FILE), 31 file_thread_(BrowserThread::FILE),
31 io_thread_(BrowserThread::IO) {} 32 io_thread_(BrowserThread::IO) {}
32 33
33 virtual ~ExtensionIconManagerTest() {} 34 virtual ~ExtensionIconManagerTest() {}
34 35
35 void ImageLoadObserved() { 36 void ImageLoadObserved() {
36 unwaited_image_loads_++; 37 unwaited_image_loads_++;
37 if (waiting_) { 38 if (waiting_) {
38 MessageLoop::current()->Quit(); 39 MessageLoop::current()->Quit();
39 } 40 }
40 } 41 }
41 42
42 void WaitForImageLoad() { 43 void WaitForImageLoad() {
43 if (unwaited_image_loads_ == 0) { 44 if (unwaited_image_loads_ == 0) {
44 waiting_ = true; 45 waiting_ = true;
45 MessageLoop::current()->Run(); 46 MessageLoop::current()->Run();
46 waiting_ = false; 47 waiting_ = false;
47 } 48 }
48 ASSERT_GT(unwaited_image_loads_, 0); 49 ASSERT_GT(unwaited_image_loads_, 0);
49 unwaited_image_loads_--; 50 unwaited_image_loads_--;
50 } 51 }
51 52
52 private: 53 private:
53 virtual void SetUp() { 54 virtual void SetUp() {
55 extensions::ExtensionTest::SetUp();
54 file_thread_.Start(); 56 file_thread_.Start();
55 io_thread_.Start(); 57 io_thread_.Start();
56 } 58 }
57 59
58 // The number of observed image loads that have not been waited for. 60 // The number of observed image loads that have not been waited for.
59 int unwaited_image_loads_; 61 int unwaited_image_loads_;
60 62
61 // Whether we are currently waiting for an image load. 63 // Whether we are currently waiting for an image load.
62 bool waiting_; 64 bool waiting_;
63 65
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 WaitForImageLoad(); 137 WaitForImageLoad();
136 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); 138 SkBitmap second_icon = icon_manager.GetIcon(extension->id());
137 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); 139 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon));
138 140
139 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); 141 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon));
140 } 142 }
141 143
142 #if defined(FILE_MANAGER_EXTENSION) 144 #if defined(FILE_MANAGER_EXTENSION)
143 // Tests loading an icon for a component extension. 145 // Tests loading an icon for a component extension.
144 TEST_F(ExtensionIconManagerTest, LoadComponentExtensionResource) { 146 TEST_F(ExtensionIconManagerTest, LoadComponentExtensionResource) {
147 scoped_ptr<Profile> profile(new TestingProfile());
145 SkBitmap default_icon = GetDefaultIcon(); 148 SkBitmap default_icon = GetDefaultIcon();
146 149
147 base::FilePath test_dir; 150 base::FilePath test_dir;
148 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 151 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
149 base::FilePath manifest_path = test_dir.AppendASCII( 152 base::FilePath manifest_path = test_dir.AppendASCII(
150 "extensions/file_manager/app.json"); 153 "extensions/file_manager/app.json");
151 154
152 JSONFileValueSerializer serializer(manifest_path); 155 JSONFileValueSerializer serializer(manifest_path);
153 scoped_ptr<DictionaryValue> manifest( 156 scoped_ptr<DictionaryValue> manifest(
154 static_cast<DictionaryValue*>(serializer.Deserialize(NULL, NULL))); 157 static_cast<DictionaryValue*>(serializer.Deserialize(NULL, NULL)));
155 ASSERT_TRUE(manifest.get() != NULL); 158 ASSERT_TRUE(manifest.get() != NULL);
156 159
157 std::string error; 160 std::string error;
158 scoped_refptr<Extension> extension(Extension::Create( 161 scoped_refptr<Extension> extension(Extension::Create(
159 manifest_path.DirName(), Manifest::COMPONENT, *manifest.get(), 162 manifest_path.DirName(), Manifest::COMPONENT, *manifest.get(),
160 Extension::NO_FLAGS, &error)); 163 Extension::NO_FLAGS, &error));
161 ASSERT_TRUE(extension.get()); 164 ASSERT_TRUE(extension.get());
162 165
163 scoped_ptr<Profile> profile(new TestingProfile());
164 TestIconManager icon_manager(this); 166 TestIconManager icon_manager(this);
165 // Load the icon and grab the bitmap. 167 // Load the icon and grab the bitmap.
166 icon_manager.LoadIcon(profile.get(), extension.get()); 168 icon_manager.LoadIcon(profile.get(), extension.get());
167 WaitForImageLoad(); 169 WaitForImageLoad();
168 SkBitmap first_icon = icon_manager.GetIcon(extension->id()); 170 SkBitmap first_icon = icon_manager.GetIcon(extension->id());
169 EXPECT_FALSE(gfx::BitmapsAreEqual(first_icon, default_icon)); 171 EXPECT_FALSE(gfx::BitmapsAreEqual(first_icon, default_icon));
170 172
171 // Remove the icon from the manager. 173 // Remove the icon from the manager.
172 icon_manager.RemoveIcon(extension->id()); 174 icon_manager.RemoveIcon(extension->id());
173 175
174 // Now re-load the icon - we should get the same result bitmap (and not the 176 // Now re-load the icon - we should get the same result bitmap (and not the
175 // default icon). 177 // default icon).
176 icon_manager.LoadIcon(profile.get(), extension.get()); 178 icon_manager.LoadIcon(profile.get(), extension.get());
177 WaitForImageLoad(); 179 WaitForImageLoad();
178 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); 180 SkBitmap second_icon = icon_manager.GetIcon(extension->id());
179 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); 181 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon));
180 182
181 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); 183 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon));
182 } 184 }
183 #endif 185 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698