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

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

Issue 882243002: [Extensions] Make extension actions use gfx::Image over gfx::ImageSkia. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 10 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
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 "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/files/file_util.h" 8 #include "base/files/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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // the factory should return favicon. 183 // the factory should return favicon.
184 TEST_F(ExtensionActionIconFactoryTest, NoIcons) { 184 TEST_F(ExtensionActionIconFactoryTest, NoIcons) {
185 // Load an extension that has browser action without default icon set in the 185 // Load an extension that has browser action without default icon set in the
186 // manifest and does not call |SetIcon| by default. 186 // manifest and does not call |SetIcon| by default.
187 scoped_refptr<Extension> extension(CreateExtension( 187 scoped_refptr<Extension> extension(CreateExtension(
188 "browser_action/no_icon", Manifest::INVALID_LOCATION)); 188 "browser_action/no_icon", Manifest::INVALID_LOCATION));
189 ASSERT_TRUE(extension.get() != NULL); 189 ASSERT_TRUE(extension.get() != NULL);
190 ExtensionAction* browser_action = GetBrowserAction(*extension.get()); 190 ExtensionAction* browser_action = GetBrowserAction(*extension.get());
191 ASSERT_TRUE(browser_action); 191 ASSERT_TRUE(browser_action);
192 ASSERT_FALSE(browser_action->default_icon()); 192 ASSERT_FALSE(browser_action->default_icon());
193 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 193 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty());
194 194
195 gfx::ImageSkia favicon = GetFavicon(); 195 gfx::ImageSkia favicon = GetFavicon();
196 196
197 ExtensionActionIconFactory icon_factory( 197 ExtensionActionIconFactory icon_factory(
198 profile(), extension.get(), browser_action, this); 198 profile(), extension.get(), browser_action, this);
199 199
200 gfx::Image icon = icon_factory.GetIcon(0); 200 gfx::Image icon = icon_factory.GetIcon(0);
201 201
202 EXPECT_TRUE(ImageRepsAreEqual( 202 EXPECT_TRUE(ImageRepsAreEqual(
203 favicon.GetRepresentation(1.0f), 203 favicon.GetRepresentation(1.0f),
204 icon.ToImageSkia()->GetRepresentation(1.0f))); 204 icon.ToImageSkia()->GetRepresentation(1.0f)));
205 } 205 }
206 206
207 // If the icon has been set using |SetIcon|, the factory should return that 207 // If the icon has been set using |SetIcon|, the factory should return that
208 // icon. 208 // icon.
209 TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) { 209 TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) {
210 // Load an extension that has browser action without default icon set in the 210 // Load an extension that has browser action without default icon set in the
211 // manifest and does not call |SetIcon| by default (but has an browser action 211 // manifest and does not call |SetIcon| by default (but has an browser action
212 // icon resource). 212 // icon resource).
213 scoped_refptr<Extension> extension(CreateExtension( 213 scoped_refptr<Extension> extension(CreateExtension(
214 "browser_action/no_icon", Manifest::INVALID_LOCATION)); 214 "browser_action/no_icon", Manifest::INVALID_LOCATION));
215 ASSERT_TRUE(extension.get() != NULL); 215 ASSERT_TRUE(extension.get() != NULL);
216 ExtensionAction* browser_action = GetBrowserAction(*extension.get()); 216 ExtensionAction* browser_action = GetBrowserAction(*extension.get());
217 ASSERT_TRUE(browser_action); 217 ASSERT_TRUE(browser_action);
218 ASSERT_FALSE(browser_action->default_icon()); 218 ASSERT_FALSE(browser_action->default_icon());
219 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 219 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty());
220 220
221 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); 221 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png");
222 ASSERT_FALSE(set_icon.IsEmpty()); 222 ASSERT_FALSE(set_icon.IsEmpty());
223 223
224 browser_action->SetIcon(0, set_icon); 224 browser_action->SetIcon(0, set_icon);
225 225
226 ASSERT_FALSE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 226 ASSERT_FALSE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty());
227 227
228 ExtensionActionIconFactory icon_factory( 228 ExtensionActionIconFactory icon_factory(
229 profile(), extension.get(), browser_action, this); 229 profile(), extension.get(), browser_action, this);
230 230
231 gfx::Image icon = icon_factory.GetIcon(0); 231 gfx::Image icon = icon_factory.GetIcon(0);
232 232
233 EXPECT_TRUE(ImageRepsAreEqual( 233 EXPECT_TRUE(ImageRepsAreEqual(
234 set_icon.ToImageSkia()->GetRepresentation(1.0f), 234 set_icon.ToImageSkia()->GetRepresentation(1.0f),
235 icon.ToImageSkia()->GetRepresentation(1.0f))); 235 icon.ToImageSkia()->GetRepresentation(1.0f)));
236 236
(...skipping 10 matching lines...) Expand all
247 TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) { 247 TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) {
248 // Load an extension that has browser action without default icon set in the 248 // Load an extension that has browser action without default icon set in the
249 // manifest and does not call |SetIcon| by default (but has an browser action 249 // manifest and does not call |SetIcon| by default (but has an browser action
250 // icon resource). 250 // icon resource).
251 scoped_refptr<Extension> extension(CreateExtension( 251 scoped_refptr<Extension> extension(CreateExtension(
252 "browser_action/no_icon", Manifest::INVALID_LOCATION)); 252 "browser_action/no_icon", Manifest::INVALID_LOCATION));
253 ASSERT_TRUE(extension.get() != NULL); 253 ASSERT_TRUE(extension.get() != NULL);
254 ExtensionAction* browser_action = GetBrowserAction(*extension.get()); 254 ExtensionAction* browser_action = GetBrowserAction(*extension.get());
255 ASSERT_TRUE(browser_action); 255 ASSERT_TRUE(browser_action);
256 ASSERT_FALSE(browser_action->default_icon()); 256 ASSERT_FALSE(browser_action->default_icon());
257 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 257 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty());
258 258
259 gfx::Image default_icon = 259 gfx::Image default_icon =
260 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), 19); 260 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), 19);
261 ASSERT_FALSE(default_icon.IsEmpty()); 261 ASSERT_FALSE(default_icon.IsEmpty());
262 262
263 scoped_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet()); 263 scoped_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet());
264 default_icon_set->Add(19, "icon.png"); 264 default_icon_set->Add(19, "icon.png");
265 265
266 browser_action->SetDefaultIconForTest(default_icon_set.Pass()); 266 browser_action->SetDefaultIconForTest(default_icon_set.Pass());
267 ASSERT_TRUE(browser_action->default_icon()); 267 ASSERT_TRUE(browser_action->default_icon());
(...skipping 22 matching lines...) Expand all
290 icon = icon_factory.GetIcon(1); 290 icon = icon_factory.GetIcon(1);
291 291
292 EXPECT_TRUE(ImageRepsAreEqual( 292 EXPECT_TRUE(ImageRepsAreEqual(
293 default_icon.ToImageSkia()->GetRepresentation(1.0f), 293 default_icon.ToImageSkia()->GetRepresentation(1.0f),
294 icon.ToImageSkia()->GetRepresentation(1.0f))); 294 icon.ToImageSkia()->GetRepresentation(1.0f)));
295 295
296 } 296 }
297 297
298 } // namespace 298 } // namespace
299 } // namespace extensions 299 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698