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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 ui::MaterialDesignController::MATERIAL_HYBRID)); | 200 ui::MaterialDesignController::MATERIAL_HYBRID)); |
201 | 201 |
202 // If there is no default icon, and the icon has not been set using |SetIcon|, | 202 // If there is no default icon, and the icon has not been set using |SetIcon|, |
203 // the factory should return favicon. | 203 // the factory should return favicon. |
204 TEST_P(ExtensionActionIconFactoryTest, NoIcons) { | 204 TEST_P(ExtensionActionIconFactoryTest, NoIcons) { |
205 // Load an extension that has browser action without default icon set in the | 205 // Load an extension that has browser action without default icon set in the |
206 // manifest and does not call |SetIcon| by default. | 206 // manifest and does not call |SetIcon| by default. |
207 scoped_refptr<Extension> extension(CreateExtension( | 207 scoped_refptr<Extension> extension(CreateExtension( |
208 "browser_action/no_icon", Manifest::INVALID_LOCATION)); | 208 "browser_action/no_icon", Manifest::INVALID_LOCATION)); |
209 ASSERT_TRUE(extension.get() != NULL); | 209 ASSERT_TRUE(extension.get() != NULL); |
210 ExtensionAction* browser_action = GetBrowserAction(*extension.get()); | 210 ExtensionAction* browser_action = GetBrowserAction(*extension); |
211 ASSERT_TRUE(browser_action); | 211 ASSERT_TRUE(browser_action); |
212 ASSERT_FALSE(browser_action->default_icon()); | 212 ASSERT_FALSE(browser_action->default_icon()); |
213 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); | 213 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); |
214 | 214 |
215 ExtensionActionIconFactory icon_factory( | 215 ExtensionActionIconFactory icon_factory( |
216 profile(), extension.get(), browser_action, this); | 216 profile(), extension.get(), browser_action, this); |
217 | 217 |
218 gfx::Image icon = icon_factory.GetIcon(0); | 218 gfx::Image icon = icon_factory.GetIcon(0); |
219 | 219 |
220 EXPECT_TRUE(ImageRepsAreEqual( | 220 EXPECT_TRUE(ImageRepsAreEqual( |
221 browser_action->GetDefaultIconImage().ToImageSkia()->GetRepresentation( | 221 browser_action->GetDefaultIconImage().ToImageSkia()->GetRepresentation( |
222 1.0f), | 222 1.0f), |
223 icon.ToImageSkia()->GetRepresentation(1.0f))); | 223 icon.ToImageSkia()->GetRepresentation(1.0f))); |
224 } | 224 } |
225 | 225 |
226 // If the icon has been set using |SetIcon|, the factory should return that | 226 // If the icon has been set using |SetIcon|, the factory should return that |
227 // icon. | 227 // icon. |
228 TEST_P(ExtensionActionIconFactoryTest, AfterSetIcon) { | 228 TEST_P(ExtensionActionIconFactoryTest, AfterSetIcon) { |
229 // Load an extension that has browser action without default icon set in the | 229 // Load an extension that has browser action without default icon set in the |
230 // manifest and does not call |SetIcon| by default (but has an browser action | 230 // manifest and does not call |SetIcon| by default (but has an browser action |
231 // icon resource). | 231 // icon resource). |
232 scoped_refptr<Extension> extension(CreateExtension( | 232 scoped_refptr<Extension> extension(CreateExtension( |
233 "browser_action/no_icon", Manifest::INVALID_LOCATION)); | 233 "browser_action/no_icon", Manifest::INVALID_LOCATION)); |
234 ASSERT_TRUE(extension.get() != NULL); | 234 ASSERT_TRUE(extension.get() != NULL); |
235 ExtensionAction* browser_action = GetBrowserAction(*extension.get()); | 235 ExtensionAction* browser_action = GetBrowserAction(*extension); |
236 ASSERT_TRUE(browser_action); | 236 ASSERT_TRUE(browser_action); |
237 ASSERT_FALSE(browser_action->default_icon()); | 237 ASSERT_FALSE(browser_action->default_icon()); |
238 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); | 238 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); |
239 | 239 |
240 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); | 240 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); |
241 ASSERT_FALSE(set_icon.IsEmpty()); | 241 ASSERT_FALSE(set_icon.IsEmpty()); |
242 | 242 |
243 browser_action->SetIcon(0, set_icon); | 243 browser_action->SetIcon(0, set_icon); |
244 | 244 |
245 ASSERT_FALSE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); | 245 ASSERT_FALSE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); |
(...skipping 18 matching lines...) Expand all Loading... |
264 | 264 |
265 // If there is a default icon, and the icon has not been set using |SetIcon|, | 265 // If there is a default icon, and the icon has not been set using |SetIcon|, |
266 // the factory should return the default icon. | 266 // the factory should return the default icon. |
267 TEST_P(ExtensionActionIconFactoryTest, DefaultIcon) { | 267 TEST_P(ExtensionActionIconFactoryTest, DefaultIcon) { |
268 // Load an extension that has browser action without default icon set in the | 268 // Load an extension that has browser action without default icon set in the |
269 // manifest and does not call |SetIcon| by default (but has an browser action | 269 // manifest and does not call |SetIcon| by default (but has an browser action |
270 // icon resource). | 270 // icon resource). |
271 scoped_refptr<Extension> extension(CreateExtension( | 271 scoped_refptr<Extension> extension(CreateExtension( |
272 "browser_action/no_icon", Manifest::INVALID_LOCATION)); | 272 "browser_action/no_icon", Manifest::INVALID_LOCATION)); |
273 ASSERT_TRUE(extension.get() != NULL); | 273 ASSERT_TRUE(extension.get() != NULL); |
274 ExtensionAction* browser_action = GetBrowserAction(*extension.get()); | 274 ExtensionAction* browser_action = GetBrowserAction(*extension); |
275 ASSERT_TRUE(browser_action); | 275 ASSERT_TRUE(browser_action); |
276 ASSERT_FALSE(browser_action->default_icon()); | 276 ASSERT_FALSE(browser_action->default_icon()); |
277 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); | 277 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); |
278 | 278 |
279 int icon_size = ExtensionAction::ActionIconSize(); | 279 int icon_size = ExtensionAction::ActionIconSize(); |
280 gfx::Image default_icon = | 280 gfx::Image default_icon = |
281 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), icon_size); | 281 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), icon_size); |
282 ASSERT_FALSE(default_icon.IsEmpty()); | 282 ASSERT_FALSE(default_icon.IsEmpty()); |
283 | 283 |
284 std::unique_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet()); | 284 std::unique_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet()); |
(...skipping 26 matching lines...) Expand all Loading... |
311 icon = icon_factory.GetIcon(1); | 311 icon = icon_factory.GetIcon(1); |
312 | 312 |
313 EXPECT_TRUE(ImageRepsAreEqual( | 313 EXPECT_TRUE(ImageRepsAreEqual( |
314 default_icon.ToImageSkia()->GetRepresentation(1.0f), | 314 default_icon.ToImageSkia()->GetRepresentation(1.0f), |
315 icon.ToImageSkia()->GetRepresentation(1.0f))); | 315 icon.ToImageSkia()->GetRepresentation(1.0f))); |
316 | 316 |
317 } | 317 } |
318 | 318 |
319 } // namespace | 319 } // namespace |
320 } // namespace extensions | 320 } // namespace extensions |
OLD | NEW |