[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] | 8ddcc92 | 2012-10-13 05:13:03 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_action.h" |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 6 | |
| 7 | #include "base/memory/ptr_util.h" |
| 8 | #include "base/message_loop/message_loop.h" |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 9 | #include "chrome/common/extensions/api/extension_action/action_info.h" |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 10 | #include "extensions/common/test_util.h" |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 11 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 12 | #include "url/gurl.h" |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 13 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 14 | namespace extensions { |
| 15 | |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 16 | namespace { |
[email protected] | 18539ee | 2010-09-16 21:39:29 | [diff] [blame] | 17 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 18 | std::unique_ptr<ExtensionAction> CreateAction(ActionInfo::Type type, |
| 19 | const ActionInfo& action_info) { |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 20 | scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 21 | return base::WrapUnique(new ExtensionAction(*extension, type, action_info)); |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | } // namespace |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 25 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 26 | TEST(ExtensionActionTest, Title) { |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 27 | ActionInfo action_info; |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 28 | action_info.default_title = "Initial Title"; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 29 | std::unique_ptr<ExtensionAction> action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 30 | CreateAction(ActionInfo::TYPE_PAGE, action_info); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 31 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 32 | ASSERT_EQ("Initial Title", action->GetTitle(1)); |
| 33 | action->SetTitle(ExtensionAction::kDefaultTabId, "foo"); |
| 34 | ASSERT_EQ("foo", action->GetTitle(1)); |
| 35 | ASSERT_EQ("foo", action->GetTitle(100)); |
| 36 | action->SetTitle(100, "bar"); |
| 37 | ASSERT_EQ("foo", action->GetTitle(1)); |
| 38 | ASSERT_EQ("bar", action->GetTitle(100)); |
| 39 | action->SetTitle(ExtensionAction::kDefaultTabId, "baz"); |
| 40 | ASSERT_EQ("baz", action->GetTitle(1)); |
| 41 | action->ClearAllValuesForTab(100); |
| 42 | ASSERT_EQ("baz", action->GetTitle(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 43 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 44 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 45 | TEST(ExtensionActionTest, Visibility) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 46 | std::unique_ptr<ExtensionAction> action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 47 | CreateAction(ActionInfo::TYPE_PAGE, ActionInfo()); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 48 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 49 | ASSERT_FALSE(action->GetIsVisible(1)); |
| 50 | action->SetIsVisible(ExtensionAction::kDefaultTabId, true); |
| 51 | ASSERT_TRUE(action->GetIsVisible(1)); |
| 52 | ASSERT_TRUE(action->GetIsVisible(100)); |
[email protected] | 48a7a425b | 2012-08-03 12:52:58 | [diff] [blame] | 53 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 54 | action->SetIsVisible(ExtensionAction::kDefaultTabId, false); |
| 55 | ASSERT_FALSE(action->GetIsVisible(1)); |
| 56 | ASSERT_FALSE(action->GetIsVisible(100)); |
| 57 | action->SetIsVisible(100, true); |
| 58 | ASSERT_FALSE(action->GetIsVisible(1)); |
| 59 | ASSERT_TRUE(action->GetIsVisible(100)); |
[email protected] | 48a7a425b | 2012-08-03 12:52:58 | [diff] [blame] | 60 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 61 | action->ClearAllValuesForTab(100); |
| 62 | ASSERT_FALSE(action->GetIsVisible(1)); |
| 63 | ASSERT_FALSE(action->GetIsVisible(100)); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 64 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 65 | std::unique_ptr<ExtensionAction> browser_action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 66 | CreateAction(ActionInfo::TYPE_BROWSER, ActionInfo()); |
| 67 | ASSERT_TRUE(browser_action->GetIsVisible(1)); |
[email protected] | a048c09 | 2012-09-21 02:33:26 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 70 | TEST(ExtensionActionTest, Icon) { |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 71 | ActionInfo action_info; |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 72 | action_info.default_icon.Add(16, "icon16.png"); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 73 | std::unique_ptr<ExtensionAction> page_action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 74 | CreateAction(ActionInfo::TYPE_PAGE, action_info); |
| 75 | ASSERT_TRUE(page_action->default_icon()); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 76 | EXPECT_EQ("icon16.png", |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 77 | page_action->default_icon()->Get( |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 78 | 16, ExtensionIconSet::MATCH_EXACTLY)); |
| 79 | EXPECT_EQ("", |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 80 | page_action->default_icon()->Get( |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 81 | 17, ExtensionIconSet::MATCH_BIGGER)); |
| 82 | } |
| 83 | |
| 84 | TEST(ExtensionActionTest, Badge) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 85 | std::unique_ptr<ExtensionAction> action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 86 | CreateAction(ActionInfo::TYPE_PAGE, ActionInfo()); |
| 87 | ASSERT_EQ("", action->GetBadgeText(1)); |
| 88 | action->SetBadgeText(ExtensionAction::kDefaultTabId, "foo"); |
| 89 | ASSERT_EQ("foo", action->GetBadgeText(1)); |
| 90 | ASSERT_EQ("foo", action->GetBadgeText(100)); |
| 91 | action->SetBadgeText(100, "bar"); |
| 92 | ASSERT_EQ("foo", action->GetBadgeText(1)); |
| 93 | ASSERT_EQ("bar", action->GetBadgeText(100)); |
| 94 | action->SetBadgeText(ExtensionAction::kDefaultTabId, "baz"); |
| 95 | ASSERT_EQ("baz", action->GetBadgeText(1)); |
| 96 | action->ClearAllValuesForTab(100); |
| 97 | ASSERT_EQ("baz", action->GetBadgeText(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 98 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 99 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 100 | TEST(ExtensionActionTest, BadgeTextColor) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 101 | std::unique_ptr<ExtensionAction> action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 102 | CreateAction(ActionInfo::TYPE_PAGE, ActionInfo()); |
| 103 | ASSERT_EQ(0x00000000u, action->GetBadgeTextColor(1)); |
| 104 | action->SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFFFF0000u); |
| 105 | ASSERT_EQ(0xFFFF0000u, action->GetBadgeTextColor(1)); |
| 106 | ASSERT_EQ(0xFFFF0000u, action->GetBadgeTextColor(100)); |
| 107 | action->SetBadgeTextColor(100, 0xFF00FF00); |
| 108 | ASSERT_EQ(0xFFFF0000u, action->GetBadgeTextColor(1)); |
| 109 | ASSERT_EQ(0xFF00FF00u, action->GetBadgeTextColor(100)); |
| 110 | action->SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFF0000FFu); |
| 111 | ASSERT_EQ(0xFF0000FFu, action->GetBadgeTextColor(1)); |
| 112 | action->ClearAllValuesForTab(100); |
| 113 | ASSERT_EQ(0xFF0000FFu, action->GetBadgeTextColor(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 114 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 115 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 116 | TEST(ExtensionActionTest, BadgeBackgroundColor) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 117 | std::unique_ptr<ExtensionAction> action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 118 | CreateAction(ActionInfo::TYPE_PAGE, ActionInfo()); |
| 119 | ASSERT_EQ(0x00000000u, action->GetBadgeBackgroundColor(1)); |
| 120 | action->SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId, |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 121 | 0xFFFF0000u); |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 122 | ASSERT_EQ(0xFFFF0000u, action->GetBadgeBackgroundColor(1)); |
| 123 | ASSERT_EQ(0xFFFF0000u, action->GetBadgeBackgroundColor(100)); |
| 124 | action->SetBadgeBackgroundColor(100, 0xFF00FF00); |
| 125 | ASSERT_EQ(0xFFFF0000u, action->GetBadgeBackgroundColor(1)); |
| 126 | ASSERT_EQ(0xFF00FF00u, action->GetBadgeBackgroundColor(100)); |
| 127 | action->SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId, |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 128 | 0xFF0000FFu); |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 129 | ASSERT_EQ(0xFF0000FFu, action->GetBadgeBackgroundColor(1)); |
| 130 | action->ClearAllValuesForTab(100); |
| 131 | ASSERT_EQ(0xFF0000FFu, action->GetBadgeBackgroundColor(100)); |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 132 | } |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 133 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 134 | TEST(ExtensionActionTest, PopupUrl) { |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 135 | GURL url_unset; |
| 136 | GURL url_foo("http://www.example.com/foo.html"); |
| 137 | GURL url_bar("http://www.example.com/bar.html"); |
| 138 | GURL url_baz("http://www.example.com/baz.html"); |
| 139 | |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 140 | ActionInfo action_info; |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 141 | action_info.default_popup_url = url_foo; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 142 | std::unique_ptr<ExtensionAction> action = |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 143 | CreateAction(ActionInfo::TYPE_PAGE, action_info); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 144 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 145 | ASSERT_EQ(url_foo, action->GetPopupUrl(1)); |
| 146 | ASSERT_EQ(url_foo, action->GetPopupUrl(100)); |
| 147 | ASSERT_TRUE(action->HasPopup(1)); |
| 148 | ASSERT_TRUE(action->HasPopup(100)); |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 149 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 150 | action->SetPopupUrl(ExtensionAction::kDefaultTabId, url_unset); |
| 151 | ASSERT_EQ(url_unset, action->GetPopupUrl(1)); |
| 152 | ASSERT_EQ(url_unset, action->GetPopupUrl(100)); |
| 153 | ASSERT_FALSE(action->HasPopup(1)); |
| 154 | ASSERT_FALSE(action->HasPopup(100)); |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 155 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 156 | action->SetPopupUrl(100, url_bar); |
| 157 | ASSERT_EQ(url_unset, action->GetPopupUrl(1)); |
| 158 | ASSERT_EQ(url_bar, action->GetPopupUrl(100)); |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 159 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 160 | action->SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz); |
| 161 | ASSERT_EQ(url_baz, action->GetPopupUrl(1)); |
| 162 | ASSERT_EQ(url_bar, action->GetPopupUrl(100)); |
[email protected] | a388c484 | 2010-01-27 17:13:15 | [diff] [blame] | 163 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 164 | action->ClearAllValuesForTab(100); |
| 165 | ASSERT_EQ(url_baz, action->GetPopupUrl(1)); |
| 166 | ASSERT_EQ(url_baz, action->GetPopupUrl(100)); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 167 | } |
[email protected] | 39eae2b7 | 2012-08-01 07:22:32 | [diff] [blame] | 168 | |
rdevlin.cronin | f19c7663 | 2015-01-29 16:57:35 | [diff] [blame] | 169 | } // namespace extensions |