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 "chrome/common/extensions/api/extension_action/action_info.h"
6 #include "chrome/common/extensions/extension_constants.h"
7 #include "chrome/common/extensions/extension_icon_set.h"
8 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
9 #include "extensions/common/extension_builder.h"
10 #include "extensions/common/feature_switch.h"
11 #include "extensions/common/install_warning.h"
12 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/manifest_constants.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace extensions
{
19 namespace errors
= manifest_errors
;
23 std::vector
<InstallWarning
> StripMissingFlagWarning(
24 const std::vector
<InstallWarning
>& install_warnings
) {
25 std::vector
<InstallWarning
> result
;
26 for (size_t i
= 0; i
< install_warnings
.size(); ++i
) {
27 if (install_warnings
[i
].message
!= errors::kScriptBadgeRequiresFlag
)
28 result
.push_back(install_warnings
[i
]);
33 class ScriptBadgeManifestTest
: public ExtensionManifestTest
{
38 TEST_F(ScriptBadgeManifestTest
, ScriptBadgeBasic
) {
39 scoped_refptr
<Extension
> extension(
41 .SetManifest(DictionaryBuilder()
42 .Set("manifest_version", 2)
43 .Set("name", "my extension")
44 .Set("version", "1.0.0.0")
46 "Check that a simple script_badge section parses")
47 .Set("icons", DictionaryBuilder()
48 .Set("16", "icon16.png")
49 .Set("32", "icon32.png")
50 .Set("19", "icon19.png")
51 .Set("48", "icon48.png"))
52 .Set("script_badge", DictionaryBuilder()
53 .Set("default_popup", "popup.html")))
55 ASSERT_TRUE(extension
.get());
56 const ActionInfo
* script_badge_info
=
57 ActionInfo::GetScriptBadgeInfo(extension
.get());
58 ASSERT_TRUE(script_badge_info
);
59 EXPECT_THAT(StripMissingFlagWarning(extension
->install_warnings()),
60 testing::ElementsAre(/*empty*/));
62 const ExtensionIconSet
& default_icon
=
63 script_badge_info
->default_icon
;
64 // Should have a default icon set.
65 ASSERT_FALSE(default_icon
.empty());
67 // Verify that correct icon paths are registered in default_icon.
68 EXPECT_EQ(2u, default_icon
.map().size());
69 EXPECT_EQ("icon16.png",
70 default_icon
.Get(extension_misc::EXTENSION_ICON_BITTY
,
71 ExtensionIconSet::MATCH_EXACTLY
));
72 EXPECT_EQ("icon32.png",
73 default_icon
.Get(2 * extension_misc::EXTENSION_ICON_BITTY
,
74 ExtensionIconSet::MATCH_EXACTLY
));
76 EXPECT_EQ("my extension", script_badge_info
->default_title
);
77 EXPECT_FALSE(script_badge_info
->default_popup_url
.is_empty());
80 TEST_F(ScriptBadgeManifestTest
, ScriptBadgeExplicitTitleAndIconsIgnored
) {
81 scoped_refptr
<Extension
> extension(
83 .SetManifest(DictionaryBuilder()
84 .Set("manifest_version", 2)
85 .Set("name", "my extension")
86 .Set("version", "1.0.0.0")
88 "Check that a simple script_badge section parses")
89 .Set("icons", DictionaryBuilder()
90 .Set("16", "icon16.png"))
91 .Set("script_badge", DictionaryBuilder()
92 .Set("default_title", "Other Extension")
93 .Set("default_icon", "malicious.png")))
95 ASSERT_TRUE(extension
.get());
96 const ActionInfo
* script_badge_info
=
97 ActionInfo::GetScriptBadgeInfo(extension
.get());
98 ASSERT_TRUE(script_badge_info
);
100 EXPECT_THAT(StripMissingFlagWarning(extension
->install_warnings()),
101 testing::ElementsAre(
102 InstallWarning(errors::kScriptBadgeTitleIgnored
,
103 manifest_keys::kScriptBadge
),
104 InstallWarning(errors::kScriptBadgeIconIgnored
,
105 manifest_keys::kScriptBadge
)));
107 const ExtensionIconSet
& default_icon
=
108 script_badge_info
->default_icon
;
109 ASSERT_FALSE(default_icon
.empty());
111 EXPECT_EQ(1u, default_icon
.map().size());
112 EXPECT_EQ("icon16.png",
113 default_icon
.Get(extension_misc::EXTENSION_ICON_BITTY
,
114 ExtensionIconSet::MATCH_EXACTLY
));
116 EXPECT_EQ("my extension", script_badge_info
->default_title
);
119 TEST_F(ScriptBadgeManifestTest
, ScriptBadgeIconFallsBackToPuzzlePiece
) {
120 scoped_refptr
<Extension
> extension(
122 .SetManifest(DictionaryBuilder()
123 .Set("manifest_version", 2)
124 .Set("name", "my extension")
125 .Set("version", "1.0.0.0")
127 "Check that a simple script_badge section parses")
128 .Set("icons", DictionaryBuilder()
129 .Set("128", "icon128.png")))
131 ASSERT_TRUE(extension
.get());
132 const ActionInfo
* script_badge_info
=
133 ActionInfo::GetScriptBadgeInfo(extension
.get());
134 ASSERT_TRUE(script_badge_info
);
135 EXPECT_THAT(extension
->install_warnings(),
136 testing::ElementsAre(/*empty*/));
138 const ExtensionIconSet
& default_icon
=
139 script_badge_info
->default_icon
;
140 ASSERT_FALSE(default_icon
.empty()) << "Should fall back to the 128px icon.";
141 EXPECT_EQ(2u, default_icon
.map().size());
142 EXPECT_EQ("icon128.png",
143 default_icon
.Get(extension_misc::EXTENSION_ICON_BITTY
,
144 ExtensionIconSet::MATCH_EXACTLY
));
145 EXPECT_EQ("icon128.png",
146 default_icon
.Get(2 * extension_misc::EXTENSION_ICON_BITTY
,
147 ExtensionIconSet::MATCH_EXACTLY
));
150 } // namespace extensions