OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 void ResetSession() { | 255 void ResetSession() { |
256 session_.reset(SyncSession::Build(context_.get(), this)); | 256 session_.reset(SyncSession::Build(context_.get(), this)); |
257 } | 257 } |
258 | 258 |
259 void SyncShareNudge() { | 259 void SyncShareNudge() { |
260 ResetSession(); | 260 ResetSession(); |
261 | 261 |
262 // Pretend we've seen a local change, to make the nudge_tracker look normal. | 262 // Pretend we've seen a local change, to make the nudge_tracker look normal. |
263 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 263 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
264 | 264 |
265 EXPECT_TRUE( | 265 EXPECT_TRUE(syncer_->NormalSyncShare(context_->GetEnabledTypes(), |
266 syncer_->NormalSyncShare( | 266 &nudge_tracker_, session_.get())); |
267 context_->GetEnabledTypes(), | |
268 nudge_tracker_, | |
269 session_.get())); | |
270 } | 267 } |
271 | 268 |
272 void SyncShareConfigure() { | 269 void SyncShareConfigure() { |
273 ResetSession(); | 270 ResetSession(); |
274 EXPECT_TRUE(syncer_->ConfigureSyncShare( | 271 EXPECT_TRUE(syncer_->ConfigureSyncShare( |
275 context_->GetEnabledTypes(), | 272 context_->GetEnabledTypes(), |
276 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 273 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, |
277 session_.get())); | 274 session_.get())); |
278 } | 275 } |
279 | 276 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 A.PutSpecifics(bookmark_data); | 632 A.PutSpecifics(bookmark_data); |
636 A.PutNonUniqueName("bookmark"); | 633 A.PutNonUniqueName("bookmark"); |
637 } | 634 } |
638 | 635 |
639 // Now sync without enabling bookmarks. | 636 // Now sync without enabling bookmarks. |
640 mock_server_->ExpectGetUpdatesRequestTypes( | 637 mock_server_->ExpectGetUpdatesRequestTypes( |
641 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); | 638 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); |
642 ResetSession(); | 639 ResetSession(); |
643 syncer_->NormalSyncShare( | 640 syncer_->NormalSyncShare( |
644 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), | 641 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), |
645 nudge_tracker_, | 642 &nudge_tracker_, session_.get()); |
646 session_.get()); | |
647 | 643 |
648 { | 644 { |
649 // Nothing should have been committed as bookmarks is throttled. | 645 // Nothing should have been committed as bookmarks is throttled. |
650 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 646 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
651 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 647 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
652 ASSERT_TRUE(entryA.good()); | 648 ASSERT_TRUE(entryA.good()); |
653 EXPECT_TRUE(entryA.GetIsUnsynced()); | 649 EXPECT_TRUE(entryA.GetIsUnsynced()); |
654 } | 650 } |
655 | 651 |
656 // Sync again with bookmarks enabled. | 652 // Sync again with bookmarks enabled. |
(...skipping 2203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2860 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); | 2856 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); |
2861 | 2857 |
2862 // The previous send was successful so this next one shouldn't generate any | 2858 // The previous send was successful so this next one shouldn't generate any |
2863 // debug info events. | 2859 // debug info events. |
2864 SyncShareNudge(); | 2860 SyncShareNudge(); |
2865 EXPECT_EQ(3U, mock_server_->requests().size()); | 2861 EXPECT_EQ(3U, mock_server_->requests().size()); |
2866 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); | 2862 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
2867 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); | 2863 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); |
2868 } | 2864 } |
2869 | 2865 |
| 2866 // Tests that commit failure with conflict will trigger GetUpdates for next |
| 2867 // sycle of sync |
| 2868 TEST_F(SyncerTest, CommitFailureWithConflict) { |
| 2869 ConfigureNoGetUpdatesRequired(); |
| 2870 CreateUnsyncedDirectory("X", "id_X"); |
| 2871 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 2872 |
| 2873 SyncShareNudge(); |
| 2874 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 2875 |
| 2876 CreateUnsyncedDirectory("Y", "id_Y"); |
| 2877 mock_server_->set_conflict_n_commits(1); |
| 2878 SyncShareNudge(); |
| 2879 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); |
| 2880 |
| 2881 nudge_tracker_.RecordSuccessfulSyncCycle(); |
| 2882 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 2883 } |
| 2884 |
2870 // Tests that sending debug info events on Commit works. | 2885 // Tests that sending debug info events on Commit works. |
2871 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_HappyCase) { | 2886 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_HappyCase) { |
2872 // Make sure GetUpdate isn't call as it would "steal" debug info events before | 2887 // Make sure GetUpdate isn't call as it would "steal" debug info events before |
2873 // Commit has a chance to send them. | 2888 // Commit has a chance to send them. |
2874 ConfigureNoGetUpdatesRequired(); | 2889 ConfigureNoGetUpdatesRequired(); |
2875 | 2890 |
2876 // Generate a debug info event and trigger a commit. | 2891 // Generate a debug info event and trigger a commit. |
2877 debug_info_getter_->AddDebugEvent(); | 2892 debug_info_getter_->AddDebugEvent(); |
2878 CreateUnsyncedDirectory("X", "id_X"); | 2893 CreateUnsyncedDirectory("X", "id_X"); |
2879 SyncShareNudge(); | 2894 SyncShareNudge(); |
(...skipping 2465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5345 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5360 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5346 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5361 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5347 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5362 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5348 } else { | 5363 } else { |
5349 EXPECT_TRUE(final_monitor_records.empty()) | 5364 EXPECT_TRUE(final_monitor_records.empty()) |
5350 << "Should not restore records after successful bookmark commit."; | 5365 << "Should not restore records after successful bookmark commit."; |
5351 } | 5366 } |
5352 } | 5367 } |
5353 | 5368 |
5354 } // namespace syncer | 5369 } // namespace syncer |
OLD | NEW |