OLD | NEW |
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/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "chrome/browser/chromeos/geolocation/simple_geolocation_provider.h" | 6 #include "chrome/browser/chromeos/geolocation/simple_geolocation_provider.h" |
7 #include "content/public/test/test_browser_thread_bundle.h" | 7 #include "content/public/test/test_browser_thread_bundle.h" |
8 #include "net/http/http_response_headers.h" | 8 #include "net/http/http_response_headers.h" |
9 #include "net/http/http_status_code.h" | 9 #include "net/http/http_status_code.h" |
10 #include "net/url_request/test_url_fetcher_factory.h" | 10 #include "net/url_request/test_url_fetcher_factory.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 209 |
210 TEST_F(SimpleGeolocationTest, InvalidResponse) { | 210 TEST_F(SimpleGeolocationTest, InvalidResponse) { |
211 SimpleGeolocationProvider provider(NULL, GURL(kTestGeolocationProviderUrl)); | 211 SimpleGeolocationProvider provider(NULL, GURL(kTestGeolocationProviderUrl)); |
212 | 212 |
213 GeolocationAPIFetcherFactory url_factory(GURL(kTestGeolocationProviderUrl), | 213 GeolocationAPIFetcherFactory url_factory(GURL(kTestGeolocationProviderUrl), |
214 "invalid JSON string", | 214 "invalid JSON string", |
215 0 /* require_retries */, | 215 0 /* require_retries */, |
216 &provider); | 216 &provider); |
217 | 217 |
218 GeolocationReceiver receiver; | 218 GeolocationReceiver receiver; |
| 219 |
219 const int timeout_seconds = 1; | 220 const int timeout_seconds = 1; |
| 221 size_t expected_retries = static_cast<size_t>( |
| 222 timeout_seconds * 1000 / kRequestRetryIntervalMilliSeconds); |
| 223 ASSERT_GE(expected_retries, 2U); |
| 224 |
220 provider.RequestGeolocation(base::TimeDelta::FromSeconds(timeout_seconds), | 225 provider.RequestGeolocation(base::TimeDelta::FromSeconds(timeout_seconds), |
221 base::Bind(&GeolocationReceiver::OnRequestDone, | 226 base::Bind(&GeolocationReceiver::OnRequestDone, |
222 base::Unretained(&receiver))); | 227 base::Unretained(&receiver))); |
223 receiver.WaitUntilRequestDone(); | 228 receiver.WaitUntilRequestDone(); |
224 | 229 |
225 EXPECT_EQ( | 230 EXPECT_EQ( |
226 "latitude=200.000000, longitude=200.000000, accuracy=-1.000000, " | 231 "latitude=200.000000, longitude=200.000000, accuracy=-1.000000, " |
227 "error_code=0, error_message='SimpleGeolocation provider at " | 232 "error_code=0, error_message='SimpleGeolocation provider at " |
228 "'https://localhost/' : JSONReader failed: Line: 1, column: 1, " | 233 "'https://localhost/' : JSONReader failed: Line: 1, column: 1, " |
229 "Unexpected token..', status=4 (TIMEOUT)", | 234 "Unexpected token..', status=4 (TIMEOUT)", |
230 receiver.position().ToString()); | 235 receiver.position().ToString()); |
231 EXPECT_TRUE(receiver.server_error()); | 236 EXPECT_TRUE(receiver.server_error()); |
232 size_t expected_retries = static_cast<size_t>( | 237 EXPECT_GE(url_factory.attempts(), 2U); |
233 timeout_seconds * 1000 / kRequestRetryIntervalMilliSeconds); | 238 if (url_factory.attempts() > expected_retries + 1) { |
234 EXPECT_LE(url_factory.attempts(), expected_retries + 1); | 239 LOG(WARNING) |
235 EXPECT_GE(url_factory.attempts(), expected_retries - 1); | 240 << "SimpleGeolocationTest::InvalidResponse: Too many attempts (" |
| 241 << url_factory.attempts() << "), no more then " << expected_retries + 1 |
| 242 << " expected."; |
| 243 } |
| 244 if (url_factory.attempts() < expected_retries - 1) { |
| 245 LOG(WARNING) |
| 246 << "SimpleGeolocationTest::InvalidResponse: Too little attempts (" |
| 247 << url_factory.attempts() << "), greater then " << expected_retries - 1 |
| 248 << " expected."; |
| 249 } |
236 } | 250 } |
237 | 251 |
238 } // namespace chromeos | 252 } // namespace chromeos |
OLD | NEW |