| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Bug: http://crbug.com/38462 | 43 // Bug: http://crbug.com/38462 |
| 44 | 44 |
| 45 | 45 |
| 46 TEST(ExtensionTest, InitFromValueInvalid) { | 46 TEST(ExtensionTest, InitFromValueInvalid) { |
| 47 #if defined(OS_WIN) | 47 #if defined(OS_WIN) |
| 48 FilePath path(FILE_PATH_LITERAL("c:\\foo")); | 48 FilePath path(FILE_PATH_LITERAL("c:\\foo")); |
| 49 #elif defined(OS_POSIX) | 49 #elif defined(OS_POSIX) |
| 50 FilePath path(FILE_PATH_LITERAL("/foo")); | 50 FilePath path(FILE_PATH_LITERAL("/foo")); |
| 51 #endif | 51 #endif |
| 52 Extension extension(path); | 52 Extension extension(path); |
| 53 int error_code = 0; |
| 53 std::string error; | 54 std::string error; |
| 54 ExtensionErrorReporter::Init(false); | 55 ExtensionErrorReporter::Init(false); |
| 55 | 56 |
| 56 // Start with a valid extension manifest | 57 // Start with a valid extension manifest |
| 57 FilePath extensions_path; | 58 FilePath extensions_path; |
| 58 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 59 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 59 extensions_path = extensions_path.AppendASCII("extensions") | 60 extensions_path = extensions_path.AppendASCII("extensions") |
| 60 .AppendASCII("good") | 61 .AppendASCII("good") |
| 61 .AppendASCII("Extensions") | 62 .AppendASCII("Extensions") |
| 62 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 63 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 63 .AppendASCII("1.0.0.0") | 64 .AppendASCII("1.0.0.0") |
| 64 .Append(Extension::kManifestFilename); | 65 .Append(Extension::kManifestFilename); |
| 65 | 66 |
| 66 JSONFileValueSerializer serializer(extensions_path); | 67 JSONFileValueSerializer serializer(extensions_path); |
| 67 scoped_ptr<DictionaryValue> valid_value( | 68 scoped_ptr<DictionaryValue> valid_value( |
| 68 static_cast<DictionaryValue*>(serializer.Deserialize(&error))); | 69 static_cast<DictionaryValue*>(serializer.Deserialize(&error_code, |
| 70 &error))); |
| 69 EXPECT_EQ("", error); | 71 EXPECT_EQ("", error); |
| 72 EXPECT_EQ(0, error_code); |
| 70 ASSERT_TRUE(valid_value.get()); | 73 ASSERT_TRUE(valid_value.get()); |
| 71 ASSERT_TRUE(extension.InitFromValue(*valid_value, true, &error)); | 74 ASSERT_TRUE(extension.InitFromValue(*valid_value, true, &error)); |
| 72 ASSERT_EQ("", error); | 75 ASSERT_EQ("", error); |
| 73 EXPECT_EQ("en_US", extension.default_locale()); | 76 EXPECT_EQ("en_US", extension.default_locale()); |
| 74 | 77 |
| 75 scoped_ptr<DictionaryValue> input_value; | 78 scoped_ptr<DictionaryValue> input_value; |
| 76 | 79 |
| 77 // Test missing and invalid versions | 80 // Test missing and invalid versions |
| 78 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); | 81 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); |
| 79 input_value->Remove(keys::kVersion, NULL); | 82 input_value->Remove(keys::kVersion, NULL); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 | 650 |
| 648 static Extension* LoadManifest(const std::string& dir, | 651 static Extension* LoadManifest(const std::string& dir, |
| 649 const std::string& test_file) { | 652 const std::string& test_file) { |
| 650 FilePath path; | 653 FilePath path; |
| 651 PathService::Get(chrome::DIR_TEST_DATA, &path); | 654 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 652 path = path.AppendASCII("extensions") | 655 path = path.AppendASCII("extensions") |
| 653 .AppendASCII(dir) | 656 .AppendASCII(dir) |
| 654 .AppendASCII(test_file); | 657 .AppendASCII(test_file); |
| 655 | 658 |
| 656 JSONFileValueSerializer serializer(path); | 659 JSONFileValueSerializer serializer(path); |
| 657 scoped_ptr<Value> result(serializer.Deserialize(NULL)); | 660 scoped_ptr<Value> result(serializer.Deserialize(NULL, NULL)); |
| 658 if (!result.get()) | 661 if (!result.get()) |
| 659 return NULL; | 662 return NULL; |
| 660 | 663 |
| 661 std::string error; | 664 std::string error; |
| 662 scoped_ptr<Extension> extension(new Extension(path.DirName())); | 665 scoped_ptr<Extension> extension(new Extension(path.DirName())); |
| 663 extension->InitFromValue(*static_cast<DictionaryValue*>(result.get()), | 666 extension->InitFromValue(*static_cast<DictionaryValue*>(result.get()), |
| 664 false, &error); | 667 false, &error); |
| 665 | 668 |
| 666 return extension.release(); | 669 return extension.release(); |
| 667 } | 670 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 scoped_ptr<Extension> new_extension( | 783 scoped_ptr<Extension> new_extension( |
| 781 LoadManifest("allow_silent_upgrade", | 784 LoadManifest("allow_silent_upgrade", |
| 782 std::string(kTests[i].base_name) + "_new.json")); | 785 std::string(kTests[i].base_name) + "_new.json")); |
| 783 | 786 |
| 784 EXPECT_EQ(kTests[i].expect_success, | 787 EXPECT_EQ(kTests[i].expect_success, |
| 785 Extension::IsPrivilegeIncrease(old_extension.get(), | 788 Extension::IsPrivilegeIncrease(old_extension.get(), |
| 786 new_extension.get())) | 789 new_extension.get())) |
| 787 << kTests[i].base_name; | 790 << kTests[i].base_name; |
| 788 } | 791 } |
| 789 } | 792 } |
| OLD | NEW |