Update path of checkdeps to buildtools checkout
[chromium-blink-merge.git] / extensions / browser / api / storage / settings_test_util.h
blobee3e64caf7d96742c6406fe0087938ec78b222e4
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_
6 #define EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_
8 #include <set>
9 #include <string>
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/test_extension_system.h"
16 #include "chrome/test/base/testing_profile.h"
17 #include "extensions/browser/api/storage/settings_namespace.h"
18 #include "extensions/browser/api/storage/settings_storage_factory.h"
19 #include "extensions/browser/event_router.h"
20 #include "extensions/common/extension.h"
22 class ValueStore;
24 namespace extensions {
26 class StorageFrontend;
27 // Utilities for extension settings API tests.
28 namespace settings_test_util {
30 // Synchronously gets the storage area for an extension from |frontend|.
31 ValueStore* GetStorage(scoped_refptr<const Extension> extension,
32 settings_namespace::Namespace setting_namespace,
33 StorageFrontend* frontend);
35 // Synchronously gets the SYNC storage for an extension from |frontend|.
36 ValueStore* GetStorage(scoped_refptr<const Extension> extension,
37 StorageFrontend* frontend);
39 // Creates an extension with |id| and adds it to the registry for |profile|.
40 scoped_refptr<const Extension> AddExtensionWithId(Profile* profile,
41 const std::string& id,
42 Manifest::Type type);
44 // Creates an extension with |id| with a set of |permissions| and adds it to
45 // the registry for |profile|.
46 scoped_refptr<const Extension> AddExtensionWithIdAndPermissions(
47 Profile* profile,
48 const std::string& id,
49 Manifest::Type type,
50 const std::set<std::string>& permissions);
52 // A mock ExtensionSystem to serve an EventRouter.
53 class MockExtensionSystem : public TestExtensionSystem {
54 public:
55 explicit MockExtensionSystem(Profile* profile);
56 virtual ~MockExtensionSystem();
58 virtual EventRouter* event_router() OVERRIDE;
60 private:
61 scoped_ptr<EventRouter> event_router_;
63 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem);
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();
74 // SettingsStorageFactory which acts as a wrapper for other factories.
75 class ScopedSettingsStorageFactory : public SettingsStorageFactory {
76 public:
77 ScopedSettingsStorageFactory();
79 explicit ScopedSettingsStorageFactory(
80 const scoped_refptr<SettingsStorageFactory>& delegate);
82 // Sets the delegate factory (equivalent to scoped_ptr::reset).
83 void Reset(const scoped_refptr<SettingsStorageFactory>& delegate);
85 // SettingsStorageFactory implementation.
86 virtual ValueStore* Create(const base::FilePath& base_path,
87 const std::string& extension_id) OVERRIDE;
88 virtual void DeleteDatabaseIfExists(
89 const base::FilePath& base_path,
90 const std::string& extension_id) OVERRIDE;
92 private:
93 // SettingsStorageFactory is refcounted.
94 virtual ~ScopedSettingsStorageFactory();
96 scoped_refptr<SettingsStorageFactory> delegate_;
99 } // namespace settings_test_util
101 } // namespace extensions
103 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_