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