Add testing/scripts/OWNERS
[chromium-blink-merge.git] / extensions / browser / api / storage / settings_test_util.h
blob262d1c1dc8cb01912dbe5ad2caff171ea8b06f3f
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/test/base/testing_profile.h"
16 #include "extensions/browser/api/storage/settings_namespace.h"
17 #include "extensions/browser/api/storage/settings_storage_factory.h"
18 #include "extensions/browser/event_router.h"
19 #include "extensions/browser/mock_extension_system.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 // Creates a kilobyte of data.
31 scoped_ptr<base::Value> CreateKilobyte();
33 // Creates a megabyte of data.
34 scoped_ptr<base::Value> CreateMegabyte();
36 // Synchronously gets the storage area for an extension from |frontend|.
37 ValueStore* GetStorage(scoped_refptr<const Extension> extension,
38 settings_namespace::Namespace setting_namespace,
39 StorageFrontend* frontend);
41 // Synchronously gets the SYNC storage for an extension from |frontend|.
42 ValueStore* GetStorage(scoped_refptr<const Extension> extension,
43 StorageFrontend* frontend);
45 // Creates an extension with |id| and adds it to the registry for |context|.
46 scoped_refptr<const Extension> AddExtensionWithId(
47 content::BrowserContext* context,
48 const std::string& id,
49 Manifest::Type type);
51 // Creates an extension with |id| with a set of |permissions| and adds it to
52 // the registry for |context|.
53 scoped_refptr<const Extension> AddExtensionWithIdAndPermissions(
54 content::BrowserContext* context,
55 const std::string& id,
56 Manifest::Type type,
57 const std::set<std::string>& permissions);
59 // A MockExtensionSystem to serve an EventRouter.
60 class MockExtensionSystemWithEventRouter : public MockExtensionSystem {
61 public:
62 explicit MockExtensionSystemWithEventRouter(content::BrowserContext* context);
63 ~MockExtensionSystemWithEventRouter() override;
65 // Factory method for SetTestingFactoryAndUse.
66 static KeyedService* Build(content::BrowserContext* context);
68 // MockExtensionSystem overrides:
69 EventRouter* event_router() override;
71 private:
72 scoped_ptr<EventRouter> event_router_;
74 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemWithEventRouter);
77 // SettingsStorageFactory which acts as a wrapper for other factories.
78 class ScopedSettingsStorageFactory : public SettingsStorageFactory {
79 public:
80 ScopedSettingsStorageFactory();
82 explicit ScopedSettingsStorageFactory(
83 const scoped_refptr<SettingsStorageFactory>& delegate);
85 // Sets the delegate factory (equivalent to scoped_ptr::reset).
86 void Reset(const scoped_refptr<SettingsStorageFactory>& delegate);
88 // SettingsStorageFactory implementation.
89 ValueStore* Create(const base::FilePath& base_path,
90 const std::string& extension_id) override;
91 void DeleteDatabaseIfExists(const base::FilePath& base_path,
92 const std::string& extension_id) override;
94 private:
95 // SettingsStorageFactory is refcounted.
96 ~ScopedSettingsStorageFactory() override;
98 scoped_refptr<SettingsStorageFactory> delegate_;
101 } // namespace settings_test_util
103 } // namespace extensions
105 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_TEST_UTIL_H_