| OLD | NEW |
| 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/sessions/sync_session.h" | 5 #include "sync/sessions/sync_session.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "sync/engine/conflict_resolver.h" | 11 #include "sync/engine/conflict_resolver.h" |
| 12 #include "sync/engine/syncer_types.h" | 12 #include "sync/engine/syncer_types.h" |
| 13 #include "sync/engine/throttled_data_type_tracker.h" | 13 #include "sync/engine/throttled_data_type_tracker.h" |
| 14 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
| 15 #include "sync/internal_api/public/base/model_type_invalidation_map_test_util.h" | 15 #include "sync/internal_api/public/base/model_type_invalidation_map_test_util.h" |
| 16 #include "sync/sessions/session_state.h" | |
| 17 #include "sync/sessions/status_controller.h" | 16 #include "sync/sessions/status_controller.h" |
| 18 #include "sync/syncable/syncable_id.h" | 17 #include "sync/syncable/syncable_id.h" |
| 19 #include "sync/syncable/write_transaction.h" | 18 #include "sync/syncable/write_transaction.h" |
| 20 #include "sync/test/engine/fake_model_worker.h" | 19 #include "sync/test/engine/fake_model_worker.h" |
| 21 #include "sync/test/engine/test_directory_setter_upper.h" | 20 #include "sync/test/engine/test_directory_setter_upper.h" |
| 22 #include "sync/test/fake_extensions_activity_monitor.h" | 21 #include "sync/test/fake_extensions_activity_monitor.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 23 |
| 25 namespace syncer { | 24 namespace syncer { |
| 26 | 25 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 186 } |
| 188 | 187 |
| 189 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { | 188 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { |
| 190 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 189 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 191 | 190 |
| 192 status()->set_last_download_updates_result(NETWORK_IO_ERROR); | 191 status()->set_last_download_updates_result(NETWORK_IO_ERROR); |
| 193 | 192 |
| 194 // When DownloadUpdatesCommand fails, these should be false. | 193 // When DownloadUpdatesCommand fails, these should be false. |
| 195 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 194 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 196 EXPECT_FALSE(status()->download_updates_succeeded()); | 195 EXPECT_FALSE(status()->download_updates_succeeded()); |
| 197 | |
| 198 // Download updates has its own loop in the syncer; it shouldn't factor | |
| 199 // into HasMoreToSync. | |
| 200 EXPECT_FALSE(session_->HasMoreToSync()); | |
| 201 } | 196 } |
| 202 | 197 |
| 203 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { | 198 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { |
| 204 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 199 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 205 | 200 |
| 206 // When the server returns changes_remaining, that means there's | 201 // When the server returns changes_remaining, that means there's |
| 207 // more to download. | 202 // more to download. |
| 208 status()->set_last_download_updates_result(SYNCER_OK); | 203 status()->set_last_download_updates_result(SYNCER_OK); |
| 209 status()->mutable_updates_response()->mutable_get_updates() | 204 status()->mutable_updates_response()->mutable_get_updates() |
| 210 ->set_changes_remaining(1000L); | 205 ->set_changes_remaining(1000L); |
| 211 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 206 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 212 EXPECT_TRUE(status()->download_updates_succeeded()); | 207 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 213 | |
| 214 // Download updates has its own loop in the syncer; it shouldn't factor | |
| 215 // into HasMoreToSync. | |
| 216 EXPECT_FALSE(session_->HasMoreToSync()); | |
| 217 } | 208 } |
| 218 | 209 |
| 219 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { | 210 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { |
| 220 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 211 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 221 | 212 |
| 222 status()->set_last_download_updates_result(SYNCER_OK); | 213 status()->set_last_download_updates_result(SYNCER_OK); |
| 223 status()->mutable_updates_response()->mutable_get_updates() | 214 status()->mutable_updates_response()->mutable_get_updates() |
| 224 ->set_changes_remaining(0); | 215 ->set_changes_remaining(0); |
| 225 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); | 216 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
| 226 EXPECT_TRUE(status()->download_updates_succeeded()); | 217 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 227 | |
| 228 // Download updates has its own loop in the syncer; it shouldn't factor | |
| 229 // into HasMoreToSync. | |
| 230 EXPECT_FALSE(session_->HasMoreToSync()); | |
| 231 } | |
| 232 | |
| 233 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { | |
| 234 // Conflict resolution happens after get updates and commit, | |
| 235 // so we need to loop back and get updates / commit again now | |
| 236 // that we have made forward progress. | |
| 237 status()->update_conflicts_resolved(true); | |
| 238 EXPECT_TRUE(session_->HasMoreToSync()); | |
| 239 } | |
| 240 | |
| 241 TEST_F(SyncSessionTest, ResetTransientState) { | |
| 242 status()->update_conflicts_resolved(true); | |
| 243 status()->increment_num_successful_commits(); | |
| 244 EXPECT_TRUE(session_->HasMoreToSync()); | |
| 245 session_->PrepareForAnotherSyncCycle(); | |
| 246 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | |
| 247 session_->source().updates_source); | |
| 248 EXPECT_FALSE(status()->conflicts_resolved()); | |
| 249 EXPECT_FALSE(session_->HasMoreToSync()); | |
| 250 } | 218 } |
| 251 | 219 |
| 252 TEST_F(SyncSessionTest, Coalesce) { | 220 TEST_F(SyncSessionTest, Coalesce) { |
| 253 std::vector<ModelSafeWorker*> workers_one, workers_two; | 221 std::vector<ModelSafeWorker*> workers_one, workers_two; |
| 254 ModelSafeRoutingInfo routes_one, routes_two; | 222 ModelSafeRoutingInfo routes_one, routes_two; |
| 255 ModelTypeInvalidationMap one_type = | 223 ModelTypeInvalidationMap one_type = |
| 256 ModelTypeSetToInvalidationMap( | 224 ModelTypeSetToInvalidationMap( |
| 257 ParamsMeaningJustOneEnabledType(), | 225 ParamsMeaningJustOneEnabledType(), |
| 258 std::string()); | 226 std::string()); |
| 259 ModelTypeInvalidationMap all_types = | 227 ModelTypeInvalidationMap all_types = |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 444 |
| 477 ASSERT_EQ(3U, invalidation_map.size()); | 445 ASSERT_EQ(3U, invalidation_map.size()); |
| 478 EXPECT_EQ(invalidation_map[BOOKMARKS].payload, payload); | 446 EXPECT_EQ(invalidation_map[BOOKMARKS].payload, payload); |
| 479 EXPECT_EQ(invalidation_map[PASSWORDS].payload, payload); | 447 EXPECT_EQ(invalidation_map[PASSWORDS].payload, payload); |
| 480 EXPECT_EQ(invalidation_map[AUTOFILL].payload, payload); | 448 EXPECT_EQ(invalidation_map[AUTOFILL].payload, payload); |
| 481 } | 449 } |
| 482 | 450 |
| 483 } // namespace | 451 } // namespace |
| 484 } // namespace sessions | 452 } // namespace sessions |
| 485 } // namespace syncer | 453 } // namespace syncer |
| OLD | NEW |