NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / extension_action_unittest.cc
blob53bc3631b416817540956504edc515cfddacbdcd
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
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "chrome/browser/extensions/extension_action.h"
7 #include "chrome/common/extensions/api/extension_action/action_info.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h"
11 namespace {
13 using extensions::ActionInfo;
15 TEST(ExtensionActionTest, Title) {
16 ActionInfo action_info;
17 action_info.default_title = "Initial Title";
18 ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, action_info);
20 ASSERT_EQ("Initial Title", action.GetTitle(1));
21 action.SetTitle(ExtensionAction::kDefaultTabId, "foo");
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));
27 action.SetTitle(ExtensionAction::kDefaultTabId, "baz");
28 ASSERT_EQ("baz", action.GetTitle(1));
29 action.ClearAllValuesForTab(100);
30 ASSERT_EQ("baz", action.GetTitle(100));
33 TEST(ExtensionActionTest, Visibility) {
34 ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo());
36 ASSERT_FALSE(action.GetIsVisible(1));
37 action.SetIsVisible(ExtensionAction::kDefaultTabId, true);
38 ASSERT_TRUE(action.GetIsVisible(1));
39 ASSERT_TRUE(action.GetIsVisible(100));
41 action.SetIsVisible(ExtensionAction::kDefaultTabId, false);
42 ASSERT_FALSE(action.GetIsVisible(1));
43 ASSERT_FALSE(action.GetIsVisible(100));
44 action.SetIsVisible(100, true);
45 ASSERT_FALSE(action.GetIsVisible(1));
46 ASSERT_TRUE(action.GetIsVisible(100));
48 action.ClearAllValuesForTab(100);
49 ASSERT_FALSE(action.GetIsVisible(1));
50 ASSERT_FALSE(action.GetIsVisible(100));
52 ExtensionAction browser_action(
53 std::string(), ActionInfo::TYPE_BROWSER, ActionInfo());
54 ASSERT_TRUE(browser_action.GetIsVisible(1));
57 TEST(ExtensionActionTest, Icon) {
58 ActionInfo action_info;
59 action_info.default_icon.Add(16, "icon16.png");
60 ExtensionAction page_action(
61 std::string(), ActionInfo::TYPE_PAGE, action_info);
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));
71 TEST(ExtensionActionTest, Badge) {
72 ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo());
73 ASSERT_EQ("", action.GetBadgeText(1));
74 action.SetBadgeText(ExtensionAction::kDefaultTabId, "foo");
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));
80 action.SetBadgeText(ExtensionAction::kDefaultTabId, "baz");
81 ASSERT_EQ("baz", action.GetBadgeText(1));
82 action.ClearAllValuesForTab(100);
83 ASSERT_EQ("baz", action.GetBadgeText(100));
86 TEST(ExtensionActionTest, BadgeTextColor) {
87 ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo());
88 ASSERT_EQ(0x00000000u, action.GetBadgeTextColor(1));
89 action.SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFFFF0000u);
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));
95 action.SetBadgeTextColor(ExtensionAction::kDefaultTabId, 0xFF0000FFu);
96 ASSERT_EQ(0xFF0000FFu, action.GetBadgeTextColor(1));
97 action.ClearAllValuesForTab(100);
98 ASSERT_EQ(0xFF0000FFu, action.GetBadgeTextColor(100));
101 TEST(ExtensionActionTest, BadgeBackgroundColor) {
102 ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, ActionInfo());
103 ASSERT_EQ(0x00000000u, action.GetBadgeBackgroundColor(1));
104 action.SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId,
105 0xFFFF0000u);
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));
111 action.SetBadgeBackgroundColor(ExtensionAction::kDefaultTabId,
112 0xFF0000FFu);
113 ASSERT_EQ(0xFF0000FFu, action.GetBadgeBackgroundColor(1));
114 action.ClearAllValuesForTab(100);
115 ASSERT_EQ(0xFF0000FFu, action.GetBadgeBackgroundColor(100));
118 TEST(ExtensionActionTest, PopupUrl) {
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");
124 ActionInfo action_info;
125 action_info.default_popup_url = url_foo;
126 ExtensionAction action(std::string(), ActionInfo::TYPE_PAGE, action_info);
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));
133 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_unset);
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));
139 action.SetPopupUrl(100, url_bar);
140 ASSERT_EQ(url_unset, action.GetPopupUrl(1));
141 ASSERT_EQ(url_bar, action.GetPopupUrl(100));
143 action.SetPopupUrl(ExtensionAction::kDefaultTabId, url_baz);
144 ASSERT_EQ(url_baz, action.GetPopupUrl(1));
145 ASSERT_EQ(url_bar, action.GetPopupUrl(100));
147 action.ClearAllValuesForTab(100);
148 ASSERT_EQ(url_baz, action.GetPopupUrl(1));
149 ASSERT_EQ(url_baz, action.GetPopupUrl(100));
152 } // namespace