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

Side by Side Diff: chrome/browser/sync/engine/process_commit_response_command_unittest.cc

Issue 2865022: sync: add CleanupDisabledTypesCommand to purge data pertaining to previously... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <vector> 5 #include <vector>
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" 8 #include "chrome/browser/sync/engine/mock_model_safe_workers.h"
9 #include "chrome/browser/sync/engine/process_commit_response_command.h" 9 #include "chrome/browser/sync/engine/process_commit_response_command.h"
10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Create an unsynced item in the database. If item_id is a local ID, it 79 // Create an unsynced item in the database. If item_id is a local ID, it
80 // will be treated as a create-new. Otherwise, if it's a server ID, we'll 80 // will be treated as a create-new. Otherwise, if it's a server ID, we'll
81 // fake the server data so that it looks like it exists on the server. 81 // fake the server data so that it looks like it exists on the server.
82 // Returns the methandle of the created item in |metahandle_out| if not NULL. 82 // Returns the methandle of the created item in |metahandle_out| if not NULL.
83 void CreateUnsyncedItem(const Id& item_id, 83 void CreateUnsyncedItem(const Id& item_id,
84 const Id& parent_id, 84 const Id& parent_id,
85 const string& name, 85 const string& name,
86 bool is_folder, 86 bool is_folder,
87 syncable::ModelType model_type, 87 syncable::ModelType model_type,
88 int64* metahandle_out) { 88 int64* metahandle_out) {
89 ScopedDirLookup dir(syncdb().manager(), syncdb().name()); 89 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
90 ASSERT_TRUE(dir.good()); 90 ASSERT_TRUE(dir.good());
91 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 91 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__);
92 Id predecessor_id = dir->GetLastChildId(&trans, parent_id); 92 Id predecessor_id = dir->GetLastChildId(&trans, parent_id);
93 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); 93 MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
94 ASSERT_TRUE(entry.good()); 94 ASSERT_TRUE(entry.good());
95 entry.Put(syncable::ID, item_id); 95 entry.Put(syncable::ID, item_id);
96 entry.Put(syncable::BASE_VERSION, 96 entry.Put(syncable::BASE_VERSION,
97 item_id.ServerKnows() ? next_old_revision_++ : 0); 97 item_id.ServerKnows() ? next_old_revision_++ : 0);
98 entry.Put(syncable::IS_UNSYNCED, true); 98 entry.Put(syncable::IS_UNSYNCED, true);
99 entry.Put(syncable::IS_DIR, is_folder); 99 entry.Put(syncable::IS_DIR, is_folder);
(...skipping 25 matching lines...) Expand all
125 bool is_folder = true; 125 bool is_folder = true;
126 int64 metahandle = 0; 126 int64 metahandle = 0;
127 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, 127 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type,
128 &metahandle); 128 &metahandle);
129 129
130 // ProcessCommitResponseCommand consumes commit_ids from the session 130 // ProcessCommitResponseCommand consumes commit_ids from the session
131 // state, so we need to update that. O(n^2) because it's a test. 131 // state, so we need to update that. O(n^2) because it's a test.
132 commit_set_->AddCommitItem(metahandle, item_id, model_type); 132 commit_set_->AddCommitItem(metahandle, item_id, model_type);
133 sync_state->set_commit_set(*commit_set_.get()); 133 sync_state->set_commit_set(*commit_set_.get());
134 134
135 ScopedDirLookup dir(syncdb().manager(), syncdb().name()); 135 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
136 ASSERT_TRUE(dir.good()); 136 ASSERT_TRUE(dir.good());
137 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 137 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__);
138 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); 138 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id);
139 ASSERT_TRUE(entry.good()); 139 ASSERT_TRUE(entry.good());
140 entry.Put(syncable::SYNCING, true); 140 entry.Put(syncable::SYNCING, true);
141 141
142 // ProcessCommitResponseCommand looks at both the commit message as well 142 // ProcessCommitResponseCommand looks at both the commit message as well
143 // as the commit response, so we need to synthesize both here. 143 // as the commit response, so we need to synthesize both here.
144 sync_pb::ClientToServerMessage* commit = 144 sync_pb::ClientToServerMessage* commit =
145 sync_state->mutable_commit_message(); 145 sync_state->mutable_commit_message();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 "Pref 1", syncable::PREFERENCES); 221 "Pref 1", syncable::PREFERENCES);
222 CreateUnprocessedCommitResult(pref_id2, id_factory_.root(), 222 CreateUnprocessedCommitResult(pref_id2, id_factory_.root(),
223 "Pref 2", syncable::PREFERENCES); 223 "Pref 2", syncable::PREFERENCES);
224 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), 224 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(),
225 "Autofill 1", syncable::AUTOFILL); 225 "Autofill 1", syncable::AUTOFILL);
226 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), 226 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(),
227 "Autofill 2", syncable::AUTOFILL); 227 "Autofill 2", syncable::AUTOFILL);
228 228
229 command_.ExecuteImpl(session()); 229 command_.ExecuteImpl(session());
230 230
231 ScopedDirLookup dir(syncdb().manager(), syncdb().name()); 231 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
232 ASSERT_TRUE(dir.good()); 232 ASSERT_TRUE(dir.good());
233 ReadTransaction trans(dir, __FILE__, __LINE__); 233 ReadTransaction trans(dir, __FILE__, __LINE__);
234 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); 234 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root());
235 ASSERT_FALSE(new_fid.IsRoot()); 235 ASSERT_FALSE(new_fid.IsRoot());
236 EXPECT_TRUE(new_fid.ServerKnows()); 236 EXPECT_TRUE(new_fid.ServerKnows());
237 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); 237 EXPECT_FALSE(bookmark_folder_id.ServerKnows());
238 EXPECT_FALSE(new_fid == bookmark_folder_id); 238 EXPECT_FALSE(new_fid == bookmark_folder_id);
239 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); 239 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid);
240 ASSERT_TRUE(b_folder.good()); 240 ASSERT_TRUE(b_folder.good());
241 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) 241 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // how this scenario used to fail, reversing the order for the second half 275 // how this scenario used to fail, reversing the order for the second half
276 // of the children. 276 // of the children.
277 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { 277 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) {
278 // Create the parent folder, a new item whose ID will change on commit. 278 // Create the parent folder, a new item whose ID will change on commit.
279 Id folder_id = id_factory_.NewLocalId(); 279 Id folder_id = id_factory_.NewLocalId();
280 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", 280 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A",
281 syncable::BOOKMARKS); 281 syncable::BOOKMARKS);
282 282
283 // Verify that the item is reachable. 283 // Verify that the item is reachable.
284 { 284 {
285 ScopedDirLookup dir(syncdb().manager(), syncdb().name()); 285 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
286 ASSERT_TRUE(dir.good()); 286 ASSERT_TRUE(dir.good());
287 ReadTransaction trans(dir, __FILE__, __LINE__); 287 ReadTransaction trans(dir, __FILE__, __LINE__);
288 ASSERT_EQ(folder_id, dir->GetFirstChildId(&trans, id_factory_.root())); 288 ASSERT_EQ(folder_id, dir->GetFirstChildId(&trans, id_factory_.root()));
289 } 289 }
290 290
291 // The first 25 children of the parent folder will be part of the commit 291 // The first 25 children of the parent folder will be part of the commit
292 // batch. 292 // batch.
293 int batch_size = 25; 293 int batch_size = 25;
294 int i = 0; 294 int i = 0;
295 for (; i < batch_size; ++i) { 295 for (; i < batch_size; ++i) {
(...skipping 12 matching lines...) Expand all
308 CreateUnsyncedItem(id, folder_id, StringPrintf("Item %d", i), false, 308 CreateUnsyncedItem(id, folder_id, StringPrintf("Item %d", i), false,
309 syncable::BOOKMARKS, NULL); 309 syncable::BOOKMARKS, NULL);
310 } 310 }
311 311
312 // Process the commit response for the parent folder and the first 312 // Process the commit response for the parent folder and the first
313 // 25 items. This should apply the values indicated by 313 // 25 items. This should apply the values indicated by
314 // each CommitResponse_EntryResponse to the syncable Entries. All new 314 // each CommitResponse_EntryResponse to the syncable Entries. All new
315 // items in the commit batch should have their IDs changed to server IDs. 315 // items in the commit batch should have their IDs changed to server IDs.
316 command_.ExecuteImpl(session()); 316 command_.ExecuteImpl(session());
317 317
318 ScopedDirLookup dir(syncdb().manager(), syncdb().name()); 318 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
319 ASSERT_TRUE(dir.good()); 319 ASSERT_TRUE(dir.good());
320 ReadTransaction trans(dir, __FILE__, __LINE__); 320 ReadTransaction trans(dir, __FILE__, __LINE__);
321 // Lookup the parent folder by finding a child of the root. We can't use 321 // Lookup the parent folder by finding a child of the root. We can't use
322 // folder_id here, because it changed during the commit. 322 // folder_id here, because it changed during the commit.
323 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); 323 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root());
324 ASSERT_FALSE(new_fid.IsRoot()); 324 ASSERT_FALSE(new_fid.IsRoot());
325 EXPECT_TRUE(new_fid.ServerKnows()); 325 EXPECT_TRUE(new_fid.ServerKnows());
326 EXPECT_FALSE(folder_id.ServerKnows()); 326 EXPECT_FALSE(folder_id.ServerKnows());
327 EXPECT_TRUE(new_fid != folder_id); 327 EXPECT_TRUE(new_fid != folder_id);
328 Entry parent(&trans, syncable::GET_BY_ID, new_fid); 328 Entry parent(&trans, syncable::GET_BY_ID, new_fid);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 427 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
428 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 428 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
429 } else { 429 } else {
430 EXPECT_TRUE(final_monitor_records.empty()) 430 EXPECT_TRUE(final_monitor_records.empty())
431 << "Should not restore records after successful bookmark commit."; 431 << "Should not restore records after successful bookmark commit.";
432 } 432 }
433 } 433 }
434 434
435 435
436 } // namespace browser_sync 436 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/download_updates_command_unittest.cc ('k') | chrome/browser/sync/engine/syncer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698