Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: sync/engine/sync_scheduler_whitebox_unittest.cc

Issue 10454105: sync: Refactor per-datatype throttling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/sync_scheduler_unittest.cc ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/engine/throttled_data_type_tracker.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_worker.h" 11 #include "sync/test/engine/fake_model_worker.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
17 using base::TimeDelta; 18 using base::TimeDelta;
(...skipping 19 matching lines...) Expand all
37 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); 38 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI)));
38 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); 39 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE)));
39 40
40 std::vector<ModelSafeWorker*> workers; 41 std::vector<ModelSafeWorker*> workers;
41 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = 42 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it =
42 workers_.begin(); it != workers_.end(); ++it) { 43 workers_.begin(); it != workers_.end(); ++it) {
43 workers.push_back(it->get()); 44 workers.push_back(it->get());
44 } 45 }
45 46
46 connection_.reset(new MockConnectionManager(NULL)); 47 connection_.reset(new MockConnectionManager(NULL));
48 throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL));
47 context_.reset( 49 context_.reset(
48 new SyncSessionContext( 50 new SyncSessionContext(
49 connection_.get(), dir_maker_.directory(), 51 connection_.get(), dir_maker_.directory(),
50 routes, workers, &extensions_activity_monitor_, 52 routes, workers, &extensions_activity_monitor_,
53 throttled_data_type_tracker_.get(),
51 std::vector<SyncEngineEventListener*>(), NULL, NULL)); 54 std::vector<SyncEngineEventListener*>(), NULL, NULL));
52 context_->set_notifications_enabled(true); 55 context_->set_notifications_enabled(true);
53 context_->set_account_name("Test"); 56 context_->set_account_name("Test");
54 scheduler_.reset( 57 scheduler_.reset(
55 new SyncScheduler("TestSyncSchedulerWhitebox", context(), syncer)); 58 new SyncScheduler("TestSyncSchedulerWhitebox", context(), syncer));
56 } 59 }
57 60
58 virtual void TearDown() { 61 virtual void TearDown() {
59 scheduler_.reset(); 62 scheduler_.reset();
60 } 63 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 112 }
110 113
111 SyncSessionContext* context() { return context_.get(); } 114 SyncSessionContext* context() { return context_.get(); }
112 115
113 private: 116 private:
114 MessageLoop message_loop_; 117 MessageLoop message_loop_;
115 scoped_ptr<MockConnectionManager> connection_; 118 scoped_ptr<MockConnectionManager> connection_;
116 scoped_ptr<SyncSessionContext> context_; 119 scoped_ptr<SyncSessionContext> context_;
117 std::vector<scoped_refptr<FakeModelWorker> > workers_; 120 std::vector<scoped_refptr<FakeModelWorker> > workers_;
118 FakeExtensionsActivityMonitor extensions_activity_monitor_; 121 FakeExtensionsActivityMonitor extensions_activity_monitor_;
122 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_;
119 TestDirectorySetterUpper dir_maker_; 123 TestDirectorySetterUpper dir_maker_;
120 124
121 protected: 125 protected:
122 // Declared here to ensure it is destructed before the objects it references. 126 // Declared here to ensure it is destructed before the objects it references.
123 scoped_ptr<SyncScheduler> scheduler_; 127 scoped_ptr<SyncScheduler> scheduler_;
124 }; 128 };
125 129
126 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) { 130 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) {
127 InitializeSyncerOnNormalMode(); 131 InitializeSyncerOnNormalMode();
128 132
129 // Now set the mode to configure. 133 // Now set the mode to configure.
130 SetMode(SyncScheduler::CONFIGURATION_MODE); 134 SetMode(SyncScheduler::CONFIGURATION_MODE);
131 135
132 SyncScheduler::JobProcessDecision decision = 136 SyncScheduler::JobProcessDecision decision =
133 CreateAndDecideJob(SyncScheduler::SyncSessionJob::NUDGE); 137 CreateAndDecideJob(SyncScheduler::SyncSessionJob::NUDGE);
134 138
135 EXPECT_EQ(decision, SyncScheduler::SAVE); 139 EXPECT_EQ(decision, SyncScheduler::SAVE);
136 } 140 }
137 141
138 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { 142 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) {
139 InitializeSyncerOnNormalMode(); 143 InitializeSyncerOnNormalMode();
140 144
141 syncable::ModelTypeSet types; 145 syncable::ModelTypeSet types;
142 types.Put(syncable::BOOKMARKS); 146 types.Put(syncable::BOOKMARKS);
143 147
144 // Mark bookmarks as throttled. 148 // Mark bookmarks as throttled.
145 context()->SetUnthrottleTime(types, 149 context()->throttled_data_type_tracker()->SetUnthrottleTime(
146 base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); 150 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2));
147 151
148 syncable::ModelTypePayloadMap types_with_payload; 152 syncable::ModelTypePayloadMap types_with_payload;
149 types_with_payload[syncable::BOOKMARKS] = ""; 153 types_with_payload[syncable::BOOKMARKS] = "";
150 154
151 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload); 155 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload);
152 SyncSession* s = scheduler_->CreateSyncSession(info); 156 SyncSession* s = scheduler_->CreateSyncSession(info);
153 157
154 // 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.
155 SyncScheduler::SyncSessionJob job(SyncScheduler::SyncSessionJob::NUDGE, 159 SyncScheduler::SyncSessionJob job(SyncScheduler::SyncSessionJob::NUDGE,
156 TimeTicks::Now(), 160 TimeTicks::Now(),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 struct SyncScheduler::SyncSessionJob job; 276 struct SyncScheduler::SyncSessionJob job;
273 job.purpose = SyncScheduler::SyncSessionJob::CONFIGURATION; 277 job.purpose = SyncScheduler::SyncSessionJob::CONFIGURATION;
274 job.scheduled_start = TimeTicks::Now(); 278 job.scheduled_start = TimeTicks::Now();
275 job.is_canary_job = true; 279 job.is_canary_job = true;
276 SyncScheduler::JobProcessDecision decision = DecideOnJob(job); 280 SyncScheduler::JobProcessDecision decision = DecideOnJob(job);
277 281
278 EXPECT_EQ(decision, SyncScheduler::CONTINUE); 282 EXPECT_EQ(decision, SyncScheduler::CONTINUE);
279 } 283 }
280 284
281 } // namespace browser_sync 285 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler_unittest.cc ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698