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

Side by Side Diff: chromeos/timezone/timezone_unittest.cc

Issue 790793008: chromeos: Remove unused private data members (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « chromeos/timezone/timezone_request.cc ('k') | no next file » | 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "chromeos/geolocation/geoposition.h" 7 #include "chromeos/geolocation/geoposition.h"
8 #include "chromeos/timezone/timezone_provider.h" 8 #include "chromeos/timezone/timezone_provider.h"
9 #include "net/http/http_response_headers.h" 9 #include "net/http/http_response_headers.h"
10 #include "net/http/http_status_code.h" 10 #include "net/http/http_status_code.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 const SimpleRequest simple_request; 203 const SimpleRequest simple_request;
204 204
205 TimeZoneAPIFetcherFactory url_factory(simple_request.url, 205 TimeZoneAPIFetcherFactory url_factory(simple_request.url,
206 simple_request.http_response, 206 simple_request.http_response,
207 0 /* require_retries */, 207 0 /* require_retries */,
208 &provider); 208 &provider);
209 209
210 TimeZoneReceiver receiver; 210 TimeZoneReceiver receiver;
211 211
212 provider.RequestTimezone(simple_request.position, 212 provider.RequestTimezone(simple_request.position,
213 false,
214 base::TimeDelta::FromSeconds(1), 213 base::TimeDelta::FromSeconds(1),
215 base::Bind(&TimeZoneReceiver::OnRequestDone, 214 base::Bind(&TimeZoneReceiver::OnRequestDone,
216 base::Unretained(&receiver))); 215 base::Unretained(&receiver)));
217 receiver.WaitUntilRequestDone(); 216 receiver.WaitUntilRequestDone();
218 217
219 EXPECT_EQ(simple_request.timezone.ToStringForDebug(), 218 EXPECT_EQ(simple_request.timezone.ToStringForDebug(),
220 receiver.timezone()->ToStringForDebug()); 219 receiver.timezone()->ToStringForDebug());
221 EXPECT_FALSE(receiver.server_error()); 220 EXPECT_FALSE(receiver.server_error());
222 EXPECT_EQ(1U, url_factory.attempts()); 221 EXPECT_EQ(1U, url_factory.attempts());
223 } 222 }
224 223
225 TEST_F(TimeZoneTest, ResponseOKWithRetries) { 224 TEST_F(TimeZoneTest, ResponseOKWithRetries) {
226 TimeZoneProvider provider(NULL, GURL(kTestTimeZoneProviderUrl)); 225 TimeZoneProvider provider(NULL, GURL(kTestTimeZoneProviderUrl));
227 const SimpleRequest simple_request; 226 const SimpleRequest simple_request;
228 227
229 TimeZoneAPIFetcherFactory url_factory(simple_request.url, 228 TimeZoneAPIFetcherFactory url_factory(simple_request.url,
230 simple_request.http_response, 229 simple_request.http_response,
231 3 /* require_retries */, 230 3 /* require_retries */,
232 &provider); 231 &provider);
233 232
234 TimeZoneReceiver receiver; 233 TimeZoneReceiver receiver;
235 234
236 provider.RequestTimezone(simple_request.position, 235 provider.RequestTimezone(simple_request.position,
237 false,
238 base::TimeDelta::FromSeconds(1), 236 base::TimeDelta::FromSeconds(1),
239 base::Bind(&TimeZoneReceiver::OnRequestDone, 237 base::Bind(&TimeZoneReceiver::OnRequestDone,
240 base::Unretained(&receiver))); 238 base::Unretained(&receiver)));
241 receiver.WaitUntilRequestDone(); 239 receiver.WaitUntilRequestDone();
242 EXPECT_EQ(simple_request.timezone.ToStringForDebug(), 240 EXPECT_EQ(simple_request.timezone.ToStringForDebug(),
243 receiver.timezone()->ToStringForDebug()); 241 receiver.timezone()->ToStringForDebug());
244 EXPECT_FALSE(receiver.server_error()); 242 EXPECT_FALSE(receiver.server_error());
245 EXPECT_EQ(4U, url_factory.attempts()); 243 EXPECT_EQ(4U, url_factory.attempts());
246 } 244 }
247 245
248 TEST_F(TimeZoneTest, InvalidResponse) { 246 TEST_F(TimeZoneTest, InvalidResponse) {
249 TimeZoneProvider provider(NULL, GURL(kTestTimeZoneProviderUrl)); 247 TimeZoneProvider provider(NULL, GURL(kTestTimeZoneProviderUrl));
250 const SimpleRequest simple_request; 248 const SimpleRequest simple_request;
251 249
252 TimeZoneAPIFetcherFactory url_factory(simple_request.url, 250 TimeZoneAPIFetcherFactory url_factory(simple_request.url,
253 "invalid JSON string", 251 "invalid JSON string",
254 0 /* require_retries */, 252 0 /* require_retries */,
255 &provider); 253 &provider);
256 254
257 TimeZoneReceiver receiver; 255 TimeZoneReceiver receiver;
258 256
259 const int timeout_seconds = 1; 257 const int timeout_seconds = 1;
260 size_t expected_retries = static_cast<size_t>( 258 size_t expected_retries = static_cast<size_t>(
261 timeout_seconds * 1000 / kRequestRetryIntervalMilliSeconds); 259 timeout_seconds * 1000 / kRequestRetryIntervalMilliSeconds);
262 ASSERT_GE(expected_retries, 2U); 260 ASSERT_GE(expected_retries, 2U);
263 261
264 provider.RequestTimezone(simple_request.position, 262 provider.RequestTimezone(simple_request.position,
265 false,
266 base::TimeDelta::FromSeconds(timeout_seconds), 263 base::TimeDelta::FromSeconds(timeout_seconds),
267 base::Bind(&TimeZoneReceiver::OnRequestDone, 264 base::Bind(&TimeZoneReceiver::OnRequestDone,
268 base::Unretained(&receiver))); 265 base::Unretained(&receiver)));
269 receiver.WaitUntilRequestDone(); 266 receiver.WaitUntilRequestDone();
270 EXPECT_EQ( 267 EXPECT_EQ(
271 "dstOffset=0.000000, rawOffset=0.000000, timeZoneId='', timeZoneName='', " 268 "dstOffset=0.000000, rawOffset=0.000000, timeZoneId='', timeZoneName='', "
272 "error_message='TimeZone provider at 'https://localhost/' : JSONReader " 269 "error_message='TimeZone provider at 'https://localhost/' : JSONReader "
273 "failed: Line: 1, column: 1, Unexpected token..', status=6 " 270 "failed: Line: 1, column: 1, Unexpected token..', status=6 "
274 "(REQUEST_ERROR)", 271 "(REQUEST_ERROR)",
275 receiver.timezone()->ToStringForDebug()); 272 receiver.timezone()->ToStringForDebug());
276 EXPECT_FALSE(receiver.server_error()); 273 EXPECT_FALSE(receiver.server_error());
277 EXPECT_GE(url_factory.attempts(), 2U); 274 EXPECT_GE(url_factory.attempts(), 2U);
278 if (url_factory.attempts() > expected_retries + 1) { 275 if (url_factory.attempts() > expected_retries + 1) {
279 LOG(WARNING) << "TimeZoneTest::InvalidResponse: Too many attempts (" 276 LOG(WARNING) << "TimeZoneTest::InvalidResponse: Too many attempts ("
280 << url_factory.attempts() << "), no more then " 277 << url_factory.attempts() << "), no more then "
281 << expected_retries + 1 << " expected."; 278 << expected_retries + 1 << " expected.";
282 } 279 }
283 if (url_factory.attempts() < expected_retries - 1) { 280 if (url_factory.attempts() < expected_retries - 1) {
284 LOG(WARNING) << "TimeZoneTest::InvalidResponse: Too less attempts (" 281 LOG(WARNING) << "TimeZoneTest::InvalidResponse: Too less attempts ("
285 << url_factory.attempts() << "), greater then " 282 << url_factory.attempts() << "), greater then "
286 << expected_retries - 1 << " expected."; 283 << expected_retries - 1 << " expected.";
287 } 284 }
288 } 285 }
289 286
290 } // namespace chromeos 287 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/timezone/timezone_request.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698