| 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_impl.h" | 7 #include "sync/engine/sync_scheduler_impl.h" |
| 8 #include "sync/engine/throttled_data_type_tracker.h" | 8 #include "sync/engine/throttled_data_type_tracker.h" |
| 9 #include "sync/sessions/sync_session_context.h" | 9 #include "sync/sessions/sync_session_context.h" |
| 10 #include "sync/sessions/test_util.h" | 10 #include "sync/sessions/test_util.h" |
| 11 #include "sync/test/engine/fake_model_worker.h" | 11 #include "sync/test/engine/fake_model_worker.h" |
| 12 #include "sync/test/engine/mock_connection_manager.h" | 12 #include "sync/test/engine/mock_connection_manager.h" |
| 13 #include "sync/test/engine/test_directory_setter_upper.h" | 13 #include "sync/test/engine/test_directory_setter_upper.h" |
| 14 #include "sync/test/fake_extensions_activity_monitor.h" | 14 #include "sync/test/fake_extensions_activity_monitor.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using base::TimeDelta; | 18 using base::TimeDelta; |
| 19 using base::TimeTicks; | 19 using base::TimeTicks; |
| 20 | 20 |
| 21 namespace syncer { | 21 namespace syncer { |
| 22 using syncer::Syncer; | |
| 23 using sessions::SyncSession; | 22 using sessions::SyncSession; |
| 24 using sessions::SyncSessionContext; | 23 using sessions::SyncSessionContext; |
| 25 using sessions::SyncSourceInfo; | 24 using sessions::SyncSourceInfo; |
| 26 using sync_pb::GetUpdatesCallerInfo; | 25 using sync_pb::GetUpdatesCallerInfo; |
| 27 | 26 |
| 28 class SyncSchedulerWhiteboxTest : public testing::Test { | 27 class SyncSchedulerWhiteboxTest : public testing::Test { |
| 29 public: | 28 public: |
| 30 virtual void SetUp() { | 29 virtual void SetUp() { |
| 31 dir_maker_.SetUp(); | 30 dir_maker_.SetUp(); |
| 32 Syncer* syncer = new Syncer(); | 31 Syncer* syncer = new Syncer(); |
| 33 | 32 |
| 34 ModelSafeRoutingInfo routes; | 33 ModelSafeRoutingInfo routes; |
| 35 routes[syncer::BOOKMARKS] = GROUP_UI; | 34 routes[BOOKMARKS] = GROUP_UI; |
| 36 routes[syncer::NIGORI] = GROUP_PASSIVE; | 35 routes[NIGORI] = GROUP_PASSIVE; |
| 37 | 36 |
| 38 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 37 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 39 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 38 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
| 40 | 39 |
| 41 std::vector<ModelSafeWorker*> workers; | 40 std::vector<ModelSafeWorker*> workers; |
| 42 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = | 41 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = |
| 43 workers_.begin(); it != workers_.end(); ++it) { | 42 workers_.begin(); it != workers_.end(); ++it) { |
| 44 workers.push_back(it->get()); | 43 workers.push_back(it->get()); |
| 45 } | 44 } |
| 46 | 45 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 135 |
| 137 SyncSchedulerImpl::JobProcessDecision decision = | 136 SyncSchedulerImpl::JobProcessDecision decision = |
| 138 CreateAndDecideJob(SyncSchedulerImpl::SyncSessionJob::NUDGE); | 137 CreateAndDecideJob(SyncSchedulerImpl::SyncSessionJob::NUDGE); |
| 139 | 138 |
| 140 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); | 139 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); |
| 141 } | 140 } |
| 142 | 141 |
| 143 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { | 142 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { |
| 144 InitializeSyncerOnNormalMode(); | 143 InitializeSyncerOnNormalMode(); |
| 145 | 144 |
| 146 syncer::ModelTypeSet types; | 145 ModelTypeSet types; |
| 147 types.Put(syncer::BOOKMARKS); | 146 types.Put(BOOKMARKS); |
| 148 | 147 |
| 149 // Mark bookmarks as throttled. | 148 // Mark bookmarks as throttled. |
| 150 context()->throttled_data_type_tracker()->SetUnthrottleTime( | 149 context()->throttled_data_type_tracker()->SetUnthrottleTime( |
| 151 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); | 150 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); |
| 152 | 151 |
| 153 syncer::ModelTypePayloadMap types_with_payload; | 152 ModelTypePayloadMap types_with_payload; |
| 154 types_with_payload[syncer::BOOKMARKS] = ""; | 153 types_with_payload[BOOKMARKS] = ""; |
| 155 | 154 |
| 156 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload); | 155 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload); |
| 157 SyncSession* s = scheduler_->CreateSyncSession(info); | 156 SyncSession* s = scheduler_->CreateSyncSession(info); |
| 158 | 157 |
| 159 // Now schedule a nudge with just bookmarks and the change is local. | 158 // Now schedule a nudge with just bookmarks and the change is local. |
| 160 SyncSchedulerImpl::SyncSessionJob job( | 159 SyncSchedulerImpl::SyncSessionJob job( |
| 161 SyncSchedulerImpl::SyncSessionJob::NUDGE, | 160 SyncSchedulerImpl::SyncSessionJob::NUDGE, |
| 162 TimeTicks::Now(), | 161 TimeTicks::Now(), |
| 163 make_linked_ptr(s), | 162 make_linked_ptr(s), |
| 164 false, | 163 false, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 struct SyncSchedulerImpl::SyncSessionJob job; | 261 struct SyncSchedulerImpl::SyncSessionJob job; |
| 263 job.purpose = SyncSchedulerImpl::SyncSessionJob::CONFIGURATION; | 262 job.purpose = SyncSchedulerImpl::SyncSessionJob::CONFIGURATION; |
| 264 job.scheduled_start = TimeTicks::Now(); | 263 job.scheduled_start = TimeTicks::Now(); |
| 265 job.is_canary_job = true; | 264 job.is_canary_job = true; |
| 266 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); | 265 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); |
| 267 | 266 |
| 268 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 267 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
| 269 } | 268 } |
| 270 | 269 |
| 271 } // namespace syncer | 270 } // namespace syncer |
| OLD | NEW |