OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_ |
6 #define EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_ | 6 #define EXTENSIONS_BROWSER_API_STORAGE_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/test_extension_system.h" | |
16 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
17 #include "extensions/browser/api/storage/settings_namespace.h" | 16 #include "extensions/browser/api/storage/settings_namespace.h" |
18 #include "extensions/browser/api/storage/settings_storage_factory.h" | 17 #include "extensions/browser/api/storage/settings_storage_factory.h" |
19 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/browser/mock_extension_system.h" |
20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
21 | 21 |
22 class ValueStore; | 22 class ValueStore; |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
26 class StorageFrontend; | 26 class StorageFrontend; |
27 // Utilities for extension settings API tests. | 27 // Utilities for extension settings API tests. |
28 namespace settings_test_util { | 28 namespace settings_test_util { |
29 | 29 |
| 30 // Creates a kilobyte of data. |
| 31 scoped_ptr<base::Value> CreateKilobyte(); |
| 32 |
| 33 // Creates a megabyte of data. |
| 34 scoped_ptr<base::Value> CreateMegabyte(); |
| 35 |
30 // Synchronously gets the storage area for an extension from |frontend|. | 36 // Synchronously gets the storage area for an extension from |frontend|. |
31 ValueStore* GetStorage(scoped_refptr<const Extension> extension, | 37 ValueStore* GetStorage(scoped_refptr<const Extension> extension, |
32 settings_namespace::Namespace setting_namespace, | 38 settings_namespace::Namespace setting_namespace, |
33 StorageFrontend* frontend); | 39 StorageFrontend* frontend); |
34 | 40 |
35 // Synchronously gets the SYNC storage for an extension from |frontend|. | 41 // Synchronously gets the SYNC storage for an extension from |frontend|. |
36 ValueStore* GetStorage(scoped_refptr<const Extension> extension, | 42 ValueStore* GetStorage(scoped_refptr<const Extension> extension, |
37 StorageFrontend* frontend); | 43 StorageFrontend* frontend); |
38 | 44 |
39 // Creates an extension with |id| and adds it to the registry for |profile|. | 45 // Creates an extension with |id| and adds it to the registry for |context|. |
40 scoped_refptr<const Extension> AddExtensionWithId(Profile* profile, | 46 scoped_refptr<const Extension> AddExtensionWithId( |
41 const std::string& id, | 47 content::BrowserContext* context, |
42 Manifest::Type type); | 48 const std::string& id, |
| 49 Manifest::Type type); |
43 | 50 |
44 // Creates an extension with |id| with a set of |permissions| and adds it to | 51 // Creates an extension with |id| with a set of |permissions| and adds it to |
45 // the registry for |profile|. | 52 // the registry for |context|. |
46 scoped_refptr<const Extension> AddExtensionWithIdAndPermissions( | 53 scoped_refptr<const Extension> AddExtensionWithIdAndPermissions( |
47 Profile* profile, | 54 content::BrowserContext* context, |
48 const std::string& id, | 55 const std::string& id, |
49 Manifest::Type type, | 56 Manifest::Type type, |
50 const std::set<std::string>& permissions); | 57 const std::set<std::string>& permissions); |
51 | 58 |
52 // A mock ExtensionSystem to serve an EventRouter. | 59 // A MockExtensionSystem to serve an EventRouter. |
53 class MockExtensionSystem : public TestExtensionSystem { | 60 class MockExtensionSystemWithEventRouter : public MockExtensionSystem { |
54 public: | 61 public: |
55 explicit MockExtensionSystem(Profile* profile); | 62 explicit MockExtensionSystemWithEventRouter(content::BrowserContext* context); |
56 virtual ~MockExtensionSystem(); | 63 virtual ~MockExtensionSystemWithEventRouter(); |
57 | 64 |
| 65 // Factory method for SetTestingFactoryAndUse. |
| 66 static KeyedService* Build(content::BrowserContext* context); |
| 67 |
| 68 // MockExtensionSystem overrides: |
58 virtual EventRouter* event_router() OVERRIDE; | 69 virtual EventRouter* event_router() OVERRIDE; |
59 | 70 |
60 private: | 71 private: |
61 scoped_ptr<EventRouter> event_router_; | 72 scoped_ptr<EventRouter> event_router_; |
62 | 73 |
63 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); | 74 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemWithEventRouter); |
64 }; | |
65 | |
66 // A Profile which returns an ExtensionSystem with enough functionality for | |
67 // the tests. | |
68 class MockProfile : public TestingProfile { | |
69 public: | |
70 explicit MockProfile(const base::FilePath& file_path); | |
71 virtual ~MockProfile(); | |
72 }; | 75 }; |
73 | 76 |
74 // SettingsStorageFactory which acts as a wrapper for other factories. | 77 // SettingsStorageFactory which acts as a wrapper for other factories. |
75 class ScopedSettingsStorageFactory : public SettingsStorageFactory { | 78 class ScopedSettingsStorageFactory : public SettingsStorageFactory { |
76 public: | 79 public: |
77 ScopedSettingsStorageFactory(); | 80 ScopedSettingsStorageFactory(); |
78 | 81 |
79 explicit ScopedSettingsStorageFactory( | 82 explicit ScopedSettingsStorageFactory( |
80 const scoped_refptr<SettingsStorageFactory>& delegate); | 83 const scoped_refptr<SettingsStorageFactory>& delegate); |
81 | 84 |
(...skipping 12 matching lines...) Expand all Loading... |
94 virtual ~ScopedSettingsStorageFactory(); | 97 virtual ~ScopedSettingsStorageFactory(); |
95 | 98 |
96 scoped_refptr<SettingsStorageFactory> delegate_; | 99 scoped_refptr<SettingsStorageFactory> delegate_; |
97 }; | 100 }; |
98 | 101 |
99 } // namespace settings_test_util | 102 } // namespace settings_test_util |
100 | 103 |
101 } // namespace extensions | 104 } // namespace extensions |
102 | 105 |
103 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_ | 106 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_ |
OLD | NEW |