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

Side by Side Diff: chrome/common/extensions/extension_action_unittest.cc

Issue 10827191: Convert extension action icons code to use ImageSkia instead of SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove includes we don't need anymore Created 8 years, 4 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
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/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension_action.h" 10 #include "chrome/common/extensions/extension_action.h"
11 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
12 #include "grit/theme_resources.h" 12 #include "grit/theme_resources.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/image/image.h" 16 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/skia_util.h" 17 #include "ui/gfx/skia_util.h"
18 #include "webkit/glue/image_decoder.h" 18 #include "webkit/glue/image_decoder.h"
19 19
20 namespace { 20 namespace {
21 21
22 bool ImagesAreEqual(const gfx::Image& i1, const gfx::Image& i2) { 22 bool ImagesAreEqual(const gfx::Image& i1, const gfx::Image& i2) {
23 return gfx::BitmapsAreEqual(*i1.ToSkBitmap(), *i2.ToSkBitmap()); 23 return gfx::BitmapsAreEqual(*i1.ToSkBitmap(), *i2.ToSkBitmap());
24 } 24 }
25 25
26 gfx::Image LoadIcon(const std::string& filename) { 26 gfx::Image LoadIcon(const std::string& filename) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 ASSERT_EQ("foo", action.GetTitle(1)); 58 ASSERT_EQ("foo", action.GetTitle(1));
59 ASSERT_EQ("bar", action.GetTitle(100)); 59 ASSERT_EQ("bar", action.GetTitle(100));
60 action.SetTitle(ExtensionAction::kDefaultTabId, "baz"); 60 action.SetTitle(ExtensionAction::kDefaultTabId, "baz");
61 ASSERT_EQ("baz", action.GetTitle(1)); 61 ASSERT_EQ("baz", action.GetTitle(1));
62 action.ClearAllValuesForTab(100); 62 action.ClearAllValuesForTab(100);
63 ASSERT_EQ("baz", action.GetTitle(100)); 63 ASSERT_EQ("baz", action.GetTitle(100));
64 } 64 }
65 65
66 TEST_F(ExtensionActionTest, Icon) { 66 TEST_F(ExtensionActionTest, Icon) {
67 gfx::Image puzzle_piece = 67 gfx::Image puzzle_piece =
68 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 68 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
Jeffrey Yasskin 2012/08/09 21:39:04 4-space indent, right?
tbarzic 2012/08/10 06:24:08 Done.
69 IDR_EXTENSIONS_FAVICON); 69 IDR_EXTENSIONS_FAVICON);
70 gfx::Image icon1 = LoadIcon("icon1.png"); 70 gfx::Image icon1 = LoadIcon("icon1.png");
71 gfx::Image icon2 = LoadIcon("icon2.png"); 71 gfx::Image icon2 = LoadIcon("icon2.png");
72 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1))); 72 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1)));
73 73
74 action.set_default_icon_path("the_default.png"); 74 action.set_default_icon_path("the_default.png");
75 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1))) 75 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1)))
76 << "Still returns the puzzle piece because the image isn't loaded yet."; 76 << "Still returns the puzzle piece because the image isn't loaded yet.";
77 action.CacheIcon("the_default.png", icon2); 77 action.CacheIcon("the_default.png", icon2);
78 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(1))); 78 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(1)));
79 79
80 action.SetIcon(ExtensionAction::kDefaultTabId, *icon1.ToSkBitmap()); 80 action.SetIcon(ExtensionAction::kDefaultTabId, icon1);
81 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(100))) 81 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(100)))
82 << "SetIcon(kDefaultTabId) overrides the default_icon_path."; 82 << "SetIcon(kDefaultTabId) overrides the default_icon_path.";
83 83
84 action.SetIcon(100, *icon2.ToSkBitmap()); 84 action.SetIcon(100, icon2);
85 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(1))); 85 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(1)));
86 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(100))); 86 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(100)));
87 } 87 }
88 88
89 TEST_F(ExtensionActionTest, IconIndex) { 89 TEST_F(ExtensionActionTest, IconIndex) {
90 gfx::Image icon1 = LoadIcon("icon1.png"); 90 gfx::Image icon1 = LoadIcon("icon1.png");
91 gfx::Image icon2 = LoadIcon("icon2.png"); 91 gfx::Image icon2 = LoadIcon("icon2.png");
92 gfx::Image puzzle_piece = 92 gfx::Image puzzle_piece =
93 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 93 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
94 IDR_EXTENSIONS_FAVICON); 94 IDR_EXTENSIONS_FAVICON);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz); 228 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz);
229 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); 229 ASSERT_EQ(url_baz, action.GetPopupUrl(1));
230 ASSERT_EQ(url_bar, action.GetPopupUrl(100)); 230 ASSERT_EQ(url_bar, action.GetPopupUrl(100));
231 231
232 action.ClearAllValuesForTab(100); 232 action.ClearAllValuesForTab(100);
233 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); 233 ASSERT_EQ(url_baz, action.GetPopupUrl(1));
234 ASSERT_EQ(url_baz, action.GetPopupUrl(100)); 234 ASSERT_EQ(url_baz, action.GetPopupUrl(100));
235 } 235 }
236 236
237 } // namespace 237 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698