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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_TEST_UTIL_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_TEST_UTIL_H_
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/api/storage/settings_namespace.h"
16 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h"
17 #include "chrome/browser/extensions/event_router.h"
18 #include "chrome/browser/extensions/extension_service.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"
26 namespace extensions {
28 class SettingsFrontend;
29 // Utilities for extension settings API tests.
30 namespace settings_test_util {
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);
38 // Synchronously gets the SYNC storage for an extension from |frontend|.
39 ValueStore* GetStorage(
40 const std::string& extension_id,
41 SettingsFrontend* frontend);
43 // An ExtensionService which allows extensions to be hand-added to be returned
44 // by GetExtensionById.
45 class MockExtensionService : public TestExtensionService {
47 MockExtensionService();
48 virtual ~MockExtensionService();
50 // Adds an extension with id |id| to be returned by GetExtensionById.
51 void AddExtensionWithId(const std::string& id, Manifest::Type type);
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,
58 const std::set<std::string>& permissions);
60 virtual const Extension* GetExtensionById(
61 const std::string& id, bool include_disabled) const OVERRIDE;
64 std::map<std::string, scoped_refptr<Extension> > extensions_;
67 // A mock ExtensionSystem to serve an EventRouter.
68 class MockExtensionSystem : public TestExtensionSystem {
70 explicit MockExtensionSystem(Profile* profile);
71 virtual ~MockExtensionSystem();
73 virtual EventRouter* event_router() OVERRIDE;
74 virtual ExtensionService* extension_service() OVERRIDE;
77 scoped_ptr<EventRouter> event_router_;
78 MockExtensionService extension_service_;
80 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem);
83 // A Profile which returns an ExtensionService with enough functionality for
85 class MockProfile : public TestingProfile {
87 explicit MockProfile(const base::FilePath& file_path);
88 virtual ~MockProfile();
91 // SettingsStorageFactory which acts as a wrapper for other factories.
92 class ScopedSettingsStorageFactory : public SettingsStorageFactory {
94 ScopedSettingsStorageFactory();
96 explicit ScopedSettingsStorageFactory(
97 const scoped_refptr<SettingsStorageFactory>& delegate);
99 // Sets the delegate factory (equivalent to scoped_ptr::reset).
100 void Reset(const scoped_refptr<SettingsStorageFactory>& delegate);
102 // SettingsStorageFactory implementation.
103 virtual ValueStore* Create(const base::FilePath& base_path,
104 const std::string& extension_id) OVERRIDE;
107 // SettingsStorageFactory is refcounted.
108 virtual ~ScopedSettingsStorageFactory();
110 scoped_refptr<SettingsStorageFactory> delegate_;
113 } // namespace settings_test_util
115 } // namespace extensions
117 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_TEST_UTIL_H_