Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: extensions/browser/api/storage/settings_test_util.cc

Issue 472343003: Use ApiUnitTest for storage API tests (storage_api_unittest and storage_frontend_unittest). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "extensions/browser/api/storage/settings_test_util.h" 5 #include "extensions/browser/api/storage/settings_test_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "extensions/browser/api/storage/storage_frontend.h" 8 #include "extensions/browser/api/storage/storage_frontend.h"
9 #include "extensions/browser/extension_registry.h" 9 #include "extensions/browser/extension_registry.h"
10 #include "extensions/browser/extension_system_provider.h" 10 #include "extensions/browser/extension_system_provider.h"
11 #include "extensions/browser/extensions_browser_client.h" 11 #include "extensions/browser/extensions_browser_client.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/common/permissions/permissions_data.h" 13 #include "extensions/common/permissions/permissions_data.h"
14 14
15 namespace extensions { 15 namespace extensions {
16 16
17 namespace settings_test_util { 17 namespace settings_test_util {
18 18
19 // Creates a kilobyte of data.
20 scoped_ptr<base::Value> CreateKilobyte() {
21 std::string kilobyte_string;
22 for (int i = 0; i < 1024; ++i) {
23 kilobyte_string += "a";
24 }
25 return scoped_ptr<base::Value>(new base::StringValue(kilobyte_string));
26 }
27
28 // Creates a megabyte of data.
29 scoped_ptr<base::Value> CreateMegabyte() {
30 base::ListValue* megabyte = new base::ListValue();
31 for (int i = 0; i < 1000; ++i) {
Ken Rockot(use gerrit already) 2014/08/17 21:28:27 I hate to be that guy, but this isn't a megabyte!
Yoyo Zhou 2014/08/17 21:45:28 I noticed too!
not at google - send to devlin 2014/08/18 20:01:24 My bad. It's half way between a real and a bizarro
32 megabyte->Append(CreateKilobyte().release());
33 }
34 return scoped_ptr<base::Value>(megabyte);
35 }
36
19 // Intended as a StorageCallback from GetStorage. 37 // Intended as a StorageCallback from GetStorage.
20 static void AssignStorage(ValueStore** dst, ValueStore* src) { 38 static void AssignStorage(ValueStore** dst, ValueStore* src) {
21 *dst = src; 39 *dst = src;
22 } 40 }
23 41
24 ValueStore* GetStorage(scoped_refptr<const Extension> extension, 42 ValueStore* GetStorage(scoped_refptr<const Extension> extension,
25 settings_namespace::Namespace settings_namespace, 43 settings_namespace::Namespace settings_namespace,
26 StorageFrontend* frontend) { 44 StorageFrontend* frontend) {
27 ValueStore* storage = NULL; 45 ValueStore* storage = NULL;
28 frontend->RunWithStorage( 46 frontend->RunWithStorage(
29 extension, settings_namespace, base::Bind(&AssignStorage, &storage)); 47 extension, settings_namespace, base::Bind(&AssignStorage, &storage));
30 base::MessageLoop::current()->RunUntilIdle(); 48 base::MessageLoop::current()->RunUntilIdle();
31 return storage; 49 return storage;
32 } 50 }
33 51
34 ValueStore* GetStorage(scoped_refptr<const Extension> extension, 52 ValueStore* GetStorage(scoped_refptr<const Extension> extension,
35 StorageFrontend* frontend) { 53 StorageFrontend* frontend) {
36 return GetStorage(extension, settings_namespace::SYNC, frontend); 54 return GetStorage(extension, settings_namespace::SYNC, frontend);
37 } 55 }
38 56
39 scoped_refptr<const Extension> AddExtensionWithId(Profile* profile, 57 scoped_refptr<const Extension> AddExtensionWithId(
40 const std::string& id, 58 content::BrowserContext* context,
41 Manifest::Type type) { 59 const std::string& id,
60 Manifest::Type type) {
42 return AddExtensionWithIdAndPermissions( 61 return AddExtensionWithIdAndPermissions(
43 profile, id, type, std::set<std::string>()); 62 context, id, type, std::set<std::string>());
44 } 63 }
45 64
46 scoped_refptr<const Extension> AddExtensionWithIdAndPermissions( 65 scoped_refptr<const Extension> AddExtensionWithIdAndPermissions(
47 Profile* profile, 66 content::BrowserContext* context,
48 const std::string& id, 67 const std::string& id,
49 Manifest::Type type, 68 Manifest::Type type,
50 const std::set<std::string>& permissions_set) { 69 const std::set<std::string>& permissions_set) {
51 base::DictionaryValue manifest; 70 base::DictionaryValue manifest;
52 manifest.SetString("name", std::string("Test extension ") + id); 71 manifest.SetString("name", std::string("Test extension ") + id);
53 manifest.SetString("version", "1.0"); 72 manifest.SetString("version", "1.0");
54 73
55 scoped_ptr<base::ListValue> permissions(new base::ListValue()); 74 scoped_ptr<base::ListValue> permissions(new base::ListValue());
56 for (std::set<std::string>::const_iterator it = permissions_set.begin(); 75 for (std::set<std::string>::const_iterator it = permissions_set.begin();
57 it != permissions_set.end(); ++it) { 76 it != permissions_set.end(); ++it) {
(...skipping 24 matching lines...) Expand all
82 Manifest::INTERNAL, 101 Manifest::INTERNAL,
83 manifest, 102 manifest,
84 Extension::NO_FLAGS, 103 Extension::NO_FLAGS,
85 id, 104 id,
86 &error)); 105 &error));
87 DCHECK(extension.get()); 106 DCHECK(extension.get());
88 DCHECK(error.empty()); 107 DCHECK(error.empty());
89 108
90 // Ensure lookups via ExtensionRegistry (and ExtensionService) work even if 109 // Ensure lookups via ExtensionRegistry (and ExtensionService) work even if
91 // the test discards the referenced to the returned extension. 110 // the test discards the referenced to the returned extension.
92 ExtensionRegistry::Get(profile)->AddEnabled(extension); 111 ExtensionRegistry::Get(context)->AddEnabled(extension);
93 112
94 for (std::set<std::string>::const_iterator it = permissions_set.begin(); 113 for (std::set<std::string>::const_iterator it = permissions_set.begin();
95 it != permissions_set.end(); ++it) { 114 it != permissions_set.end(); ++it) {
96 DCHECK(extension->permissions_data()->HasAPIPermission(*it)); 115 DCHECK(extension->permissions_data()->HasAPIPermission(*it));
97 } 116 }
98 117
99 return extension; 118 return extension;
100 } 119 }
101 120
102 // MockExtensionSystem 121 // MockExtensionSystemWithEventRouter
103 122
104 MockExtensionSystem::MockExtensionSystem(Profile* profile) 123 MockExtensionSystemWithEventRouter::MockExtensionSystemWithEventRouter(
105 : TestExtensionSystem(profile) {} 124 content::BrowserContext* context)
106 MockExtensionSystem::~MockExtensionSystem() {} 125 : MockExtensionSystem(context) {
126 }
107 127
108 EventRouter* MockExtensionSystem::event_router() { 128 MockExtensionSystemWithEventRouter::~MockExtensionSystemWithEventRouter() {
129 }
130
131 KeyedService* MockExtensionSystemWithEventRouter::Build(
132 content::BrowserContext* context) {
133 return new MockExtensionSystemWithEventRouter(context);
134 }
135
136 EventRouter* MockExtensionSystemWithEventRouter::event_router() {
109 if (!event_router_.get()) 137 if (!event_router_.get())
110 event_router_.reset(new EventRouter(profile_, NULL)); 138 event_router_.reset(new EventRouter(browser_context(), NULL));
111 return event_router_.get(); 139 return event_router_.get();
112 } 140 }
113 141
114 KeyedService* BuildMockExtensionSystem(content::BrowserContext* profile) {
115 return new MockExtensionSystem(static_cast<Profile*>(profile));
116 }
117
118 // MockProfile
119
120 MockProfile::MockProfile(const base::FilePath& file_path)
121 : TestingProfile(file_path) {
122 ExtensionsBrowserClient::Get()
123 ->GetExtensionSystemFactory()
124 ->SetTestingFactoryAndUse(this, &BuildMockExtensionSystem);
125 }
126
127 MockProfile::~MockProfile() {}
128
129 // ScopedSettingsFactory 142 // ScopedSettingsFactory
130 143
131 ScopedSettingsStorageFactory::ScopedSettingsStorageFactory() {} 144 ScopedSettingsStorageFactory::ScopedSettingsStorageFactory() {}
132 145
133 ScopedSettingsStorageFactory::ScopedSettingsStorageFactory( 146 ScopedSettingsStorageFactory::ScopedSettingsStorageFactory(
134 const scoped_refptr<SettingsStorageFactory>& delegate) 147 const scoped_refptr<SettingsStorageFactory>& delegate)
135 : delegate_(delegate) {} 148 : delegate_(delegate) {}
136 149
137 ScopedSettingsStorageFactory::~ScopedSettingsStorageFactory() {} 150 ScopedSettingsStorageFactory::~ScopedSettingsStorageFactory() {}
138 151
(...skipping 11 matching lines...) Expand all
150 163
151 void ScopedSettingsStorageFactory::DeleteDatabaseIfExists( 164 void ScopedSettingsStorageFactory::DeleteDatabaseIfExists(
152 const base::FilePath& base_path, 165 const base::FilePath& base_path,
153 const std::string& extension_id) { 166 const std::string& extension_id) {
154 delegate_->DeleteDatabaseIfExists(base_path, extension_id); 167 delegate_->DeleteDatabaseIfExists(base_path, extension_id);
155 } 168 }
156 169
157 } // namespace settings_test_util 170 } // namespace settings_test_util
158 171
159 } // namespace extensions 172 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/storage/settings_test_util.h ('k') | extensions/browser/api/storage/storage_api_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698