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 #ifndef EXTENSIONS_BROWSER_TEST_EXTENSIONS_BROWSER_CLIENT_H_
6 #define EXTENSIONS_BROWSER_TEST_EXTENSIONS_BROWSER_CLIENT_H_
8 #include "base/compiler_specific.h"
9 #include "extensions/browser/extensions_browser_client.h"
10 #include "extensions/browser/updater/extension_cache.h"
12 namespace extensions
{
14 // A simplified ExtensionsBrowserClient for a single normal browser context and
15 // an optional incognito browser context associated with it. A test that uses
16 // this class should call ExtensionsBrowserClient::Set() with its instance.
17 class TestExtensionsBrowserClient
: public ExtensionsBrowserClient
{
19 // |main_context| is required and must not be an incognito context.
20 explicit TestExtensionsBrowserClient(content::BrowserContext
* main_context
);
21 ~TestExtensionsBrowserClient() override
;
23 void set_process_manager_delegate(ProcessManagerDelegate
* delegate
) {
24 process_manager_delegate_
= delegate
;
26 void set_extension_system_factory(ExtensionSystemProvider
* factory
) {
27 extension_system_factory_
= factory
;
29 void set_extension_cache(scoped_ptr
<ExtensionCache
> extension_cache
) {
30 extension_cache_
= extension_cache
.Pass();
33 // Associates an incognito context with |main_context_|.
34 void SetIncognitoContext(content::BrowserContext
* incognito_context
);
36 // ExtensionsBrowserClient overrides:
37 bool IsShuttingDown() override
;
38 bool AreExtensionsDisabled(const base::CommandLine
& command_line
,
39 content::BrowserContext
* context
) override
;
40 bool IsValidContext(content::BrowserContext
* context
) override
;
41 bool IsSameContext(content::BrowserContext
* first
,
42 content::BrowserContext
* second
) override
;
43 bool HasOffTheRecordContext(content::BrowserContext
* context
) override
;
44 content::BrowserContext
* GetOffTheRecordContext(
45 content::BrowserContext
* context
) override
;
46 content::BrowserContext
* GetOriginalContext(
47 content::BrowserContext
* context
) override
;
48 bool IsGuestSession(content::BrowserContext
* context
) const override
;
49 bool IsExtensionIncognitoEnabled(
50 const std::string
& extension_id
,
51 content::BrowserContext
* context
) const override
;
52 bool CanExtensionCrossIncognito(
53 const extensions::Extension
* extension
,
54 content::BrowserContext
* context
) const override
;
55 net::URLRequestJob
* MaybeCreateResourceBundleRequestJob(
56 net::URLRequest
* request
,
57 net::NetworkDelegate
* network_delegate
,
58 const base::FilePath
& directory_path
,
59 const std::string
& content_security_policy
,
60 bool send_cors_header
) override
;
61 bool AllowCrossRendererResourceLoad(net::URLRequest
* request
,
63 const Extension
* extension
,
64 InfoMap
* extension_info_map
) override
;
65 PrefService
* GetPrefServiceForContext(
66 content::BrowserContext
* context
) override
;
67 void GetEarlyExtensionPrefsObservers(
68 content::BrowserContext
* context
,
69 std::vector
<ExtensionPrefsObserver
*>* observers
) const override
;
70 ProcessManagerDelegate
* GetProcessManagerDelegate() const override
;
71 scoped_ptr
<ExtensionHostDelegate
> CreateExtensionHostDelegate() override
;
72 bool DidVersionUpdate(content::BrowserContext
* context
) override
;
73 void PermitExternalProtocolHandler() override
;
74 scoped_ptr
<AppSorting
> CreateAppSorting() override
;
75 bool IsRunningInForcedAppMode() override
;
76 ApiActivityMonitor
* GetApiActivityMonitor(
77 content::BrowserContext
* context
) override
;
78 ExtensionSystemProvider
* GetExtensionSystemFactory() override
;
79 void RegisterExtensionFunctions(
80 ExtensionFunctionRegistry
* registry
) const override
;
81 scoped_ptr
<RuntimeAPIDelegate
> CreateRuntimeAPIDelegate(
82 content::BrowserContext
* context
) const override
;
83 ComponentExtensionResourceManager
* GetComponentExtensionResourceManager()
85 void BroadcastEventToRenderers(const std::string
& event_name
,
86 scoped_ptr
<base::ListValue
> args
) override
;
87 net::NetLog
* GetNetLog() override
;
88 ExtensionCache
* GetExtensionCache() override
;
89 bool IsBackgroundUpdateAllowed() override
;
90 bool IsMinBrowserVersionSupported(const std::string
& min_version
) override
;
93 content::BrowserContext
* main_context_
; // Not owned.
94 content::BrowserContext
* incognito_context_
; // Not owned, defaults to NULL.
96 // Not owned, defaults to NULL.
97 ProcessManagerDelegate
* process_manager_delegate_
;
99 // Not owned, defaults to NULL.
100 ExtensionSystemProvider
* extension_system_factory_
;
102 scoped_ptr
<ExtensionCache
> extension_cache_
;
104 DISALLOW_COPY_AND_ASSIGN(TestExtensionsBrowserClient
);
107 } // namespace extensions
109 #endif // EXTENSIONS_BROWSER_TEST_EXTENSIONS_BROWSER_CLIENT_H_