OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 // SyncChangeProcessor which just records the changes made, accessed after | 91 // SyncChangeProcessor which just records the changes made, accessed after |
92 // being converted to the more useful SettingSyncData via changes(). | 92 // being converted to the more useful SettingSyncData via changes(). |
93 class MockSyncChangeProcessor : public syncer::SyncChangeProcessor { | 93 class MockSyncChangeProcessor : public syncer::SyncChangeProcessor { |
94 public: | 94 public: |
95 MockSyncChangeProcessor() : fail_all_requests_(false) {} | 95 MockSyncChangeProcessor() : fail_all_requests_(false) {} |
96 | 96 |
97 // syncer::SyncChangeProcessor implementation. | 97 // syncer::SyncChangeProcessor implementation. |
98 virtual syncer::SyncError ProcessSyncChanges( | 98 virtual syncer::SyncError ProcessSyncChanges( |
99 const tracked_objects::Location& from_here, | 99 const tracked_objects::Location& from_here, |
100 const syncer::SyncChangeList& change_list) OVERRIDE { | 100 const syncer::SyncChangeList& change_list) override { |
101 if (fail_all_requests_) { | 101 if (fail_all_requests_) { |
102 return syncer::SyncError( | 102 return syncer::SyncError( |
103 FROM_HERE, | 103 FROM_HERE, |
104 syncer::SyncError::DATATYPE_ERROR, | 104 syncer::SyncError::DATATYPE_ERROR, |
105 "MockSyncChangeProcessor: configured to fail", | 105 "MockSyncChangeProcessor: configured to fail", |
106 change_list[0].sync_data().GetDataType()); | 106 change_list[0].sync_data().GetDataType()); |
107 } | 107 } |
108 for (syncer::SyncChangeList::const_iterator it = change_list.begin(); | 108 for (syncer::SyncChangeList::const_iterator it = change_list.begin(); |
109 it != change_list.end(); ++it) { | 109 it != change_list.end(); ++it) { |
110 changes_.push_back(SettingSyncData(*it)); | 110 changes_.push_back(SettingSyncData(*it)); |
111 } | 111 } |
112 return syncer::SyncError(); | 112 return syncer::SyncError(); |
113 } | 113 } |
114 | 114 |
115 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | 115 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const |
116 OVERRIDE { | 116 override { |
117 return syncer::SyncDataList(); | 117 return syncer::SyncDataList(); |
118 } | 118 } |
119 | 119 |
120 // Mock methods. | 120 // Mock methods. |
121 | 121 |
122 const SettingSyncDataList& changes() { return changes_; } | 122 const SettingSyncDataList& changes() { return changes_; } |
123 | 123 |
124 void ClearChanges() { | 124 void ClearChanges() { |
125 changes_.clear(); | 125 changes_.clear(); |
126 } | 126 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // and allows individually created objects to be returned. | 165 // and allows individually created objects to be returned. |
166 class TestingValueStoreFactory : public SettingsStorageFactory { | 166 class TestingValueStoreFactory : public SettingsStorageFactory { |
167 public: | 167 public: |
168 TestingValueStore* GetExisting(const std::string& extension_id) { | 168 TestingValueStore* GetExisting(const std::string& extension_id) { |
169 DCHECK(created_.count(extension_id)); | 169 DCHECK(created_.count(extension_id)); |
170 return created_[extension_id]; | 170 return created_[extension_id]; |
171 } | 171 } |
172 | 172 |
173 // SettingsStorageFactory implementation. | 173 // SettingsStorageFactory implementation. |
174 virtual ValueStore* Create(const base::FilePath& base_path, | 174 virtual ValueStore* Create(const base::FilePath& base_path, |
175 const std::string& extension_id) OVERRIDE { | 175 const std::string& extension_id) override { |
176 TestingValueStore* new_storage = new TestingValueStore(); | 176 TestingValueStore* new_storage = new TestingValueStore(); |
177 DCHECK(!created_.count(extension_id)); | 177 DCHECK(!created_.count(extension_id)); |
178 created_[extension_id] = new_storage; | 178 created_[extension_id] = new_storage; |
179 return new_storage; | 179 return new_storage; |
180 } | 180 } |
181 | 181 |
182 // Testing value stores don't actually create a real database. Don't delete | 182 // Testing value stores don't actually create a real database. Don't delete |
183 // any files. | 183 // any files. |
184 virtual void DeleteDatabaseIfExists( | 184 virtual void DeleteDatabaseIfExists( |
185 const base::FilePath& base_path, | 185 const base::FilePath& base_path, |
186 const std::string& extension_id) OVERRIDE {} | 186 const std::string& extension_id) override {} |
187 | 187 |
188 private: | 188 private: |
189 // SettingsStorageFactory is refcounted. | 189 // SettingsStorageFactory is refcounted. |
190 virtual ~TestingValueStoreFactory() {} | 190 virtual ~TestingValueStoreFactory() {} |
191 | 191 |
192 // None of these storage areas are owned by this factory, so care must be | 192 // None of these storage areas are owned by this factory, so care must be |
193 // taken when calling GetExisting. | 193 // taken when calling GetExisting. |
194 std::map<std::string, TestingValueStore*> created_; | 194 std::map<std::string, TestingValueStore*> created_; |
195 }; | 195 }; |
196 | 196 |
197 } // namespace | 197 } // namespace |
198 | 198 |
199 class ExtensionSettingsSyncTest : public testing::Test { | 199 class ExtensionSettingsSyncTest : public testing::Test { |
200 public: | 200 public: |
201 ExtensionSettingsSyncTest() | 201 ExtensionSettingsSyncTest() |
202 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | 202 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), |
203 file_thread_(BrowserThread::FILE, base::MessageLoop::current()), | 203 file_thread_(BrowserThread::FILE, base::MessageLoop::current()), |
204 storage_factory_(new util::ScopedSettingsStorageFactory()), | 204 storage_factory_(new util::ScopedSettingsStorageFactory()), |
205 sync_processor_(new MockSyncChangeProcessor), | 205 sync_processor_(new MockSyncChangeProcessor), |
206 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( | 206 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( |
207 sync_processor_.get())) {} | 207 sync_processor_.get())) {} |
208 | 208 |
209 virtual void SetUp() OVERRIDE { | 209 virtual void SetUp() override { |
210 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 210 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
211 profile_.reset(new TestingProfile(temp_dir_.path())); | 211 profile_.reset(new TestingProfile(temp_dir_.path())); |
212 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); | 212 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); |
213 frontend_.reset( | 213 frontend_.reset( |
214 StorageFrontend::CreateForTesting(storage_factory_, profile_.get())); | 214 StorageFrontend::CreateForTesting(storage_factory_, profile_.get())); |
215 | 215 |
216 ExtensionsBrowserClient::Get() | 216 ExtensionsBrowserClient::Get() |
217 ->GetExtensionSystemFactory() | 217 ->GetExtensionSystemFactory() |
218 ->SetTestingFactoryAndUse( | 218 ->SetTestingFactoryAndUse( |
219 profile_.get(), &util::MockExtensionSystemWithEventRouter::Build); | 219 profile_.get(), &util::MockExtensionSystemWithEventRouter::Build); |
220 } | 220 } |
221 | 221 |
222 virtual void TearDown() OVERRIDE { | 222 virtual void TearDown() override { |
223 frontend_.reset(); | 223 frontend_.reset(); |
224 profile_.reset(); | 224 profile_.reset(); |
225 // Execute any pending deletion tasks. | 225 // Execute any pending deletion tasks. |
226 message_loop_.RunUntilIdle(); | 226 message_loop_.RunUntilIdle(); |
227 } | 227 } |
228 | 228 |
229 protected: | 229 protected: |
230 // Adds a record of an extension or app to the extension service, then returns | 230 // Adds a record of an extension or app to the extension service, then returns |
231 // its storage area. | 231 // its storage area. |
232 ValueStore* AddExtensionAndGetStorage( | 232 ValueStore* AddExtensionAndGetStorage( |
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 settings_namespace::SYNC, | 1486 settings_namespace::SYNC, |
1487 base::Bind(&UnlimitedSyncStorageTestCallback)); | 1487 base::Bind(&UnlimitedSyncStorageTestCallback)); |
1488 frontend_->RunWithStorage(extension, | 1488 frontend_->RunWithStorage(extension, |
1489 settings_namespace::LOCAL, | 1489 settings_namespace::LOCAL, |
1490 base::Bind(&UnlimitedLocalStorageTestCallback)); | 1490 base::Bind(&UnlimitedLocalStorageTestCallback)); |
1491 | 1491 |
1492 base::MessageLoop::current()->RunUntilIdle(); | 1492 base::MessageLoop::current()->RunUntilIdle(); |
1493 } | 1493 } |
1494 | 1494 |
1495 } // namespace extensions | 1495 } // namespace extensions |
OLD | NEW |