OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_action_manager.h" | 5 #include "chrome/browser/extensions/extension_action_manager.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 bool ExtensionActionManagerTest::TitlesMatch(const Extension& extension, | 91 bool ExtensionActionManagerTest::TitlesMatch(const Extension& extension, |
92 const ExtensionAction& action) { | 92 const ExtensionAction& action) { |
93 return action.GetTitle(ExtensionAction::kDefaultTabId) == extension.name(); | 93 return action.GetTitle(ExtensionAction::kDefaultTabId) == extension.name(); |
94 } | 94 } |
95 | 95 |
96 bool ExtensionActionManagerTest::IconsMatch(const Extension& extension, | 96 bool ExtensionActionManagerTest::IconsMatch(const Extension& extension, |
97 int extension_key, | 97 int extension_key, |
98 const ExtensionAction& action, | 98 const ExtensionAction& action, |
99 int action_key) { | 99 int action_key) { |
100 return action.default_icon()->Get(action_key, | 100 return action.default_icon()->Get(action_key, |
101 ExtensionIconSet::MATCH_EXACTLY) == | 101 ExtensionIconSet::MATCH_BIGGER) == |
102 IconsInfo::GetIcons(&extension).Get(extension_key, | 102 IconsInfo::GetIcons(&extension) |
103 ExtensionIconSet::MATCH_EXACTLY); | 103 .Get(extension_key, ExtensionIconSet::MATCH_EXACTLY); |
104 } | 104 } |
105 | 105 |
106 ExtensionAction* ExtensionActionManagerTest::GetAction( | 106 ExtensionAction* ExtensionActionManagerTest::GetAction( |
107 const char* action_type, | 107 const char* action_type, |
108 const Extension& extension) { | 108 const Extension& extension) { |
109 return (action_type == kBrowserAction) ? | 109 return (action_type == kBrowserAction) ? |
110 manager_->GetBrowserAction(extension) : | 110 manager_->GetBrowserAction(extension) : |
111 manager_->GetPageAction(extension); | 111 manager_->GetPageAction(extension); |
112 } | 112 } |
113 | 113 |
114 void ExtensionActionManagerTest::TestPopulateMissingValues( | 114 void ExtensionActionManagerTest::TestPopulateMissingValues( |
115 const char* action_type) { | 115 const char* action_type) { |
116 // Test that the largest icon from the extension's "icons" key is chosen as a | 116 // Test that the largest icon from the extension's "icons" key is chosen as a |
117 // replacement for missing action default_icons keys. "19" should not be | 117 // replacement for missing action default_icons keys. "19" should not be |
118 // replaced because "38" can always be used in its place. | 118 // replaced because "38" can always be used in its place. |
119 scoped_refptr<Extension> extension = BuildExtension( | 119 scoped_refptr<Extension> extension = BuildExtension( |
120 DictionaryBuilder().Set("48", "icon48.png") | 120 DictionaryBuilder().Set("48", "icon48.png") |
121 .Set("128", "icon128.png"), | 121 .Set("128", "icon128.png"), |
122 DictionaryBuilder().Pass(), | 122 DictionaryBuilder().Pass(), |
123 action_type); | 123 action_type); |
124 | 124 |
125 ASSERT_TRUE(extension.get()); | 125 ASSERT_TRUE(extension.get()); |
126 const ExtensionAction* action = GetAction(action_type, *extension.get()); | 126 const ExtensionAction* action = GetAction(action_type, *extension.get()); |
127 ASSERT_TRUE(action); | 127 ASSERT_TRUE(action); |
128 | 128 |
129 ASSERT_TRUE(TitlesMatch(*extension.get(), *action)); | 129 ASSERT_TRUE(TitlesMatch(*extension.get(), *action)); |
130 ASSERT_TRUE(IconsMatch(*extension.get(), 128, *action, 38)); | 130 ASSERT_TRUE(IconsMatch(*extension.get(), 48, *action, 38)); |
131 | 131 |
132 // Test that the action's missing default_icons are not replaced with smaller | 132 // Test that the action's missing default_icons are not replaced with smaller |
133 // icons. | 133 // icons. |
134 extension = BuildExtension( | 134 extension = BuildExtension( |
135 DictionaryBuilder().Set("24", "icon24.png"), | 135 DictionaryBuilder().Set("24", "icon24.png"), |
136 DictionaryBuilder().Pass(), | 136 DictionaryBuilder().Pass(), |
137 action_type); | 137 action_type); |
138 | 138 |
139 ASSERT_TRUE(extension.get()); | 139 ASSERT_TRUE(extension.get()); |
140 action = GetAction(action_type, *extension.get()); | 140 action = GetAction(action_type, *extension.get()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 manager()->GetBestFitAction(*extension.get(), ActionInfo::TYPE_BROWSER); | 217 manager()->GetBestFitAction(*extension.get(), ActionInfo::TYPE_BROWSER); |
218 | 218 |
219 // Now these values match because |extension| does not have page action | 219 // Now these values match because |extension| does not have page action |
220 // defaults. | 220 // defaults. |
221 ASSERT_TRUE(TitlesMatch(*extension.get(), *action)); | 221 ASSERT_TRUE(TitlesMatch(*extension.get(), *action)); |
222 ASSERT_TRUE(IconsMatch(*extension.get(), 48, *action, 38)); | 222 ASSERT_TRUE(IconsMatch(*extension.get(), 48, *action, 38)); |
223 } | 223 } |
224 | 224 |
225 } // namespace | 225 } // namespace |
226 } // namespace extensions | 226 } // namespace extensions |
OLD | NEW |