| 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" | |
| 12 #include "sync/engine/syncer_types.h" | 11 #include "sync/engine/syncer_types.h" |
| 13 #include "sync/engine/throttled_data_type_tracker.h" | 12 #include "sync/engine/throttled_data_type_tracker.h" |
| 14 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
| 15 #include "sync/internal_api/public/base/model_type_invalidation_map_test_util.h" | 14 #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" | 15 #include "sync/sessions/status_controller.h" |
| 18 #include "sync/syncable/syncable_id.h" | 16 #include "sync/syncable/syncable_id.h" |
| 19 #include "sync/syncable/write_transaction.h" | 17 #include "sync/syncable/write_transaction.h" |
| 20 #include "sync/test/engine/fake_model_worker.h" | 18 #include "sync/test/engine/fake_model_worker.h" |
| 21 #include "sync/test/engine/test_directory_setter_upper.h" | 19 #include "sync/test/engine/test_directory_setter_upper.h" |
| 22 #include "sync/test/fake_extensions_activity_monitor.h" | 20 #include "sync/test/fake_extensions_activity_monitor.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 22 |
| 25 namespace syncer { | 23 namespace syncer { |
| 26 | 24 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 153 |
| 156 TEST_F(SyncSessionTest, EnabledGroups) { | 154 TEST_F(SyncSessionTest, EnabledGroups) { |
| 157 scoped_ptr<SyncSession> session(MakeSession()); | 155 scoped_ptr<SyncSession> session(MakeSession()); |
| 158 std::set<ModelSafeGroup> expected_enabled_groups; | 156 std::set<ModelSafeGroup> expected_enabled_groups; |
| 159 expected_enabled_groups.insert(GROUP_PASSIVE); | 157 expected_enabled_groups.insert(GROUP_PASSIVE); |
| 160 expected_enabled_groups.insert(GROUP_UI); | 158 expected_enabled_groups.insert(GROUP_UI); |
| 161 expected_enabled_groups.insert(GROUP_DB); | 159 expected_enabled_groups.insert(GROUP_DB); |
| 162 EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups()); | 160 EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups()); |
| 163 } | 161 } |
| 164 | 162 |
| 165 TEST_F(SyncSessionTest, ScopedContextHelpers) { | |
| 166 ConflictResolver resolver; | |
| 167 EXPECT_FALSE(context_->resolver()); | |
| 168 { | |
| 169 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver); | |
| 170 EXPECT_EQ(&resolver, context_->resolver()); | |
| 171 } | |
| 172 EXPECT_FALSE(context_->resolver()); | |
| 173 } | |
| 174 | |
| 175 TEST_F(SyncSessionTest, SetWriteTransaction) { | 163 TEST_F(SyncSessionTest, SetWriteTransaction) { |
| 176 TestDirectorySetterUpper dir_maker; | 164 TestDirectorySetterUpper dir_maker; |
| 177 dir_maker.SetUp(); | 165 dir_maker.SetUp(); |
| 178 syncable::Directory* directory = dir_maker.directory(); | 166 syncable::Directory* directory = dir_maker.directory(); |
| 179 | 167 |
| 180 scoped_ptr<SyncSession> session(MakeSession()); | 168 scoped_ptr<SyncSession> session(MakeSession()); |
| 181 EXPECT_TRUE(NULL == session->write_transaction()); | 169 EXPECT_TRUE(NULL == session->write_transaction()); |
| 182 { | 170 { |
| 183 WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory); | 171 WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory); |
| 184 sessions::ScopedSetSessionWriteTransaction set_trans(session.get(), &trans); | 172 sessions::ScopedSetSessionWriteTransaction set_trans(session.get(), &trans); |
| 185 EXPECT_TRUE(&trans == session->write_transaction()); | 173 EXPECT_TRUE(&trans == session->write_transaction()); |
| 186 } | 174 } |
| 187 } | 175 } |
| 188 | 176 |
| 189 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { | 177 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { |
| 190 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 178 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 191 | 179 |
| 192 status()->set_last_download_updates_result(NETWORK_IO_ERROR); | 180 status()->set_last_download_updates_result(NETWORK_IO_ERROR); |
| 193 | 181 |
| 194 // When DownloadUpdatesCommand fails, these should be false. | 182 // When DownloadUpdatesCommand fails, these should be false. |
| 195 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 183 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 196 EXPECT_FALSE(status()->download_updates_succeeded()); | 184 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 } | 185 } |
| 202 | 186 |
| 203 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { | 187 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { |
| 204 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 188 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 205 | 189 |
| 206 // When the server returns changes_remaining, that means there's | 190 // When the server returns changes_remaining, that means there's |
| 207 // more to download. | 191 // more to download. |
| 208 status()->set_last_download_updates_result(SYNCER_OK); | 192 status()->set_last_download_updates_result(SYNCER_OK); |
| 209 status()->mutable_updates_response()->mutable_get_updates() | 193 status()->mutable_updates_response()->mutable_get_updates() |
| 210 ->set_changes_remaining(1000L); | 194 ->set_changes_remaining(1000L); |
| 211 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 195 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 212 EXPECT_TRUE(status()->download_updates_succeeded()); | 196 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 } | 197 } |
| 218 | 198 |
| 219 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { | 199 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { |
| 220 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 200 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 221 | 201 |
| 222 status()->set_last_download_updates_result(SYNCER_OK); | 202 status()->set_last_download_updates_result(SYNCER_OK); |
| 223 status()->mutable_updates_response()->mutable_get_updates() | 203 status()->mutable_updates_response()->mutable_get_updates() |
| 224 ->set_changes_remaining(0); | 204 ->set_changes_remaining(0); |
| 225 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); | 205 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
| 226 EXPECT_TRUE(status()->download_updates_succeeded()); | 206 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 } | 207 } |
| 251 | 208 |
| 252 TEST_F(SyncSessionTest, Coalesce) { | 209 TEST_F(SyncSessionTest, Coalesce) { |
| 253 std::vector<ModelSafeWorker*> workers_one, workers_two; | 210 std::vector<ModelSafeWorker*> workers_one, workers_two; |
| 254 ModelSafeRoutingInfo routes_one, routes_two; | 211 ModelSafeRoutingInfo routes_one, routes_two; |
| 255 ModelTypeInvalidationMap one_type = | 212 ModelTypeInvalidationMap one_type = |
| 256 ModelTypeSetToInvalidationMap( | 213 ModelTypeSetToInvalidationMap( |
| 257 ParamsMeaningJustOneEnabledType(), | 214 ParamsMeaningJustOneEnabledType(), |
| 258 std::string()); | 215 std::string()); |
| 259 ModelTypeInvalidationMap all_types = | 216 ModelTypeInvalidationMap all_types = |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 433 |
| 477 ASSERT_EQ(3U, invalidation_map.size()); | 434 ASSERT_EQ(3U, invalidation_map.size()); |
| 478 EXPECT_EQ(invalidation_map[BOOKMARKS].payload, payload); | 435 EXPECT_EQ(invalidation_map[BOOKMARKS].payload, payload); |
| 479 EXPECT_EQ(invalidation_map[PASSWORDS].payload, payload); | 436 EXPECT_EQ(invalidation_map[PASSWORDS].payload, payload); |
| 480 EXPECT_EQ(invalidation_map[AUTOFILL].payload, payload); | 437 EXPECT_EQ(invalidation_map[AUTOFILL].payload, payload); |
| 481 } | 438 } |
| 482 | 439 |
| 483 } // namespace | 440 } // namespace |
| 484 } // namespace sessions | 441 } // namespace sessions |
| 485 } // namespace syncer | 442 } // namespace syncer |
| OLD | NEW |