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" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 unsynced_handles.push_back(2); | 208 unsynced_handles.push_back(2); |
209 status()->set_unsynced_handles(unsynced_handles); | 209 status()->set_unsynced_handles(unsynced_handles); |
210 EXPECT_FALSE(session_->HasMoreToSync()); | 210 EXPECT_FALSE(session_->HasMoreToSync()); |
211 status()->increment_num_successful_commits(); | 211 status()->increment_num_successful_commits(); |
212 EXPECT_TRUE(session_->HasMoreToSync()); | 212 EXPECT_TRUE(session_->HasMoreToSync()); |
213 } | 213 } |
214 | 214 |
215 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { | 215 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { |
216 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 216 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
217 | 217 |
218 status()->set_last_download_updates_result(NETWORK_IO_ERROR); | |
219 | |
220 // When DownloadUpdatesCommand fails, these should be false. | 218 // When DownloadUpdatesCommand fails, these should be false. |
221 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 219 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
222 EXPECT_FALSE(status()->download_updates_succeeded()); | 220 EXPECT_FALSE(status()->download_updates_succeeded()); |
223 | 221 |
224 // Download updates has its own loop in the syncer; it shouldn't factor | 222 // Download updates has its own loop in the syncer; it shouldn't factor |
225 // into HasMoreToSync. | 223 // into HasMoreToSync. |
226 EXPECT_FALSE(session_->HasMoreToSync()); | 224 EXPECT_FALSE(session_->HasMoreToSync()); |
227 } | 225 } |
228 | 226 |
229 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { | 227 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { |
230 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 228 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
231 | 229 |
232 // When the server returns changes_remaining, that means there's | 230 // When the server returns changes_remaining, that means there's |
233 // more to download. | 231 // more to download. |
234 status()->set_last_download_updates_result(SYNCER_OK); | |
235 status()->mutable_updates_response()->mutable_get_updates() | 232 status()->mutable_updates_response()->mutable_get_updates() |
236 ->set_changes_remaining(1000L); | 233 ->set_changes_remaining(1000L); |
237 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 234 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
238 EXPECT_TRUE(status()->download_updates_succeeded()); | 235 EXPECT_TRUE(status()->download_updates_succeeded()); |
239 | 236 |
240 // Download updates has its own loop in the syncer; it shouldn't factor | 237 // Download updates has its own loop in the syncer; it shouldn't factor |
241 // into HasMoreToSync. | 238 // into HasMoreToSync. |
242 EXPECT_FALSE(session_->HasMoreToSync()); | 239 EXPECT_FALSE(session_->HasMoreToSync()); |
243 } | 240 } |
244 | 241 |
245 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { | 242 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { |
246 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); | 243 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
247 | 244 |
248 status()->set_last_download_updates_result(SYNCER_OK); | 245 // When the server returns a timestamp, that means we're up to date. |
249 status()->mutable_updates_response()->mutable_get_updates() | 246 status()->mutable_updates_response()->mutable_get_updates() |
250 ->set_changes_remaining(0); | 247 ->set_changes_remaining(0); |
251 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); | 248 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
252 EXPECT_TRUE(status()->download_updates_succeeded()); | 249 EXPECT_TRUE(status()->download_updates_succeeded()); |
253 | 250 |
254 // Download updates has its own loop in the syncer; it shouldn't factor | 251 // Download updates has its own loop in the syncer; it shouldn't factor |
255 // into HasMoreToSync. | 252 // into HasMoreToSync. |
256 EXPECT_FALSE(session_->HasMoreToSync()); | 253 EXPECT_FALSE(session_->HasMoreToSync()); |
257 } | 254 } |
258 | 255 |
| 256 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemainingForSubset) { |
| 257 status()->set_updates_request_types(ParamsMeaningJustOneEnabledType()); |
| 258 |
| 259 // When the server returns a timestamp, that means we're up to date for that |
| 260 // type. But there may still be more to download if there are other |
| 261 // datatypes that we didn't request on this go-round. |
| 262 status()->mutable_updates_response()->mutable_get_updates() |
| 263 ->set_changes_remaining(0); |
| 264 |
| 265 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
| 266 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 267 |
| 268 // Download updates has its own loop in the syncer; it shouldn't factor |
| 269 // into HasMoreToSync. |
| 270 EXPECT_FALSE(session_->HasMoreToSync()); |
| 271 } |
| 272 |
| 273 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemainingAndEntries) { |
| 274 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 275 // The actual entry count should not factor into the HasMoreToSync |
| 276 // determination. |
| 277 status()->mutable_updates_response()->mutable_get_updates()->add_entries(); |
| 278 status()->mutable_updates_response()->mutable_get_updates() |
| 279 ->set_changes_remaining(1000000L);; |
| 280 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 281 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 282 |
| 283 // Download updates has its own loop in the syncer; it shouldn't factor |
| 284 // into HasMoreToSync. |
| 285 EXPECT_FALSE(session_->HasMoreToSync()); |
| 286 } |
| 287 |
| 288 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemainingAndEntries) { |
| 289 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 290 // The actual entry count should not factor into the HasMoreToSync |
| 291 // determination. |
| 292 status()->mutable_updates_response()->mutable_get_updates()->add_entries(); |
| 293 status()->mutable_updates_response()->mutable_get_updates() |
| 294 ->set_changes_remaining(0); |
| 295 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
| 296 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 297 |
| 298 // Download updates has its own loop in the syncer; it shouldn't factor |
| 299 // into HasMoreToSync. |
| 300 EXPECT_FALSE(session_->HasMoreToSync()); |
| 301 } |
| 302 |
259 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { | 303 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { |
260 // Conflict resolution happens after get updates and commit, | 304 // Conflict resolution happens after get updates and commit, |
261 // so we need to loop back and get updates / commit again now | 305 // so we need to loop back and get updates / commit again now |
262 // that we have made forward progress. | 306 // that we have made forward progress. |
263 status()->update_conflicts_resolved(true); | 307 status()->update_conflicts_resolved(true); |
264 EXPECT_TRUE(session_->HasMoreToSync()); | 308 EXPECT_TRUE(session_->HasMoreToSync()); |
265 } | 309 } |
266 | 310 |
267 TEST_F(SyncSessionTest, ResetTransientState) { | 311 TEST_F(SyncSessionTest, ResetTransientState) { |
268 status()->update_conflicts_resolved(true); | 312 status()->update_conflicts_resolved(true); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); | 587 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); |
544 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); | 588 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); |
545 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); | 589 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); |
546 EXPECT_EQ(payload2, original[syncable::SESSIONS]); | 590 EXPECT_EQ(payload2, original[syncable::SESSIONS]); |
547 EXPECT_EQ(payload3, original[syncable::THEMES]); | 591 EXPECT_EQ(payload3, original[syncable::THEMES]); |
548 } | 592 } |
549 | 593 |
550 } // namespace | 594 } // namespace |
551 } // namespace sessions | 595 } // namespace sessions |
552 } // namespace browser_sync | 596 } // namespace browser_sync |
OLD | NEW |