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