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 "extensions/common/extension_icon_set.h"
7 #include "extensions/common/constants.h"
8 #include "testing/gtest/include/gtest/gtest.h"
12 TEST(ExtensionIconSet
, Basic
) {
13 ExtensionIconSet icons
;
14 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_LARGE
,
15 ExtensionIconSet::MATCH_EXACTLY
));
16 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_LARGE
,
17 ExtensionIconSet::MATCH_BIGGER
));
18 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_LARGE
,
19 ExtensionIconSet::MATCH_SMALLER
));
20 EXPECT_TRUE(icons
.map().empty());
22 icons
.Add(extension_misc::EXTENSION_ICON_LARGE
, "large.png");
23 EXPECT_EQ("large.png", icons
.Get(extension_misc::EXTENSION_ICON_LARGE
,
24 ExtensionIconSet::MATCH_EXACTLY
));
25 EXPECT_EQ("large.png", icons
.Get(extension_misc::EXTENSION_ICON_LARGE
,
26 ExtensionIconSet::MATCH_BIGGER
));
27 EXPECT_EQ("large.png", icons
.Get(extension_misc::EXTENSION_ICON_LARGE
,
28 ExtensionIconSet::MATCH_SMALLER
));
29 EXPECT_EQ("large.png", icons
.Get(extension_misc::EXTENSION_ICON_MEDIUM
,
30 ExtensionIconSet::MATCH_BIGGER
));
31 EXPECT_EQ("large.png", icons
.Get(extension_misc::EXTENSION_ICON_EXTRA_LARGE
,
32 ExtensionIconSet::MATCH_SMALLER
));
33 EXPECT_EQ("large.png", icons
.Get(0, ExtensionIconSet::MATCH_BIGGER
));
34 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_MEDIUM
,
35 ExtensionIconSet::MATCH_SMALLER
));
36 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_EXTRA_LARGE
,
37 ExtensionIconSet::MATCH_BIGGER
));
39 icons
.Add(extension_misc::EXTENSION_ICON_SMALLISH
, "smallish.png");
40 icons
.Add(extension_misc::EXTENSION_ICON_SMALL
, "small.png");
41 icons
.Add(extension_misc::EXTENSION_ICON_EXTRA_LARGE
, "extra_large.png");
43 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_MEDIUM
,
44 ExtensionIconSet::MATCH_EXACTLY
));
45 EXPECT_EQ("small.png", icons
.Get(extension_misc::EXTENSION_ICON_MEDIUM
,
46 ExtensionIconSet::MATCH_SMALLER
));
47 EXPECT_EQ("large.png", icons
.Get(extension_misc::EXTENSION_ICON_MEDIUM
,
48 ExtensionIconSet::MATCH_BIGGER
));
49 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_BITTY
,
50 ExtensionIconSet::MATCH_SMALLER
));
51 EXPECT_EQ("", icons
.Get(extension_misc::EXTENSION_ICON_GIGANTOR
,
52 ExtensionIconSet::MATCH_BIGGER
));
55 TEST(ExtensionIconSet
, Values
) {
56 ExtensionIconSet icons
;
57 EXPECT_FALSE(icons
.ContainsPath("foo"));
59 icons
.Add(extension_misc::EXTENSION_ICON_BITTY
, "foo");
60 icons
.Add(extension_misc::EXTENSION_ICON_GIGANTOR
, "bar");
62 EXPECT_TRUE(icons
.ContainsPath("foo"));
63 EXPECT_TRUE(icons
.ContainsPath("bar"));
64 EXPECT_FALSE(icons
.ContainsPath("baz"));
65 EXPECT_FALSE(icons
.ContainsPath(std::string()));
68 EXPECT_FALSE(icons
.ContainsPath("foo"));
71 TEST(ExtensionIconSet
, FindSize
) {
72 ExtensionIconSet icons
;
73 EXPECT_EQ(extension_misc::EXTENSION_ICON_INVALID
,
74 icons
.GetIconSizeFromPath("foo"));
76 icons
.Add(extension_misc::EXTENSION_ICON_BITTY
, "foo");
77 icons
.Add(extension_misc::EXTENSION_ICON_GIGANTOR
, "bar");
79 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY
,
80 icons
.GetIconSizeFromPath("foo"));
81 EXPECT_EQ(extension_misc::EXTENSION_ICON_GIGANTOR
,
82 icons
.GetIconSizeFromPath("bar"));
83 EXPECT_EQ(extension_misc::EXTENSION_ICON_INVALID
,
84 icons
.GetIconSizeFromPath("baz"));
85 EXPECT_EQ(extension_misc::EXTENSION_ICON_INVALID
,
86 icons
.GetIconSizeFromPath(std::string()));
89 EXPECT_EQ(extension_misc::EXTENSION_ICON_INVALID
,
90 icons
.GetIconSizeFromPath("foo"));