| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/sync/sessions/sync_session.h" | 5 #include "chrome/browser/sync/sessions/sync_session.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/engine/conflict_resolver.h" | 7 #include "chrome/browser/sync/engine/conflict_resolver.h" |
| 8 #include "chrome/browser/sync/engine/syncer_types.h" | 8 #include "chrome/browser/sync/engine/syncer_types.h" |
| 9 #include "chrome/browser/sync/engine/syncer_util.h" | 9 #include "chrome/browser/sync/engine/syncer_util.h" |
| 10 #include "chrome/browser/sync/syncable/directory_manager.h" | 10 #include "chrome/browser/sync/syncable/directory_manager.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 EXPECT_TRUE(session_->HasMoreToSync()); | 126 EXPECT_TRUE(session_->HasMoreToSync()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST_F(SyncSessionTest, MoreToSyncIfConflictSetsBuilt) { | 129 TEST_F(SyncSessionTest, MoreToSyncIfConflictSetsBuilt) { |
| 130 // If we built conflict sets, then we need to loop back and try | 130 // If we built conflict sets, then we need to loop back and try |
| 131 // to get updates & commit again. | 131 // to get updates & commit again. |
| 132 status()->update_conflict_sets_built(true); | 132 status()->update_conflict_sets_built(true); |
| 133 EXPECT_TRUE(session_->HasMoreToSync()); | 133 EXPECT_TRUE(session_->HasMoreToSync()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(SyncSessionTest, MoreToSyncIfDidNotGetZeroUpdates) { | 136 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { |
| 137 // We're not done getting updates until we get an empty response. | 137 // When DownloadUpdatesCommand fails, these should be false. |
| 138 ClientToServerResponse response; | 138 EXPECT_FALSE(status()->server_says_nothing_more_to_download()); |
| 139 response.mutable_get_updates()->add_entries(); | 139 EXPECT_FALSE(status()->download_updates_succeeded()); |
| 140 status()->mutable_updates_response()->CopyFrom(response); | 140 |
| 141 EXPECT_TRUE(session_->HasMoreToSync()); | 141 // Download updates has its own loop in the syncer; it shouldn't factor |
| 142 status()->mutable_updates_response()->Clear(); | 142 // into HasMoreToSync. |
| 143 EXPECT_FALSE(session_->HasMoreToSync()); | 143 EXPECT_FALSE(session_->HasMoreToSync()); |
| 144 status()->mutable_updates_response()->CopyFrom(response); | |
| 145 EXPECT_TRUE(session_->HasMoreToSync()); | |
| 146 } | 144 } |
| 147 | 145 |
| 146 TEST_F(SyncSessionTest, MoreToDownloadIfGotTimestamp) { |
| 147 // When the server returns a timestamp, that means there's more to download. |
| 148 status()->mutable_updates_response()->mutable_get_updates() |
| 149 ->set_new_timestamp(1000000L); |
| 150 EXPECT_FALSE(status()->server_says_nothing_more_to_download()); |
| 151 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 152 |
| 153 // Download updates has its own loop in the syncer; it shouldn't factor |
| 154 // into HasMoreToSync. |
| 155 EXPECT_FALSE(session_->HasMoreToSync()); |
| 156 } |
| 157 |
| 158 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoTimestamp) { |
| 159 // When the server returns a timestamp, that means we're up to date. |
| 160 status()->mutable_updates_response()->mutable_get_updates() |
| 161 ->clear_new_timestamp(); |
| 162 EXPECT_TRUE(status()->server_says_nothing_more_to_download()); |
| 163 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 164 |
| 165 // Download updates has its own loop in the syncer; it shouldn't factor |
| 166 // into HasMoreToSync. |
| 167 EXPECT_FALSE(session_->HasMoreToSync()); |
| 168 } |
| 169 |
| 170 TEST_F(SyncSessionTest, MoreToDownloadIfGotTimestampAndEntries) { |
| 171 // The actual entry count should not factor into the HasMoreToSync |
| 172 // determination. |
| 173 status()->mutable_updates_response()->mutable_get_updates()->add_entries(); |
| 174 status()->mutable_updates_response()->mutable_get_updates() |
| 175 ->set_new_timestamp(1000000L);; |
| 176 EXPECT_FALSE(status()->server_says_nothing_more_to_download()); |
| 177 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 178 |
| 179 // Download updates has its own loop in the syncer; it shouldn't factor |
| 180 // into HasMoreToSync. |
| 181 EXPECT_FALSE(session_->HasMoreToSync()); |
| 182 } |
| 183 |
| 184 |
| 148 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { | 185 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { |
| 149 // Conflict resolution happens after get updates and commit, | 186 // Conflict resolution happens after get updates and commit, |
| 150 // so we need to loop back and get updates / commit again now | 187 // so we need to loop back and get updates / commit again now |
| 151 // that we have made forward progress. | 188 // that we have made forward progress. |
| 152 status()->update_conflicts_resolved(true); | 189 status()->update_conflicts_resolved(true); |
| 153 EXPECT_TRUE(session_->HasMoreToSync()); | 190 EXPECT_TRUE(session_->HasMoreToSync()); |
| 154 } | 191 } |
| 155 | 192 |
| 156 TEST_F(SyncSessionTest, MoreToSyncIfTimestampDirty) { | |
| 157 // If there are more changes on the server that weren't processed during this | |
| 158 // GetUpdates request, the client should send another GetUpdates request and | |
| 159 // use new_timestamp as the from_timestamp value within GetUpdatesMessage. | |
| 160 status()->set_got_new_timestamp(); | |
| 161 status()->update_conflicts_resolved(true); | |
| 162 EXPECT_TRUE(session_->HasMoreToSync()); | |
| 163 } | |
| 164 | |
| 165 | |
| 166 } // namespace | 193 } // namespace |
| 167 } // namespace sessions | 194 } // namespace sessions |
| 168 } // namespace browser_sync | 195 } // namespace browser_sync |
| OLD | NEW |