OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 EXPECT_EQ(errors::kInvalidPrivacyBlacklists, error); | 212 EXPECT_EQ(errors::kInvalidPrivacyBlacklists, error); |
213 | 213 |
214 // Test invalid privacy blacklists list item. | 214 // Test invalid privacy blacklists list item. |
215 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); | 215 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); |
216 ListValue* privacy_blacklists = NULL; | 216 ListValue* privacy_blacklists = NULL; |
217 input_value->GetList(keys::kPrivacyBlacklists, &privacy_blacklists); | 217 input_value->GetList(keys::kPrivacyBlacklists, &privacy_blacklists); |
218 ASSERT_FALSE(NULL == privacy_blacklists); | 218 ASSERT_FALSE(NULL == privacy_blacklists); |
219 privacy_blacklists->Set(0, Value::CreateIntegerValue(42)); | 219 privacy_blacklists->Set(0, Value::CreateIntegerValue(42)); |
220 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); | 220 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); |
221 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPrivacyBlacklistsPath)); | 221 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPrivacyBlacklistsPath)); |
| 222 |
| 223 // Test invalid UI surface count (both page action and browser action). |
| 224 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); |
| 225 DictionaryValue* action = new DictionaryValue; |
| 226 action->SetString(keys::kPageActionId, "MyExtensionActionId"); |
| 227 action->SetString(keys::kName, "MyExtensionActionName"); |
| 228 ListValue* action_list = new ListValue; |
| 229 action_list->Append(action->DeepCopy()); |
| 230 input_value->Set(keys::kPageActions, action_list); |
| 231 input_value->Set(keys::kBrowserAction, action); |
| 232 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); |
| 233 EXPECT_STREQ(error.c_str(), errors::kOneUISurfaceOnly); |
222 } | 234 } |
223 | 235 |
224 TEST(ExtensionTest, InitFromValueValid) { | 236 TEST(ExtensionTest, InitFromValueValid) { |
225 #if defined(OS_WIN) | 237 #if defined(OS_WIN) |
226 FilePath path(FILE_PATH_LITERAL("C:\\foo")); | 238 FilePath path(FILE_PATH_LITERAL("C:\\foo")); |
227 #elif defined(OS_POSIX) | 239 #elif defined(OS_POSIX) |
228 FilePath path(FILE_PATH_LITERAL("/foo")); | 240 FilePath path(FILE_PATH_LITERAL("/foo")); |
229 #endif | 241 #endif |
230 Extension extension(path); | 242 Extension extension(path); |
231 std::string error; | 243 std::string error; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 error_msg = ""; | 406 error_msg = ""; |
395 | 407 |
396 // Same test (name key), but with browser action. | 408 // Same test (name key), but with browser action. |
397 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); | 409 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); |
398 copy->Remove(keys::kPageActionIcons, NULL); | 410 copy->Remove(keys::kPageActionIcons, NULL); |
399 action.reset(extension.LoadExtensionActionHelper( | 411 action.reset(extension.LoadExtensionActionHelper( |
400 copy.get(), &error_msg, ExtensionAction::BROWSER_ACTION)); | 412 copy.get(), &error_msg, ExtensionAction::BROWSER_ACTION)); |
401 ASSERT_TRUE(NULL != action.get()); | 413 ASSERT_TRUE(NULL != action.get()); |
402 | 414 |
403 // Now test that we can parse the new format for page actions. | 415 // Now test that we can parse the new format for page actions. |
404 | 416 |
405 // Now setup some values to use in the page action. | 417 // Now setup some values to use in the page action. |
406 const std::string kTitle("MyExtensionActionTitle"); | 418 const std::string kTitle("MyExtensionActionTitle"); |
407 const std::string kIcon("image1.png"); | 419 const std::string kIcon("image1.png"); |
408 | 420 |
409 // Add the dictionary for the contextual action. | 421 // Add the dictionary for the contextual action. |
410 input.Clear(); | 422 input.Clear(); |
411 input.SetString(keys::kPageActionDefaultTitle, kTitle); | 423 input.SetString(keys::kPageActionDefaultTitle, kTitle); |
412 input.SetString(keys::kPageActionDefaultIcon, kIcon); | 424 input.SetString(keys::kPageActionDefaultIcon, kIcon); |
413 | 425 |
414 // Parse as page action and read back the values from the object. | 426 // Parse as page action and read back the values from the object. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 scoped_ptr<Extension> new_extension( | 680 scoped_ptr<Extension> new_extension( |
669 LoadManifest("allow_silent_upgrade", | 681 LoadManifest("allow_silent_upgrade", |
670 std::string(kTests[i].base_name) + "_new.json")); | 682 std::string(kTests[i].base_name) + "_new.json")); |
671 | 683 |
672 EXPECT_EQ(kTests[i].expect_success, | 684 EXPECT_EQ(kTests[i].expect_success, |
673 Extension::IsPrivilegeIncrease(old_extension.get(), | 685 Extension::IsPrivilegeIncrease(old_extension.get(), |
674 new_extension.get())) | 686 new_extension.get())) |
675 << kTests[i].base_name; | 687 << kTests[i].base_name; |
676 } | 688 } |
677 } | 689 } |
OLD | NEW |