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

Side by Side Diff: components/domain_reliability/scheduler_unittest.cc

Issue 252613002: Domain Reliability: More security review. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ;_; Created 6 years, 7 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
« no previous file with comments | « components/domain_reliability/scheduler.cc ('k') | components/domain_reliability/test_util.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/domain_reliability/scheduler.h" 5 #include "components/domain_reliability/scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "components/domain_reliability/config.h"
9 #include "components/domain_reliability/test_util.h" 10 #include "components/domain_reliability/test_util.h"
10 #include "components/domain_reliability/util.h" 11 #include "components/domain_reliability/util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 using base::TimeDelta; 14 using base::TimeDelta;
14 using base::TimeTicks; 15 using base::TimeTicks;
15 16
16 namespace domain_reliability { 17 namespace domain_reliability {
17 18
18 class DomainReliabilitySchedulerTest : public testing::Test { 19 class DomainReliabilitySchedulerTest : public testing::Test {
19 public: 20 public:
20 DomainReliabilitySchedulerTest() : 21 DomainReliabilitySchedulerTest()
21 num_collectors_(0), 22 : num_collectors_(0),
22 params_(CreateDefaultParams()), 23 params_(CreateDefaultParams()),
23 callback_called_(false) { 24 callback_called_(false) {}
24 }
25 25
26 void CreateScheduler(int num_collectors) { 26 void CreateScheduler(int num_collectors) {
27 DCHECK_LT(0, num_collectors); 27 DCHECK_LT(0, num_collectors);
28 DCHECK(!scheduler_); 28 DCHECK(!scheduler_);
29 29
30 num_collectors_ = num_collectors; 30 num_collectors_ = num_collectors;
31 scheduler_.reset(new DomainReliabilityScheduler( 31 scheduler_.reset(new DomainReliabilityScheduler(
32 &time_, 32 &time_,
33 num_collectors_, 33 num_collectors_,
34 params_, 34 params_,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 << "got upload between " << callback_min_.InSeconds() 73 << "got upload between " << callback_min_.InSeconds()
74 << " and " << callback_max_.InSeconds() << " seconds from now"; 74 << " and " << callback_max_.InSeconds() << " seconds from now";
75 } else { 75 } else {
76 return ::testing::AssertionFailure() 76 return ::testing::AssertionFailure()
77 << "expected upload between " << expected_min.InSeconds() 77 << "expected upload between " << expected_min.InSeconds()
78 << " and " << expected_max.InSeconds() << " seconds from now, " 78 << " and " << expected_max.InSeconds() << " seconds from now, "
79 << "got no upload"; 79 << "got no upload";
80 } 80 }
81 } 81 }
82 82
83 ::testing::AssertionResult CheckStartingUpload(int expected_collector) { 83 ::testing::AssertionResult CheckStartingUpload(size_t expected_collector) {
84 DCHECK(scheduler_); 84 DCHECK(scheduler_);
85 DCHECK_LE(0, expected_collector);
86 DCHECK_GT(num_collectors_, expected_collector); 85 DCHECK_GT(num_collectors_, expected_collector);
87 86
88 int collector; 87 size_t collector = scheduler_->OnUploadStart();
89 scheduler_->OnUploadStart(&collector);
90 if (collector == expected_collector) 88 if (collector == expected_collector)
91 return ::testing::AssertionSuccess(); 89 return ::testing::AssertionSuccess();
92 90
93 return ::testing::AssertionFailure() 91 return ::testing::AssertionFailure()
94 << "expected upload to collector " << expected_collector 92 << "expected upload to collector " << expected_collector
95 << ", got upload to collector " << collector; 93 << ", got upload to collector " << collector;
96 } 94 }
97 95
98 TimeDelta min_delay() const { return params_.minimum_upload_delay; } 96 TimeDelta min_delay() const { return params_.minimum_upload_delay; }
99 TimeDelta max_delay() const { return params_.maximum_upload_delay; } 97 TimeDelta max_delay() const { return params_.maximum_upload_delay; }
100 TimeDelta retry_interval() const { return params_.upload_retry_interval; } 98 TimeDelta retry_interval() const { return params_.upload_retry_interval; }
101 TimeDelta zero_delta() const { return base::TimeDelta::FromMicroseconds(0); } 99 TimeDelta zero_delta() const { return base::TimeDelta::FromMicroseconds(0); }
102 100
103 protected: 101 protected:
104 void ScheduleUploadCallback(TimeDelta min, TimeDelta max) { 102 void ScheduleUploadCallback(TimeDelta min, TimeDelta max) {
105 callback_called_ = true; 103 callback_called_ = true;
106 callback_min_ = min; 104 callback_min_ = min;
107 callback_max_ = max; 105 callback_max_ = max;
108 } 106 }
109 107
110 MockTime time_; 108 MockTime time_;
111 int num_collectors_; 109 size_t num_collectors_;
112 DomainReliabilityScheduler::Params params_; 110 DomainReliabilityScheduler::Params params_;
113 scoped_ptr<DomainReliabilityScheduler> scheduler_; 111 scoped_ptr<DomainReliabilityScheduler> scheduler_;
114 112
115 bool callback_called_; 113 bool callback_called_;
116 TimeDelta callback_min_; 114 TimeDelta callback_min_;
117 TimeDelta callback_max_; 115 TimeDelta callback_max_;
118 }; 116 };
119 117
120 TEST_F(DomainReliabilitySchedulerTest, Create) { 118 TEST_F(DomainReliabilitySchedulerTest, Create) {
121 CreateScheduler(1); 119 CreateScheduler(1);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 204
207 ASSERT_TRUE(CheckPendingUpload(zero_delta(), max_delay() - min_delay())); 205 ASSERT_TRUE(CheckPendingUpload(zero_delta(), max_delay() - min_delay()));
208 time_.Advance(retry_interval()); 206 time_.Advance(retry_interval());
209 207
210 // T = min_delay + retry_interval; collector 0 should be active again. 208 // T = min_delay + retry_interval; collector 0 should be active again.
211 ASSERT_TRUE(CheckStartingUpload(0)); 209 ASSERT_TRUE(CheckStartingUpload(0));
212 scheduler_->OnUploadComplete(true); 210 scheduler_->OnUploadComplete(true);
213 } 211 }
214 212
215 } // namespace domain_reliability 213 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/scheduler.cc ('k') | components/domain_reliability/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698