| 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/throttled_data_type_tracker.h" |
| 7 #include "sync/engine/sync_scheduler.h" | 8 #include "sync/engine/sync_scheduler.h" |
| 8 #include "sync/sessions/sync_session_context.h" | 9 #include "sync/sessions/sync_session_context.h" |
| 9 #include "sync/sessions/test_util.h" | 10 #include "sync/sessions/test_util.h" |
| 10 #include "sync/test/engine/fake_model_safe_worker_registrar.h" | 11 #include "sync/test/engine/fake_model_safe_worker_registrar.h" |
| 11 #include "sync/test/engine/mock_connection_manager.h" | 12 #include "sync/test/engine/mock_connection_manager.h" |
| 12 #include "sync/test/engine/test_directory_setter_upper.h" | 13 #include "sync/test/engine/test_directory_setter_upper.h" |
| 13 #include "sync/test/fake_extensions_activity_monitor.h" | 14 #include "sync/test/fake_extensions_activity_monitor.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 31 Syncer* syncer = new Syncer(); | 32 Syncer* syncer = new Syncer(); |
| 32 ModelSafeRoutingInfo routes; | 33 ModelSafeRoutingInfo routes; |
| 33 routes[syncable::BOOKMARKS] = GROUP_UI; | 34 routes[syncable::BOOKMARKS] = GROUP_UI; |
| 34 routes[syncable::NIGORI] = GROUP_PASSIVE; | 35 routes[syncable::NIGORI] = GROUP_PASSIVE; |
| 35 registrar_.reset(new FakeModelSafeWorkerRegistrar(routes)); | 36 registrar_.reset(new FakeModelSafeWorkerRegistrar(routes)); |
| 36 connection_.reset(new MockConnectionManager(NULL)); | 37 connection_.reset(new MockConnectionManager(NULL)); |
| 37 context_ = | 38 context_ = |
| 38 new SyncSessionContext( | 39 new SyncSessionContext( |
| 39 connection_.get(), dir_maker_.directory(), | 40 connection_.get(), dir_maker_.directory(), |
| 40 registrar_.get(), &extensions_activity_monitor_, | 41 registrar_.get(), &extensions_activity_monitor_, |
| 42 &throttled_data_type_tracker_, |
| 41 std::vector<SyncEngineEventListener*>(), NULL, NULL); | 43 std::vector<SyncEngineEventListener*>(), NULL, NULL); |
| 42 context_->set_notifications_enabled(true); | 44 context_->set_notifications_enabled(true); |
| 43 context_->set_account_name("Test"); | 45 context_->set_account_name("Test"); |
| 44 scheduler_.reset( | 46 scheduler_.reset( |
| 45 new SyncScheduler("TestSyncSchedulerWhitebox", context_, syncer)); | 47 new SyncScheduler("TestSyncSchedulerWhitebox", context_, syncer)); |
| 46 } | 48 } |
| 47 | 49 |
| 48 virtual void TearDown() { | 50 virtual void TearDown() { |
| 49 scheduler_.reset(); | 51 scheduler_.reset(); |
| 50 } | 52 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 104 |
| 103 protected: | 105 protected: |
| 104 scoped_ptr<SyncScheduler> scheduler_; | 106 scoped_ptr<SyncScheduler> scheduler_; |
| 105 | 107 |
| 106 private: | 108 private: |
| 107 MessageLoop message_loop_; | 109 MessageLoop message_loop_; |
| 108 scoped_ptr<MockConnectionManager> connection_; | 110 scoped_ptr<MockConnectionManager> connection_; |
| 109 SyncSessionContext* context_; | 111 SyncSessionContext* context_; |
| 110 scoped_ptr<FakeModelSafeWorkerRegistrar> registrar_; | 112 scoped_ptr<FakeModelSafeWorkerRegistrar> registrar_; |
| 111 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 113 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 114 ThrottledDataTypeTracker throttled_data_type_tracker_; |
| 112 TestDirectorySetterUpper dir_maker_; | 115 TestDirectorySetterUpper dir_maker_; |
| 113 }; | 116 }; |
| 114 | 117 |
| 115 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) { | 118 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) { |
| 116 InitializeSyncerOnNormalMode(); | 119 InitializeSyncerOnNormalMode(); |
| 117 | 120 |
| 118 // Now set the mode to configure. | 121 // Now set the mode to configure. |
| 119 SetMode(SyncScheduler::CONFIGURATION_MODE); | 122 SetMode(SyncScheduler::CONFIGURATION_MODE); |
| 120 | 123 |
| 121 SyncScheduler::JobProcessDecision decision = | 124 SyncScheduler::JobProcessDecision decision = |
| 122 CreateAndDecideJob(SyncScheduler::SyncSessionJob::NUDGE); | 125 CreateAndDecideJob(SyncScheduler::SyncSessionJob::NUDGE); |
| 123 | 126 |
| 124 EXPECT_EQ(decision, SyncScheduler::SAVE); | 127 EXPECT_EQ(decision, SyncScheduler::SAVE); |
| 125 } | 128 } |
| 126 | 129 |
| 127 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { | 130 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { |
| 128 InitializeSyncerOnNormalMode(); | 131 InitializeSyncerOnNormalMode(); |
| 129 | 132 |
| 130 syncable::ModelTypeSet types; | 133 syncable::ModelTypeSet types; |
| 131 types.Put(syncable::BOOKMARKS); | 134 types.Put(syncable::BOOKMARKS); |
| 132 | 135 |
| 133 // Mark bookmarks as throttled. | 136 // Mark bookmarks as throttled. |
| 134 context()->SetUnthrottleTime(types, | 137 context()->throttled_data_type_tracker()->SetUnthrottleTime( |
| 135 base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); | 138 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); |
| 136 | 139 |
| 137 syncable::ModelTypePayloadMap types_with_payload; | 140 syncable::ModelTypePayloadMap types_with_payload; |
| 138 types_with_payload[syncable::BOOKMARKS] = ""; | 141 types_with_payload[syncable::BOOKMARKS] = ""; |
| 139 | 142 |
| 140 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload); | 143 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload); |
| 141 SyncSession* s = scheduler_->CreateSyncSession(info); | 144 SyncSession* s = scheduler_->CreateSyncSession(info); |
| 142 | 145 |
| 143 // Now schedule a nudge with just bookmarks and the change is local. | 146 // Now schedule a nudge with just bookmarks and the change is local. |
| 144 SyncScheduler::SyncSessionJob job(SyncScheduler::SyncSessionJob::NUDGE, | 147 SyncScheduler::SyncSessionJob job(SyncScheduler::SyncSessionJob::NUDGE, |
| 145 TimeTicks::Now(), | 148 TimeTicks::Now(), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 struct SyncScheduler::SyncSessionJob job; | 264 struct SyncScheduler::SyncSessionJob job; |
| 262 job.purpose = SyncScheduler::SyncSessionJob::CONFIGURATION; | 265 job.purpose = SyncScheduler::SyncSessionJob::CONFIGURATION; |
| 263 job.scheduled_start = TimeTicks::Now(); | 266 job.scheduled_start = TimeTicks::Now(); |
| 264 job.is_canary_job = true; | 267 job.is_canary_job = true; |
| 265 SyncScheduler::JobProcessDecision decision = DecideOnJob(job); | 268 SyncScheduler::JobProcessDecision decision = DecideOnJob(job); |
| 266 | 269 |
| 267 EXPECT_EQ(decision, SyncScheduler::CONTINUE); | 270 EXPECT_EQ(decision, SyncScheduler::CONTINUE); |
| 268 } | 271 } |
| 269 | 272 |
| 270 } // namespace browser_sync | 273 } // namespace browser_sync |
| OLD | NEW |