| 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" |
| 11 #include "chrome/browser/sync/syncable/syncable.h" | 11 #include "chrome/browser/sync/syncable/syncable.h" |
| 12 #include "chrome/test/sync/engine/test_directory_setter_upper.h" | 12 #include "chrome/test/sync/engine/test_directory_setter_upper.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using syncable::MultiTypeTimeStamp; | |
| 16 using syncable::WriteTransaction; | 15 using syncable::WriteTransaction; |
| 17 | 16 |
| 18 namespace browser_sync { | 17 namespace browser_sync { |
| 19 namespace sessions { | 18 namespace sessions { |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 class SyncSessionTest : public testing::Test, | 21 class SyncSessionTest : public testing::Test, |
| 23 public SyncSession::Delegate, | 22 public SyncSession::Delegate, |
| 24 public ModelSafeWorkerRegistrar { | 23 public ModelSafeWorkerRegistrar { |
| 25 public: | 24 public: |
| 26 SyncSessionTest() : controller_invocations_allowed_(false) { | 25 SyncSessionTest() : controller_invocations_allowed_(false) { |
| 27 GetModelSafeRoutingInfo(&routes_); | 26 GetModelSafeRoutingInfo(&routes_); |
| 28 } | 27 } |
| 29 | 28 |
| 30 SyncSession* MakeSession() { | 29 SyncSession* MakeSession() { |
| 31 return new SyncSession(context_.get(), this, SyncSourceInfo(), routes_, | 30 return new SyncSession(context_.get(), this, SyncSourceInfo(), routes_, |
| 32 std::vector<ModelSafeWorker*>()); | 31 std::vector<ModelSafeWorker*>()); |
| 33 } | 32 } |
| 34 | 33 |
| 35 virtual void SetUp() { | 34 virtual void SetUp() { |
| 36 context_.reset(new SyncSessionContext(NULL, NULL, this, | 35 context_.reset(new SyncSessionContext(NULL, NULL, this, |
| 37 std::vector<SyncEngineEventListener*>())); | 36 std::vector<SyncEngineEventListener*>())); |
| 38 routes_.clear(); | 37 routes_.clear(); |
| 39 routes_[syncable::BOOKMARKS] = GROUP_UI; | 38 routes_[syncable::BOOKMARKS] = GROUP_UI; |
| 40 routes_[syncable::AUTOFILL] = GROUP_UI; | 39 routes_[syncable::AUTOFILL] = GROUP_UI; |
| 41 session_.reset(MakeSession()); | 40 session_.reset(MakeSession()); |
| 42 } | 41 } |
| 43 virtual void TearDown() { | 42 virtual void TearDown() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 70 out->swap(routes_); | 69 out->swap(routes_); |
| 71 } | 70 } |
| 72 | 71 |
| 73 StatusController* status() { return session_->status_controller(); } | 72 StatusController* status() { return session_->status_controller(); } |
| 74 protected: | 73 protected: |
| 75 void FailControllerInvocationIfDisabled(const std::string& msg) { | 74 void FailControllerInvocationIfDisabled(const std::string& msg) { |
| 76 if (!controller_invocations_allowed_) | 75 if (!controller_invocations_allowed_) |
| 77 FAIL() << msg; | 76 FAIL() << msg; |
| 78 } | 77 } |
| 79 | 78 |
| 80 MultiTypeTimeStamp ParamsMeaningAllEnabledTypes() { | 79 syncable::ModelTypeBitSet ParamsMeaningAllEnabledTypes() { |
| 81 MultiTypeTimeStamp request_params; | 80 syncable::ModelTypeBitSet request_params; |
| 82 request_params.timestamp = 2000; | 81 request_params[syncable::BOOKMARKS] = true; |
| 83 request_params.data_types[syncable::BOOKMARKS] = true; | 82 request_params[syncable::AUTOFILL] = true; |
| 84 request_params.data_types[syncable::AUTOFILL] = true; | |
| 85 return request_params; | 83 return request_params; |
| 86 } | 84 } |
| 87 | 85 |
| 88 MultiTypeTimeStamp ParamsMeaningJustOneEnabledType() { | 86 syncable::ModelTypeBitSet ParamsMeaningJustOneEnabledType() { |
| 89 MultiTypeTimeStamp request_params; | 87 syncable::ModelTypeBitSet request_params; |
| 90 request_params.timestamp = 5000; | 88 request_params[syncable::AUTOFILL] = true; |
| 91 request_params.data_types[syncable::AUTOFILL] = true; | |
| 92 return request_params; | 89 return request_params; |
| 93 } | 90 } |
| 94 | 91 |
| 95 bool controller_invocations_allowed_; | 92 bool controller_invocations_allowed_; |
| 96 scoped_ptr<SyncSession> session_; | 93 scoped_ptr<SyncSession> session_; |
| 97 scoped_ptr<SyncSessionContext> context_; | 94 scoped_ptr<SyncSessionContext> context_; |
| 98 ModelSafeRoutingInfo routes_; | 95 ModelSafeRoutingInfo routes_; |
| 99 }; | 96 }; |
| 100 | 97 |
| 101 TEST_F(SyncSessionTest, ScopedContextHelpers) { | 98 TEST_F(SyncSessionTest, ScopedContextHelpers) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 148 } |
| 152 | 149 |
| 153 TEST_F(SyncSessionTest, MoreToSyncIfConflictSetsBuilt) { | 150 TEST_F(SyncSessionTest, MoreToSyncIfConflictSetsBuilt) { |
| 154 // If we built conflict sets, then we need to loop back and try | 151 // If we built conflict sets, then we need to loop back and try |
| 155 // to get updates & commit again. | 152 // to get updates & commit again. |
| 156 status()->update_conflict_sets_built(true); | 153 status()->update_conflict_sets_built(true); |
| 157 EXPECT_TRUE(session_->HasMoreToSync()); | 154 EXPECT_TRUE(session_->HasMoreToSync()); |
| 158 } | 155 } |
| 159 | 156 |
| 160 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { | 157 TEST_F(SyncSessionTest, MoreToDownloadIfDownloadFailed) { |
| 161 status()->set_updates_request_parameters(ParamsMeaningAllEnabledTypes()); | 158 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 162 | 159 |
| 163 // When DownloadUpdatesCommand fails, these should be false. | 160 // When DownloadUpdatesCommand fails, these should be false. |
| 164 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 161 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 165 EXPECT_FALSE(status()->download_updates_succeeded()); | 162 EXPECT_FALSE(status()->download_updates_succeeded()); |
| 166 | 163 |
| 167 // Download updates has its own loop in the syncer; it shouldn't factor | 164 // Download updates has its own loop in the syncer; it shouldn't factor |
| 168 // into HasMoreToSync. | 165 // into HasMoreToSync. |
| 169 EXPECT_FALSE(session_->HasMoreToSync()); | 166 EXPECT_FALSE(session_->HasMoreToSync()); |
| 170 } | 167 } |
| 171 | 168 |
| 172 TEST_F(SyncSessionTest, MoreToDownloadIfGotTimestamp) { | 169 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemaining) { |
| 173 status()->set_updates_request_parameters(ParamsMeaningAllEnabledTypes()); | 170 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 174 | 171 |
| 175 // When the server returns a timestamp, that means there's more to download. | 172 // When the server returns changes_remaining, that means there's |
| 173 // more to download. |
| 176 status()->mutable_updates_response()->mutable_get_updates() | 174 status()->mutable_updates_response()->mutable_get_updates() |
| 177 ->set_new_timestamp(1000000L); | 175 ->set_changes_remaining(1000L); |
| 178 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 176 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 179 EXPECT_TRUE(status()->download_updates_succeeded()); | 177 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 180 | 178 |
| 181 // Download updates has its own loop in the syncer; it shouldn't factor | 179 // Download updates has its own loop in the syncer; it shouldn't factor |
| 182 // into HasMoreToSync. | 180 // into HasMoreToSync. |
| 183 EXPECT_FALSE(session_->HasMoreToSync()); | 181 EXPECT_FALSE(session_->HasMoreToSync()); |
| 184 } | 182 } |
| 185 | 183 |
| 186 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoTimestamp) { | 184 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) { |
| 187 status()->set_updates_request_parameters(ParamsMeaningAllEnabledTypes()); | 185 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 188 | 186 |
| 189 // When the server returns a timestamp, that means we're up to date. | 187 // When the server returns a timestamp, that means we're up to date. |
| 190 status()->mutable_updates_response()->mutable_get_updates() | 188 status()->mutable_updates_response()->mutable_get_updates() |
| 191 ->clear_new_timestamp(); | 189 ->set_changes_remaining(0); |
| 192 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); | 190 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
| 193 EXPECT_TRUE(status()->download_updates_succeeded()); | 191 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 194 | 192 |
| 195 // Download updates has its own loop in the syncer; it shouldn't factor | 193 // Download updates has its own loop in the syncer; it shouldn't factor |
| 196 // into HasMoreToSync. | 194 // into HasMoreToSync. |
| 197 EXPECT_FALSE(session_->HasMoreToSync()); | 195 EXPECT_FALSE(session_->HasMoreToSync()); |
| 198 } | 196 } |
| 199 | 197 |
| 200 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoTimestampForSubset) { | 198 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemainingForSubset) { |
| 201 status()->set_updates_request_parameters(ParamsMeaningJustOneEnabledType()); | 199 status()->set_updates_request_types(ParamsMeaningJustOneEnabledType()); |
| 202 | 200 |
| 203 // When the server returns a timestamp, that means we're up to date for that | 201 // When the server returns a timestamp, that means we're up to date for that |
| 204 // type. But there may still be more to download if there are other | 202 // type. But there may still be more to download if there are other |
| 205 // datatypes that we didn't request on this go-round. | 203 // datatypes that we didn't request on this go-round. |
| 206 status()->mutable_updates_response()->mutable_get_updates() | 204 status()->mutable_updates_response()->mutable_get_updates() |
| 207 ->clear_new_timestamp(); | 205 ->set_changes_remaining(0); |
| 208 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 206 |
| 207 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
| 209 EXPECT_TRUE(status()->download_updates_succeeded()); | 208 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 210 | 209 |
| 211 // Download updates has its own loop in the syncer; it shouldn't factor | 210 // Download updates has its own loop in the syncer; it shouldn't factor |
| 212 // into HasMoreToSync. | 211 // into HasMoreToSync. |
| 213 EXPECT_FALSE(session_->HasMoreToSync()); | 212 EXPECT_FALSE(session_->HasMoreToSync()); |
| 214 } | 213 } |
| 215 | 214 |
| 216 TEST_F(SyncSessionTest, MoreToDownloadIfGotTimestampAndEntries) { | 215 TEST_F(SyncSessionTest, MoreToDownloadIfGotChangesRemainingAndEntries) { |
| 217 status()->set_updates_request_parameters(ParamsMeaningAllEnabledTypes()); | 216 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 218 // The actual entry count should not factor into the HasMoreToSync | 217 // The actual entry count should not factor into the HasMoreToSync |
| 219 // determination. | 218 // determination. |
| 220 status()->mutable_updates_response()->mutable_get_updates()->add_entries(); | 219 status()->mutable_updates_response()->mutable_get_updates()->add_entries(); |
| 221 status()->mutable_updates_response()->mutable_get_updates() | 220 status()->mutable_updates_response()->mutable_get_updates() |
| 222 ->set_new_timestamp(1000000L);; | 221 ->set_changes_remaining(1000000L);; |
| 223 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 222 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 224 EXPECT_TRUE(status()->download_updates_succeeded()); | 223 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 225 | 224 |
| 226 // Download updates has its own loop in the syncer; it shouldn't factor | 225 // Download updates has its own loop in the syncer; it shouldn't factor |
| 227 // into HasMoreToSync. | 226 // into HasMoreToSync. |
| 228 EXPECT_FALSE(session_->HasMoreToSync()); | 227 EXPECT_FALSE(session_->HasMoreToSync()); |
| 229 } | 228 } |
| 230 | 229 |
| 230 TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemainingAndEntries) { |
| 231 status()->set_updates_request_types(ParamsMeaningAllEnabledTypes()); |
| 232 // The actual entry count should not factor into the HasMoreToSync |
| 233 // determination. |
| 234 status()->mutable_updates_response()->mutable_get_updates()->add_entries(); |
| 235 status()->mutable_updates_response()->mutable_get_updates() |
| 236 ->set_changes_remaining(0); |
| 237 EXPECT_TRUE(status()->ServerSaysNothingMoreToDownload()); |
| 238 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 239 |
| 240 // Download updates has its own loop in the syncer; it shouldn't factor |
| 241 // into HasMoreToSync. |
| 242 EXPECT_FALSE(session_->HasMoreToSync()); |
| 243 } |
| 231 | 244 |
| 232 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { | 245 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { |
| 233 // Conflict resolution happens after get updates and commit, | 246 // Conflict resolution happens after get updates and commit, |
| 234 // so we need to loop back and get updates / commit again now | 247 // so we need to loop back and get updates / commit again now |
| 235 // that we have made forward progress. | 248 // that we have made forward progress. |
| 236 status()->update_conflicts_resolved(true); | 249 status()->update_conflicts_resolved(true); |
| 237 EXPECT_TRUE(session_->HasMoreToSync()); | 250 EXPECT_TRUE(session_->HasMoreToSync()); |
| 238 } | 251 } |
| 239 | 252 |
| 240 } // namespace | 253 } // namespace |
| 241 } // namespace sessions | 254 } // namespace sessions |
| 242 } // namespace browser_sync | 255 } // namespace browser_sync |
| OLD | NEW |