Update broken references to image assets
[chromium-blink-merge.git] / extensions / test / test_extensions_client.cc
blobb0b02f1f58760d7dd7c0b4bed59a87f8c555f297
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/test/test_extensions_client.h"
7 #include "base/stl_util.h"
8 #include "extensions/common/api/generated_schemas.h"
9 #include "extensions/common/common_manifest_handlers.h"
10 #include "extensions/common/extension_urls.h"
11 #include "extensions/common/features/api_feature.h"
12 #include "extensions/common/features/base_feature_provider.h"
13 #include "extensions/common/features/behavior_feature.h"
14 #include "extensions/common/features/feature_provider.h"
15 #include "extensions/common/features/json_feature_provider_source.h"
16 #include "extensions/common/features/manifest_feature.h"
17 #include "extensions/common/features/permission_feature.h"
18 #include "extensions/common/manifest_handler.h"
19 #include "extensions/common/permissions/extensions_api_permissions.h"
20 #include "extensions/common/permissions/permissions_info.h"
21 #include "extensions/common/url_pattern_set.h"
22 #include "extensions/test/test_permission_message_provider.h"
23 #include "grit/extensions_resources.h"
25 namespace extensions {
27 namespace {
29 template <class FeatureClass>
30 SimpleFeature* CreateFeature() {
31 return new FeatureClass;
34 } // namespace
36 TestExtensionsClient::TestExtensionsClient() {
39 TestExtensionsClient::~TestExtensionsClient() {
42 void TestExtensionsClient::AddBrowserImagePathsFilter(
43 BrowserImagePathsFilter* filter) {
44 browser_image_filters_.insert(filter);
47 void TestExtensionsClient::RemoveBrowserImagePathsFilter(
48 BrowserImagePathsFilter* filter) {
49 browser_image_filters_.erase(filter);
52 void TestExtensionsClient::Initialize() {
53 // Registration could already be finalized in unit tests, where the utility
54 // thread runs in-process.
55 if (!ManifestHandler::IsRegistrationFinalized()) {
56 RegisterCommonManifestHandlers();
57 ManifestHandler::FinalizeRegistration();
60 // Allow the core API permissions.
61 static ExtensionsAPIPermissions extensions_api_permissions;
62 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions);
65 const PermissionMessageProvider&
66 TestExtensionsClient::GetPermissionMessageProvider() const {
67 static TestPermissionMessageProvider provider;
68 return provider;
71 const std::string TestExtensionsClient::GetProductName() {
72 return "extensions_test";
75 scoped_ptr<FeatureProvider> TestExtensionsClient::CreateFeatureProvider(
76 const std::string& name) const {
77 scoped_ptr<FeatureProvider> provider;
78 scoped_ptr<JSONFeatureProviderSource> source(
79 CreateFeatureProviderSource(name));
80 if (name == "api") {
81 provider.reset(new BaseFeatureProvider(source->dictionary(),
82 CreateFeature<APIFeature>));
83 } else if (name == "manifest") {
84 provider.reset(new BaseFeatureProvider(source->dictionary(),
85 CreateFeature<ManifestFeature>));
86 } else if (name == "permission") {
87 provider.reset(new BaseFeatureProvider(source->dictionary(),
88 CreateFeature<PermissionFeature>));
89 } else if (name == "behavior") {
90 provider.reset(new BaseFeatureProvider(source->dictionary(),
91 CreateFeature<BehaviorFeature>));
92 } else {
93 NOTREACHED();
95 return provider.Pass();
98 scoped_ptr<JSONFeatureProviderSource>
99 TestExtensionsClient::CreateFeatureProviderSource(
100 const std::string& name) const {
101 scoped_ptr<JSONFeatureProviderSource> source(
102 new JSONFeatureProviderSource(name));
103 if (name == "api") {
104 source->LoadJSON(IDR_EXTENSION_API_FEATURES);
105 } else if (name == "manifest") {
106 source->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES);
107 } else if (name == "permission") {
108 source->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES);
109 } else if (name == "behavior") {
110 source->LoadJSON(IDR_EXTENSION_BEHAVIOR_FEATURES);
111 } else {
112 NOTREACHED();
113 source.reset();
115 return source.Pass();
118 void TestExtensionsClient::FilterHostPermissions(
119 const URLPatternSet& hosts,
120 URLPatternSet* new_hosts,
121 PermissionIDSet* permissions) const {
124 void TestExtensionsClient::SetScriptingWhitelist(
125 const ExtensionsClient::ScriptingWhitelist& whitelist) {
126 scripting_whitelist_ = whitelist;
129 const ExtensionsClient::ScriptingWhitelist&
130 TestExtensionsClient::GetScriptingWhitelist() const {
131 return scripting_whitelist_;
134 URLPatternSet TestExtensionsClient::GetPermittedChromeSchemeHosts(
135 const Extension* extension,
136 const APIPermissionSet& api_permissions) const {
137 URLPatternSet hosts;
138 return hosts;
141 bool TestExtensionsClient::IsScriptableURL(const GURL& url,
142 std::string* error) const {
143 return true;
146 bool TestExtensionsClient::IsAPISchemaGenerated(
147 const std::string& name) const {
148 return api::GeneratedSchemas::IsGenerated(name);
151 base::StringPiece TestExtensionsClient::GetAPISchema(
152 const std::string& name) const {
153 return api::GeneratedSchemas::Get(name);
156 void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI* api) const {
159 bool TestExtensionsClient::ShouldSuppressFatalErrors() const {
160 return true;
163 void TestExtensionsClient::RecordDidSuppressFatalError() {
166 std::string TestExtensionsClient::GetWebstoreBaseURL() const {
167 return extension_urls::kChromeWebstoreBaseURL;
170 std::string TestExtensionsClient::GetWebstoreUpdateURL() const {
171 return extension_urls::kChromeWebstoreUpdateURL;
174 bool TestExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
175 return true;
178 std::set<base::FilePath> TestExtensionsClient::GetBrowserImagePaths(
179 const Extension* extension) {
180 std::set<base::FilePath> result =
181 ExtensionsClient::GetBrowserImagePaths(extension);
182 for (auto filter : browser_image_filters_)
183 filter->Filter(extension, &result);
184 return result;
187 } // namespace extensions