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" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
14 #include "chrome/common/extensions/extension_error_reporter.h" | |
15 #include "chrome/common/extensions/extension_error_utils.h" | 14 #include "chrome/common/extensions/extension_error_utils.h" |
16 #include "chrome/common/json_value_serializer.h" | 15 #include "chrome/common/json_value_serializer.h" |
17 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
18 #include "net/base/mime_sniffer.h" | 17 #include "net/base/mime_sniffer.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 namespace keys = extension_manifest_keys; | 20 namespace keys = extension_manifest_keys; |
22 namespace values = extension_manifest_values; | 21 namespace values = extension_manifest_values; |
23 namespace errors = extension_manifest_errors; | 22 namespace errors = extension_manifest_errors; |
24 | 23 |
(...skipping 20 matching lines...) Expand all Loading... |
45 | 44 |
46 TEST(ExtensionTest, InitFromValueInvalid) { | 45 TEST(ExtensionTest, InitFromValueInvalid) { |
47 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
48 FilePath path(FILE_PATH_LITERAL("c:\\foo")); | 47 FilePath path(FILE_PATH_LITERAL("c:\\foo")); |
49 #elif defined(OS_POSIX) | 48 #elif defined(OS_POSIX) |
50 FilePath path(FILE_PATH_LITERAL("/foo")); | 49 FilePath path(FILE_PATH_LITERAL("/foo")); |
51 #endif | 50 #endif |
52 Extension extension(path); | 51 Extension extension(path); |
53 int error_code = 0; | 52 int error_code = 0; |
54 std::string error; | 53 std::string error; |
55 ExtensionErrorReporter::Init(false); | |
56 | 54 |
57 // Start with a valid extension manifest | 55 // Start with a valid extension manifest |
58 FilePath extensions_path; | 56 FilePath extensions_path; |
59 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 57 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
60 extensions_path = extensions_path.AppendASCII("extensions") | 58 extensions_path = extensions_path.AppendASCII("extensions") |
61 .AppendASCII("good") | 59 .AppendASCII("good") |
62 .AppendASCII("Extensions") | 60 .AppendASCII("Extensions") |
63 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 61 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
64 .AppendASCII("1.0.0.0") | 62 .AppendASCII("1.0.0.0") |
65 .Append(Extension::kManifestFilename); | 63 .Append(Extension::kManifestFilename); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Test missing and invalid permissions array | 203 // Test missing and invalid permissions array |
206 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); | 204 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); |
207 EXPECT_TRUE(extension.InitFromValue(*input_value, true, &error)); | 205 EXPECT_TRUE(extension.InitFromValue(*input_value, true, &error)); |
208 ListValue* permissions = NULL; | 206 ListValue* permissions = NULL; |
209 input_value->GetList(keys::kPermissions, &permissions); | 207 input_value->GetList(keys::kPermissions, &permissions); |
210 ASSERT_FALSE(NULL == permissions); | 208 ASSERT_FALSE(NULL == permissions); |
211 | 209 |
212 permissions = new ListValue; | 210 permissions = new ListValue; |
213 input_value->Set(keys::kPermissions, permissions); | 211 input_value->Set(keys::kPermissions, permissions); |
214 EXPECT_TRUE(extension.InitFromValue(*input_value, true, &error)); | 212 EXPECT_TRUE(extension.InitFromValue(*input_value, true, &error)); |
215 EXPECT_EQ(0u, ExtensionErrorReporter::GetInstance()->GetErrors()->size()); | |
216 | 213 |
217 input_value->Set(keys::kPermissions, Value::CreateIntegerValue(9)); | 214 input_value->Set(keys::kPermissions, Value::CreateIntegerValue(9)); |
218 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); | 215 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); |
219 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPermissions)); | 216 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPermissions)); |
220 | 217 |
221 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); | 218 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); |
222 input_value->GetList(keys::kPermissions, &permissions); | 219 input_value->GetList(keys::kPermissions, &permissions); |
223 permissions->Set(0, Value::CreateIntegerValue(24)); | 220 permissions->Set(0, Value::CreateIntegerValue(24)); |
224 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); | 221 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); |
225 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPermission)); | 222 EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPermission)); |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 scoped_ptr<Extension> new_extension( | 784 scoped_ptr<Extension> new_extension( |
788 LoadManifest("allow_silent_upgrade", | 785 LoadManifest("allow_silent_upgrade", |
789 std::string(kTests[i].base_name) + "_new.json")); | 786 std::string(kTests[i].base_name) + "_new.json")); |
790 | 787 |
791 EXPECT_EQ(kTests[i].expect_success, | 788 EXPECT_EQ(kTests[i].expect_success, |
792 Extension::IsPrivilegeIncrease(old_extension.get(), | 789 Extension::IsPrivilegeIncrease(old_extension.get(), |
793 new_extension.get())) | 790 new_extension.get())) |
794 << kTests[i].base_name; | 791 << kTests[i].base_name; |
795 } | 792 } |
796 } | 793 } |
OLD | NEW |