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

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: android webview init fix merged in. Created 7 years, 3 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 "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "extensions/common/manifest.h" 21 #include "extensions/common/manifest.h"
22 #include "sync/api/sync_change_processor.h" 22 #include "sync/api/sync_change_processor.h"
23 #include "sync/api/sync_error_factory.h" 23 #include "sync/api/sync_error_factory.h"
24 #include "sync/api/sync_error_factory_mock.h" 24 #include "sync/api/sync_error_factory_mock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 using base::DictionaryValue; 27 using base::DictionaryValue;
28 using base::ListValue; 28 using base::ListValue;
29 using base::Value; 29 using base::Value;
30 using content::BrowserThread;
31 30
32 namespace extensions { 31 namespace extensions {
33 32
34 namespace util = settings_test_util; 33 namespace util = settings_test_util;
35 34
36 namespace { 35 namespace {
37 36
38 // To save typing ValueStore::DEFAULTS everywhere. 37 // To save typing ValueStore::DEFAULTS everywhere.
39 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; 38 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS;
40 39
(...skipping 157 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 197 // None of these storage areas are owned by this factory, so care must be
199 // taken when calling GetExisting. 198 // taken when calling GetExisting.
200 std::map<std::string, TestingValueStore*> created_; 199 std::map<std::string, TestingValueStore*> created_;
201 }; 200 };
202 201
203 } // namespace 202 } // namespace
204 203
205 class ExtensionSettingsSyncTest : public testing::Test { 204 class ExtensionSettingsSyncTest : public testing::Test {
206 public: 205 public:
207 ExtensionSettingsSyncTest() 206 ExtensionSettingsSyncTest()
208 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 207 : storage_factory_(new util::ScopedSettingsStorageFactory()),
209 file_thread_(BrowserThread::FILE, base::MessageLoop::current()),
210 storage_factory_(new util::ScopedSettingsStorageFactory()),
211 sync_processor_(new MockSyncChangeProcessor), 208 sync_processor_(new MockSyncChangeProcessor),
212 sync_processor_delegate_(new SyncChangeProcessorDelegate( 209 sync_processor_delegate_(new SyncChangeProcessorDelegate(
213 sync_processor_.get())) {} 210 sync_processor_.get())) {}
214 211
215 virtual void SetUp() OVERRIDE { 212 virtual void SetUp() OVERRIDE {
216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 213 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
217 profile_.reset(new util::MockProfile(temp_dir_.path())); 214 profile_.reset(new util::MockProfile(temp_dir_.path()));
218 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); 215 storage_factory_->Reset(new LeveldbSettingsStorageFactory());
219 frontend_.reset( 216 frontend_.reset(
220 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); 217 SettingsFrontend::Create(storage_factory_.get(), profile_.get()));
221 } 218 }
222 219
223 virtual void TearDown() OVERRIDE { 220 virtual void TearDown() OVERRIDE {
224 frontend_.reset(); 221 frontend_.reset();
225 profile_.reset(); 222 profile_.reset();
226 // Execute any pending deletion tasks. 223 // Execute any pending deletion tasks.
227 message_loop_.RunUntilIdle(); 224 base::RunLoop().RunUntilIdle();
228 } 225 }
229 226
230 protected: 227 protected:
231 // Adds a record of an extension or app to the extension service, then returns 228 // Adds a record of an extension or app to the extension service, then returns
232 // its storage area. 229 // its storage area.
233 ValueStore* AddExtensionAndGetStorage( 230 ValueStore* AddExtensionAndGetStorage(
234 const std::string& id, Manifest::Type type) { 231 const std::string& id, Manifest::Type type) {
235 ExtensionServiceInterface* esi = 232 ExtensionServiceInterface* esi =
236 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); 233 extensions::ExtensionSystem::Get(profile_.get())->extension_service();
237 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> 234 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)->
(...skipping 16 matching lines...) Expand all
254 std::map<std::string, SettingSyncDataList> as_map; 251 std::map<std::string, SettingSyncDataList> as_map;
255 for (syncer::SyncDataList::iterator it = as_list.begin(); 252 for (syncer::SyncDataList::iterator it = as_list.begin();
256 it != as_list.end(); ++it) { 253 it != as_list.end(); ++it) {
257 SettingSyncData sync_data(*it); 254 SettingSyncData sync_data(*it);
258 as_map[sync_data.extension_id()].push_back(sync_data); 255 as_map[sync_data.extension_id()].push_back(sync_data);
259 } 256 }
260 return as_map; 257 return as_map;
261 } 258 }
262 259
263 // Need these so that the DCHECKs for running on FILE or UI threads pass. 260 // Need these so that the DCHECKs for running on FILE or UI threads pass.
264 base::MessageLoop message_loop_; 261 content::TestBrowserThreadBundle thread_bundle_;
265 content::TestBrowserThread ui_thread_;
266 content::TestBrowserThread file_thread_;
267 262
268 base::ScopedTempDir temp_dir_; 263 base::ScopedTempDir temp_dir_;
269 scoped_ptr<util::MockProfile> profile_; 264 scoped_ptr<util::MockProfile> profile_;
270 scoped_ptr<SettingsFrontend> frontend_; 265 scoped_ptr<SettingsFrontend> frontend_;
271 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; 266 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_;
272 scoped_ptr<MockSyncChangeProcessor> sync_processor_; 267 scoped_ptr<MockSyncChangeProcessor> sync_processor_;
273 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; 268 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_;
274 }; 269 };
275 270
276 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS 271 // 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()); 1417 ASSERT_EQ(1u, sync_processor_->changes().size());
1423 SettingSyncData sync_data = sync_processor_->changes()[0]; 1418 SettingSyncData sync_data = sync_processor_->changes()[0];
1424 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type()); 1419 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type());
1425 EXPECT_EQ("ext", sync_data.extension_id()); 1420 EXPECT_EQ("ext", sync_data.extension_id());
1426 EXPECT_EQ("key.with.spot", sync_data.key()); 1421 EXPECT_EQ("key.with.spot", sync_data.key());
1427 EXPECT_TRUE(sync_data.value().Equals(string_value.get())); 1422 EXPECT_TRUE(sync_data.value().Equals(string_value.get()));
1428 } 1423 }
1429 } 1424 }
1430 1425
1431 } // namespace extensions 1426 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/storage/settings_frontend_unittest.cc ('k') | chrome/browser/extensions/data_deleter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698