blob: 05ca13f41043aa0e94e7a0da806234a7672f5849 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// 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_MOCK_EXTENSION_SYSTEM_H_
#define EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_system_provider.h"
#include "extensions/common/one_shot_event.h"
namespace extensions {
// An empty ExtensionSystem for testing. Tests that need only specific
// parts of ExtensionSystem should derive from this class and override
// functions as needed. To use this, use
// TestExtensionsBrowserClient::set_extension_system_factory
// with the MockExtensionSystemFactory below.
class MockExtensionSystem : public ExtensionSystem {
public:
explicit MockExtensionSystem(content::BrowserContext* context);
~MockExtensionSystem() override;
content::BrowserContext* browser_context() { return browser_context_; }
// ExtensionSystem overrides:
void InitForRegularProfile(bool extensions_enabled) override;
ExtensionService* extension_service() override;
RuntimeData* runtime_data() override;
ManagementPolicy* management_policy() override;
SharedUserScriptMaster* shared_user_script_master() override;
StateStore* state_store() override;
StateStore* rules_store() override;
InfoMap* info_map() override;
QuotaService* quota_service() override;
const OneShotEvent& ready() const override;
ContentVerifier* content_verifier() override;
scoped_ptr<ExtensionSet> GetDependentExtensions(
const Extension* extension) override;
private:
content::BrowserContext* browser_context_;
OneShotEvent ready_;
DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem);
};
// A factory to create a MockExtensionSystem. Sample use:
//
// MockExtensionSystemFactory<MockExtensionSystemSubclass> factory;
// TestExtensionsBrowserClient::set_extension_system_factory(factory);
template <typename T>
class MockExtensionSystemFactory : public ExtensionSystemProvider {
public:
MockExtensionSystemFactory()
: ExtensionSystemProvider(
"MockExtensionSystem",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(ExtensionRegistryFactory::GetInstance());
}
~MockExtensionSystemFactory() override {}
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override {
return new T(context);
}
// ExtensionSystemProvider overrides:
ExtensionSystem* GetForBrowserContext(
content::BrowserContext* context) override {
return static_cast<ExtensionSystem*>(
GetServiceForBrowserContext(context, true));
}
private:
DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_
|