OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ | |
7 | |
8 #include <set> | |
9 #include <string> | |
10 | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/linked_ptr.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "chrome/browser/extensions/event_router.h" | |
16 #include "chrome/browser/extensions/extension_service.h" | |
17 #include "chrome/browser/extensions/settings/settings_namespace.h" | |
18 #include "chrome/browser/extensions/settings/settings_storage_factory.h" | |
19 #include "chrome/browser/extensions/test_extension_service.h" | |
20 #include "chrome/browser/extensions/test_extension_system.h" | |
21 #include "chrome/common/extensions/extension.h" | |
22 #include "chrome/test/base/testing_profile.h" | |
23 | |
24 class ValueStore; | |
25 | |
26 namespace extensions { | |
27 | |
28 class SettingsFrontend; | |
29 // Utilities for extension settings API tests. | |
30 namespace settings_test_util { | |
31 | |
32 // Synchronously gets the storage area for an extension from |frontend|. | |
33 ValueStore* GetStorage( | |
34 const std::string& extension_id, | |
35 settings_namespace::Namespace setting_namespace, | |
36 SettingsFrontend* frontend); | |
37 | |
38 // Synchronously gets the SYNC storage for an extension from |frontend|. | |
39 ValueStore* GetStorage( | |
40 const std::string& extension_id, | |
41 SettingsFrontend* frontend); | |
42 | |
43 // An ExtensionService which allows extensions to be hand-added to be returned | |
44 // by GetExtensionById. | |
45 class MockExtensionService : public TestExtensionService { | |
46 public: | |
47 MockExtensionService(); | |
48 virtual ~MockExtensionService(); | |
49 | |
50 // Adds an extension with id |id| to be returned by GetExtensionById. | |
51 void AddExtensionWithId(const std::string& id, Extension::Type type); | |
52 | |
53 // Adds an extension with id |id| to be returned by GetExtensionById, with | |
54 // a set of permissions. | |
55 void AddExtensionWithIdAndPermissions( | |
56 const std::string& id, | |
57 Extension::Type type, | |
58 const std::set<std::string>& permissions); | |
59 | |
60 virtual const Extension* GetExtensionById( | |
61 const std::string& id, bool include_disabled) const OVERRIDE; | |
62 | |
63 private: | |
64 std::map<std::string, scoped_refptr<Extension> > extensions_; | |
65 }; | |
66 | |
67 // A mock ExtensionSystem to serve an EventRouter. | |
68 class MockExtensionSystem : public TestExtensionSystem { | |
69 public: | |
70 explicit MockExtensionSystem(Profile* profile); | |
71 virtual ~MockExtensionSystem(); | |
72 | |
73 virtual EventRouter* event_router() OVERRIDE; | |
74 virtual ExtensionService* extension_service() OVERRIDE; | |
75 | |
76 private: | |
77 scoped_ptr<EventRouter> event_router_; | |
78 MockExtensionService extension_service_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); | |
81 }; | |
82 | |
83 // A Profile which returns an ExtensionService with enough functionality for | |
84 // the tests. | |
85 class MockProfile : public TestingProfile { | |
86 public: | |
87 explicit MockProfile(const FilePath& file_path); | |
88 virtual ~MockProfile(); | |
89 }; | |
90 | |
91 // SettingsStorageFactory which acts as a wrapper for other factories. | |
92 class ScopedSettingsStorageFactory : public SettingsStorageFactory { | |
93 public: | |
94 ScopedSettingsStorageFactory(); | |
95 | |
96 explicit ScopedSettingsStorageFactory( | |
97 const scoped_refptr<SettingsStorageFactory>& delegate); | |
98 | |
99 // Sets the delegate factory (equivalent to scoped_ptr::reset). | |
100 void Reset(const scoped_refptr<SettingsStorageFactory>& delegate); | |
101 | |
102 // SettingsStorageFactory implementation. | |
103 virtual ValueStore* Create(const FilePath& base_path, | |
104 const std::string& extension_id) OVERRIDE; | |
105 | |
106 private: | |
107 // SettingsStorageFactory is refcounted. | |
108 virtual ~ScopedSettingsStorageFactory(); | |
109 | |
110 scoped_refptr<SettingsStorageFactory> delegate_; | |
111 }; | |
112 | |
113 } // namespace settings_test_util | |
114 | |
115 } // namespace extensions | |
116 | |
117 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ | |
OLD | NEW |