OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "chrome/browser/extensions/event_router.h" | 15 #include "chrome/browser/extensions/event_router.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/settings/settings_namespace.h" | 17 #include "chrome/browser/extensions/settings/settings_namespace.h" |
18 #include "chrome/browser/extensions/settings/settings_storage_factory.h" | 18 #include "chrome/browser/extensions/settings/settings_storage_factory.h" |
19 #include "chrome/browser/extensions/test_extension_service.h" | 19 #include "chrome/browser/extensions/test_extension_service.h" |
| 20 #include "chrome/browser/extensions/test_extension_system.h" |
20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
22 | 23 |
23 class ValueStore; | 24 class ValueStore; |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 | 27 |
27 class SettingsFrontend; | 28 class SettingsFrontend; |
28 // Utilities for extension settings API tests. | 29 // Utilities for extension settings API tests. |
29 namespace settings_test_util { | 30 namespace settings_test_util { |
(...skipping 26 matching lines...) Expand all Loading... |
56 Extension::Type type, | 57 Extension::Type type, |
57 const std::set<std::string>& permissions); | 58 const std::set<std::string>& permissions); |
58 | 59 |
59 virtual const Extension* GetExtensionById( | 60 virtual const Extension* GetExtensionById( |
60 const std::string& id, bool include_disabled) const OVERRIDE; | 61 const std::string& id, bool include_disabled) const OVERRIDE; |
61 | 62 |
62 private: | 63 private: |
63 std::map<std::string, scoped_refptr<Extension> > extensions_; | 64 std::map<std::string, scoped_refptr<Extension> > extensions_; |
64 }; | 65 }; |
65 | 66 |
66 // A Profile which returns ExtensionService and EventRouters with | 67 // A mock ExtensionSystem to serve an EventRouter. |
67 // enough functionality for the tests. | 68 class MockExtensionSystem : public TestExtensionSystem { |
| 69 public: |
| 70 explicit MockExtensionSystem(Profile* profile); |
| 71 virtual ~MockExtensionSystem(); |
| 72 |
| 73 virtual EventRouter* event_router() OVERRIDE; |
| 74 |
| 75 private: |
| 76 scoped_ptr<EventRouter> event_router_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); |
| 79 }; |
| 80 |
| 81 // A Profile which returns an ExtensionService with enough functionality for |
| 82 // the tests. |
68 class MockProfile : public TestingProfile { | 83 class MockProfile : public TestingProfile { |
69 public: | 84 public: |
70 explicit MockProfile(const FilePath& file_path); | 85 explicit MockProfile(const FilePath& file_path); |
71 virtual ~MockProfile(); | 86 virtual ~MockProfile(); |
72 | 87 |
73 // Returns the same object as GetExtensionService, but not coaxed into an | 88 // Returns the same object as GetExtensionService, but not coaxed into an |
74 // ExtensionService; use this method from tests. | 89 // ExtensionService; use this method from tests. |
75 MockExtensionService* GetMockExtensionService(); | 90 MockExtensionService* GetMockExtensionService(); |
76 | |
77 virtual ExtensionService* GetExtensionService() OVERRIDE; | 91 virtual ExtensionService* GetExtensionService() OVERRIDE; |
78 virtual EventRouter* GetExtensionEventRouter() OVERRIDE; | |
79 | 92 |
80 private: | 93 private: |
81 MockExtensionService extension_service_; | 94 MockExtensionService extension_service_; |
82 scoped_ptr<EventRouter> event_router_; | |
83 }; | 95 }; |
84 | 96 |
85 // SettingsStorageFactory which acts as a wrapper for other factories. | 97 // SettingsStorageFactory which acts as a wrapper for other factories. |
86 class ScopedSettingsStorageFactory : public SettingsStorageFactory { | 98 class ScopedSettingsStorageFactory : public SettingsStorageFactory { |
87 public: | 99 public: |
88 ScopedSettingsStorageFactory(); | 100 ScopedSettingsStorageFactory(); |
89 | 101 |
90 explicit ScopedSettingsStorageFactory( | 102 explicit ScopedSettingsStorageFactory( |
91 const scoped_refptr<SettingsStorageFactory>& delegate); | 103 const scoped_refptr<SettingsStorageFactory>& delegate); |
92 | 104 |
93 // Sets the delegate factory (equivalent to scoped_ptr::reset). | 105 // Sets the delegate factory (equivalent to scoped_ptr::reset). |
94 void Reset(const scoped_refptr<SettingsStorageFactory>& delegate); | 106 void Reset(const scoped_refptr<SettingsStorageFactory>& delegate); |
95 | 107 |
96 // SettingsStorageFactory implementation. | 108 // SettingsStorageFactory implementation. |
97 virtual ValueStore* Create( | 109 virtual ValueStore* Create( |
98 const FilePath& base_path, const std::string& extension_id) OVERRIDE; | 110 const FilePath& base_path, const std::string& extension_id) OVERRIDE; |
99 | 111 |
100 private: | 112 private: |
101 // SettingsStorageFactory is refcounted. | 113 // SettingsStorageFactory is refcounted. |
102 virtual ~ScopedSettingsStorageFactory(); | 114 virtual ~ScopedSettingsStorageFactory(); |
103 | 115 |
104 scoped_refptr<SettingsStorageFactory> delegate_; | 116 scoped_refptr<SettingsStorageFactory> delegate_; |
105 }; | 117 }; |
106 | 118 |
107 } // namespace settings_test_util | 119 } // namespace settings_test_util |
108 | 120 |
109 } // namespace extensions | 121 } // namespace extensions |
110 | 122 |
111 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ | 123 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_TEST_UTIL_H_ |
OLD | NEW |