| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 scoped_ptr<ExtensionAction> action; | 215 scoped_ptr<ExtensionAction> action; |
| 216 | 216 |
| 217 // First try with an empty dictionary. | 217 // First try with an empty dictionary. |
| 218 action = LoadAction("page_action_empty.json"); | 218 action = LoadAction("page_action_empty.json"); |
| 219 ASSERT_TRUE(action != NULL); | 219 ASSERT_TRUE(action != NULL); |
| 220 | 220 |
| 221 // Now setup some values to use in the action. | 221 // Now setup some values to use in the action. |
| 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 std::string img2("image2.png"); | |
| 226 | 225 |
| 227 action = LoadAction("page_action.json"); | 226 action = LoadAction("page_action.json"); |
| 228 ASSERT_TRUE(NULL != action.get()); | 227 ASSERT_TRUE(NULL != action.get()); |
| 229 ASSERT_EQ(id, action->id()); | 228 ASSERT_EQ(id, action->id()); |
| 230 | 229 |
| 231 // No title, so fall back to name. | 230 // No title, so fall back to name. |
| 232 ASSERT_EQ(name, action->GetTitle(1)); | 231 ASSERT_EQ(name, action->GetTitle(1)); |
| 233 ASSERT_EQ(2u, action->icon_paths()->size()); | 232 ASSERT_EQ(img1, action->default_icon_path()); |
| 234 ASSERT_EQ(img1, (*action->icon_paths())[0]); | |
| 235 ASSERT_EQ(img2, (*action->icon_paths())[1]); | |
| 236 | 233 |
| 237 // Same test with explicitly set type. | 234 // Same test with explicitly set type. |
| 238 action = LoadAction("page_action_type.json"); | 235 action = LoadAction("page_action_type.json"); |
| 239 ASSERT_TRUE(NULL != action.get()); | 236 ASSERT_TRUE(NULL != action.get()); |
| 240 | 237 |
| 241 // Try an action without id key. | 238 // Try an action without id key. |
| 242 action = LoadAction("page_action_no_id.json"); | 239 action = LoadAction("page_action_no_id.json"); |
| 243 ASSERT_TRUE(NULL != action.get()); | 240 ASSERT_TRUE(NULL != action.get()); |
| 244 | 241 |
| 245 // Then try without the name key. It's optional, so no error. | 242 // Then try without the name key. It's optional, so no error. |
| 246 action = LoadAction("page_action_no_name.json"); | 243 action = LoadAction("page_action_no_name.json"); |
| 247 ASSERT_TRUE(NULL != action.get()); | 244 ASSERT_TRUE(NULL != action.get()); |
| 248 ASSERT_TRUE(action->GetTitle(1).empty()); | 245 ASSERT_TRUE(action->GetTitle(1).empty()); |
| 249 | 246 |
| 250 // Then try without the icon paths key. | 247 // Then try without the icon paths key. |
| 251 action = LoadAction("page_action_no_icon.json"); | 248 action = LoadAction("page_action_no_icon.json"); |
| 252 ASSERT_TRUE(NULL != action.get()); | 249 ASSERT_TRUE(NULL != action.get()); |
| 253 | 250 |
| 254 // Now test that we can parse the new format for page actions. | 251 // Now test that we can parse the new format for page actions. |
| 255 const std::string kTitle("MyExtensionActionTitle"); | 252 const std::string kTitle("MyExtensionActionTitle"); |
| 256 const std::string kIcon("image1.png"); | 253 const std::string kIcon("image1.png"); |
| 257 const std::string kPopupHtmlFile("a_popup.html"); | 254 const std::string kPopupHtmlFile("a_popup.html"); |
| 258 | 255 |
| 259 action = LoadAction("page_action_new_format.json"); | 256 action = LoadAction("page_action_new_format.json"); |
| 260 ASSERT_TRUE(action.get()); | 257 ASSERT_TRUE(action.get()); |
| 261 ASSERT_EQ(kTitle, action->GetTitle(1)); | 258 ASSERT_EQ(kTitle, action->GetTitle(1)); |
| 262 ASSERT_EQ(0u, action->icon_paths()->size()); | 259 ASSERT_FALSE(action->default_icon_path().empty()); |
| 263 | 260 |
| 264 // Invalid title should give an error even with a valid name. | 261 // Invalid title should give an error even with a valid name. |
| 265 LoadActionAndExpectError("page_action_invalid_title.json", | 262 LoadActionAndExpectError("page_action_invalid_title.json", |
| 266 errors::kInvalidPageActionDefaultTitle); | 263 errors::kInvalidPageActionDefaultTitle); |
| 267 | 264 |
| 268 // Invalid name should give an error only with no title. | 265 // Invalid name should give an error only with no title. |
| 269 action = LoadAction("page_action_invalid_name.json"); | 266 action = LoadAction("page_action_invalid_name.json"); |
| 270 ASSERT_TRUE(NULL != action.get()); | 267 ASSERT_TRUE(NULL != action.get()); |
| 271 ASSERT_EQ(kTitle, action->GetTitle(1)); | 268 ASSERT_EQ(kTitle, action->GetTitle(1)); |
| 272 | 269 |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 | 1205 |
| 1209 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | 1206 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { |
| 1210 scoped_refptr<Extension> extension( | 1207 scoped_refptr<Extension> extension( |
| 1211 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1208 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1212 Extension::INTERNAL, 2, FilePath(), | 1209 Extension::INTERNAL, 2, FilePath(), |
| 1213 Extension::NO_FLAGS)); | 1210 Extension::NO_FLAGS)); |
| 1214 if (extension) | 1211 if (extension) |
| 1215 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1212 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1216 } | 1213 } |
| 1217 #endif // !defined(OS_CHROMEOS) | 1214 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |