| 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::WriteTransaction; | 15 using syncable::WriteTransaction; |
| 16 | 16 |
| 17 namespace browser_sync { | 17 namespace browser_sync { |
| 18 namespace sessions { | 18 namespace sessions { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class SyncSessionTest : public testing::Test, | 21 class SyncSessionTest : public testing::Test, |
| 22 public SyncSession::Delegate { | 22 public SyncSession::Delegate, |
| 23 public ModelSafeWorkerRegistrar { |
| 23 public: | 24 public: |
| 24 SyncSessionTest() : controller_invocations_allowed_(false) {} | 25 SyncSessionTest() : controller_invocations_allowed_(false) {} |
| 25 virtual void SetUp() { | 26 virtual void SetUp() { |
| 26 context_.reset(new SyncSessionContext(NULL, NULL, NULL)); | 27 context_.reset(new SyncSessionContext(NULL, NULL, this)); |
| 27 session_.reset(new SyncSession(context_.get(), this)); | 28 session_.reset(new SyncSession(context_.get(), this)); |
| 28 } | 29 } |
| 29 virtual void TearDown() { | 30 virtual void TearDown() { |
| 30 session_.reset(); | 31 session_.reset(); |
| 31 context_.reset(); | 32 context_.reset(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { | 35 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { |
| 35 FailControllerInvocationIfDisabled("OnSilencedUntil"); | 36 FailControllerInvocationIfDisabled("OnSilencedUntil"); |
| 36 } | 37 } |
| 37 virtual bool IsSyncingCurrentlySilenced() { | 38 virtual bool IsSyncingCurrentlySilenced() { |
| 38 FailControllerInvocationIfDisabled("IsSyncingCurrentlySilenced"); | 39 FailControllerInvocationIfDisabled("IsSyncingCurrentlySilenced"); |
| 39 return false; | 40 return false; |
| 40 } | 41 } |
| 41 virtual void OnReceivedLongPollIntervalUpdate( | 42 virtual void OnReceivedLongPollIntervalUpdate( |
| 42 const base::TimeDelta& new_interval) { | 43 const base::TimeDelta& new_interval) { |
| 43 FailControllerInvocationIfDisabled("OnReceivedLongPollIntervalUpdate"); | 44 FailControllerInvocationIfDisabled("OnReceivedLongPollIntervalUpdate"); |
| 44 } | 45 } |
| 45 virtual void OnReceivedShortPollIntervalUpdate( | 46 virtual void OnReceivedShortPollIntervalUpdate( |
| 46 const base::TimeDelta& new_interval) { | 47 const base::TimeDelta& new_interval) { |
| 47 FailControllerInvocationIfDisabled("OnReceivedShortPollIntervalUpdate"); | 48 FailControllerInvocationIfDisabled("OnReceivedShortPollIntervalUpdate"); |
| 48 } | 49 } |
| 49 | 50 |
| 51 // ModelSafeWorkerRegistrar implementation. |
| 52 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) {} |
| 53 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {} |
| 54 |
| 50 StatusController* status() { return session_->status_controller(); } | 55 StatusController* status() { return session_->status_controller(); } |
| 51 protected: | 56 protected: |
| 52 void FailControllerInvocationIfDisabled(const std::string& msg) { | 57 void FailControllerInvocationIfDisabled(const std::string& msg) { |
| 53 if (!controller_invocations_allowed_) | 58 if (!controller_invocations_allowed_) |
| 54 FAIL() << msg; | 59 FAIL() << msg; |
| 55 } | 60 } |
| 56 bool controller_invocations_allowed_; | 61 bool controller_invocations_allowed_; |
| 57 scoped_ptr<SyncSession> session_; | 62 scoped_ptr<SyncSession> session_; |
| 58 scoped_ptr<SyncSessionContext> context_; | 63 scoped_ptr<SyncSessionContext> context_; |
| 59 }; | 64 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 EXPECT_EQ(channel, context_->syncer_event_channel()); | 76 EXPECT_EQ(channel, context_->syncer_event_channel()); |
| 72 } | 77 } |
| 73 EXPECT_FALSE(context_->resolver()); | 78 EXPECT_FALSE(context_->resolver()); |
| 74 EXPECT_FALSE(context_->syncer_event_channel()); | 79 EXPECT_FALSE(context_->syncer_event_channel()); |
| 75 } | 80 } |
| 76 | 81 |
| 77 TEST_F(SyncSessionTest, SetWriteTransaction) { | 82 TEST_F(SyncSessionTest, SetWriteTransaction) { |
| 78 TestDirectorySetterUpper db; | 83 TestDirectorySetterUpper db; |
| 79 db.SetUp(); | 84 db.SetUp(); |
| 80 session_.reset(NULL); | 85 session_.reset(NULL); |
| 81 context_.reset(new SyncSessionContext(NULL, db.manager(), NULL)); | 86 context_.reset(new SyncSessionContext(NULL, db.manager(), this)); |
| 82 session_.reset(new SyncSession(context_.get(), this)); | 87 session_.reset(new SyncSession(context_.get(), this)); |
| 83 context_->set_account_name(db.name()); | 88 context_->set_account_name(db.name()); |
| 84 syncable::ScopedDirLookup dir(context_->directory_manager(), | 89 syncable::ScopedDirLookup dir(context_->directory_manager(), |
| 85 context_->account_name()); | 90 context_->account_name()); |
| 86 ASSERT_TRUE(dir.good()); | 91 ASSERT_TRUE(dir.good()); |
| 87 | 92 |
| 88 SyncSession session(context_.get(), this); | 93 SyncSession session(context_.get(), this); |
| 89 EXPECT_TRUE(NULL == session.write_transaction()); | 94 EXPECT_TRUE(NULL == session.write_transaction()); |
| 90 { | 95 { |
| 91 WriteTransaction trans(dir, syncable::UNITTEST, __FILE__, __LINE__); | 96 WriteTransaction trans(dir, syncable::UNITTEST, __FILE__, __LINE__); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 status()->set_conflicts_resolved(true); | 163 status()->set_conflicts_resolved(true); |
| 159 EXPECT_TRUE(session_->HasMoreToSync()); | 164 EXPECT_TRUE(session_->HasMoreToSync()); |
| 160 status()->ResetTransientState(); | 165 status()->ResetTransientState(); |
| 161 EXPECT_FALSE(session_->HasMoreToSync()); | 166 EXPECT_FALSE(session_->HasMoreToSync()); |
| 162 } | 167 } |
| 163 | 168 |
| 164 | 169 |
| 165 } // namespace | 170 } // namespace |
| 166 } // namespace sessions | 171 } // namespace sessions |
| 167 } // namespace browser_sync | 172 } // namespace browser_sync |
| OLD | NEW |