OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 const std::string id("MyExtensionActionId"); | 222 const std::string id("MyExtensionActionId"); |
223 const std::string name("MyExtensionActionName"); | 223 const std::string name("MyExtensionActionName"); |
224 std::string img1("image1.png"); | 224 std::string img1("image1.png"); |
225 | 225 |
226 action = LoadAction("page_action.json"); | 226 action = LoadAction("page_action.json"); |
227 ASSERT_TRUE(NULL != action.get()); | 227 ASSERT_TRUE(NULL != action.get()); |
228 ASSERT_EQ(id, action->id()); | 228 ASSERT_EQ(id, action->id()); |
229 | 229 |
230 // No title, so fall back to name. | 230 // No title, so fall back to name. |
231 ASSERT_EQ(name, action->GetTitle(1)); | 231 ASSERT_EQ(name, action->GetTitle(1)); |
232 ASSERT_EQ(img1, action->default_icon_path()); | 232 ASSERT_EQ(img1, |
| 233 action->default_icon()->Get(extension_misc::EXTENSION_ICON_ACTION, |
| 234 ExtensionIconSet::MATCH_EXACTLY)); |
233 | 235 |
234 // Same test with explicitly set type. | 236 // Same test with explicitly set type. |
235 action = LoadAction("page_action_type.json"); | 237 action = LoadAction("page_action_type.json"); |
236 ASSERT_TRUE(NULL != action.get()); | 238 ASSERT_TRUE(NULL != action.get()); |
237 | 239 |
238 // Try an action without id key. | 240 // Try an action without id key. |
239 action = LoadAction("page_action_no_id.json"); | 241 action = LoadAction("page_action_no_id.json"); |
240 ASSERT_TRUE(NULL != action.get()); | 242 ASSERT_TRUE(NULL != action.get()); |
241 | 243 |
242 // Then try without the name key. It's optional, so no error. | 244 // Then try without the name key. It's optional, so no error. |
243 action = LoadAction("page_action_no_name.json"); | 245 action = LoadAction("page_action_no_name.json"); |
244 ASSERT_TRUE(NULL != action.get()); | 246 ASSERT_TRUE(NULL != action.get()); |
245 ASSERT_TRUE(action->GetTitle(1).empty()); | 247 ASSERT_TRUE(action->GetTitle(1).empty()); |
246 | 248 |
247 // Then try without the icon paths key. | 249 // Then try without the icon paths key. |
248 action = LoadAction("page_action_no_icon.json"); | 250 action = LoadAction("page_action_no_icon.json"); |
249 ASSERT_TRUE(NULL != action.get()); | 251 ASSERT_TRUE(NULL != action.get()); |
250 | 252 |
251 // Now test that we can parse the new format for page actions. | 253 // Now test that we can parse the new format for page actions. |
252 const std::string kTitle("MyExtensionActionTitle"); | 254 const std::string kTitle("MyExtensionActionTitle"); |
253 const std::string kIcon("image1.png"); | 255 const std::string kIcon("image1.png"); |
254 const std::string kPopupHtmlFile("a_popup.html"); | 256 const std::string kPopupHtmlFile("a_popup.html"); |
255 | 257 |
256 action = LoadAction("page_action_new_format.json"); | 258 action = LoadAction("page_action_new_format.json"); |
257 ASSERT_TRUE(action.get()); | 259 ASSERT_TRUE(action.get()); |
258 ASSERT_EQ(kTitle, action->GetTitle(1)); | 260 ASSERT_EQ(kTitle, action->GetTitle(1)); |
259 ASSERT_FALSE(action->default_icon_path().empty()); | 261 ASSERT_TRUE(action->default_icon()); |
260 | 262 |
261 // Invalid title should give an error even with a valid name. | 263 // Invalid title should give an error even with a valid name. |
262 LoadActionAndExpectError("page_action_invalid_title.json", | 264 LoadActionAndExpectError("page_action_invalid_title.json", |
263 errors::kInvalidPageActionDefaultTitle); | 265 errors::kInvalidPageActionDefaultTitle); |
264 | 266 |
265 // Invalid name should give an error only with no title. | 267 // Invalid name should give an error only with no title. |
266 action = LoadAction("page_action_invalid_name.json"); | 268 action = LoadAction("page_action_invalid_name.json"); |
267 ASSERT_TRUE(NULL != action.get()); | 269 ASSERT_TRUE(NULL != action.get()); |
268 ASSERT_EQ(kTitle, action->GetTitle(1)); | 270 ASSERT_EQ(kTitle, action->GetTitle(1)); |
269 | 271 |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 | 1207 |
1206 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | 1208 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { |
1207 scoped_refptr<Extension> extension( | 1209 scoped_refptr<Extension> extension( |
1208 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1210 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
1209 Extension::INTERNAL, 2, FilePath(), | 1211 Extension::INTERNAL, 2, FilePath(), |
1210 Extension::NO_FLAGS)); | 1212 Extension::NO_FLAGS)); |
1211 if (extension) | 1213 if (extension) |
1212 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1214 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
1213 } | 1215 } |
1214 #endif // !defined(OS_CHROMEOS) | 1216 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |