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/extension_action_icon_factory.h" | 5 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 ExtensionActionIconFactoryTest() : quit_in_icon_updated_(false) {} | 89 ExtensionActionIconFactoryTest() : quit_in_icon_updated_(false) {} |
90 | 90 |
91 ~ExtensionActionIconFactoryTest() override {} | 91 ~ExtensionActionIconFactoryTest() override {} |
92 | 92 |
93 void WaitForIconUpdate() { | 93 void WaitForIconUpdate() { |
94 quit_in_icon_updated_ = true; | 94 quit_in_icon_updated_ = true; |
95 base::RunLoop().Run(); | 95 base::RunLoop().Run(); |
96 quit_in_icon_updated_ = false; | 96 quit_in_icon_updated_ = false; |
97 } | 97 } |
98 | 98 |
99 scoped_refptr<Extension> CreateExtension(const char* name, | 99 scoped_refptr<Extension> CreateExtension(const char* name) { |
100 Manifest::Location location) { | |
101 // Create and load an extension. | 100 // Create and load an extension. |
102 base::FilePath test_file; | 101 base::FilePath test_file; |
103 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) { | 102 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) { |
104 EXPECT_FALSE(true); | 103 EXPECT_FALSE(true); |
105 return NULL; | 104 return NULL; |
106 } | 105 } |
107 test_file = test_file.AppendASCII("extensions/api_test").AppendASCII(name); | 106 test_file = test_file.AppendASCII("extensions/api_test").AppendASCII(name); |
108 int error_code = 0; | 107 int error_code = 0; |
109 std::string error; | 108 std::string error; |
110 JSONFileValueDeserializer deserializer( | 109 JSONFileValueDeserializer deserializer( |
111 test_file.AppendASCII("manifest.json")); | 110 test_file.AppendASCII("manifest.json")); |
112 std::unique_ptr<base::DictionaryValue> valid_value = | 111 std::unique_ptr<base::DictionaryValue> valid_value = |
113 base::DictionaryValue::From( | 112 base::DictionaryValue::From( |
114 deserializer.Deserialize(&error_code, &error)); | 113 deserializer.Deserialize(&error_code, &error)); |
115 EXPECT_EQ(0, error_code) << error; | 114 EXPECT_EQ(0, error_code) << error; |
116 if (error_code != 0) | 115 if (error_code != 0) |
117 return NULL; | 116 return NULL; |
118 | 117 |
119 EXPECT_TRUE(valid_value.get()); | 118 EXPECT_TRUE(valid_value.get()); |
120 if (!valid_value) | 119 if (!valid_value) |
121 return NULL; | 120 return NULL; |
122 | 121 |
123 scoped_refptr<Extension> extension = | 122 scoped_refptr<Extension> extension = |
124 Extension::Create(test_file, location, *valid_value, | 123 Extension::Create(test_file, Manifest::UNPACKED, *valid_value, |
125 Extension::NO_FLAGS, &error); | 124 Extension::NO_FLAGS, &error); |
126 EXPECT_TRUE(extension.get()) << error; | 125 EXPECT_TRUE(extension.get()) << error; |
127 if (extension.get()) | 126 if (extension.get()) |
128 extension_service_->AddExtension(extension.get()); | 127 extension_service_->AddExtension(extension.get()); |
129 return extension; | 128 return extension; |
130 } | 129 } |
131 | 130 |
132 // testing::Test overrides: | 131 // testing::Test overrides: |
133 void SetUp() override { | 132 void SetUp() override { |
134 profile_.reset(new TestingProfile); | 133 profile_.reset(new TestingProfile); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 ExtensionActionIconFactoryTest_MaterialDesign, | 183 ExtensionActionIconFactoryTest_MaterialDesign, |
185 ExtensionActionIconFactoryTest, | 184 ExtensionActionIconFactoryTest, |
186 testing::Values(ui::MaterialDesignController::MATERIAL_NORMAL, | 185 testing::Values(ui::MaterialDesignController::MATERIAL_NORMAL, |
187 ui::MaterialDesignController::MATERIAL_HYBRID)); | 186 ui::MaterialDesignController::MATERIAL_HYBRID)); |
188 | 187 |
189 // If there is no default icon, and the icon has not been set using |SetIcon|, | 188 // If there is no default icon, and the icon has not been set using |SetIcon|, |
190 // the factory should return favicon. | 189 // the factory should return favicon. |
191 TEST_P(ExtensionActionIconFactoryTest, NoIcons) { | 190 TEST_P(ExtensionActionIconFactoryTest, NoIcons) { |
192 // Load an extension that has browser action without default icon set in the | 191 // Load an extension that has browser action without default icon set in the |
193 // manifest and does not call |SetIcon| by default. | 192 // manifest and does not call |SetIcon| by default. |
194 scoped_refptr<Extension> extension(CreateExtension( | 193 scoped_refptr<Extension> extension(CreateExtension("browser_action/no_icon")); |
195 "browser_action/no_icon", Manifest::INVALID_LOCATION)); | |
196 ASSERT_TRUE(extension.get() != NULL); | 194 ASSERT_TRUE(extension.get() != NULL); |
197 ExtensionAction* browser_action = GetBrowserAction(*extension); | 195 ExtensionAction* browser_action = GetBrowserAction(*extension); |
198 ASSERT_TRUE(browser_action); | 196 ASSERT_TRUE(browser_action); |
199 ASSERT_FALSE(browser_action->default_icon()); | 197 ASSERT_FALSE(browser_action->default_icon()); |
200 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); | 198 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); |
201 | 199 |
202 ExtensionActionIconFactory icon_factory( | 200 ExtensionActionIconFactory icon_factory( |
203 profile(), extension.get(), browser_action, this); | 201 profile(), extension.get(), browser_action, this); |
204 | 202 |
205 gfx::Image icon = icon_factory.GetIcon(0); | 203 gfx::Image icon = icon_factory.GetIcon(0); |
206 | 204 |
207 EXPECT_TRUE(ImageRepsAreEqual( | 205 EXPECT_TRUE(ImageRepsAreEqual( |
208 browser_action->GetDefaultIconImage().ToImageSkia()->GetRepresentation( | 206 browser_action->GetDefaultIconImage().ToImageSkia()->GetRepresentation( |
209 1.0f), | 207 1.0f), |
210 icon.ToImageSkia()->GetRepresentation(1.0f))); | 208 icon.ToImageSkia()->GetRepresentation(1.0f))); |
211 } | 209 } |
212 | 210 |
213 // If the icon has been set using |SetIcon|, the factory should return that | 211 // If the icon has been set using |SetIcon|, the factory should return that |
214 // icon. | 212 // icon. |
215 TEST_P(ExtensionActionIconFactoryTest, AfterSetIcon) { | 213 TEST_P(ExtensionActionIconFactoryTest, AfterSetIcon) { |
216 // Load an extension that has browser action without default icon set in the | 214 // Load an extension that has browser action without default icon set in the |
217 // manifest and does not call |SetIcon| by default (but has an browser action | 215 // manifest and does not call |SetIcon| by default (but has an browser action |
218 // icon resource). | 216 // icon resource). |
219 scoped_refptr<Extension> extension(CreateExtension( | 217 scoped_refptr<Extension> extension(CreateExtension("browser_action/no_icon")); |
220 "browser_action/no_icon", Manifest::INVALID_LOCATION)); | |
221 ASSERT_TRUE(extension.get() != NULL); | 218 ASSERT_TRUE(extension.get() != NULL); |
222 ExtensionAction* browser_action = GetBrowserAction(*extension); | 219 ExtensionAction* browser_action = GetBrowserAction(*extension); |
223 ASSERT_TRUE(browser_action); | 220 ASSERT_TRUE(browser_action); |
224 ASSERT_FALSE(browser_action->default_icon()); | 221 ASSERT_FALSE(browser_action->default_icon()); |
225 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); | 222 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); |
226 | 223 |
227 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); | 224 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); |
228 ASSERT_FALSE(set_icon.IsEmpty()); | 225 ASSERT_FALSE(set_icon.IsEmpty()); |
229 | 226 |
230 browser_action->SetIcon(0, set_icon); | 227 browser_action->SetIcon(0, set_icon); |
(...skipping 17 matching lines...) Expand all Loading... |
248 1.0f), | 245 1.0f), |
249 icon.ToImageSkia()->GetRepresentation(1.0f))); | 246 icon.ToImageSkia()->GetRepresentation(1.0f))); |
250 } | 247 } |
251 | 248 |
252 // If there is a default icon, and the icon has not been set using |SetIcon|, | 249 // If there is a default icon, and the icon has not been set using |SetIcon|, |
253 // the factory should return the default icon. | 250 // the factory should return the default icon. |
254 TEST_P(ExtensionActionIconFactoryTest, DefaultIcon) { | 251 TEST_P(ExtensionActionIconFactoryTest, DefaultIcon) { |
255 // Load an extension that has browser action without default icon set in the | 252 // Load an extension that has browser action without default icon set in the |
256 // manifest and does not call |SetIcon| by default (but has an browser action | 253 // manifest and does not call |SetIcon| by default (but has an browser action |
257 // icon resource). | 254 // icon resource). |
258 scoped_refptr<Extension> extension(CreateExtension( | 255 scoped_refptr<Extension> extension(CreateExtension("browser_action/no_icon")); |
259 "browser_action/no_icon", Manifest::INVALID_LOCATION)); | |
260 ASSERT_TRUE(extension.get() != NULL); | 256 ASSERT_TRUE(extension.get() != NULL); |
261 ExtensionAction* browser_action = GetBrowserAction(*extension); | 257 ExtensionAction* browser_action = GetBrowserAction(*extension); |
262 ASSERT_TRUE(browser_action); | 258 ASSERT_TRUE(browser_action); |
263 ASSERT_FALSE(browser_action->default_icon()); | 259 ASSERT_FALSE(browser_action->default_icon()); |
264 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); | 260 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); |
265 | 261 |
266 scoped_refptr<const Extension> extension_with_icon = | 262 scoped_refptr<const Extension> extension_with_icon = |
267 CreateExtension("browser_action_with_icon", Manifest::INVALID_LOCATION); | 263 CreateExtension("browser_action_with_icon"); |
268 ASSERT_TRUE(extension_with_icon); | 264 ASSERT_TRUE(extension_with_icon); |
269 | 265 |
270 int icon_size = ExtensionAction::ActionIconSize(); | 266 int icon_size = ExtensionAction::ActionIconSize(); |
271 gfx::Image default_icon = | 267 gfx::Image default_icon = |
272 EnsureImageSize(LoadIcon("browser_action_with_icon/icon.png"), icon_size); | 268 EnsureImageSize(LoadIcon("browser_action_with_icon/icon.png"), icon_size); |
273 ASSERT_FALSE(default_icon.IsEmpty()); | 269 ASSERT_FALSE(default_icon.IsEmpty()); |
274 | 270 |
275 browser_action = GetBrowserAction(*extension_with_icon); | 271 browser_action = GetBrowserAction(*extension_with_icon); |
276 ASSERT_TRUE(browser_action->default_icon()); | 272 ASSERT_TRUE(browser_action->default_icon()); |
277 | 273 |
(...skipping 21 matching lines...) Expand all Loading... |
299 icon = icon_factory.GetIcon(1); | 295 icon = icon_factory.GetIcon(1); |
300 | 296 |
301 EXPECT_TRUE(ImageRepsAreEqual( | 297 EXPECT_TRUE(ImageRepsAreEqual( |
302 default_icon.ToImageSkia()->GetRepresentation(1.0f), | 298 default_icon.ToImageSkia()->GetRepresentation(1.0f), |
303 icon.ToImageSkia()->GetRepresentation(1.0f))); | 299 icon.ToImageSkia()->GetRepresentation(1.0f))); |
304 | 300 |
305 } | 301 } |
306 | 302 |
307 } // namespace | 303 } // namespace |
308 } // namespace extensions | 304 } // namespace extensions |
OLD | NEW |