| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 virtual ~ExtensionActionIconFactoryTest() {} | 89 virtual ~ExtensionActionIconFactoryTest() {} |
| 90 | 90 |
| 91 void WaitForIconUpdate() { | 91 void WaitForIconUpdate() { |
| 92 quit_in_icon_updated_ = true; | 92 quit_in_icon_updated_ = true; |
| 93 MessageLoop::current()->Run(); | 93 MessageLoop::current()->Run(); |
| 94 quit_in_icon_updated_ = false; | 94 quit_in_icon_updated_ = false; |
| 95 } | 95 } |
| 96 | 96 |
| 97 scoped_refptr<Extension> CreateExtension(const char* name, | 97 scoped_refptr<Extension> CreateExtension(const char* name, |
| 98 Extension::Location location) { | 98 Manifest::Location location) { |
| 99 // Create and load an extension. | 99 // Create and load an extension. |
| 100 FilePath test_file; | 100 FilePath test_file; |
| 101 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) { | 101 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) { |
| 102 EXPECT_FALSE(true); | 102 EXPECT_FALSE(true); |
| 103 return NULL; | 103 return NULL; |
| 104 } | 104 } |
| 105 test_file = test_file.AppendASCII("extensions/api_test").AppendASCII(name); | 105 test_file = test_file.AppendASCII("extensions/api_test").AppendASCII(name); |
| 106 int error_code = 0; | 106 int error_code = 0; |
| 107 std::string error; | 107 std::string error; |
| 108 JSONFileValueSerializer serializer(test_file.AppendASCII("manifest.json")); | 108 JSONFileValueSerializer serializer(test_file.AppendASCII("manifest.json")); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactoryTest); | 171 DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactoryTest); |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 // If there is no default icon, and the icon has not been set using |SetIcon|, | 174 // If there is no default icon, and the icon has not been set using |SetIcon|, |
| 175 // the factory should return favicon. | 175 // the factory should return favicon. |
| 176 TEST_F(ExtensionActionIconFactoryTest, NoIcons) { | 176 TEST_F(ExtensionActionIconFactoryTest, NoIcons) { |
| 177 // Load an extension that has browser action without default icon set in the | 177 // Load an extension that has browser action without default icon set in the |
| 178 // manifest and does not call |SetIcon| by default. | 178 // manifest and does not call |SetIcon| by default. |
| 179 scoped_refptr<Extension> extension(CreateExtension( | 179 scoped_refptr<Extension> extension(CreateExtension( |
| 180 "browser_action/no_icon", Extension::INVALID)); | 180 "browser_action/no_icon", Manifest::INVALID_LOCATION)); |
| 181 ASSERT_TRUE(extension.get() != NULL); | 181 ASSERT_TRUE(extension.get() != NULL); |
| 182 ExtensionAction* browser_action = GetBrowserAction(*extension); | 182 ExtensionAction* browser_action = GetBrowserAction(*extension); |
| 183 ASSERT_TRUE(browser_action); | 183 ASSERT_TRUE(browser_action); |
| 184 ASSERT_FALSE(browser_action->default_icon()); | 184 ASSERT_FALSE(browser_action->default_icon()); |
| 185 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); | 185 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); |
| 186 | 186 |
| 187 gfx::ImageSkia favicon = GetFavicon(); | 187 gfx::ImageSkia favicon = GetFavicon(); |
| 188 | 188 |
| 189 ExtensionActionIconFactory icon_factory(extension, browser_action, this); | 189 ExtensionActionIconFactory icon_factory(extension, browser_action, this); |
| 190 | 190 |
| 191 gfx::Image icon = icon_factory.GetIcon(0); | 191 gfx::Image icon = icon_factory.GetIcon(0); |
| 192 | 192 |
| 193 EXPECT_TRUE(ImageRepsAreEqual( | 193 EXPECT_TRUE(ImageRepsAreEqual( |
| 194 favicon.GetRepresentation(ui::SCALE_FACTOR_100P), | 194 favicon.GetRepresentation(ui::SCALE_FACTOR_100P), |
| 195 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); | 195 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // If the icon has been set using |SetIcon|, the factory should return that | 198 // If the icon has been set using |SetIcon|, the factory should return that |
| 199 // icon. | 199 // icon. |
| 200 TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) { | 200 TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) { |
| 201 // Load an extension that has browser action without default icon set in the | 201 // Load an extension that has browser action without default icon set in the |
| 202 // manifest and does not call |SetIcon| by default (but has an browser action | 202 // manifest and does not call |SetIcon| by default (but has an browser action |
| 203 // icon resource). | 203 // icon resource). |
| 204 scoped_refptr<Extension> extension(CreateExtension( | 204 scoped_refptr<Extension> extension(CreateExtension( |
| 205 "browser_action/no_icon", Extension::INVALID)); | 205 "browser_action/no_icon", Manifest::INVALID_LOCATION)); |
| 206 ASSERT_TRUE(extension.get() != NULL); | 206 ASSERT_TRUE(extension.get() != NULL); |
| 207 ExtensionAction* browser_action = GetBrowserAction(*extension); | 207 ExtensionAction* browser_action = GetBrowserAction(*extension); |
| 208 ASSERT_TRUE(browser_action); | 208 ASSERT_TRUE(browser_action); |
| 209 ASSERT_FALSE(browser_action->default_icon()); | 209 ASSERT_FALSE(browser_action->default_icon()); |
| 210 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); | 210 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); |
| 211 | 211 |
| 212 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); | 212 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); |
| 213 ASSERT_FALSE(set_icon.IsEmpty()); | 213 ASSERT_FALSE(set_icon.IsEmpty()); |
| 214 | 214 |
| 215 browser_action->SetIcon(0, set_icon); | 215 browser_action->SetIcon(0, set_icon); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 232 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); | 232 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); |
| 233 } | 233 } |
| 234 | 234 |
| 235 // If there is a default icon, and the icon has not been set using |SetIcon|, | 235 // If there is a default icon, and the icon has not been set using |SetIcon|, |
| 236 // the factory should return the default icon. | 236 // the factory should return the default icon. |
| 237 TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) { | 237 TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) { |
| 238 // Load an extension that has browser action without default icon set in the | 238 // Load an extension that has browser action without default icon set in the |
| 239 // manifest and does not call |SetIcon| by default (but has an browser action | 239 // manifest and does not call |SetIcon| by default (but has an browser action |
| 240 // icon resource). | 240 // icon resource). |
| 241 scoped_refptr<Extension> extension(CreateExtension( | 241 scoped_refptr<Extension> extension(CreateExtension( |
| 242 "browser_action/no_icon", Extension::INVALID)); | 242 "browser_action/no_icon", Manifest::INVALID_LOCATION)); |
| 243 ASSERT_TRUE(extension.get() != NULL); | 243 ASSERT_TRUE(extension.get() != NULL); |
| 244 ExtensionAction* browser_action = GetBrowserAction(*extension); | 244 ExtensionAction* browser_action = GetBrowserAction(*extension); |
| 245 ASSERT_TRUE(browser_action); | 245 ASSERT_TRUE(browser_action); |
| 246 ASSERT_FALSE(browser_action->default_icon()); | 246 ASSERT_FALSE(browser_action->default_icon()); |
| 247 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); | 247 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); |
| 248 | 248 |
| 249 gfx::Image default_icon = | 249 gfx::Image default_icon = |
| 250 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), 19); | 250 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), 19); |
| 251 ASSERT_FALSE(default_icon.IsEmpty()); | 251 ASSERT_FALSE(default_icon.IsEmpty()); |
| 252 | 252 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 279 icon = icon_factory.GetIcon(1); | 279 icon = icon_factory.GetIcon(1); |
| 280 | 280 |
| 281 EXPECT_TRUE(ImageRepsAreEqual( | 281 EXPECT_TRUE(ImageRepsAreEqual( |
| 282 default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P), | 282 default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P), |
| 283 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); | 283 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); |
| 284 | 284 |
| 285 } | 285 } |
| 286 | 286 |
| 287 } // namespace | 287 } // namespace |
| 288 } // namespace extensions | 288 } // namespace extensions |
| OLD | NEW |