| 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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 static int IndexToChannel(int index) { return index + 4; } | 156 static int IndexToChannel(int index) { return index + 4; } |
| 157 | 157 |
| 158 // Creates wifi data containing the specified number of access points, with | 158 // Creates wifi data containing the specified number of access points, with |
| 159 // some differentiating charactistics in each. | 159 // some differentiating charactistics in each. |
| 160 static WifiData CreateReferenceWifiScanData(int ap_count) { | 160 static WifiData CreateReferenceWifiScanData(int ap_count) { |
| 161 WifiData data; | 161 WifiData data; |
| 162 for (int i = 0; i < ap_count; ++i) { | 162 for (int i = 0; i < ap_count; ++i) { |
| 163 AccessPointData ap; | 163 AccessPointData ap; |
| 164 ap.mac_address = | 164 ap.mac_address = |
| 165 ASCIIToUTF16(base::StringPrintf("%02d-34-56-78-54-32", i)); | 165 base::ASCIIToUTF16(base::StringPrintf("%02d-34-56-78-54-32", i)); |
| 166 ap.radio_signal_strength = ap_count - i; | 166 ap.radio_signal_strength = ap_count - i; |
| 167 ap.channel = IndexToChannel(i); | 167 ap.channel = IndexToChannel(i); |
| 168 ap.signal_to_noise = i + 42; | 168 ap.signal_to_noise = i + 42; |
| 169 ap.ssid = ASCIIToUTF16("Some nice+network|name\\"); | 169 ap.ssid = base::ASCIIToUTF16("Some nice+network|name\\"); |
| 170 data.access_point_data.insert(ap); | 170 data.access_point_data.insert(ap); |
| 171 } | 171 } |
| 172 return data; | 172 return data; |
| 173 } | 173 } |
| 174 | 174 |
| 175 static void CreateReferenceWifiScanDataJson( | 175 static void CreateReferenceWifiScanDataJson( |
| 176 int ap_count, int start_index, base::ListValue* wifi_access_point_list) { | 176 int ap_count, int start_index, base::ListValue* wifi_access_point_list) { |
| 177 std::vector<std::string> wifi_data; | 177 std::vector<std::string> wifi_data; |
| 178 for (int i = 0; i < ap_count; ++i) { | 178 for (int i = 0; i < ap_count; ++i) { |
| 179 base::DictionaryValue* ap = new base::DictionaryValue(); | 179 base::DictionaryValue* ap = new base::DictionaryValue(); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 fetcher->delegate()->OnURLFetchComplete(fetcher); | 414 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 415 | 415 |
| 416 provider->GetPosition(&position); | 416 provider->GetPosition(&position); |
| 417 EXPECT_EQ(51.0, position.latitude); | 417 EXPECT_EQ(51.0, position.latitude); |
| 418 EXPECT_EQ(-0.1, position.longitude); | 418 EXPECT_EQ(-0.1, position.longitude); |
| 419 EXPECT_EQ(1200.4, position.accuracy); | 419 EXPECT_EQ(1200.4, position.accuracy); |
| 420 EXPECT_FALSE(position.timestamp.is_null()); | 420 EXPECT_FALSE(position.timestamp.is_null()); |
| 421 EXPECT_TRUE(position.Validate()); | 421 EXPECT_TRUE(position.Validate()); |
| 422 | 422 |
| 423 // Token should be in the store. | 423 // Token should be in the store. |
| 424 EXPECT_EQ(UTF8ToUTF16(REFERENCE_ACCESS_TOKEN), | 424 EXPECT_EQ(base::UTF8ToUTF16(REFERENCE_ACCESS_TOKEN), |
| 425 access_token_store_->access_token_set_[test_server_url_]); | 425 access_token_store_->access_token_set_[test_server_url_]); |
| 426 | 426 |
| 427 // Wifi updated again, with one less AP. This is 'close enough' to the | 427 // Wifi updated again, with one less AP. This is 'close enough' to the |
| 428 // previous scan, so no new request made. | 428 // previous scan, so no new request made. |
| 429 const int kSecondScanAps = kFirstScanAps - 1; | 429 const int kSecondScanAps = kFirstScanAps - 1; |
| 430 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kSecondScanAps)); | 430 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kSecondScanAps)); |
| 431 main_message_loop_.RunUntilIdle(); | 431 main_message_loop_.RunUntilIdle(); |
| 432 fetcher = get_url_fetcher_and_advance_id(); | 432 fetcher = get_url_fetcher_and_advance_id(); |
| 433 EXPECT_FALSE(fetcher); | 433 EXPECT_FALSE(fetcher); |
| 434 | 434 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 510 |
| 511 fetcher = get_url_fetcher_and_advance_id(); | 511 fetcher = get_url_fetcher_and_advance_id(); |
| 512 ASSERT_TRUE(fetcher != NULL); | 512 ASSERT_TRUE(fetcher != NULL); |
| 513 | 513 |
| 514 EXPECT_TRUE(IsTestServerUrl(fetcher->GetOriginalURL())); | 514 EXPECT_TRUE(IsTestServerUrl(fetcher->GetOriginalURL())); |
| 515 } | 515 } |
| 516 | 516 |
| 517 TEST_F(GeolocationNetworkProviderTest, | 517 TEST_F(GeolocationNetworkProviderTest, |
| 518 NetworkRequestWithWifiDataDeferredForPermission) { | 518 NetworkRequestWithWifiDataDeferredForPermission) { |
| 519 access_token_store_->access_token_set_[test_server_url_] = | 519 access_token_store_->access_token_set_[test_server_url_] = |
| 520 UTF8ToUTF16(REFERENCE_ACCESS_TOKEN); | 520 base::UTF8ToUTF16(REFERENCE_ACCESS_TOKEN); |
| 521 scoped_ptr<LocationProvider> provider(CreateProvider(false)); | 521 scoped_ptr<LocationProvider> provider(CreateProvider(false)); |
| 522 EXPECT_TRUE(provider->StartProvider(false)); | 522 EXPECT_TRUE(provider->StartProvider(false)); |
| 523 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); | 523 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); |
| 524 EXPECT_FALSE(fetcher); | 524 EXPECT_FALSE(fetcher); |
| 525 | 525 |
| 526 static const int kScanCount = 4; | 526 static const int kScanCount = 4; |
| 527 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kScanCount)); | 527 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kScanCount)); |
| 528 main_message_loop_.RunUntilIdle(); | 528 main_message_loop_.RunUntilIdle(); |
| 529 | 529 |
| 530 fetcher = get_url_fetcher_and_advance_id(); | 530 fetcher = get_url_fetcher_and_advance_id(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 556 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); | 556 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); |
| 557 } else { | 557 } else { |
| 558 const int evicted = i - kCacheSize; | 558 const int evicted = i - kCacheSize; |
| 559 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); | 559 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); |
| 560 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); | 560 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); |
| 561 } | 561 } |
| 562 } | 562 } |
| 563 } | 563 } |
| 564 | 564 |
| 565 } // namespace content | 565 } // namespace content |
| OLD | NEW |