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 "device/geolocation/network_location_provider.h" | 5 #include "device/geolocation/network_location_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "device/geolocation/fake_access_token_store.h" | 23 #include "device/geolocation/fake_access_token_store.h" |
24 #include "device/geolocation/location_arbitrator_impl.h" | 24 #include "device/geolocation/location_arbitrator.h" |
25 #include "device/geolocation/wifi_data_provider.h" | 25 #include "device/geolocation/wifi_data_provider.h" |
26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
27 #include "net/url_request/test_url_fetcher_factory.h" | 27 #include "net/url_request/test_url_fetcher_factory.h" |
28 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
31 namespace device { | 31 namespace device { |
32 | 32 |
33 // Constants used in multiple tests. | 33 // Constants used in multiple tests. |
34 const char kTestServerUrl[] = "https://www.geolocation.test/service"; | 34 const char kTestServerUrl[] = "https://www.geolocation.test/service"; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 int wifi_start_index, | 256 int wifi_start_index, |
257 const std::string& expected_access_token) { | 257 const std::string& expected_access_token) { |
258 const GURL& request_url = request.GetOriginalURL(); | 258 const GURL& request_url = request.GetOriginalURL(); |
259 | 259 |
260 EXPECT_TRUE(IsTestServerUrl(request_url)); | 260 EXPECT_TRUE(IsTestServerUrl(request_url)); |
261 | 261 |
262 // Check to see that the api key is being appended for the default | 262 // Check to see that the api key is being appended for the default |
263 // network provider url. | 263 // network provider url. |
264 bool is_default_url = | 264 bool is_default_url = |
265 UrlWithoutQuery(request_url) == | 265 UrlWithoutQuery(request_url) == |
266 UrlWithoutQuery(LocationArbitratorImpl::DefaultNetworkProviderURL()); | 266 UrlWithoutQuery(LocationArbitrator::DefaultNetworkProviderURL()); |
267 EXPECT_EQ(is_default_url, !request_url.query().empty()); | 267 EXPECT_EQ(is_default_url, !request_url.query().empty()); |
268 | 268 |
269 const std::string& upload_data = request.upload_data(); | 269 const std::string& upload_data = request.upload_data(); |
270 ASSERT_FALSE(upload_data.empty()); | 270 ASSERT_FALSE(upload_data.empty()); |
271 std::string json_parse_error_msg; | 271 std::string json_parse_error_msg; |
272 std::unique_ptr<base::Value> parsed_json = | 272 std::unique_ptr<base::Value> parsed_json = |
273 base::JSONReader::ReadAndReturnError(upload_data, base::JSON_PARSE_RFC, | 273 base::JSONReader::ReadAndReturnError(upload_data, base::JSON_PARSE_RFC, |
274 nullptr, &json_parse_error_msg); | 274 nullptr, &json_parse_error_msg); |
275 EXPECT_TRUE(json_parse_error_msg.empty()); | 275 EXPECT_TRUE(json_parse_error_msg.empty()); |
276 ASSERT_TRUE(parsed_json); | 276 ASSERT_TRUE(parsed_json); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 334 |
335 TEST_F(GeolocationNetworkProviderTest, StartProvider) { | 335 TEST_F(GeolocationNetworkProviderTest, StartProvider) { |
336 std::unique_ptr<LocationProvider> provider(CreateProvider(true)); | 336 std::unique_ptr<LocationProvider> provider(CreateProvider(true)); |
337 EXPECT_TRUE(provider->StartProvider(false)); | 337 EXPECT_TRUE(provider->StartProvider(false)); |
338 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); | 338 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); |
339 ASSERT_TRUE(fetcher); | 339 ASSERT_TRUE(fetcher); |
340 CheckRequestIsValid(*fetcher, 0, 0, 0, std::string()); | 340 CheckRequestIsValid(*fetcher, 0, 0, 0, std::string()); |
341 } | 341 } |
342 | 342 |
343 TEST_F(GeolocationNetworkProviderTest, StartProviderDefaultUrl) { | 343 TEST_F(GeolocationNetworkProviderTest, StartProviderDefaultUrl) { |
344 test_server_url_ = LocationArbitratorImpl::DefaultNetworkProviderURL(); | 344 test_server_url_ = LocationArbitrator::DefaultNetworkProviderURL(); |
345 std::unique_ptr<LocationProvider> provider(CreateProvider(true)); | 345 std::unique_ptr<LocationProvider> provider(CreateProvider(true)); |
346 EXPECT_TRUE(provider->StartProvider(false)); | 346 EXPECT_TRUE(provider->StartProvider(false)); |
347 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); | 347 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); |
348 ASSERT_TRUE(fetcher); | 348 ASSERT_TRUE(fetcher); |
349 CheckRequestIsValid(*fetcher, 0, 0, 0, std::string()); | 349 CheckRequestIsValid(*fetcher, 0, 0, 0, std::string()); |
350 } | 350 } |
351 | 351 |
352 TEST_F(GeolocationNetworkProviderTest, StartProviderLongRequest) { | 352 TEST_F(GeolocationNetworkProviderTest, StartProviderLongRequest) { |
353 std::unique_ptr<LocationProvider> provider(CreateProvider(true)); | 353 std::unique_ptr<LocationProvider> provider(CreateProvider(true)); |
354 EXPECT_TRUE(provider->StartProvider(false)); | 354 EXPECT_TRUE(provider->StartProvider(false)); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); | 554 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); |
555 } else { | 555 } else { |
556 const int evicted = i - kCacheSize; | 556 const int evicted = i - kCacheSize; |
557 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); | 557 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); |
558 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); | 558 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); |
559 } | 559 } |
560 } | 560 } |
561 } | 561 } |
562 | 562 |
563 } // namespace device | 563 } // namespace device |
OLD | NEW |