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

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

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

Powered by Google App Engine
This is Rietveld 408576698