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

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

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 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
« no previous file with comments | « sync/engine/process_commit_response_command.cc ('k') | sync/engine/process_updates_command.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "sync/engine/process_commit_response_command.h" 5 #include "sync/engine/process_commit_response_command.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "sync/protocol/bookmark_specifics.pb.h" 11 #include "sync/protocol/bookmark_specifics.pb.h"
12 #include "sync/protocol/sync.pb.h" 12 #include "sync/protocol/sync.pb.h"
13 #include "sync/sessions/sync_session.h" 13 #include "sync/sessions/sync_session.h"
14 #include "sync/syncable/entry.h" 14 #include "sync/syncable/entry.h"
15 #include "sync/syncable/mutable_entry.h" 15 #include "sync/syncable/mutable_entry.h"
16 #include "sync/syncable/read_transaction.h" 16 #include "sync/syncable/read_transaction.h"
17 #include "sync/syncable/syncable_id.h" 17 #include "sync/syncable/syncable_id.h"
18 #include "sync/syncable/write_transaction.h" 18 #include "sync/syncable/write_transaction.h"
19 #include "sync/test/engine/fake_model_worker.h" 19 #include "sync/test/engine/fake_model_worker.h"
20 #include "sync/test/engine/syncer_command_test.h" 20 #include "sync/test/engine/syncer_command_test.h"
21 #include "sync/test/engine/test_id_factory.h" 21 #include "sync/test/engine/test_id_factory.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 namespace csync { 24 namespace syncer {
25 25
26 using sessions::SyncSession; 26 using sessions::SyncSession;
27 using std::string; 27 using std::string;
28 using syncable::BASE_VERSION; 28 using syncable::BASE_VERSION;
29 using syncable::Entry; 29 using syncable::Entry;
30 using syncable::IS_DIR; 30 using syncable::IS_DIR;
31 using syncable::IS_UNSYNCED; 31 using syncable::IS_UNSYNCED;
32 using syncable::Id; 32 using syncable::Id;
33 using syncable::MutableEntry; 33 using syncable::MutableEntry;
34 using syncable::NON_UNIQUE_NAME; 34 using syncable::NON_UNIQUE_NAME;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Create a new unsynced item in the database, and synthesize a commit 111 // Create a new unsynced item in the database, and synthesize a commit
112 // record and a commit response for it in the syncer session. If item_id 112 // record and a commit response for it in the syncer session. If item_id
113 // is a local ID, the item will be a create operation. Otherwise, it 113 // is a local ID, the item will be a create operation. Otherwise, it
114 // will be an edit. 114 // will be an edit.
115 void CreateUnprocessedCommitResult( 115 void CreateUnprocessedCommitResult(
116 const Id& item_id, 116 const Id& item_id,
117 const Id& parent_id, 117 const Id& parent_id,
118 const string& name, 118 const string& name,
119 syncable::ModelType model_type, 119 syncable::ModelType model_type,
120 sessions::OrderedCommitSet *commit_set, 120 sessions::OrderedCommitSet *commit_set,
121 csync::ClientToServerMessage *commit, 121 syncer::ClientToServerMessage *commit,
122 csync::ClientToServerResponse *response) { 122 syncer::ClientToServerResponse *response) {
123 bool is_folder = true; 123 bool is_folder = true;
124 int64 metahandle = 0; 124 int64 metahandle = 0;
125 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, 125 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type,
126 &metahandle); 126 &metahandle);
127 127
128 // ProcessCommitResponseCommand consumes commit_ids from the session 128 // ProcessCommitResponseCommand consumes commit_ids from the session
129 // state, so we need to update that. O(n^2) because it's a test. 129 // state, so we need to update that. O(n^2) because it's a test.
130 commit_set->AddCommitItem(metahandle, item_id, model_type); 130 commit_set->AddCommitItem(metahandle, item_id, model_type);
131 131
132 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 132 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 TestIdFactory id_factory_; 183 TestIdFactory id_factory_;
184 private: 184 private:
185 int64 next_old_revision_; 185 int64 next_old_revision_;
186 int64 next_new_revision_; 186 int64 next_new_revision_;
187 int64 next_server_position_; 187 int64 next_server_position_;
188 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest); 188 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest);
189 }; 189 };
190 190
191 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) { 191 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) {
192 sessions::OrderedCommitSet commit_set(session()->routing_info()); 192 sessions::OrderedCommitSet commit_set(session()->routing_info());
193 csync::ClientToServerMessage request; 193 syncer::ClientToServerMessage request;
194 csync::ClientToServerResponse response; 194 syncer::ClientToServerResponse response;
195 195
196 Id bookmark_folder_id = id_factory_.NewLocalId(); 196 Id bookmark_folder_id = id_factory_.NewLocalId();
197 Id bookmark_id1 = id_factory_.NewLocalId(); 197 Id bookmark_id1 = id_factory_.NewLocalId();
198 Id bookmark_id2 = id_factory_.NewLocalId(); 198 Id bookmark_id2 = id_factory_.NewLocalId();
199 Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId(); 199 Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId();
200 Id autofill_id1 = id_factory_.NewLocalId(); 200 Id autofill_id1 = id_factory_.NewLocalId();
201 Id autofill_id2 = id_factory_.NewLocalId(); 201 Id autofill_id2 = id_factory_.NewLocalId();
202 CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(), 202 CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(),
203 "A bookmark folder", syncable::BOOKMARKS, 203 "A bookmark folder", syncable::BOOKMARKS,
204 &commit_set, &request, &response); 204 &commit_set, &request, &response);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // In particular, the folder has 50 children, which alternate between being 267 // In particular, the folder has 50 children, which alternate between being
268 // new items and preexisting items. This mixture of new and old is meant to 268 // new items and preexisting items. This mixture of new and old is meant to
269 // be a torture test of the code in ProcessCommitResponseCommand that changes 269 // be a torture test of the code in ProcessCommitResponseCommand that changes
270 // an item's ID from a local ID to a server-generated ID on the first commit. 270 // an item's ID from a local ID to a server-generated ID on the first commit.
271 // We commit only the first 25 children in the sibling order, leaving the 271 // We commit only the first 25 children in the sibling order, leaving the
272 // second 25 children as unsynced items. http://crbug.com/33081 describes 272 // second 25 children as unsynced items. http://crbug.com/33081 describes
273 // how this scenario used to fail, reversing the order for the second half 273 // how this scenario used to fail, reversing the order for the second half
274 // of the children. 274 // of the children.
275 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { 275 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) {
276 sessions::OrderedCommitSet commit_set(session()->routing_info()); 276 sessions::OrderedCommitSet commit_set(session()->routing_info());
277 csync::ClientToServerMessage request; 277 syncer::ClientToServerMessage request;
278 csync::ClientToServerResponse response; 278 syncer::ClientToServerResponse response;
279 279
280 // Create the parent folder, a new item whose ID will change on commit. 280 // Create the parent folder, a new item whose ID will change on commit.
281 Id folder_id = id_factory_.NewLocalId(); 281 Id folder_id = id_factory_.NewLocalId();
282 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", 282 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A",
283 syncable::BOOKMARKS, 283 syncable::BOOKMARKS,
284 &commit_set, &request, &response); 284 &commit_set, &request, &response);
285 285
286 // Verify that the item is reachable. 286 // Verify that the item is reachable.
287 { 287 {
288 syncable::ReadTransaction trans(FROM_HERE, directory()); 288 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 }; 395 };
396 INSTANTIATE_TEST_CASE_P(ProcessCommitResponse, 396 INSTANTIATE_TEST_CASE_P(ProcessCommitResponse,
397 MixedResult, 397 MixedResult,
398 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT)); 398 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT));
399 399
400 // This test commits 2 items (one bookmark, one autofill) and validates what 400 // This test commits 2 items (one bookmark, one autofill) and validates what
401 // happens to the extensions activity records. Commits could fail or succeed, 401 // happens to the extensions activity records. Commits could fail or succeed,
402 // depending on the test parameter. 402 // depending on the test parameter.
403 TEST_P(MixedResult, ExtensionActivity) { 403 TEST_P(MixedResult, ExtensionActivity) {
404 sessions::OrderedCommitSet commit_set(session()->routing_info()); 404 sessions::OrderedCommitSet commit_set(session()->routing_info());
405 csync::ClientToServerMessage request; 405 syncer::ClientToServerMessage request;
406 csync::ClientToServerResponse response; 406 syncer::ClientToServerResponse response;
407 407
408 EXPECT_NE(routing_info().find(syncable::BOOKMARKS)->second, 408 EXPECT_NE(routing_info().find(syncable::BOOKMARKS)->second,
409 routing_info().find(syncable::AUTOFILL)->second) 409 routing_info().find(syncable::AUTOFILL)->second)
410 << "To not be lame, this test requires more than one active group."; 410 << "To not be lame, this test requires more than one active group.";
411 411
412 // Bookmark item setup. 412 // Bookmark item setup.
413 CreateUnprocessedCommitResult(id_factory_.NewServerId(), 413 CreateUnprocessedCommitResult(id_factory_.NewServerId(),
414 id_factory_.root(), "Some bookmark", syncable::BOOKMARKS, 414 id_factory_.root(), "Some bookmark", syncable::BOOKMARKS,
415 &commit_set, &request, &response); 415 &commit_set, &request, &response);
416 if (ShouldFailBookmarkCommit()) 416 if (ShouldFailBookmarkCommit())
(...skipping 27 matching lines...) Expand all
444 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id); 444 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id);
445 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 445 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
446 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 446 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
447 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 447 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
448 } else { 448 } else {
449 EXPECT_TRUE(final_monitor_records.empty()) 449 EXPECT_TRUE(final_monitor_records.empty())
450 << "Should not restore records after successful bookmark commit."; 450 << "Should not restore records after successful bookmark commit.";
451 } 451 }
452 } 452 }
453 453
454 } // namespace csync 454 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/process_commit_response_command.cc ('k') | sync/engine/process_updates_command.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698