| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "content/browser/geolocation/fake_access_token_store.h" | 13 #include "content/browser/geolocation/fake_access_token_store.h" |
| 14 #include "content/browser/geolocation/location_arbitrator.h" | 14 #include "content/browser/geolocation/location_arbitrator_impl.h" |
| 15 #include "content/browser/geolocation/network_location_provider.h" | 15 #include "content/browser/geolocation/network_location_provider.h" |
| 16 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 17 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 // Constants used in multiple tests. | 22 // Constants used in multiple tests. |
| 23 const char kTestServerUrl[] = "https://www.geolocation.test/service"; | 23 const char kTestServerUrl[] = "https://www.geolocation.test/service"; |
| 24 const char kAccessTokenString[] = "accessToken"; | 24 const char kAccessTokenString[] = "accessToken"; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 int expected_wifi_aps, | 257 int expected_wifi_aps, |
| 258 int wifi_start_index, | 258 int wifi_start_index, |
| 259 const std::string& expected_access_token) { | 259 const std::string& expected_access_token) { |
| 260 const GURL& request_url = request.GetOriginalURL(); | 260 const GURL& request_url = request.GetOriginalURL(); |
| 261 | 261 |
| 262 EXPECT_TRUE(IsTestServerUrl(request_url)); | 262 EXPECT_TRUE(IsTestServerUrl(request_url)); |
| 263 | 263 |
| 264 // Check to see that the api key is being appended for the default | 264 // Check to see that the api key is being appended for the default |
| 265 // network provider url. | 265 // network provider url. |
| 266 bool is_default_url = UrlWithoutQuery(request_url) == | 266 bool is_default_url = UrlWithoutQuery(request_url) == |
| 267 UrlWithoutQuery(GeolocationArbitrator::DefaultNetworkProviderURL()); | 267 UrlWithoutQuery(GeolocationArbitratorImpl::DefaultNetworkProviderURL()); |
| 268 EXPECT_EQ(is_default_url, !request_url.query().empty()); | 268 EXPECT_EQ(is_default_url, !request_url.query().empty()); |
| 269 | 269 |
| 270 const std::string& upload_data = request.upload_data(); | 270 const std::string& upload_data = request.upload_data(); |
| 271 ASSERT_FALSE(upload_data.empty()); | 271 ASSERT_FALSE(upload_data.empty()); |
| 272 std::string json_parse_error_msg; | 272 std::string json_parse_error_msg; |
| 273 scoped_ptr<base::Value> parsed_json( | 273 scoped_ptr<base::Value> parsed_json( |
| 274 base::JSONReader::ReadAndReturnError( | 274 base::JSONReader::ReadAndReturnError( |
| 275 upload_data, | 275 upload_data, |
| 276 base::JSON_PARSE_RFC, | 276 base::JSON_PARSE_RFC, |
| 277 NULL, | 277 NULL, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 340 |
| 341 TEST_F(GeolocationNetworkProviderTest, StartProvider) { | 341 TEST_F(GeolocationNetworkProviderTest, StartProvider) { |
| 342 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); | 342 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); |
| 343 EXPECT_TRUE(provider->StartProvider(false)); | 343 EXPECT_TRUE(provider->StartProvider(false)); |
| 344 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); | 344 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); |
| 345 ASSERT_TRUE(fetcher != NULL); | 345 ASSERT_TRUE(fetcher != NULL); |
| 346 CheckRequestIsValid(*fetcher, 0, 0, 0, ""); | 346 CheckRequestIsValid(*fetcher, 0, 0, 0, ""); |
| 347 } | 347 } |
| 348 | 348 |
| 349 TEST_F(GeolocationNetworkProviderTest, StartProviderDefaultUrl) { | 349 TEST_F(GeolocationNetworkProviderTest, StartProviderDefaultUrl) { |
| 350 test_server_url_ = GeolocationArbitrator::DefaultNetworkProviderURL(); | 350 test_server_url_ = GeolocationArbitratorImpl::DefaultNetworkProviderURL(); |
| 351 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); | 351 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); |
| 352 EXPECT_TRUE(provider->StartProvider(false)); | 352 EXPECT_TRUE(provider->StartProvider(false)); |
| 353 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); | 353 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); |
| 354 ASSERT_TRUE(fetcher != NULL); | 354 ASSERT_TRUE(fetcher != NULL); |
| 355 CheckRequestIsValid(*fetcher, 0, 0, 0, ""); | 355 CheckRequestIsValid(*fetcher, 0, 0, 0, ""); |
| 356 } | 356 } |
| 357 | 357 |
| 358 | 358 |
| 359 TEST_F(GeolocationNetworkProviderTest, StartProviderLongRequest) { | 359 TEST_F(GeolocationNetworkProviderTest, StartProviderLongRequest) { |
| 360 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); | 360 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); | 575 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); |
| 576 } else { | 576 } else { |
| 577 const int evicted = i - kCacheSize; | 577 const int evicted = i - kCacheSize; |
| 578 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); | 578 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); |
| 579 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); | 579 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace content | 584 } // namespace content |
| OLD | NEW |