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

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

Issue 10905005: Change browser/page action default icon defined in manifest to support hidpi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missing test for icon factory; need to update comments in browser/ui/ Created 8 years, 3 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/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/image/image_skia.h" 17 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
18 #include "webkit/glue/image_decoder.h" 19 #include "webkit/glue/image_decoder.h"
19 20
21 using ::testing::Return;
22
20 namespace { 23 namespace {
21 24
22 bool ImagesAreEqual(const gfx::Image& i1, const gfx::Image& i2) {
23 return gfx::BitmapsAreEqual(*i1.ToSkBitmap(), *i2.ToSkBitmap());
24 }
25
26 gfx::Image LoadIcon(const std::string& filename) {
27 FilePath path;
28 PathService::Get(chrome::DIR_TEST_DATA, &path);
29 path = path.AppendASCII("extensions").AppendASCII(filename);
30
31 std::string file_contents;
32 file_util::ReadFileToString(path, &file_contents);
33 const unsigned char* data =
34 reinterpret_cast<const unsigned char*>(file_contents.data());
35
36 SkBitmap bitmap;
37 webkit_glue::ImageDecoder decoder;
38 bitmap = decoder.Decode(data, file_contents.length());
39
40 return gfx::Image(bitmap);
41 }
42
43 class ExtensionActionTest : public testing::Test { 25 class ExtensionActionTest : public testing::Test {
44 public: 26 public:
45 ExtensionActionTest() 27 ExtensionActionTest()
46 : action("", ExtensionAction::TYPE_PAGE) { 28 : action("", ExtensionAction::TYPE_PAGE) {
47 } 29 }
48 30
49 ExtensionAction action; 31 ExtensionAction action;
50 }; 32 };
51 33
52 TEST_F(ExtensionActionTest, Title) { 34 TEST_F(ExtensionActionTest, Title) {
53 ASSERT_EQ("", action.GetTitle(1)); 35 ASSERT_EQ("", action.GetTitle(1));
54 action.SetTitle(ExtensionAction::kDefaultTabId, "foo"); 36 action.SetTitle(ExtensionAction::kDefaultTabId, "foo");
55 ASSERT_EQ("foo", action.GetTitle(1)); 37 ASSERT_EQ("foo", action.GetTitle(1));
56 ASSERT_EQ("foo", action.GetTitle(100)); 38 ASSERT_EQ("foo", action.GetTitle(100));
57 action.SetTitle(100, "bar"); 39 action.SetTitle(100, "bar");
58 ASSERT_EQ("foo", action.GetTitle(1)); 40 ASSERT_EQ("foo", action.GetTitle(1));
59 ASSERT_EQ("bar", action.GetTitle(100)); 41 ASSERT_EQ("bar", action.GetTitle(100));
60 action.SetTitle(ExtensionAction::kDefaultTabId, "baz"); 42 action.SetTitle(ExtensionAction::kDefaultTabId, "baz");
61 ASSERT_EQ("baz", action.GetTitle(1)); 43 ASSERT_EQ("baz", action.GetTitle(1));
62 action.ClearAllValuesForTab(100); 44 action.ClearAllValuesForTab(100);
63 ASSERT_EQ("baz", action.GetTitle(100)); 45 ASSERT_EQ("baz", action.GetTitle(100));
64 } 46 }
65 47
66 TEST_F(ExtensionActionTest, Icon) {
67 gfx::Image puzzle_piece =
68 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
69 IDR_EXTENSIONS_FAVICON);
70 gfx::Image icon1 = LoadIcon("icon1.png");
71 gfx::Image icon2 = LoadIcon("icon2.png");
tbarzic 2012/09/14 22:24:17 this will be covered in extension_action_icon_fact
72 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1)));
73
74 action.set_default_icon_path("the_default.png");
75 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1)))
76 << "Still returns the puzzle piece because the image isn't loaded yet.";
77 action.CacheIcon(icon2);
78 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(1)));
79
80 action.SetIcon(ExtensionAction::kDefaultTabId, icon1);
81 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(100)))
82 << "SetIcon(kDefaultTabId) overrides the default_icon_path.";
83
84 action.SetIcon(100, icon2);
85 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(1)));
86 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(100)));
87 }
88
89 TEST_F(ExtensionActionTest, Visibility) { 48 TEST_F(ExtensionActionTest, Visibility) {
90 // Supports the icon animation. 49 // Supports the icon animation.
91 MessageLoop message_loop; 50 MessageLoop message_loop;
92 51
93 ASSERT_FALSE(action.GetIsVisible(1)); 52 ASSERT_FALSE(action.GetIsVisible(1));
94 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId)); 53 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId));
95 action.SetAppearance(ExtensionAction::kDefaultTabId, ExtensionAction::ACTIVE); 54 action.SetAppearance(ExtensionAction::kDefaultTabId, ExtensionAction::ACTIVE);
96 ASSERT_TRUE(action.GetIsVisible(1)); 55 ASSERT_TRUE(action.GetIsVisible(1));
97 ASSERT_TRUE(action.GetIsVisible(100)); 56 ASSERT_TRUE(action.GetIsVisible(100));
98 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId)); 57 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz); 158 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz);
200 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); 159 ASSERT_EQ(url_baz, action.GetPopupUrl(1));
201 ASSERT_EQ(url_bar, action.GetPopupUrl(100)); 160 ASSERT_EQ(url_bar, action.GetPopupUrl(100));
202 161
203 action.ClearAllValuesForTab(100); 162 action.ClearAllValuesForTab(100);
204 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); 163 ASSERT_EQ(url_baz, action.GetPopupUrl(1));
205 ASSERT_EQ(url_baz, action.GetPopupUrl(100)); 164 ASSERT_EQ(url_baz, action.GetPopupUrl(100));
206 } 165 }
207 166
208 } // namespace 167 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_action.cc ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698