[email protected] | 3349b59 | 2012-04-26 12:35:28 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4a3dab2 | 2009-11-11 17:36:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | b19fe57 | 2013-07-18 04:54:26 | [diff] [blame] | 5 | #include "base/message_loop/message_loop.h" |
[email protected] | 8ddcc92 | 2012-10-13 05:13:03 | [diff] [blame] | 6 | #include "chrome/browser/extensions/extension_action.h" |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 7 | #include "chrome/common/extensions/api/extension_action/action_info.h" |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 8 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 9 | #include "url/gurl.h" |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 10 | |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 11 | namespace { |
[email protected] | 18539ee | 2010-09-16 21:39:29 | [diff] [blame] | 12 | |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 13 | using extensions::ActionInfo; |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 14 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 15 | TEST(ExtensionActionTest, Title) { |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 16 | ActionInfo action_info; |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 17 | action_info.default_title = "Initial Title"; |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 18 | ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, action_info); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 19 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 20 | ASSERT_EQ("Initial Title", action.GetTitle(1)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 21 | action.SetTitle(ExtensionAction::kDefaultTabId, "foo"); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 22 | ASSERT_EQ("foo", action.GetTitle(1)); |
| 23 | ASSERT_EQ("foo", action.GetTitle(100)); |
| 24 | action.SetTitle(100, "bar"); |
| 25 | ASSERT_EQ("foo", action.GetTitle(1)); |
| 26 | ASSERT_EQ("bar", action.GetTitle(100)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 27 | action.SetTitle(ExtensionAction::kDefaultTabId, "baz"); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 28 | ASSERT_EQ("baz", action.GetTitle(1)); |
| 29 | action.ClearAllValuesForTab(100); |
| 30 | ASSERT_EQ("baz", action.GetTitle(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 31 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 32 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 33 | TEST(ExtensionActionTest, Visibility) { |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 34 | ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo()); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 35 | |
[email protected] | e3a8a92 | 2010-10-02 02:04:30 | [diff] [blame] | 36 | ASSERT_FALSE(action.GetIsVisible(1)); |
[email protected] | 82bf778 | 2014-02-05 09:41:31 | [diff] [blame] | 37 | action.SetIsVisible(ExtensionAction::kDefaultTabId, true); |
[email protected] | e3a8a92 | 2010-10-02 02:04:30 | [diff] [blame] | 38 | ASSERT_TRUE(action.GetIsVisible(1)); |
| 39 | ASSERT_TRUE(action.GetIsVisible(100)); |
[email protected] | 48a7a425b | 2012-08-03 12:52:58 | [diff] [blame] | 40 | |
[email protected] | 82bf778 | 2014-02-05 09:41:31 | [diff] [blame] | 41 | action.SetIsVisible(ExtensionAction::kDefaultTabId, false); |
[email protected] | e3a8a92 | 2010-10-02 02:04:30 | [diff] [blame] | 42 | ASSERT_FALSE(action.GetIsVisible(1)); |
| 43 | ASSERT_FALSE(action.GetIsVisible(100)); |
[email protected] | 82bf778 | 2014-02-05 09:41:31 | [diff] [blame] | 44 | action.SetIsVisible(100, true); |
[email protected] | e3a8a92 | 2010-10-02 02:04:30 | [diff] [blame] | 45 | ASSERT_FALSE(action.GetIsVisible(1)); |
| 46 | ASSERT_TRUE(action.GetIsVisible(100)); |
[email protected] | 48a7a425b | 2012-08-03 12:52:58 | [diff] [blame] | 47 | |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 48 | action.ClearAllValuesForTab(100); |
[email protected] | e3a8a92 | 2010-10-02 02:04:30 | [diff] [blame] | 49 | ASSERT_FALSE(action.GetIsVisible(1)); |
| 50 | ASSERT_FALSE(action.GetIsVisible(100)); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 51 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 52 | ExtensionAction browser_action( |
| 53 | std::string(), ActionInfo::TYPE_BROWSER, ActionInfo()); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 54 | ASSERT_TRUE(browser_action.GetIsVisible(1)); |
[email protected] | a048c09 | 2012-09-21 02:33:26 | [diff] [blame] | 55 | } |
| 56 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 57 | TEST(ExtensionActionTest, Icon) { |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 58 | ActionInfo action_info; |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 59 | action_info.default_icon.Add(16, "icon16.png"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 60 | ExtensionAction page_action( |
| 61 | std::string(), ActionInfo::TYPE_PAGE, action_info); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 62 | ASSERT_TRUE(page_action.default_icon()); |
| 63 | EXPECT_EQ("icon16.png", |
| 64 | page_action.default_icon()->Get( |
| 65 | 16, ExtensionIconSet::MATCH_EXACTLY)); |
| 66 | EXPECT_EQ("", |
| 67 | page_action.default_icon()->Get( |
| 68 | 17, ExtensionIconSet::MATCH_BIGGER)); |
| 69 | } |
| 70 | |
| 71 | TEST(ExtensionActionTest, Badge) { |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 72 | ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo()); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 73 | ASSERT_EQ("", action.GetBadgeText(1)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 74 | action.SetBadgeText(ExtensionAction::kDefaultTabId, "foo"); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 75 | ASSERT_EQ("foo", action.GetBadgeText(1)); |
| 76 | ASSERT_EQ("foo", action.GetBadgeText(100)); |
| 77 | action.SetBadgeText(100, "bar"); |
| 78 | ASSERT_EQ("foo", action.GetBadgeText(1)); |
| 79 | ASSERT_EQ("bar", action.GetBadgeText(100)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 80 | action.SetBadgeText(ExtensionAction::kDefaultTabId, "baz"); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 81 | ASSERT_EQ("baz", action.GetBadgeText(1)); |
| 82 | action.ClearAllValuesForTab(100); |
| 83 | ASSERT_EQ("baz", action.GetBadgeText(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 84 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 85 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 86 | TEST(ExtensionActionTest, BadgeTextColor) { |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 87 | ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo()); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 88 | ASSERT_EQ(0x00000000u, action.GetBadgeTextColor(1)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 89 | action.SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFFFF0000u); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 90 | ASSERT_EQ(0xFFFF0000u, action.GetBadgeTextColor(1)); |
| 91 | ASSERT_EQ(0xFFFF0000u, action.GetBadgeTextColor(100)); |
| 92 | action.SetBadgeTextColor(100, 0xFF00FF00); |
| 93 | ASSERT_EQ(0xFFFF0000u, action.GetBadgeTextColor(1)); |
| 94 | ASSERT_EQ(0xFF00FF00u, action.GetBadgeTextColor(100)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 95 | action.SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFF0000FFu); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 96 | ASSERT_EQ(0xFF0000FFu, action.GetBadgeTextColor(1)); |
| 97 | action.ClearAllValuesForTab(100); |
| 98 | ASSERT_EQ(0xFF0000FFu, action.GetBadgeTextColor(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 99 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 100 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 101 | TEST(ExtensionActionTest, BadgeBackgroundColor) { |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 102 | ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo()); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 103 | ASSERT_EQ(0x00000000u, action.GetBadgeBackgroundColor(1)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 104 | action.SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId, |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 105 | 0xFFFF0000u); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 106 | ASSERT_EQ(0xFFFF0000u, action.GetBadgeBackgroundColor(1)); |
| 107 | ASSERT_EQ(0xFFFF0000u, action.GetBadgeBackgroundColor(100)); |
| 108 | action.SetBadgeBackgroundColor(100, 0xFF00FF00); |
| 109 | ASSERT_EQ(0xFFFF0000u, action.GetBadgeBackgroundColor(1)); |
| 110 | ASSERT_EQ(0xFF00FF00u, action.GetBadgeBackgroundColor(100)); |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 111 | action.SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId, |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 112 | 0xFF0000FFu); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 113 | ASSERT_EQ(0xFF0000FFu, action.GetBadgeBackgroundColor(1)); |
| 114 | action.ClearAllValuesForTab(100); |
| 115 | ASSERT_EQ(0xFF0000FFu, action.GetBadgeBackgroundColor(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 116 | } |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 117 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 118 | TEST(ExtensionActionTest, PopupUrl) { |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 119 | GURL url_unset; |
| 120 | GURL url_foo("http://www.example.com/foo.html"); |
| 121 | GURL url_bar("http://www.example.com/bar.html"); |
| 122 | GURL url_baz("http://www.example.com/baz.html"); |
| 123 | |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 124 | ActionInfo action_info; |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 125 | action_info.default_popup_url = url_foo; |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 126 | ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, action_info); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 127 | |
| 128 | ASSERT_EQ(url_foo, action.GetPopupUrl(1)); |
| 129 | ASSERT_EQ(url_foo, action.GetPopupUrl(100)); |
| 130 | ASSERT_TRUE(action.HasPopup(1)); |
| 131 | ASSERT_TRUE(action.HasPopup(100)); |
| 132 | |
| 133 | action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_unset); |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 134 | ASSERT_EQ(url_unset, action.GetPopupUrl(1)); |
| 135 | ASSERT_EQ(url_unset, action.GetPopupUrl(100)); |
| 136 | ASSERT_FALSE(action.HasPopup(1)); |
| 137 | ASSERT_FALSE(action.HasPopup(100)); |
| 138 | |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 139 | action.SetPopupUrl(100, url_bar); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 140 | ASSERT_EQ(url_unset, action.GetPopupUrl(1)); |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 141 | ASSERT_EQ(url_bar, action.GetPopupUrl(100)); |
| 142 | |
| 143 | action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz); |
| 144 | ASSERT_EQ(url_baz, action.GetPopupUrl(1)); |
| 145 | ASSERT_EQ(url_bar, action.GetPopupUrl(100)); |
| 146 | |
| 147 | action.ClearAllValuesForTab(100); |
| 148 | ASSERT_EQ(url_baz, action.GetPopupUrl(1)); |
| 149 | ASSERT_EQ(url_baz, action.GetPopupUrl(100)); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 150 | } |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 151 | |
| 152 | } // namespace |