| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_TEST_SYNC_ENGINE_SYNCER_COMMAND_TEST_H_ | 5 #ifndef CHROME_TEST_SYNC_ENGINE_SYNCER_COMMAND_TEST_H_ |
| 6 #define CHROME_TEST_SYNC_ENGINE_SYNCER_COMMAND_TEST_H_ | 6 #define CHROME_TEST_SYNC_ENGINE_SYNCER_COMMAND_TEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" |
| 13 #include "chrome/browser/sync/engine/model_safe_worker.h" | 14 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 14 #include "chrome/browser/sync/sessions/sync_session.h" | 15 #include "chrome/browser/sync/sessions/sync_session.h" |
| 15 #include "chrome/browser/sync/sessions/sync_session_context.h" | 16 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 16 #include "chrome/test/sync/engine/mock_connection_manager.h" | 17 #include "chrome/test/sync/engine/mock_connection_manager.h" |
| 17 #include "chrome/test/sync/engine/test_directory_setter_upper.h" | 18 #include "chrome/test/sync/engine/test_directory_setter_upper.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace browser_sync { | 21 namespace browser_sync { |
| 21 | 22 |
| 22 // A test fixture that simplifies writing unit tests for individual | 23 // A test fixture that simplifies writing unit tests for individual |
| 23 // SyncerCommands, providing convenient access to a test directory | 24 // SyncerCommands, providing convenient access to a test directory |
| 24 // and a syncer session. | 25 // and a syncer session. |
| 25 template<typename T> | 26 template<typename T> |
| 26 class SyncerCommandTestWithParam : public testing::TestWithParam<T>, | 27 class SyncerCommandTestWithParam : public testing::TestWithParam<T>, |
| 27 public sessions::SyncSession::Delegate, | 28 public sessions::SyncSession::Delegate, |
| 28 public ModelSafeWorkerRegistrar { | 29 public ModelSafeWorkerRegistrar { |
| 29 public: | 30 public: |
| 30 enum UseMockDirectory { | 31 enum UseMockDirectory { |
| 31 USE_MOCK_DIRECTORY | 32 USE_MOCK_DIRECTORY |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 // SyncSession::Delegate implementation. | 35 // SyncSession::Delegate implementation. |
| 35 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { | 36 virtual void OnSilencedUntil( |
| 37 const base::TimeTicks& silenced_until) OVERRIDE { |
| 36 FAIL() << "Should not get silenced."; | 38 FAIL() << "Should not get silenced."; |
| 37 } | 39 } |
| 38 virtual bool IsSyncingCurrentlySilenced() { | 40 virtual bool IsSyncingCurrentlySilenced() OVERRIDE { |
| 39 ADD_FAILURE() << "No requests for silenced state should be made."; | 41 ADD_FAILURE() << "No requests for silenced state should be made."; |
| 40 return false; | 42 return false; |
| 41 } | 43 } |
| 42 virtual void OnReceivedLongPollIntervalUpdate( | 44 virtual void OnReceivedLongPollIntervalUpdate( |
| 43 const base::TimeDelta& new_interval) { | 45 const base::TimeDelta& new_interval) OVERRIDE { |
| 44 FAIL() << "Should not get poll interval update."; | 46 FAIL() << "Should not get poll interval update."; |
| 45 } | 47 } |
| 46 virtual void OnReceivedShortPollIntervalUpdate( | 48 virtual void OnReceivedShortPollIntervalUpdate( |
| 47 const base::TimeDelta& new_interval) { | 49 const base::TimeDelta& new_interval) OVERRIDE { |
| 48 FAIL() << "Should not get poll interval update."; | 50 FAIL() << "Should not get poll interval update."; |
| 49 } | 51 } |
| 50 virtual void OnShouldStopSyncingPermanently() { | 52 virtual void OnReceivedSessionsCommitDelay( |
| 53 const base::TimeDelta& new_delay) OVERRIDE { |
| 54 FAIL() << "Should not get sessions commit delay."; |
| 55 } |
| 56 virtual void OnShouldStopSyncingPermanently() OVERRIDE { |
| 51 FAIL() << "Shouldn't be forced to stop syncing."; | 57 FAIL() << "Shouldn't be forced to stop syncing."; |
| 52 } | 58 } |
| 53 virtual void SignalUpdatedToken(const std::string& token) { | 59 virtual void SignalUpdatedToken(const std::string& token) OVERRIDE { |
| 54 FAIL() << "Should never update token."; | 60 FAIL() << "Should never update token."; |
| 55 } | 61 } |
| 56 | 62 |
| 57 // ModelSafeWorkerRegistrar implementation. | 63 // ModelSafeWorkerRegistrar implementation. |
| 58 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) { | 64 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) OVERRIDE { |
| 59 std::vector<scoped_refptr<ModelSafeWorker> >::iterator it; | 65 std::vector<scoped_refptr<ModelSafeWorker> >::iterator it; |
| 60 for (it = workers_.begin(); it != workers_.end(); ++it) | 66 for (it = workers_.begin(); it != workers_.end(); ++it) |
| 61 out->push_back(*it); | 67 out->push_back(*it); |
| 62 } | 68 } |
| 63 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 69 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE { |
| 64 ModelSafeRoutingInfo copy(routing_info_); | 70 ModelSafeRoutingInfo copy(routing_info_); |
| 65 out->swap(copy); | 71 out->swap(copy); |
| 66 } | 72 } |
| 67 | 73 |
| 68 protected: | 74 protected: |
| 69 SyncerCommandTestWithParam() : syncdb_(new TestDirectorySetterUpper()) {} | 75 SyncerCommandTestWithParam() : syncdb_(new TestDirectorySetterUpper()) {} |
| 70 | 76 |
| 71 explicit SyncerCommandTestWithParam(UseMockDirectory use_mock) | 77 explicit SyncerCommandTestWithParam(UseMockDirectory use_mock) |
| 72 : syncdb_(new MockDirectorySetterUpper()) {} | 78 : syncdb_(new MockDirectorySetterUpper()) {} |
| 73 | 79 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 : SyncerCommandTestWithParam<void*>( | 160 : SyncerCommandTestWithParam<void*>( |
| 155 SyncerCommandTestWithParam<void*>::USE_MOCK_DIRECTORY) {} | 161 SyncerCommandTestWithParam<void*>::USE_MOCK_DIRECTORY) {} |
| 156 MockDirectorySetterUpper::MockDirectory* mock_directory() { | 162 MockDirectorySetterUpper::MockDirectory* mock_directory() { |
| 157 return static_cast<MockDirectorySetterUpper*>(syncdb())->directory(); | 163 return static_cast<MockDirectorySetterUpper*>(syncdb())->directory(); |
| 158 } | 164 } |
| 159 }; | 165 }; |
| 160 | 166 |
| 161 } // namespace browser_sync | 167 } // namespace browser_sync |
| 162 | 168 |
| 163 #endif // CHROME_TEST_SYNC_ENGINE_SYNCER_COMMAND_TEST_H_ | 169 #endif // CHROME_TEST_SYNC_ENGINE_SYNCER_COMMAND_TEST_H_ |
| OLD | NEW |