blob: 8ea62be6e6685eb53db295eff770391c8d93f322 [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_TEST_EXTENSIONS_BROWSER_CLIENT_H_
#define EXTENSIONS_BROWSER_TEST_EXTENSIONS_BROWSER_CLIENT_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#include "components/update_client/update_client.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/updater/extension_cache.h"
namespace extensions {
class KioskDelegate;
// A simplified ExtensionsBrowserClient for a single normal browser context and
// an optional incognito browser context associated with it. A test that uses
// this class should call ExtensionsBrowserClient::Set() with its instance.
class TestExtensionsBrowserClient : public ExtensionsBrowserClient {
public:
// |main_context| is required and must not be an incognito context.
explicit TestExtensionsBrowserClient(content::BrowserContext* main_context);
~TestExtensionsBrowserClient() override;
void set_process_manager_delegate(ProcessManagerDelegate* delegate) {
process_manager_delegate_ = delegate;
}
void set_extension_system_factory(ExtensionSystemProvider* factory) {
extension_system_factory_ = factory;
}
void set_extension_cache(std::unique_ptr<ExtensionCache> extension_cache) {
extension_cache_ = std::move(extension_cache);
}
void set_lock_screen_context(content::BrowserContext* context) {
lock_screen_context_ = context;
}
// Sets a factory to respond to calls of the CreateUpdateClient method.
void SetUpdateClientFactory(
const base::Callback<update_client::UpdateClient*(void)>& factory);
// Associates an incognito context with |main_context_|.
void SetIncognitoContext(content::BrowserContext* incognito_context);
// ExtensionsBrowserClient overrides:
bool IsShuttingDown() override;
bool AreExtensionsDisabled(const base::CommandLine& command_line,
content::BrowserContext* context) override;
bool IsValidContext(content::BrowserContext* context) override;
bool IsSameContext(content::BrowserContext* first,
content::BrowserContext* second) override;
bool HasOffTheRecordContext(content::BrowserContext* context) override;
content::BrowserContext* GetOffTheRecordContext(
content::BrowserContext* context) override;
content::BrowserContext* GetOriginalContext(
content::BrowserContext* context) override;
#if defined(OS_CHROMEOS)
std::string GetUserIdHashFromContext(
content::BrowserContext* context) override;
#endif
bool IsGuestSession(content::BrowserContext* context) const override;
bool IsExtensionIncognitoEnabled(
const std::string& extension_id,
content::BrowserContext* context) const override;
bool CanExtensionCrossIncognito(
const extensions::Extension* extension,
content::BrowserContext* context) const override;
net::URLRequestJob* MaybeCreateResourceBundleRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const base::FilePath& directory_path,
const std::string& content_security_policy,
bool send_cors_header) override;
bool AllowCrossRendererResourceLoad(net::URLRequest* request,
bool is_incognito,
const Extension* extension,
InfoMap* extension_info_map) override;
PrefService* GetPrefServiceForContext(
content::BrowserContext* context) override;
void GetEarlyExtensionPrefsObservers(
content::BrowserContext* context,
std::vector<ExtensionPrefsObserver*>* observers) const override;
ProcessManagerDelegate* GetProcessManagerDelegate() const override;
std::unique_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() override;
bool DidVersionUpdate(content::BrowserContext* context) override;
void PermitExternalProtocolHandler() override;
bool IsRunningInForcedAppMode() override;
bool IsLoggedInAsPublicAccount() override;
ExtensionSystemProvider* GetExtensionSystemFactory() override;
void RegisterExtensionFunctions(
ExtensionFunctionRegistry* registry) const override;
void RegisterExtensionInterfaces(service_manager::BinderRegistryWithArgs<
content::RenderFrameHost*>* registry,
content::RenderFrameHost* render_frame_host,
const Extension* extension) const override;
std::unique_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate(
content::BrowserContext* context) const override;
const ComponentExtensionResourceManager*
GetComponentExtensionResourceManager() override;
void BroadcastEventToRenderers(
events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> args) override;
net::NetLog* GetNetLog() override;
ExtensionCache* GetExtensionCache() override;
bool IsBackgroundUpdateAllowed() override;
bool IsMinBrowserVersionSupported(const std::string& min_version) override;
ExtensionWebContentsObserver* GetExtensionWebContentsObserver(
content::WebContents* web_contents) override;
KioskDelegate* GetKioskDelegate() override;
scoped_refptr<update_client::UpdateClient> CreateUpdateClient(
content::BrowserContext* context) override;
bool IsLockScreenContext(content::BrowserContext* context) override;
ExtensionSystemProvider* extension_system_factory() {
return extension_system_factory_;
}
private:
// Not owned.
content::BrowserContext* main_context_;
// Not owned, defaults to nullptr.
content::BrowserContext* incognito_context_;
// Not owned, defaults to nullptr.
content::BrowserContext* lock_screen_context_;
// Not owned, defaults to nullptr.
ProcessManagerDelegate* process_manager_delegate_;
// Not owned, defaults to nullptr.
ExtensionSystemProvider* extension_system_factory_;
std::unique_ptr<ExtensionCache> extension_cache_;
base::Callback<update_client::UpdateClient*(void)> update_client_factory_;
DISALLOW_COPY_AND_ASSIGN(TestExtensionsBrowserClient);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_TEST_EXTENSIONS_BROWSER_CLIENT_H_