| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_error_utils.h" | 13 #include "chrome/common/extensions/extension_error_utils.h" |
| 14 #include "chrome/common/extensions/extension_manifest_constants.h" | 14 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 15 #include "chrome/common/extensions/features/feature.h" | 15 #include "chrome/common/extensions/features/feature.h" |
| 16 #include "chrome/common/extensions/permissions/permission_set.h" | 16 #include "chrome/common/extensions/permissions/permission_set.h" |
| 17 #include "chrome/common/extensions/permissions/permissions_info.h" | 17 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 18 #include "chrome/common/extensions/permissions/socket_permission.h" | 18 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using extensions::Extension; | 21 using extensions::Extension; |
| 22 | 22 |
| 23 namespace errors = extension_manifest_errors; | 23 namespace errors = extension_manifest_errors; |
| 24 namespace keys = extension_manifest_keys; | 24 namespace keys = extension_manifest_keys; |
| 25 namespace values = extension_manifest_values; | 25 namespace values = extension_manifest_values; |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 static scoped_refptr<Extension> LoadManifest(const std::string& dir, | 28 scoped_refptr<Extension> LoadManifest(const std::string& dir, |
| 29 const std::string& test_file, | 29 const std::string& test_file, |
| 30 int extra_flags) { | 30 int extra_flags) { |
| 31 FilePath path; | 31 FilePath path; |
| 32 PathService::Get(chrome::DIR_TEST_DATA, &path); | 32 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 33 path = path.AppendASCII("extensions") | 33 path = path.AppendASCII("extensions") |
| 34 .AppendASCII(dir) | 34 .AppendASCII(dir) |
| 35 .AppendASCII(test_file); | 35 .AppendASCII(test_file); |
| 36 | 36 |
| 37 JSONFileValueSerializer serializer(path); | 37 JSONFileValueSerializer serializer(path); |
| 38 std::string error; | 38 std::string error; |
| 39 scoped_ptr<Value> result(serializer.Deserialize(NULL, &error)); | 39 scoped_ptr<Value> result(serializer.Deserialize(NULL, &error)); |
| 40 if (!result.get()) { | 40 if (!result.get()) { |
| 41 EXPECT_EQ("", error); | 41 EXPECT_EQ("", error); |
| 42 return NULL; | 42 return NULL; |
| 43 } | 43 } |
| 44 | 44 |
| 45 scoped_refptr<Extension> extension = Extension::Create( | 45 scoped_refptr<Extension> extension = Extension::Create( |
| 46 path.DirName(), Extension::INVALID, | 46 path.DirName(), Extension::INVALID, |
| 47 *static_cast<DictionaryValue*>(result.get()), extra_flags, &error); | 47 *static_cast<DictionaryValue*>(result.get()), extra_flags, &error); |
| 48 EXPECT_TRUE(extension) << error; | 48 EXPECT_TRUE(extension) << error; |
| 49 return extension; | 49 return extension; |
| 50 } | 50 } |
| 51 | 51 |
| 52 static scoped_refptr<Extension> LoadManifest(const std::string& dir, | 52 scoped_refptr<Extension> LoadManifest(const std::string& dir, |
| 53 const std::string& test_file) { | 53 const std::string& test_file) { |
| 54 return LoadManifest(dir, test_file, Extension::NO_FLAGS); | 54 return LoadManifest(dir, test_file, Extension::NO_FLAGS); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void CompareLists(const std::vector<std::string>& expected, | |
| 58 const std::vector<std::string>& actual) { | |
| 59 ASSERT_EQ(expected.size(), actual.size()); | |
| 60 | |
| 61 for (size_t i = 0; i < expected.size(); ++i) { | |
| 62 EXPECT_EQ(expected[i], actual[i]); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 57 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 67 int schemes = URLPattern::SCHEME_ALL; | 58 int schemes = URLPattern::SCHEME_ALL; |
| 68 extent->AddPattern(URLPattern(schemes, pattern)); | 59 extent->AddPattern(URLPattern(schemes, pattern)); |
| 69 } | 60 } |
| 70 | 61 |
| 71 static size_t IndexOf(const std::vector<string16>& warnings, | 62 size_t IndexOf(const std::vector<string16>& warnings, |
| 72 const std::string& warning) { | 63 const std::string& warning) { |
| 73 for (size_t i = 0; i < warnings.size(); ++i) { | 64 for (size_t i = 0; i < warnings.size(); ++i) { |
| 74 if (warnings[i] == ASCIIToUTF16(warning)) | 65 if (warnings[i] == ASCIIToUTF16(warning)) |
| 75 return i; | 66 return i; |
| 76 } | 67 } |
| 77 | 68 |
| 78 return warnings.size(); | 69 return warnings.size(); |
| 79 } | 70 } |
| 80 | 71 |
| 81 static bool Contains(const std::vector<string16>& warnings, | 72 bool Contains(const std::vector<string16>& warnings, |
| 82 const std::string& warning) { | 73 const std::string& warning) { |
| 83 return IndexOf(warnings, warning) != warnings.size(); | 74 return IndexOf(warnings, warning) != warnings.size(); |
| 84 } | 75 } |
| 85 | 76 |
| 86 } // namespace | 77 } // namespace |
| 87 | 78 |
| 88 namespace extensions { | 79 namespace extensions { |
| 89 | 80 |
| 90 class PermissionsTest : public testing::Test { | 81 class PermissionsTest : public testing::Test { |
| 91 }; | 82 }; |
| 92 | 83 |
| (...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 apis.insert(APIPermission::kWebRequest); | 1335 apis.insert(APIPermission::kWebRequest); |
| 1345 apis.insert(APIPermission::kFileBrowserHandler); | 1336 apis.insert(APIPermission::kFileBrowserHandler); |
| 1346 EXPECT_EQ(2U, apis.size()); | 1337 EXPECT_EQ(2U, apis.size()); |
| 1347 | 1338 |
| 1348 scoped_refptr<PermissionSet> perm_set; | 1339 scoped_refptr<PermissionSet> perm_set; |
| 1349 perm_set = new PermissionSet(apis, empty_extent, empty_extent); | 1340 perm_set = new PermissionSet(apis, empty_extent, empty_extent); |
| 1350 EXPECT_EQ(4U, perm_set->apis().size()); | 1341 EXPECT_EQ(4U, perm_set->apis().size()); |
| 1351 } | 1342 } |
| 1352 | 1343 |
| 1353 } // namespace extensions | 1344 } // namespace extensions |
| OLD | NEW |