Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1046)

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 14358004: Almost all actions in Declarative Web Request require all_urls host permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: All URLs -> all hosts; also rebased Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_unittest.h" 5 #include "chrome/common/extensions/extension_unittest.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h"
10 #include "base/format_macros.h" 9 #include "base/format_macros.h"
11 #include "base/json/json_file_value_serializer.h"
12 #include "base/path_service.h" 10 #include "base/path_service.h"
13 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
14 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
15 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
16 #include "chrome/common/chrome_paths.h" 14 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 16 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
19 #include "chrome/common/extensions/background_info.h" 17 #include "chrome/common/extensions/background_info.h"
20 #include "chrome/common/extensions/command.h" 18 #include "chrome/common/extensions/command.h"
21 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/extensions/extension_file_util.h" 20 #include "chrome/common/extensions/extension_file_util.h"
23 #include "chrome/common/extensions/extension_manifest_constants.h" 21 #include "chrome/common/extensions/extension_manifest_constants.h"
22 #include "chrome/common/extensions/extension_test_util.h"
24 #include "chrome/common/extensions/features/feature.h" 23 #include "chrome/common/extensions/features/feature.h"
25 #include "chrome/common/extensions/incognito_handler.h" 24 #include "chrome/common/extensions/incognito_handler.h"
26 #include "chrome/common/extensions/manifest.h" 25 #include "chrome/common/extensions/manifest.h"
27 #include "chrome/common/extensions/manifest_handler.h" 26 #include "chrome/common/extensions/manifest_handler.h"
28 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 27 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
29 #include "chrome/common/extensions/permissions/api_permission.h" 28 #include "chrome/common/extensions/permissions/api_permission.h"
30 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" 29 #include "chrome/common/extensions/permissions/chrome_api_permissions.h"
31 #include "chrome/common/extensions/permissions/permission_set.h" 30 #include "chrome/common/extensions/permissions/permission_set.h"
32 #include "chrome/common/extensions/permissions/scoped_testing_permissions_info.h " 31 #include "chrome/common/extensions/permissions/scoped_testing_permissions_info.h "
33 #include "chrome/common/extensions/permissions/socket_permission.h" 32 #include "chrome/common/extensions/permissions/socket_permission.h"
34 #include "chrome/common/extensions/permissions/usb_device_permission.h" 33 #include "chrome/common/extensions/permissions/usb_device_permission.h"
35 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
36 #include "extensions/common/error_utils.h" 35 #include "extensions/common/error_utils.h"
37 #include "extensions/common/extension_resource.h" 36 #include "extensions/common/extension_resource.h"
38 #include "extensions/common/id_util.h" 37 #include "extensions/common/id_util.h"
39 #include "googleurl/src/gurl.h" 38 #include "googleurl/src/gurl.h"
40 #include "net/base/mime_sniffer.h" 39 #include "net/base/mime_sniffer.h"
41 #include "net/dns/mock_host_resolver.h" 40 #include "net/dns/mock_host_resolver.h"
42 #include "skia/ext/image_operations.h" 41 #include "skia/ext/image_operations.h"
43 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
44 #include "third_party/skia/include/core/SkBitmap.h" 43 #include "third_party/skia/include/core/SkBitmap.h"
45 #include "ui/gfx/codec/png_codec.h" 44 #include "ui/gfx/codec/png_codec.h"
46 45
47 using content::SocketPermissionRequest; 46 using content::SocketPermissionRequest;
47 using extension_test_util::LoadManifest;
48 using extension_test_util::LoadManifestUnchecked;
49 using extension_test_util::LoadManifestStrict;
48 50
49 namespace keys = extension_manifest_keys; 51 namespace keys = extension_manifest_keys;
50 namespace values = extension_manifest_values; 52 namespace values = extension_manifest_values;
51 namespace errors = extension_manifest_errors; 53 namespace errors = extension_manifest_errors;
52 54
53 namespace extensions { 55 namespace extensions {
54 namespace {
55
56 scoped_refptr<Extension> LoadManifestUnchecked(
57 const std::string& dir,
58 const std::string& test_file,
59 Manifest::Location location,
60 int extra_flags,
61 std::string* error) {
62 base::FilePath path;
63 PathService::Get(chrome::DIR_TEST_DATA, &path);
64 path = path.AppendASCII("extensions")
65 .AppendASCII(dir)
66 .AppendASCII(test_file);
67
68 JSONFileValueSerializer serializer(path);
69 scoped_ptr<Value> result(serializer.Deserialize(NULL, error));
70 if (!result.get())
71 return NULL;
72
73 scoped_refptr<Extension> extension = Extension::Create(
74 path.DirName(), location, *static_cast<DictionaryValue*>(result.get()),
75 extra_flags, error);
76 return extension;
77 }
78
79 static scoped_refptr<Extension> LoadManifest(const std::string& dir,
80 const std::string& test_file,
81 Manifest::Location location,
82 int extra_flags) {
83 std::string error;
84 scoped_refptr<Extension> extension = LoadManifestUnchecked(dir, test_file,
85 location, extra_flags, &error);
86
87 EXPECT_TRUE(extension) << test_file << ":" << error;
88 return extension;
89 }
90
91 static scoped_refptr<Extension> LoadManifest(const std::string& dir,
92 const std::string& test_file,
93 int extra_flags) {
94 return LoadManifest(dir, test_file, Manifest::INVALID_LOCATION, extra_flags);
95 }
96
97 static scoped_refptr<Extension> LoadManifest(const std::string& dir,
98 const std::string& test_file) {
99 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
100 }
101
102 static scoped_refptr<Extension> LoadManifestStrict(
103 const std::string& dir,
104 const std::string& test_file) {
105 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
106 }
107
108 } // namespace
109 56
110 ExtensionTest::ExtensionTest() : permissions_info_(ChromeAPIPermissions()) {} 57 ExtensionTest::ExtensionTest() : permissions_info_(ChromeAPIPermissions()) {}
111 58
112 void ExtensionTest::SetUp() { 59 void ExtensionTest::SetUp() {
113 testing::Test::SetUp(); 60 testing::Test::SetUp();
114 (new BackgroundManifestHandler)->Register(); 61 (new BackgroundManifestHandler)->Register();
115 // We need the IncognitoHandler registered for all tests, since 62 // We need the IncognitoHandler registered for all tests, since
116 // Extension uses it in Extension::CheckPlatformAppFeatures() as part of the 63 // Extension uses it in Extension::CheckPlatformAppFeatures() as part of the
117 // creation process. 64 // creation process.
118 (new IncognitoHandler)->Register(); 65 (new IncognitoHandler)->Register();
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 error.clear(); 905 error.clear();
959 extension = LoadManifestUnchecked("optional_only_permission", 906 extension = LoadManifestUnchecked("optional_only_permission",
960 "manifest2.json", 907 "manifest2.json",
961 Manifest::INTERNAL, Extension::NO_FLAGS, 908 Manifest::INTERNAL, Extension::NO_FLAGS,
962 &error); 909 &error);
963 EXPECT_TRUE(extension != NULL); 910 EXPECT_TRUE(extension != NULL);
964 EXPECT_TRUE(error.empty()); 911 EXPECT_TRUE(error.empty());
965 } 912 }
966 913
967 } // namespace extensions 914 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_test_util.cc ('k') | chrome/common/extensions/permissions/permission_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698