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

Side by Side Diff: chrome/browser/sync/abstract_profile_sync_service_test.cc

Issue 10958007: sync: Refactor CreateRoot() test helper function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Found more stuff to clean up Created 8 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 "chrome/browser/sync/abstract_profile_sync_service_test.h" 5 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "chrome/browser/sync/test_profile_sync_service.h" 10 #include "chrome/browser/sync/test_profile_sync_service.h"
11 #include "sync/internal_api/public/test/test_user_share.h"
11 #include "sync/internal_api/public/write_transaction.h" 12 #include "sync/internal_api/public/write_transaction.h"
12 #include "sync/protocol/sync.pb.h" 13 #include "sync/protocol/sync.pb.h"
13 #include "sync/syncable/entry.h"
14 #include "sync/syncable/mutable_entry.h"
15 #include "sync/syncable/write_transaction.h"
16 #include "sync/test/engine/test_id_factory.h"
17 #include "sync/util/cryptographer.h" 14 #include "sync/util/cryptographer.h"
18 15
19 using syncer::TestIdFactory;
20 using content::BrowserThread; 16 using content::BrowserThread;
21 using syncer::ModelType; 17 using syncer::ModelType;
22 using syncer::UserShare; 18 using syncer::UserShare;
23 using syncer::syncable::BASE_VERSION;
24 using syncer::syncable::CREATE;
25 using syncer::syncable::IS_DEL;
26 using syncer::syncable::IS_DIR;
27 using syncer::syncable::IS_UNAPPLIED_UPDATE;
28 using syncer::syncable::IS_UNSYNCED;
29 using syncer::syncable::MutableEntry;
30 using syncer::syncable::SERVER_IS_DIR;
31 using syncer::syncable::SERVER_VERSION;
32 using syncer::syncable::SPECIFICS;
33 using syncer::syncable::UNIQUE_SERVER_TAG;
34 using syncer::syncable::UNITTEST;
35 using syncer::syncable::WriteTransaction;
36
37 /* static */
38 const std::string ProfileSyncServiceTestHelper::GetTagForType(
39 ModelType model_type) {
40 return syncer::ModelTypeToRootTag(model_type);
41 }
42
43 /* static */
44 bool ProfileSyncServiceTestHelper::CreateRoot(ModelType model_type,
45 UserShare* user_share,
46 TestIdFactory* ids) {
47 syncer::syncable::Directory* directory = user_share->directory.get();
48
49 std::string tag_name = GetTagForType(model_type);
50
51 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory);
52 MutableEntry node(&wtrans,
53 CREATE,
54 wtrans.root_id(),
55 tag_name);
56 node.Put(UNIQUE_SERVER_TAG, tag_name);
57 node.Put(IS_DIR, true);
58 node.Put(SERVER_IS_DIR, false);
59 node.Put(IS_UNSYNCED, false);
60 node.Put(IS_UNAPPLIED_UPDATE, false);
61 node.Put(SERVER_VERSION, 20);
62 node.Put(BASE_VERSION, 20);
63 node.Put(IS_DEL, false);
64 node.Put(syncer::syncable::ID, ids->MakeServer(tag_name));
65 sync_pb::EntitySpecifics specifics;
66 syncer::AddDefaultFieldValue(model_type, &specifics);
67 node.Put(SPECIFICS, specifics);
68
69 return true;
70 }
71 19
72 /* static */ 20 /* static */
73 syncer::ImmutableChangeRecordList 21 syncer::ImmutableChangeRecordList
74 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList( 22 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList(
75 int64 node_id, syncer::ChangeRecord::Action action) { 23 int64 node_id, syncer::ChangeRecord::Action action) {
76 syncer::ChangeRecord record; 24 syncer::ChangeRecord record;
77 record.action = action; 25 record.action = action;
78 record.id = node_id; 26 record.id = node_id;
79 syncer::ChangeRecordList records(1, record); 27 syncer::ChangeRecordList records(1, record);
80 return syncer::ImmutableChangeRecordList(&records); 28 return syncer::ImmutableChangeRecordList(&records);
(...skipping 30 matching lines...) Expand all
111 // Pump messages posted by the sync core thread (which may end up 59 // Pump messages posted by the sync core thread (which may end up
112 // posting on the IO thread). 60 // posting on the IO thread).
113 ui_loop_.RunAllPending(); 61 ui_loop_.RunAllPending();
114 io_thread_.Stop(); 62 io_thread_.Stop();
115 file_thread_.Stop(); 63 file_thread_.Stop();
116 db_thread_.Stop(); 64 db_thread_.Stop();
117 ui_loop_.RunAllPending(); 65 ui_loop_.RunAllPending();
118 } 66 }
119 67
120 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) { 68 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) {
121 return ProfileSyncServiceTestHelper::CreateRoot( 69 return syncer::TestUserShare::CreateRoot(model_type,
122 model_type, 70 service_->GetUserShare());
123 service_->GetUserShare(),
124 service_->id_factory());
125 } 71 }
126 72
127 // static 73 // static
128 ProfileKeyedService* AbstractProfileSyncServiceTest::BuildTokenService( 74 ProfileKeyedService* AbstractProfileSyncServiceTest::BuildTokenService(
129 Profile* profile) { 75 Profile* profile) {
130 return new TokenService; 76 return new TokenService;
131 } 77 }
132 78
133 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test, 79 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test,
134 ModelType model_type) 80 ModelType model_type)
(...skipping 12 matching lines...) Expand all
147 return callback_; 93 return callback_;
148 } 94 }
149 95
150 bool CreateRootHelper::success() { 96 bool CreateRootHelper::success() {
151 return success_; 97 return success_;
152 } 98 }
153 99
154 void CreateRootHelper::CreateRootCallback() { 100 void CreateRootHelper::CreateRootCallback() {
155 success_ = test_->CreateRoot(model_type_); 101 success_ = test_->CreateRoot(model_type_);
156 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698