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 28 matching lines...) Expand all Loading... |
39 using extensions::PermissionSet; | 39 using extensions::PermissionSet; |
40 using extensions::SocketPermission; | 40 using extensions::SocketPermission; |
41 using extensions::SocketPermissionData; | 41 using extensions::SocketPermissionData; |
42 | 42 |
43 namespace keys = extension_manifest_keys; | 43 namespace keys = extension_manifest_keys; |
44 namespace values = extension_manifest_values; | 44 namespace values = extension_manifest_values; |
45 namespace errors = extension_manifest_errors; | 45 namespace errors = extension_manifest_errors; |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
| 49 std::string GetPageActionIconPathAt(const ExtensionAction* action, int index) { |
| 50 const ExtensionIconSet* icon_set = action->page_action_icons()[index]; |
| 51 return icon_set->Get(extension_misc::EXTENSION_ICON_ACTION, |
| 52 ExtensionIconSet::MATCH_EXACTLY); |
| 53 } |
| 54 |
49 void CompareLists(const std::vector<std::string>& expected, | 55 void CompareLists(const std::vector<std::string>& expected, |
50 const std::vector<std::string>& actual) { | 56 const std::vector<std::string>& actual) { |
51 ASSERT_EQ(expected.size(), actual.size()); | 57 ASSERT_EQ(expected.size(), actual.size()); |
52 | 58 |
53 for (size_t i = 0; i < expected.size(); ++i) { | 59 for (size_t i = 0; i < expected.size(); ++i) { |
54 EXPECT_EQ(expected[i], actual[i]); | 60 EXPECT_EQ(expected[i], actual[i]); |
55 } | 61 } |
56 } | 62 } |
57 | 63 |
58 static scoped_refptr<Extension> LoadManifestUnchecked( | 64 static scoped_refptr<Extension> LoadManifestUnchecked( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 const std::string name("MyExtensionActionName"); | 229 const std::string name("MyExtensionActionName"); |
224 std::string img1("image1.png"); | 230 std::string img1("image1.png"); |
225 std::string img2("image2.png"); | 231 std::string img2("image2.png"); |
226 | 232 |
227 action = LoadAction("page_action.json"); | 233 action = LoadAction("page_action.json"); |
228 ASSERT_TRUE(NULL != action.get()); | 234 ASSERT_TRUE(NULL != action.get()); |
229 ASSERT_EQ(id, action->id()); | 235 ASSERT_EQ(id, action->id()); |
230 | 236 |
231 // No title, so fall back to name. | 237 // No title, so fall back to name. |
232 ASSERT_EQ(name, action->GetTitle(1)); | 238 ASSERT_EQ(name, action->GetTitle(1)); |
233 ASSERT_EQ(2u, action->icon_paths()->size()); | 239 ASSERT_EQ(2u, action->page_action_icons().size()); |
234 ASSERT_EQ(img1, (*action->icon_paths())[0]); | 240 ASSERT_EQ(img1, GetPageActionIconPathAt(action.get(), 0)); |
235 ASSERT_EQ(img2, (*action->icon_paths())[1]); | 241 ASSERT_EQ(img2, GetPageActionIconPathAt(action.get(), 1)); |
236 | 242 |
237 // Same test with explicitly set type. | 243 // Same test with explicitly set type. |
238 action = LoadAction("page_action_type.json"); | 244 action = LoadAction("page_action_type.json"); |
239 ASSERT_TRUE(NULL != action.get()); | 245 ASSERT_TRUE(NULL != action.get()); |
240 | 246 |
241 // Try an action without id key. | 247 // Try an action without id key. |
242 action = LoadAction("page_action_no_id.json"); | 248 action = LoadAction("page_action_no_id.json"); |
243 ASSERT_TRUE(NULL != action.get()); | 249 ASSERT_TRUE(NULL != action.get()); |
244 | 250 |
245 // Then try without the name key. It's optional, so no error. | 251 // Then try without the name key. It's optional, so no error. |
246 action = LoadAction("page_action_no_name.json"); | 252 action = LoadAction("page_action_no_name.json"); |
247 ASSERT_TRUE(NULL != action.get()); | 253 ASSERT_TRUE(NULL != action.get()); |
248 ASSERT_TRUE(action->GetTitle(1).empty()); | 254 ASSERT_TRUE(action->GetTitle(1).empty()); |
249 | 255 |
250 // Then try without the icon paths key. | 256 // Then try without the icon paths key. |
251 action = LoadAction("page_action_no_icon.json"); | 257 action = LoadAction("page_action_no_icon.json"); |
252 ASSERT_TRUE(NULL != action.get()); | 258 ASSERT_TRUE(NULL != action.get()); |
253 | 259 |
254 // Now test that we can parse the new format for page actions. | 260 // Now test that we can parse the new format for page actions. |
255 const std::string kTitle("MyExtensionActionTitle"); | 261 const std::string kTitle("MyExtensionActionTitle"); |
256 const std::string kIcon("image1.png"); | 262 const std::string kIcon("image1.png"); |
257 const std::string kPopupHtmlFile("a_popup.html"); | 263 const std::string kPopupHtmlFile("a_popup.html"); |
258 | 264 |
259 action = LoadAction("page_action_new_format.json"); | 265 action = LoadAction("page_action_new_format.json"); |
260 ASSERT_TRUE(action.get()); | 266 ASSERT_TRUE(action.get()); |
261 ASSERT_EQ(kTitle, action->GetTitle(1)); | 267 ASSERT_EQ(kTitle, action->GetTitle(1)); |
262 ASSERT_EQ(0u, action->icon_paths()->size()); | 268 ASSERT_EQ(0u, action->page_action_icons().size()); |
263 | 269 |
264 // Invalid title should give an error even with a valid name. | 270 // Invalid title should give an error even with a valid name. |
265 LoadActionAndExpectError("page_action_invalid_title.json", | 271 LoadActionAndExpectError("page_action_invalid_title.json", |
266 errors::kInvalidPageActionDefaultTitle); | 272 errors::kInvalidPageActionDefaultTitle); |
267 | 273 |
268 // Invalid name should give an error only with no title. | 274 // Invalid name should give an error only with no title. |
269 action = LoadAction("page_action_invalid_name.json"); | 275 action = LoadAction("page_action_invalid_name.json"); |
270 ASSERT_TRUE(NULL != action.get()); | 276 ASSERT_TRUE(NULL != action.get()); |
271 ASSERT_EQ(kTitle, action->GetTitle(1)); | 277 ASSERT_EQ(kTitle, action->GetTitle(1)); |
272 | 278 |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 | 1214 |
1209 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | 1215 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { |
1210 scoped_refptr<Extension> extension( | 1216 scoped_refptr<Extension> extension( |
1211 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1217 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
1212 Extension::INTERNAL, 2, FilePath(), | 1218 Extension::INTERNAL, 2, FilePath(), |
1213 Extension::NO_FLAGS)); | 1219 Extension::NO_FLAGS)); |
1214 if (extension) | 1220 if (extension) |
1215 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1221 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
1216 } | 1222 } |
1217 #endif // !defined(OS_CHROMEOS) | 1223 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |