| 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 "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 "chrome/common/extensions/extension_icon_factory_delegate.h" |
| 11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 12 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/image/image_skia.h" | 18 #include "ui/gfx/image/image_skia.h" |
| 17 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 18 #include "webkit/glue/image_decoder.h" | 20 #include "webkit/glue/image_decoder.h" |
| 19 | 21 |
| 22 using ::testing::Return; |
| 23 |
| 20 namespace { | 24 namespace { |
| 21 | 25 |
| 22 bool ImagesAreEqual(const gfx::Image& i1, const gfx::Image& i2) { | 26 bool ImagesAreEqual(const gfx::Image& i1, const gfx::Image& i2) { |
| 23 return gfx::BitmapsAreEqual(*i1.ToSkBitmap(), *i2.ToSkBitmap()); | 27 return gfx::BitmapsAreEqual(*i1.ToSkBitmap(), *i2.ToSkBitmap()); |
| 24 } | 28 } |
| 25 | 29 |
| 26 gfx::Image LoadIcon(const std::string& filename) { | 30 gfx::Image LoadIcon(const std::string& filename) { |
| 27 FilePath path; | 31 FilePath path; |
| 28 PathService::Get(chrome::DIR_TEST_DATA, &path); | 32 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 29 path = path.AppendASCII("extensions").AppendASCII(filename); | 33 path = path.AppendASCII("extensions").AppendASCII(filename); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 42 | 46 |
| 43 class ExtensionActionTest : public testing::Test { | 47 class ExtensionActionTest : public testing::Test { |
| 44 public: | 48 public: |
| 45 ExtensionActionTest() | 49 ExtensionActionTest() |
| 46 : action("", ExtensionAction::TYPE_PAGE) { | 50 : action("", ExtensionAction::TYPE_PAGE) { |
| 47 } | 51 } |
| 48 | 52 |
| 49 ExtensionAction action; | 53 ExtensionAction action; |
| 50 }; | 54 }; |
| 51 | 55 |
| 56 class MockActionIconFactory : public ExtensionIconFactoryDelegate { |
| 57 public: |
| 58 virtual ~MockActionIconFactory() {} |
| 59 |
| 60 MOCK_METHOD2(GetIcon, gfx::ImageSkia(const ExtensionIconSet* icon_set, |
| 61 const gfx::Size& desired_size)); |
| 62 }; |
| 63 |
| 52 TEST_F(ExtensionActionTest, Title) { | 64 TEST_F(ExtensionActionTest, Title) { |
| 53 ASSERT_EQ("", action.GetTitle(1)); | 65 ASSERT_EQ("", action.GetTitle(1)); |
| 54 action.SetTitle(ExtensionAction::kDefaultTabId, "foo"); | 66 action.SetTitle(ExtensionAction::kDefaultTabId, "foo"); |
| 55 ASSERT_EQ("foo", action.GetTitle(1)); | 67 ASSERT_EQ("foo", action.GetTitle(1)); |
| 56 ASSERT_EQ("foo", action.GetTitle(100)); | 68 ASSERT_EQ("foo", action.GetTitle(100)); |
| 57 action.SetTitle(100, "bar"); | 69 action.SetTitle(100, "bar"); |
| 58 ASSERT_EQ("foo", action.GetTitle(1)); | 70 ASSERT_EQ("foo", action.GetTitle(1)); |
| 59 ASSERT_EQ("bar", action.GetTitle(100)); | 71 ASSERT_EQ("bar", action.GetTitle(100)); |
| 60 action.SetTitle(ExtensionAction::kDefaultTabId, "baz"); | 72 action.SetTitle(ExtensionAction::kDefaultTabId, "baz"); |
| 61 ASSERT_EQ("baz", action.GetTitle(1)); | 73 ASSERT_EQ("baz", action.GetTitle(1)); |
| 62 action.ClearAllValuesForTab(100); | 74 action.ClearAllValuesForTab(100); |
| 63 ASSERT_EQ("baz", action.GetTitle(100)); | 75 ASSERT_EQ("baz", action.GetTitle(100)); |
| 64 } | 76 } |
| 65 | 77 |
| 66 TEST_F(ExtensionActionTest, Icon) { | 78 TEST_F(ExtensionActionTest, Icon) { |
| 67 gfx::Image puzzle_piece = | 79 gfx::Image puzzle_piece = |
| 68 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 80 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 69 IDR_EXTENSIONS_FAVICON); | 81 IDR_EXTENSIONS_FAVICON); |
| 70 gfx::Image icon1 = LoadIcon("icon1.png"); | 82 gfx::Image icon1 = LoadIcon("icon1.png"); |
| 71 gfx::Image icon2 = LoadIcon("icon2.png"); | 83 gfx::Image icon2 = LoadIcon("icon2.png"); |
| 72 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1))); | |
| 73 | 84 |
| 74 action.set_default_icon_path("the_default.png"); | 85 |
| 75 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, action.GetIcon(1))) | 86 scoped_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet()); |
| 76 << "Still returns the puzzle piece because the image isn't loaded yet."; | 87 MockActionIconFactory icon_factory_mock; |
| 77 action.CacheIcon(icon2); | 88 |
| 78 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(1))); | 89 EXPECT_CALL(icon_factory_mock, GetIcon(default_icon_set.get(), |
| 90 gfx::Size(19, 19))) |
| 91 .WillOnce(Return(*icon2.ToImageSkia())); |
| 92 |
| 93 ASSERT_TRUE(ImagesAreEqual(puzzle_piece, |
| 94 action.GetIcon(1, &icon_factory_mock))); |
| 95 |
| 96 action.set_default_icon(default_icon_set.Pass()); |
| 97 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(1, &icon_factory_mock))); |
| 79 | 98 |
| 80 action.SetIcon(ExtensionAction::kDefaultTabId, icon1); | 99 action.SetIcon(ExtensionAction::kDefaultTabId, icon1); |
| 81 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(100))) | 100 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(100, &icon_factory_mock))) |
| 82 << "SetIcon(kDefaultTabId) overrides the default_icon_path."; | 101 << "SetIcon(kDefaultTabId) overrides the default_icon."; |
| 83 | 102 |
| 84 action.SetIcon(100, icon2); | 103 action.SetIcon(100, icon2); |
| 85 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(1))); | 104 ASSERT_TRUE(ImagesAreEqual(icon1, action.GetIcon(1, &icon_factory_mock))); |
| 86 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(100))); | 105 ASSERT_TRUE(ImagesAreEqual(icon2, action.GetIcon(100, &icon_factory_mock))); |
| 87 } | 106 } |
| 88 | 107 |
| 108 |
| 89 TEST_F(ExtensionActionTest, Visibility) { | 109 TEST_F(ExtensionActionTest, Visibility) { |
| 90 // Supports the icon animation. | 110 // Supports the icon animation. |
| 91 MessageLoop message_loop; | 111 MessageLoop message_loop; |
| 92 | 112 |
| 93 ASSERT_FALSE(action.GetIsVisible(1)); | 113 ASSERT_FALSE(action.GetIsVisible(1)); |
| 94 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId)); | 114 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId)); |
| 95 action.SetAppearance(ExtensionAction::kDefaultTabId, ExtensionAction::ACTIVE); | 115 action.SetAppearance(ExtensionAction::kDefaultTabId, ExtensionAction::ACTIVE); |
| 96 ASSERT_TRUE(action.GetIsVisible(1)); | 116 ASSERT_TRUE(action.GetIsVisible(1)); |
| 97 ASSERT_TRUE(action.GetIsVisible(100)); | 117 ASSERT_TRUE(action.GetIsVisible(100)); |
| 98 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId)); | 118 EXPECT_FALSE(action.GetIconAnimation(ExtensionAction::kDefaultTabId)); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz); | 219 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz); |
| 200 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); | 220 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); |
| 201 ASSERT_EQ(url_bar, action.GetPopupUrl(100)); | 221 ASSERT_EQ(url_bar, action.GetPopupUrl(100)); |
| 202 | 222 |
| 203 action.ClearAllValuesForTab(100); | 223 action.ClearAllValuesForTab(100); |
| 204 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); | 224 ASSERT_EQ(url_baz, action.GetPopupUrl(1)); |
| 205 ASSERT_EQ(url_baz, action.GetPopupUrl(100)); | 225 ASSERT_EQ(url_baz, action.GetPopupUrl(100)); |
| 206 } | 226 } |
| 207 | 227 |
| 208 } // namespace | 228 } // namespace |
| OLD | NEW |