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

Side by Side Diff: chrome/browser/extensions/api/storage/settings_sync_unittest.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 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 (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/run_loop.h"
11 #include "chrome/browser/extensions/api/storage/leveldb_settings_storage_factory .h" 11 #include "chrome/browser/extensions/api/storage/leveldb_settings_storage_factory .h"
12 #include "chrome/browser/extensions/api/storage/settings_frontend.h" 12 #include "chrome/browser/extensions/api/storage/settings_frontend.h"
13 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h" 13 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h"
14 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" 14 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
15 #include "chrome/browser/extensions/api/storage/settings_test_util.h" 15 #include "chrome/browser/extensions/api/storage/settings_test_util.h"
16 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" 16 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h"
17 #include "chrome/browser/extensions/extension_system.h" 17 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/extensions/test_extension_service.h" 18 #include "chrome/browser/extensions/test_extension_service.h"
19 #include "chrome/browser/value_store/testing_value_store.h" 19 #include "chrome/browser/value_store/testing_value_store.h"
20 #include "chrome/common/extensions/manifest.h" 20 #include "chrome/common/extensions/manifest.h"
21 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "sync/api/sync_change_processor.h" 23 #include "sync/api/sync_change_processor.h"
23 #include "sync/api/sync_error_factory.h" 24 #include "sync/api/sync_error_factory.h"
24 #include "sync/api/sync_error_factory_mock.h" 25 #include "sync/api/sync_error_factory_mock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 using base::DictionaryValue; 28 using base::DictionaryValue;
28 using base::ListValue; 29 using base::ListValue;
29 using base::Value; 30 using base::Value;
30 using content::BrowserThread; 31 using content::BrowserThread;
31 32
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // None of these storage areas are owned by this factory, so care must be 199 // None of these storage areas are owned by this factory, so care must be
199 // taken when calling GetExisting. 200 // taken when calling GetExisting.
200 std::map<std::string, TestingValueStore*> created_; 201 std::map<std::string, TestingValueStore*> created_;
201 }; 202 };
202 203
203 } // namespace 204 } // namespace
204 205
205 class ExtensionSettingsSyncTest : public testing::Test { 206 class ExtensionSettingsSyncTest : public testing::Test {
206 public: 207 public:
207 ExtensionSettingsSyncTest() 208 ExtensionSettingsSyncTest()
208 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 209 : storage_factory_(new util::ScopedSettingsStorageFactory()),
209 file_thread_(BrowserThread::FILE, base::MessageLoop::current()),
210 storage_factory_(new util::ScopedSettingsStorageFactory()),
211 sync_processor_(new MockSyncChangeProcessor), 210 sync_processor_(new MockSyncChangeProcessor),
212 sync_processor_delegate_(new SyncChangeProcessorDelegate( 211 sync_processor_delegate_(new SyncChangeProcessorDelegate(
213 sync_processor_.get())) {} 212 sync_processor_.get())) {}
214 213
215 virtual void SetUp() OVERRIDE { 214 virtual void SetUp() OVERRIDE {
216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 215 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
217 profile_.reset(new util::MockProfile(temp_dir_.path())); 216 profile_.reset(new util::MockProfile(temp_dir_.path()));
218 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); 217 storage_factory_->Reset(new LeveldbSettingsStorageFactory());
219 frontend_.reset( 218 frontend_.reset(
220 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); 219 SettingsFrontend::Create(storage_factory_.get(), profile_.get()));
221 } 220 }
222 221
223 virtual void TearDown() OVERRIDE { 222 virtual void TearDown() OVERRIDE {
224 frontend_.reset(); 223 frontend_.reset();
225 profile_.reset(); 224 profile_.reset();
226 // Execute any pending deletion tasks. 225 // Execute any pending deletion tasks.
227 message_loop_.RunUntilIdle(); 226 base::RunLoop().RunUntilIdle();
228 } 227 }
229 228
230 protected: 229 protected:
231 // 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
232 // its storage area. 231 // its storage area.
233 ValueStore* AddExtensionAndGetStorage( 232 ValueStore* AddExtensionAndGetStorage(
234 const std::string& id, Manifest::Type type) { 233 const std::string& id, Manifest::Type type) {
235 ExtensionServiceInterface* esi = 234 ExtensionServiceInterface* esi =
236 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); 235 extensions::ExtensionSystem::Get(profile_.get())->extension_service();
237 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> 236 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)->
(...skipping 16 matching lines...) Expand all
254 std::map<std::string, SettingSyncDataList> as_map; 253 std::map<std::string, SettingSyncDataList> as_map;
255 for (syncer::SyncDataList::iterator it = as_list.begin(); 254 for (syncer::SyncDataList::iterator it = as_list.begin();
256 it != as_list.end(); ++it) { 255 it != as_list.end(); ++it) {
257 SettingSyncData sync_data(*it); 256 SettingSyncData sync_data(*it);
258 as_map[sync_data.extension_id()].push_back(sync_data); 257 as_map[sync_data.extension_id()].push_back(sync_data);
259 } 258 }
260 return as_map; 259 return as_map;
261 } 260 }
262 261
263 // Need these so that the DCHECKs for running on FILE or UI threads pass. 262 // Need these so that the DCHECKs for running on FILE or UI threads pass.
264 base::MessageLoop message_loop_; 263 content::TestBrowserThreadBundle thread_bundle_;
265 content::TestBrowserThread ui_thread_;
266 content::TestBrowserThread file_thread_;
267 264
268 base::ScopedTempDir temp_dir_; 265 base::ScopedTempDir temp_dir_;
269 scoped_ptr<util::MockProfile> profile_; 266 scoped_ptr<util::MockProfile> profile_;
270 scoped_ptr<SettingsFrontend> frontend_; 267 scoped_ptr<SettingsFrontend> frontend_;
271 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; 268 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_;
272 scoped_ptr<MockSyncChangeProcessor> sync_processor_; 269 scoped_ptr<MockSyncChangeProcessor> sync_processor_;
273 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; 270 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_;
274 }; 271 };
275 272
276 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS 273 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 ASSERT_EQ(1u, sync_processor_->changes().size()); 1419 ASSERT_EQ(1u, sync_processor_->changes().size());
1423 SettingSyncData sync_data = sync_processor_->changes()[0]; 1420 SettingSyncData sync_data = sync_processor_->changes()[0];
1424 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type()); 1421 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type());
1425 EXPECT_EQ("ext", sync_data.extension_id()); 1422 EXPECT_EQ("ext", sync_data.extension_id());
1426 EXPECT_EQ("key.with.spot", sync_data.key()); 1423 EXPECT_EQ("key.with.spot", sync_data.key());
1427 EXPECT_TRUE(sync_data.value().Equals(string_value.get())); 1424 EXPECT_TRUE(sync_data.value().Equals(string_value.get()));
1428 } 1425 }
1429 } 1426 }
1430 1427
1431 } // namespace extensions 1428 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698