| 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 12 matching lines...) Expand all Loading... |
| 23 public SyncSession::Delegate, | 23 public SyncSession::Delegate, |
| 24 public ModelSafeWorkerRegistrar { | 24 public ModelSafeWorkerRegistrar { |
| 25 public: | 25 public: |
| 26 SyncSessionTest() : controller_invocations_allowed_(false) { | 26 SyncSessionTest() : controller_invocations_allowed_(false) { |
| 27 GetModelSafeRoutingInfo(&routes_); | 27 GetModelSafeRoutingInfo(&routes_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SyncSession* MakeSession() { | 30 SyncSession* MakeSession() { |
| 31 return new SyncSession(context_.get(), this, SyncSourceInfo(), routes_, | 31 return new SyncSession(context_.get(), this, SyncSourceInfo(), routes_, |
| 32 std::vector<ModelSafeWorker*>()); | 32 std::vector<ModelSafeWorker*>()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual void SetUp() { | 35 virtual void SetUp() { |
| 36 context_.reset(new SyncSessionContext(NULL, NULL, this, | 36 context_.reset(new SyncSessionContext(NULL, NULL, this, |
| 37 std::vector<SyncEngineEventListener*>())); | 37 std::vector<SyncEngineEventListener*>())); |
| 38 routes_.clear(); | 38 routes_.clear(); |
| 39 routes_[syncable::BOOKMARKS] = GROUP_UI; | 39 routes_[syncable::BOOKMARKS] = GROUP_UI; |
| 40 routes_[syncable::AUTOFILL] = GROUP_UI; | 40 routes_[syncable::AUTOFILL] = GROUP_UI; |
| 41 session_.reset(MakeSession()); | 41 session_ = MakeSession(); |
| 42 } | 42 } |
| 43 virtual void TearDown() { | 43 virtual void TearDown() { |
| 44 session_.reset(); | 44 session_ = NULL; |
| 45 context_.reset(); | 45 context_.reset(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { | 48 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { |
| 49 FailControllerInvocationIfDisabled("OnSilencedUntil"); | 49 FailControllerInvocationIfDisabled("OnSilencedUntil"); |
| 50 } | 50 } |
| 51 virtual bool IsSyncingCurrentlySilenced() { | 51 virtual bool IsSyncingCurrentlySilenced() { |
| 52 FailControllerInvocationIfDisabled("IsSyncingCurrentlySilenced"); | 52 FailControllerInvocationIfDisabled("IsSyncingCurrentlySilenced"); |
| 53 return false; | 53 return false; |
| 54 } | 54 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 | 87 |
| 88 MultiTypeTimeStamp ParamsMeaningJustOneEnabledType() { | 88 MultiTypeTimeStamp ParamsMeaningJustOneEnabledType() { |
| 89 MultiTypeTimeStamp request_params; | 89 MultiTypeTimeStamp request_params; |
| 90 request_params.timestamp = 5000; | 90 request_params.timestamp = 5000; |
| 91 request_params.data_types[syncable::AUTOFILL] = true; | 91 request_params.data_types[syncable::AUTOFILL] = true; |
| 92 return request_params; | 92 return request_params; |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool controller_invocations_allowed_; | 95 bool controller_invocations_allowed_; |
| 96 scoped_ptr<SyncSession> session_; | 96 scoped_refptr<SyncSession> session_; |
| 97 scoped_ptr<SyncSessionContext> context_; | 97 scoped_ptr<SyncSessionContext> context_; |
| 98 ModelSafeRoutingInfo routes_; | 98 ModelSafeRoutingInfo routes_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 TEST_F(SyncSessionTest, ScopedContextHelpers) { | 101 TEST_F(SyncSessionTest, ScopedContextHelpers) { |
| 102 ConflictResolver resolver; | 102 ConflictResolver resolver; |
| 103 EXPECT_FALSE(context_->resolver()); | 103 EXPECT_FALSE(context_->resolver()); |
| 104 { | 104 { |
| 105 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver); | 105 ScopedSessionContextConflictResolver s_resolver(context_.get(), &resolver); |
| 106 EXPECT_EQ(&resolver, context_->resolver()); | 106 EXPECT_EQ(&resolver, context_->resolver()); |
| 107 } | 107 } |
| 108 EXPECT_FALSE(context_->resolver()); | 108 EXPECT_FALSE(context_->resolver()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 TEST_F(SyncSessionTest, SetWriteTransaction) { | 111 TEST_F(SyncSessionTest, SetWriteTransaction) { |
| 112 TestDirectorySetterUpper db; | 112 TestDirectorySetterUpper db; |
| 113 db.SetUp(); | 113 db.SetUp(); |
| 114 session_.reset(NULL); | 114 session_ = NULL; |
| 115 context_.reset(new SyncSessionContext(NULL, db.manager(), this, | 115 context_.reset(new SyncSessionContext(NULL, db.manager(), this, |
| 116 std::vector<SyncEngineEventListener*>())); | 116 std::vector<SyncEngineEventListener*>())); |
| 117 session_.reset(MakeSession()); | 117 session_ = MakeSession(); |
| 118 context_->set_account_name(db.name()); | 118 context_->set_account_name(db.name()); |
| 119 syncable::ScopedDirLookup dir(context_->directory_manager(), | 119 syncable::ScopedDirLookup dir(context_->directory_manager(), |
| 120 context_->account_name()); | 120 context_->account_name()); |
| 121 ASSERT_TRUE(dir.good()); | 121 ASSERT_TRUE(dir.good()); |
| 122 | 122 |
| 123 scoped_ptr<SyncSession> session(MakeSession()); | 123 scoped_refptr<SyncSession> session(MakeSession()); |
| 124 EXPECT_TRUE(NULL == session->write_transaction()); | 124 EXPECT_TRUE(NULL == session->write_transaction()); |
| 125 { | 125 { |
| 126 WriteTransaction trans(dir, syncable::UNITTEST, __FILE__, __LINE__); | 126 WriteTransaction trans(dir, syncable::UNITTEST, __FILE__, __LINE__); |
| 127 sessions::ScopedSetSessionWriteTransaction set_trans(session.get(), &trans); | 127 sessions::ScopedSetSessionWriteTransaction set_trans(session.get(), &trans); |
| 128 EXPECT_TRUE(&trans == session->write_transaction()); | 128 EXPECT_TRUE(&trans == session->write_transaction()); |
| 129 } | 129 } |
| 130 db.TearDown(); | 130 db.TearDown(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 TEST_F(SyncSessionTest, MoreToSyncIfUnsyncedGreaterThanCommitted) { | 133 TEST_F(SyncSessionTest, MoreToSyncIfUnsyncedGreaterThanCommitted) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 status()->mutable_updates_response()->mutable_get_updates() | 221 status()->mutable_updates_response()->mutable_get_updates() |
| 222 ->set_new_timestamp(1000000L);; | 222 ->set_new_timestamp(1000000L);; |
| 223 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); | 223 EXPECT_FALSE(status()->ServerSaysNothingMoreToDownload()); |
| 224 EXPECT_TRUE(status()->download_updates_succeeded()); | 224 EXPECT_TRUE(status()->download_updates_succeeded()); |
| 225 | 225 |
| 226 // Download updates has its own loop in the syncer; it shouldn't factor | 226 // Download updates has its own loop in the syncer; it shouldn't factor |
| 227 // into HasMoreToSync. | 227 // into HasMoreToSync. |
| 228 EXPECT_FALSE(session_->HasMoreToSync()); | 228 EXPECT_FALSE(session_->HasMoreToSync()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 | |
| 232 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { | 231 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { |
| 233 // Conflict resolution happens after get updates and commit, | 232 // Conflict resolution happens after get updates and commit, |
| 234 // so we need to loop back and get updates / commit again now | 233 // so we need to loop back and get updates / commit again now |
| 235 // that we have made forward progress. | 234 // that we have made forward progress. |
| 236 status()->update_conflicts_resolved(true); | 235 status()->update_conflicts_resolved(true); |
| 237 EXPECT_TRUE(session_->HasMoreToSync()); | 236 EXPECT_TRUE(session_->HasMoreToSync()); |
| 238 } | 237 } |
| 239 | 238 |
| 239 TEST_F(SyncSessionTest, ResetTransientState) { |
| 240 status()->update_conflicts_resolved(true); |
| 241 status()->increment_num_successful_commits(); |
| 242 EXPECT_TRUE(session_->HasMoreToSync()); |
| 243 session_->ResetTransientState(); |
| 244 EXPECT_FALSE(status()->conflicts_resolved()); |
| 245 EXPECT_FALSE(session_->HasMoreToSync()); |
| 246 EXPECT_FALSE(status()->TestAndClearIsDirty()); |
| 247 } |
| 248 |
| 249 TEST_F(SyncSessionTest, Coalesce) { |
| 250 |
| 251 } |
| 252 |
| 240 } // namespace | 253 } // namespace |
| 241 } // namespace sessions | 254 } // namespace sessions |
| 242 } // namespace browser_sync | 255 } // namespace browser_sync |
| OLD | NEW |