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/manifest_tests/extension_manifest_test.h"
7 #include "extensions/common/error_utils.h"
8 #include "extensions/common/extension_builder.h"
9 #include "extensions/common/extension_icon_set.h"
10 #include "extensions/common/manifest_constants.h"
11 #include "extensions/common/value_builder.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace extensions
{
16 namespace errors
= manifest_errors
;
20 class BrowserActionManifestTest
: public ExtensionManifestTest
{
23 TEST_F(BrowserActionManifestTest
,
24 BrowserActionManifestIcons_NoDefaultIcons
) {
25 scoped_refptr
<const Extension
> extension
=
27 .SetManifest(DictionaryBuilder()
28 .Set("name", "No default properties")
29 .Set("version", "1.0.0")
30 .Set("manifest_version", 2)
31 .Set("browser_action", DictionaryBuilder()
32 .Set("default_title", "Title")))
35 ASSERT_TRUE(extension
.get());
36 const ActionInfo
* browser_action_info
=
37 ActionInfo::GetBrowserActionInfo(extension
.get());
38 ASSERT_TRUE(browser_action_info
);
39 EXPECT_TRUE(browser_action_info
->default_icon
.empty());
42 TEST_F(BrowserActionManifestTest
,
43 BrowserActionManifestIcons_StringDefaultIcon
) {
44 scoped_refptr
<const Extension
> extension
=
46 .SetManifest(DictionaryBuilder()
47 .Set("name", "String default icon")
48 .Set("version", "1.0.0")
49 .Set("manifest_version", 2)
50 .Set("browser_action", DictionaryBuilder()
51 .Set("default_icon", "icon.png")))
54 ASSERT_TRUE(extension
.get());
55 const ActionInfo
* browser_action_info
=
56 ActionInfo::GetBrowserActionInfo(extension
.get());
57 ASSERT_TRUE(browser_action_info
);
58 ASSERT_FALSE(browser_action_info
->default_icon
.empty());
60 const ExtensionIconSet
& icons
= browser_action_info
->default_icon
;
62 EXPECT_EQ(1u, icons
.map().size());
63 EXPECT_EQ("icon.png", icons
.Get(19, ExtensionIconSet::MATCH_EXACTLY
));
66 TEST_F(BrowserActionManifestTest
,
67 BrowserActionManifestIcons_DictDefaultIcon
) {
68 scoped_refptr
<const Extension
> extension
=
70 .SetManifest(DictionaryBuilder()
71 .Set("name", "Dictionary default icon")
72 .Set("version", "1.0.0")
73 .Set("manifest_version", 2)
74 .Set("browser_action", DictionaryBuilder()
75 .Set("default_icon", DictionaryBuilder()
76 .Set("19", "icon19.png")
77 .Set("24", "icon24.png") // Should be ignored.
78 .Set("38", "icon38.png"))))
81 ASSERT_TRUE(extension
.get());
82 const ActionInfo
* browser_action_info
=
83 ActionInfo::GetBrowserActionInfo(extension
.get());
84 ASSERT_TRUE(browser_action_info
);
85 ASSERT_FALSE(browser_action_info
->default_icon
.empty());
87 const ExtensionIconSet
& icons
= browser_action_info
->default_icon
;
89 // 24px icon should be ignored.
90 EXPECT_EQ(2u, icons
.map().size());
91 EXPECT_EQ("icon19.png", icons
.Get(19, ExtensionIconSet::MATCH_EXACTLY
));
92 EXPECT_EQ("icon38.png", icons
.Get(38, ExtensionIconSet::MATCH_EXACTLY
));
95 TEST_F(BrowserActionManifestTest
,
96 BrowserActionManifestIcons_InvalidDefaultIcon
) {
97 scoped_ptr
<base::DictionaryValue
> manifest_value
= DictionaryBuilder()
98 .Set("name", "Invalid default icon").Set("version", "1.0.0")
99 .Set("manifest_version", 2)
100 .Set("browser_action",
101 DictionaryBuilder().Set(
103 DictionaryBuilder().Set("19", std::string()) // Invalid value.
104 .Set("24", "icon24.png").Set("38", "icon38.png"))).Build();
106 base::string16 error
= ErrorUtils::FormatErrorMessageUTF16(
107 errors::kInvalidIconPath
, "19");
108 LoadAndExpectError(Manifest(manifest_value
.get(), "Invalid default icon"),
109 errors::kInvalidIconPath
);
113 } // namespace extensions