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

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

Powered by Google App Engine
This is Rietveld 408576698