| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_TEST_UTIL_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_TEST_UTIL_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 | |
| 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_storage_factory.h" | |
| 16 #include "chrome/browser/extensions/extension_service.h" | |
| 17 #include "chrome/browser/extensions/test_extension_service.h" | |
| 18 #include "chrome/browser/extensions/test_extension_system.h" | |
| 19 #include "chrome/test/base/testing_profile.h" | |
| 20 #include "extensions/browser/api/storage/settings_namespace.h" | |
| 21 #include "extensions/browser/event_router.h" | |
| 22 #include "extensions/common/extension.h" | |
| 23 | |
| 24 class ValueStore; | |
| 25 | |
| 26 namespace extensions { | |
| 27 | |
| 28 class SettingsFrontend; | |
| 29 // Utilities for extension settings API tests. | |
| 30 namespace settings_test_util { | |
| 31 | |
| 32 // Synchronously gets the storage area for an extension from |frontend|. | |
| 33 ValueStore* GetStorage(scoped_refptr<const Extension> extension, | |
| 34 settings_namespace::Namespace setting_namespace, | |
| 35 SettingsFrontend* frontend); | |
| 36 | |
| 37 // Synchronously gets the SYNC storage for an extension from |frontend|. | |
| 38 ValueStore* GetStorage(scoped_refptr<const Extension> extension, | |
| 39 SettingsFrontend* frontend); | |
| 40 | |
| 41 // Creates an extension with |id| and adds it to the registry for |profile|. | |
| 42 scoped_refptr<const Extension> AddExtensionWithId(Profile* profile, | |
| 43 const std::string& id, | |
| 44 Manifest::Type type); | |
| 45 | |
| 46 // Creates an extension with |id| with a set of |permissions| and adds it to | |
| 47 // the registry for |profile|. | |
| 48 scoped_refptr<const Extension> AddExtensionWithIdAndPermissions( | |
| 49 Profile* profile, | |
| 50 const std::string& id, | |
| 51 Manifest::Type type, | |
| 52 const std::set<std::string>& permissions); | |
| 53 | |
| 54 // A mock ExtensionSystem to serve an EventRouter. | |
| 55 class MockExtensionSystem : public TestExtensionSystem { | |
| 56 public: | |
| 57 explicit MockExtensionSystem(Profile* profile); | |
| 58 virtual ~MockExtensionSystem(); | |
| 59 | |
| 60 virtual EventRouter* event_router() OVERRIDE; | |
| 61 virtual ExtensionService* extension_service() OVERRIDE; | |
| 62 | |
| 63 private: | |
| 64 scoped_ptr<EventRouter> event_router_; | |
| 65 TestExtensionService extension_service_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); | |
| 68 }; | |
| 69 | |
| 70 // A Profile which returns an ExtensionService with enough functionality for | |
| 71 // the tests. | |
| 72 class MockProfile : public TestingProfile { | |
| 73 public: | |
| 74 explicit MockProfile(const base::FilePath& file_path); | |
| 75 virtual ~MockProfile(); | |
| 76 }; | |
| 77 | |
| 78 // SettingsStorageFactory which acts as a wrapper for other factories. | |
| 79 class ScopedSettingsStorageFactory : public SettingsStorageFactory { | |
| 80 public: | |
| 81 ScopedSettingsStorageFactory(); | |
| 82 | |
| 83 explicit ScopedSettingsStorageFactory( | |
| 84 const scoped_refptr<SettingsStorageFactory>& delegate); | |
| 85 | |
| 86 // Sets the delegate factory (equivalent to scoped_ptr::reset). | |
| 87 void Reset(const scoped_refptr<SettingsStorageFactory>& delegate); | |
| 88 | |
| 89 // SettingsStorageFactory implementation. | |
| 90 virtual ValueStore* Create(const base::FilePath& base_path, | |
| 91 const std::string& extension_id) OVERRIDE; | |
| 92 virtual void DeleteDatabaseIfExists( | |
| 93 const base::FilePath& base_path, | |
| 94 const std::string& extension_id) OVERRIDE; | |
| 95 | |
| 96 private: | |
| 97 // SettingsStorageFactory is refcounted. | |
| 98 virtual ~ScopedSettingsStorageFactory(); | |
| 99 | |
| 100 scoped_refptr<SettingsStorageFactory> delegate_; | |
| 101 }; | |
| 102 | |
| 103 } // namespace settings_test_util | |
| 104 | |
| 105 } // namespace extensions | |
| 106 | |
| 107 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_TEST_UTIL_H_ | |
| OLD | NEW |