OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/time.h" | 6 #include "base/time.h" |
7 #include "sync/engine/sync_scheduler.h" | 7 #include "sync/engine/sync_scheduler.h" |
8 #include "sync/sessions/sync_session_context.h" | 8 #include "sync/sessions/sync_session_context.h" |
9 #include "sync/sessions/test_util.h" | 9 #include "sync/sessions/test_util.h" |
10 #include "sync/test/engine/fake_model_safe_worker_registrar.h" | 10 #include "sync/test/engine/fake_model_safe_worker_registrar.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 class SyncSchedulerWhiteboxTest : public testing::Test { | 27 class SyncSchedulerWhiteboxTest : public testing::Test { |
28 public: | 28 public: |
29 virtual void SetUp() { | 29 virtual void SetUp() { |
30 dir_maker_.SetUp(); | 30 dir_maker_.SetUp(); |
31 Syncer* syncer = new Syncer(); | 31 Syncer* syncer = new Syncer(); |
32 ModelSafeRoutingInfo routes; | 32 ModelSafeRoutingInfo routes; |
33 routes[syncable::BOOKMARKS] = GROUP_UI; | 33 routes[syncable::BOOKMARKS] = GROUP_UI; |
34 routes[syncable::NIGORI] = GROUP_PASSIVE; | 34 routes[syncable::NIGORI] = GROUP_PASSIVE; |
35 registrar_.reset(new FakeModelSafeWorkerRegistrar(routes)); | 35 registrar_.reset(new FakeModelSafeWorkerRegistrar(routes)); |
36 connection_.reset(new MockConnectionManager(NULL)); | 36 connection_.reset(new MockConnectionManager(NULL)); |
37 connection_->SetServerReachable(); | |
38 context_ = | 37 context_ = |
39 new SyncSessionContext( | 38 new SyncSessionContext( |
40 connection_.get(), dir_maker_.directory(), | 39 connection_.get(), dir_maker_.directory(), |
41 registrar_.get(), &extensions_activity_monitor_, | 40 registrar_.get(), &extensions_activity_monitor_, |
42 std::vector<SyncEngineEventListener*>(), NULL); | 41 std::vector<SyncEngineEventListener*>(), NULL); |
43 context_->set_notifications_enabled(true); | 42 context_->set_notifications_enabled(true); |
44 context_->set_account_name("Test"); | 43 context_->set_account_name("Test"); |
45 scheduler_.reset( | 44 scheduler_.reset( |
46 new SyncScheduler("TestSyncSchedulerWhitebox", context_, syncer)); | 45 new SyncScheduler("TestSyncSchedulerWhitebox", context_, syncer)); |
47 } | 46 } |
48 | 47 |
49 virtual void TearDown() { | 48 virtual void TearDown() { |
50 scheduler_.reset(); | 49 scheduler_.reset(); |
51 } | 50 } |
52 | 51 |
53 void SetMode(SyncScheduler::Mode mode) { | 52 void SetMode(SyncScheduler::Mode mode) { |
54 scheduler_->mode_ = mode; | 53 scheduler_->mode_ = mode; |
55 } | 54 } |
56 | 55 |
57 void SetLastSyncedTime(base::TimeTicks ticks) { | 56 void SetLastSyncedTime(base::TimeTicks ticks) { |
58 scheduler_->last_sync_session_end_time_ = ticks; | 57 scheduler_->last_sync_session_end_time_ = ticks; |
59 } | 58 } |
60 | 59 |
61 void SetServerConnection(bool connected) { | |
62 scheduler_->server_connection_ok_ = connected; | |
63 } | |
64 | |
65 void ResetWaitInterval() { | 60 void ResetWaitInterval() { |
66 scheduler_->wait_interval_.reset(); | 61 scheduler_->wait_interval_.reset(); |
67 } | 62 } |
68 | 63 |
69 void SetWaitIntervalToThrottled() { | 64 void SetWaitIntervalToThrottled() { |
70 scheduler_->wait_interval_.reset(new SyncScheduler::WaitInterval( | 65 scheduler_->wait_interval_.reset(new SyncScheduler::WaitInterval( |
71 SyncScheduler::WaitInterval::THROTTLED, TimeDelta::FromSeconds(1))); | 66 SyncScheduler::WaitInterval::THROTTLED, TimeDelta::FromSeconds(1))); |
72 } | 67 } |
73 | 68 |
74 void SetWaitIntervalToExponentialBackoff() { | 69 void SetWaitIntervalToExponentialBackoff() { |
75 scheduler_->wait_interval_.reset( | 70 scheduler_->wait_interval_.reset( |
76 new SyncScheduler::WaitInterval( | 71 new SyncScheduler::WaitInterval( |
77 SyncScheduler::WaitInterval::EXPONENTIAL_BACKOFF, | 72 SyncScheduler::WaitInterval::EXPONENTIAL_BACKOFF, |
78 TimeDelta::FromSeconds(1))); | 73 TimeDelta::FromSeconds(1))); |
79 } | 74 } |
80 | 75 |
81 void SetWaitIntervalHadNudge(bool had_nudge) { | 76 void SetWaitIntervalHadNudge(bool had_nudge) { |
82 scheduler_->wait_interval_->had_nudge = had_nudge; | 77 scheduler_->wait_interval_->had_nudge = had_nudge; |
83 } | 78 } |
84 | 79 |
85 SyncScheduler::JobProcessDecision DecideOnJob( | 80 SyncScheduler::JobProcessDecision DecideOnJob( |
86 const SyncScheduler::SyncSessionJob& job) { | 81 const SyncScheduler::SyncSessionJob& job) { |
87 return scheduler_->DecideOnJob(job); | 82 return scheduler_->DecideOnJob(job); |
88 } | 83 } |
89 | 84 |
90 void InitializeSyncerOnNormalMode() { | 85 void InitializeSyncerOnNormalMode() { |
91 SetMode(SyncScheduler::NORMAL_MODE); | 86 SetMode(SyncScheduler::NORMAL_MODE); |
92 ResetWaitInterval(); | 87 ResetWaitInterval(); |
93 SetServerConnection(true); | |
94 SetLastSyncedTime(base::TimeTicks::Now()); | 88 SetLastSyncedTime(base::TimeTicks::Now()); |
95 } | 89 } |
96 | 90 |
97 SyncScheduler::JobProcessDecision CreateAndDecideJob( | 91 SyncScheduler::JobProcessDecision CreateAndDecideJob( |
98 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { | 92 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { |
99 SyncSession* s = scheduler_->CreateSyncSession(SyncSourceInfo()); | 93 SyncSession* s = scheduler_->CreateSyncSession(SyncSourceInfo()); |
100 SyncScheduler::SyncSessionJob job(purpose, TimeTicks::Now(), | 94 SyncScheduler::SyncSessionJob job(purpose, TimeTicks::Now(), |
101 make_linked_ptr(s), | 95 make_linked_ptr(s), |
102 false, | 96 false, |
103 FROM_HERE); | 97 FROM_HERE); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 struct SyncScheduler::SyncSessionJob job; | 261 struct SyncScheduler::SyncSessionJob job; |
268 job.purpose = SyncScheduler::SyncSessionJob::CONFIGURATION; | 262 job.purpose = SyncScheduler::SyncSessionJob::CONFIGURATION; |
269 job.scheduled_start = TimeTicks::Now(); | 263 job.scheduled_start = TimeTicks::Now(); |
270 job.is_canary_job = true; | 264 job.is_canary_job = true; |
271 SyncScheduler::JobProcessDecision decision = DecideOnJob(job); | 265 SyncScheduler::JobProcessDecision decision = DecideOnJob(job); |
272 | 266 |
273 EXPECT_EQ(decision, SyncScheduler::CONTINUE); | 267 EXPECT_EQ(decision, SyncScheduler::CONTINUE); |
274 } | 268 } |
275 | 269 |
276 } // namespace browser_sync | 270 } // namespace browser_sync |
OLD | NEW |