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

Side by Side Diff: components/network_time/network_time_tracker_unittest.cc

Issue 1835823002: network_time_tracker: add temporary time protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsleevi review 1 Created 4 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
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/network_time/network_time_tracker.h" 5 #include "components/network_time/network_time_tracker.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/stringprintf.h"
10 #include "base/test/simple_test_clock.h" 12 #include "base/test/simple_test_clock.h"
11 #include "base/test/simple_test_tick_clock.h" 13 #include "base/test/simple_test_tick_clock.h"
14 #include "components/client_update_protocol/ecdsa.h"
12 #include "components/network_time/network_time_pref_names.h" 15 #include "components/network_time/network_time_pref_names.h"
13 #include "components/prefs/testing_pref_service.h" 16 #include "components/prefs/testing_pref_service.h"
17 #include "net/http/http_response_headers.h"
18 #include "net/url_request/test_url_fetcher_factory.h"
19 #include "net/url_request/url_request_test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
15 21
16 namespace network_time { 22 namespace network_time {
17 23
18 class NetworkTimeTrackerTest : public testing::Test { 24 class NetworkTimeTrackerTest : public testing::Test {
19 public: 25 public:
20 ~NetworkTimeTrackerTest() override {} 26 ~NetworkTimeTrackerTest() override {}
21 27
22 void SetUp() override { 28 NetworkTimeTrackerTest() {
29 url_fetcher_factory_.reset(new net::TestURLFetcherFactory());
23 NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); 30 NetworkTimeTracker::RegisterPrefs(pref_service_.registry());
24 31
25 clock_ = new base::SimpleTestClock(); 32 clock_ = new base::SimpleTestClock();
26 tick_clock_ = new base::SimpleTestTickClock(); 33 tick_clock_ = new base::SimpleTestTickClock();
27 // Do this to be sure that |is_null| returns false. 34 // Do this to be sure that |is_null| returns false.
28 clock_->Advance(base::TimeDelta::FromDays(111)); 35 clock_->Advance(base::TimeDelta::FromDays(111));
29 tick_clock_->Advance(base::TimeDelta::FromDays(222)); 36 tick_clock_->Advance(base::TimeDelta::FromDays(222));
30 37
38 scoped_refptr<net::URLRequestContextGetter> getter =
39 new net::TestURLRequestContextGetter(message_loop_.task_runner());
31 tracker_.reset(new NetworkTimeTracker( 40 tracker_.reset(new NetworkTimeTracker(
32 std::unique_ptr<base::Clock>(clock_), 41 std::unique_ptr<base::Clock>(clock_),
33 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_)); 42 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_, getter));
34 43
35 // Can not be smaller than 15, it's the NowFromSystemTime() resolution. 44 // Can not be smaller than 15, it's the NowFromSystemTime() resolution.
36 resolution_ = base::TimeDelta::FromMilliseconds(17); 45 resolution_ = base::TimeDelta::FromMilliseconds(17);
37 latency_ = base::TimeDelta::FromMilliseconds(50); 46 latency_ = base::TimeDelta::FromMilliseconds(50);
38 adjustment_ = 7 * base::TimeDelta::FromMilliseconds(kTicksResolutionMs); 47 adjustment_ = 7 * base::TimeDelta::FromMilliseconds(kTicksResolutionMs);
39 } 48 }
40 49
41 // Replaces |tracker_| with a new object, while preserving the 50 // Replaces |tracker_| with a new object, while preserving the
42 // testing clocks. 51 // testing clocks.
43 void Reset() { 52 void Reset() {
44 base::SimpleTestClock* new_clock = new base::SimpleTestClock(); 53 base::SimpleTestClock* new_clock = new base::SimpleTestClock();
45 new_clock->SetNow(clock_->Now()); 54 new_clock->SetNow(clock_->Now());
46 base::SimpleTestTickClock* new_tick_clock = new base::SimpleTestTickClock(); 55 base::SimpleTestTickClock* new_tick_clock = new base::SimpleTestTickClock();
47 new_tick_clock->SetNowTicks(tick_clock_->NowTicks()); 56 new_tick_clock->SetNowTicks(tick_clock_->NowTicks());
48 clock_ = new_clock; 57 clock_ = new_clock;
49 tick_clock_= new_tick_clock; 58 tick_clock_= new_tick_clock;
59 scoped_refptr<net::URLRequestContextGetter> getter =
60 new net::TestURLRequestContextGetter(message_loop_.task_runner());
50 tracker_.reset(new NetworkTimeTracker( 61 tracker_.reset(new NetworkTimeTracker(
51 std::unique_ptr<base::Clock>(clock_), 62 std::unique_ptr<base::Clock>(clock_),
52 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_)); 63 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_, getter));
64 }
65
66 // Helper for verifying signatures over time server responses. Sets the
67 // client's internal nonce, which is normally randomly generated, to a
68 // predictable value.
69 void OverrideNonce(uint32_t nonce) {
70 tracker_->query_signer_->request_query_cup2key_ =
71 base::StringPrintf("%d:%u", 1 /* key version */, nonce);
53 } 72 }
54 73
55 // Updates the notifier's time with the specified parameters. 74 // Updates the notifier's time with the specified parameters.
56 void UpdateNetworkTime(const base::Time& network_time, 75 void UpdateNetworkTime(const base::Time& network_time,
57 const base::TimeDelta& resolution, 76 const base::TimeDelta& resolution,
58 const base::TimeDelta& latency, 77 const base::TimeDelta& latency,
59 const base::TimeTicks& post_time) { 78 const base::TimeTicks& post_time) {
60 tracker_->UpdateNetworkTime( 79 tracker_->UpdateNetworkTime(
61 network_time, resolution, latency, post_time); 80 network_time, resolution, latency, post_time);
62 } 81 }
63 82
64 // Advances both the system clock and the tick clock. This should be used for 83 // Advances both the system clock and the tick clock. This should be used for
65 // the normal passage of time, i.e. when neither clock is doing anything odd. 84 // the normal passage of time, i.e. when neither clock is doing anything odd.
66 void AdvanceBoth(const base::TimeDelta& delta) { 85 void AdvanceBoth(const base::TimeDelta& delta) {
67 tick_clock_->Advance(delta); 86 tick_clock_->Advance(delta);
68 clock_->Advance(delta); 87 clock_->Advance(delta);
69 } 88 }
70 89
71 protected: 90 protected:
91 base::MessageLoop message_loop_;
72 base::TimeDelta resolution_; 92 base::TimeDelta resolution_;
73 base::TimeDelta latency_; 93 base::TimeDelta latency_;
74 base::TimeDelta adjustment_; 94 base::TimeDelta adjustment_;
75 base::SimpleTestClock* clock_; 95 base::SimpleTestClock* clock_;
76 base::SimpleTestTickClock* tick_clock_; 96 base::SimpleTestTickClock* tick_clock_;
77 TestingPrefServiceSimple pref_service_; 97 TestingPrefServiceSimple pref_service_;
78 std::unique_ptr<NetworkTimeTracker> tracker_; 98 std::unique_ptr<NetworkTimeTracker> tracker_;
99 std::unique_ptr<net::TestURLFetcherFactory> url_fetcher_factory_;
79 }; 100 };
80 101
81 TEST_F(NetworkTimeTrackerTest, Uninitialized) { 102 TEST_F(NetworkTimeTrackerTest, Uninitialized) {
82 base::Time network_time; 103 base::Time network_time;
83 base::TimeDelta uncertainty; 104 base::TimeDelta uncertainty;
84 EXPECT_FALSE(tracker_->GetNetworkTime(&network_time, &uncertainty)); 105 EXPECT_FALSE(tracker_->GetNetworkTime(&network_time, &uncertainty));
85 } 106 }
86 107
87 TEST_F(NetworkTimeTrackerTest, LongPostingDelay) { 108 TEST_F(NetworkTimeTrackerTest, LongPostingDelay) {
88 // The request arrives at the server, which records the time. Advance the 109 // The request arrives at the server, which records the time. Advance the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 EXPECT_GT(out_network_time + uncertainty / 2, clock_->Now()); 145 EXPECT_GT(out_network_time + uncertainty / 2, clock_->Now());
125 } 146 }
126 147
127 TEST_F(NetworkTimeTrackerTest, ClockIsWack) { 148 TEST_F(NetworkTimeTrackerTest, ClockIsWack) {
128 // Now let's assume the system clock is completely wrong. 149 // Now let's assume the system clock is completely wrong.
129 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90); 150 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90);
130 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_, 151 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_,
131 tick_clock_->NowTicks()); 152 tick_clock_->NowTicks());
132 153
133 base::Time out_network_time; 154 base::Time out_network_time;
134 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, NULL)); 155 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, nullptr));
135 EXPECT_EQ(in_network_time, out_network_time); 156 EXPECT_EQ(in_network_time, out_network_time);
136 } 157 }
137 158
138 TEST_F(NetworkTimeTrackerTest, ClocksDivergeSlightly) { 159 TEST_F(NetworkTimeTrackerTest, ClocksDivergeSlightly) {
139 // The two clocks are allowed to diverge a little bit. 160 // The two clocks are allowed to diverge a little bit.
140 base::Time in_network_time = clock_->Now(); 161 base::Time in_network_time = clock_->Now();
141 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_, 162 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_,
142 tick_clock_->NowTicks()); 163 tick_clock_->NowTicks());
143 164
144 base::TimeDelta small = base::TimeDelta::FromSeconds(30); 165 base::TimeDelta small = base::TimeDelta::FromSeconds(30);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 EXPECT_EQ(resolution_ + latency_ + adjustment_, uncertainty); 199 EXPECT_EQ(resolution_ + latency_ + adjustment_, uncertainty);
179 } 200 }
180 201
181 TEST_F(NetworkTimeTrackerTest, SpringForward) { 202 TEST_F(NetworkTimeTrackerTest, SpringForward) {
182 // Simulate the wall clock advancing faster than the tick clock. 203 // Simulate the wall clock advancing faster than the tick clock.
183 UpdateNetworkTime(clock_->Now(), resolution_, latency_, 204 UpdateNetworkTime(clock_->Now(), resolution_, latency_,
184 tick_clock_->NowTicks()); 205 tick_clock_->NowTicks());
185 tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); 206 tick_clock_->Advance(base::TimeDelta::FromSeconds(1));
186 clock_->Advance(base::TimeDelta::FromDays(1)); 207 clock_->Advance(base::TimeDelta::FromDays(1));
187 base::Time out_network_time; 208 base::Time out_network_time;
188 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 209 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
189 } 210 }
190 211
191 TEST_F(NetworkTimeTrackerTest, FallBack) { 212 TEST_F(NetworkTimeTrackerTest, FallBack) {
192 // Simulate the wall clock running backward. 213 // Simulate the wall clock running backward.
193 UpdateNetworkTime(clock_->Now(), resolution_, latency_, 214 UpdateNetworkTime(clock_->Now(), resolution_, latency_,
194 tick_clock_->NowTicks()); 215 tick_clock_->NowTicks());
195 tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); 216 tick_clock_->Advance(base::TimeDelta::FromSeconds(1));
196 clock_->Advance(base::TimeDelta::FromDays(-1)); 217 clock_->Advance(base::TimeDelta::FromDays(-1));
197 base::Time out_network_time; 218 base::Time out_network_time;
198 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 219 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
199 } 220 }
200 221
201 TEST_F(NetworkTimeTrackerTest, SuspendAndResume) { 222 TEST_F(NetworkTimeTrackerTest, SuspendAndResume) {
202 // Simulate the wall clock advancing while the tick clock stands still, as 223 // Simulate the wall clock advancing while the tick clock stands still, as
203 // would happen in a suspend+resume cycle. 224 // would happen in a suspend+resume cycle.
204 UpdateNetworkTime(clock_->Now(), resolution_, latency_, 225 UpdateNetworkTime(clock_->Now(), resolution_, latency_,
205 tick_clock_->NowTicks()); 226 tick_clock_->NowTicks());
206 clock_->Advance(base::TimeDelta::FromHours(1)); 227 clock_->Advance(base::TimeDelta::FromHours(1));
207 base::Time out_network_time; 228 base::Time out_network_time;
208 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 229 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
209 } 230 }
210 231
211 TEST_F(NetworkTimeTrackerTest, Serialize) { 232 TEST_F(NetworkTimeTrackerTest, Serialize) {
212 // Test that we can serialize and deserialize state and get consistent 233 // Test that we can serialize and deserialize state and get consistent
213 // results. 234 // results.
214 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90); 235 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90);
215 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_, 236 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_,
216 tick_clock_->NowTicks()); 237 tick_clock_->NowTicks());
217 base::Time out_network_time; 238 base::Time out_network_time;
218 base::TimeDelta out_uncertainty; 239 base::TimeDelta out_uncertainty;
(...skipping 11 matching lines...) Expand all
230 } 251 }
231 252
232 TEST_F(NetworkTimeTrackerTest, DeserializeOldFormat) { 253 TEST_F(NetworkTimeTrackerTest, DeserializeOldFormat) {
233 // Test that deserializing old data (which do not record the uncertainty and 254 // Test that deserializing old data (which do not record the uncertainty and
234 // tick clock) causes the serialized data to be ignored. 255 // tick clock) causes the serialized data to be ignored.
235 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90); 256 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90);
236 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_, 257 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_,
237 tick_clock_->NowTicks()); 258 tick_clock_->NowTicks());
238 259
239 base::Time out_network_time; 260 base::Time out_network_time;
240 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, NULL)); 261 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, nullptr));
241 double local, network; 262 double local, network;
242 const base::DictionaryValue* saved_prefs = 263 const base::DictionaryValue* saved_prefs =
243 pref_service_.GetDictionary(prefs::kNetworkTimeMapping); 264 pref_service_.GetDictionary(prefs::kNetworkTimeMapping);
244 saved_prefs->GetDouble("local", &local); 265 saved_prefs->GetDouble("local", &local);
245 saved_prefs->GetDouble("network", &network); 266 saved_prefs->GetDouble("network", &network);
246 base::DictionaryValue prefs; 267 base::DictionaryValue prefs;
247 prefs.SetDouble("local", local); 268 prefs.SetDouble("local", local);
248 prefs.SetDouble("network", network); 269 prefs.SetDouble("network", network);
249 pref_service_.Set(prefs::kNetworkTimeMapping, prefs); 270 pref_service_.Set(prefs::kNetworkTimeMapping, prefs);
250 Reset(); 271 Reset();
251 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 272 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
252 } 273 }
253 274
254 TEST_F(NetworkTimeTrackerTest, SerializeWithLongDelay) { 275 TEST_F(NetworkTimeTrackerTest, SerializeWithLongDelay) {
255 // Test that if the serialized data are more than a week old, they are 276 // Test that if the serialized data are more than a week old, they are
256 // discarded. 277 // discarded.
257 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90); 278 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90);
258 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_, 279 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_,
259 tick_clock_->NowTicks()); 280 tick_clock_->NowTicks());
260 base::Time out_network_time; 281 base::Time out_network_time;
261 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, NULL)); 282 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, nullptr));
262 AdvanceBoth(base::TimeDelta::FromDays(8)); 283 AdvanceBoth(base::TimeDelta::FromDays(8));
263 Reset(); 284 Reset();
264 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 285 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
265 } 286 }
266 287
267 TEST_F(NetworkTimeTrackerTest, SerializeWithTickClockAdvance) { 288 TEST_F(NetworkTimeTrackerTest, SerializeWithTickClockAdvance) {
268 // Test that serialized data are discarded if the wall clock and tick clock 289 // Test that serialized data are discarded if the wall clock and tick clock
269 // have not advanced consistently since data were serialized. 290 // have not advanced consistently since data were serialized.
270 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90); 291 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90);
271 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_, 292 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_,
272 tick_clock_->NowTicks()); 293 tick_clock_->NowTicks());
273 base::Time out_network_time; 294 base::Time out_network_time;
274 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, NULL)); 295 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, nullptr));
275 tick_clock_->Advance(base::TimeDelta::FromDays(1)); 296 tick_clock_->Advance(base::TimeDelta::FromDays(1));
276 Reset(); 297 Reset();
277 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 298 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
278 } 299 }
279 300
280 TEST_F(NetworkTimeTrackerTest, SerializeWithWallClockAdvance) { 301 TEST_F(NetworkTimeTrackerTest, SerializeWithWallClockAdvance) {
281 // Test that serialized data are discarded if the wall clock and tick clock 302 // Test that serialized data are discarded if the wall clock and tick clock
282 // have not advanced consistently since data were serialized. 303 // have not advanced consistently since data were serialized.
283 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90); 304 base::Time in_network_time = clock_->Now() - base::TimeDelta::FromDays(90);
284 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_, 305 UpdateNetworkTime(in_network_time - latency_ / 2, resolution_, latency_,
285 tick_clock_->NowTicks()); 306 tick_clock_->NowTicks());
286 307
287 base::Time out_network_time; 308 base::Time out_network_time;
288 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, NULL)); 309 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, nullptr));
289 clock_->Advance(base::TimeDelta::FromDays(1)); 310 clock_->Advance(base::TimeDelta::FromDays(1));
290 Reset(); 311 Reset();
291 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, NULL)); 312 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
313 }
314
315 TEST_F(NetworkTimeTrackerTest, UpdateFromNetwork) {
316 base::Time out_network_time;
317 EXPECT_EQ(nullptr, url_fetcher_factory_->GetFetcherByID(0));
318 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
319
320 // How to update:
321 //
322 // curl http://clients2.google.com/time/1/current?cup2key=1:123123123
323 //
324 // where 1 is the key version and 123123123 is the nonce.
325 //
326 // Copy the nonce, the response, and the x-cup-server-proof header
327 // into the test.
328
329 tracker_->QueryTimeService();
330 OverrideNonce(123123123);
331 net::TestURLFetcher* fetcher = url_fetcher_factory_->GetFetcherByID(0);
332 ASSERT_NE(nullptr, fetcher);
333 EXPECT_EQ("", fetcher->upload_data());
334
335 fetcher->set_response_code(200);
336 fetcher->SetResponseString(
337 ")]}'\n"
338 "{\"current_time_millis\":1461621971825,\"server_nonce\":-6."
339 "006853099049523E85}");
340
341 net::HttpResponseHeaders* headers =
342 new net::HttpResponseHeaders(std::string());
343 headers->AddHeader(
344 "x-cup-server-proof: "
345 "304402202e0f24db1ea69f1bbe81da4108f381fcf7a2781c53cf7663cb47083cb5fe8efd"
346 "022009d2b67c0deceaaf849f7c529be96701ed5f15d5efcaf401a94e0801accc9832:"
347 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
348 fetcher->set_response_headers(headers);
349 fetcher->delegate()->OnURLFetchComplete(fetcher);
350
351 EXPECT_TRUE(tracker_->GetNetworkTime(&out_network_time, nullptr));
352 EXPECT_EQ(base::Time::UnixEpoch() +
353 base::TimeDelta::FromMilliseconds(1461621971825),
354 out_network_time);
355 EXPECT_TRUE(tracker_->query_timer_.IsRunning());
356 }
357
358 TEST_F(NetworkTimeTrackerTest, NoNetworkQueryWhileSynced) {
359 base::Time in_network_time = clock_->Now();
360 UpdateNetworkTime(in_network_time, resolution_, latency_,
361 tick_clock_->NowTicks());
362
363 tracker_->QueryTimeService();
364 net::TestURLFetcher* fetcher = url_fetcher_factory_->GetFetcherByID(0);
365 EXPECT_EQ(nullptr, fetcher); // No query should be started.
366 }
367
368 TEST_F(NetworkTimeTrackerTest, UpdateFromNetworkBadSignature) {
369 base::Time out_network_time;
370 EXPECT_EQ(nullptr, url_fetcher_factory_->GetFetcherByID(0));
371 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
372
373 tracker_->QueryTimeService();
374 OverrideNonce(123123123);
375 net::TestURLFetcher* fetcher = url_fetcher_factory_->GetFetcherByID(0);
376 ASSERT_NE(nullptr, fetcher);
377 EXPECT_EQ("", fetcher->upload_data());
378
379 fetcher->set_response_code(200);
380 fetcher->SetResponseString(
381 ")]}'\n"
382 "{\"current_time_millis\":1461621971825,\"server_nonce\":-6."
383 "006853099049523E85}");
384
385 net::HttpResponseHeaders* headers = new net::HttpResponseHeaders("");
386 headers->AddHeader("x-cup-server-proof: deadbeef:deadbeef");
387 fetcher->set_response_headers(headers);
388 fetcher->delegate()->OnURLFetchComplete(fetcher);
389
390 EXPECT_FALSE(tracker_->GetNetworkTime(&out_network_time, nullptr));
391 EXPECT_TRUE(tracker_->query_timer_.IsRunning());
292 } 392 }
293 393
294 } // namespace network_time 394 } // namespace network_time
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698