Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 // Stops the specified (nested) message loop when the listener is called back. | 29 // Stops the specified (nested) message loop when the listener is called back. |
| 30 class MessageLoopQuitListener { | 30 class MessageLoopQuitListener { |
| 31 public: | 31 public: |
| 32 MessageLoopQuitListener() | 32 MessageLoopQuitListener() |
| 33 : client_message_loop_(base::MessageLoop::current()), | 33 : client_message_loop_(base::MessageLoop::current()), |
| 34 updated_provider_(NULL) { | 34 updated_provider_(NULL) { |
| 35 CHECK(client_message_loop_); | 35 CHECK(client_message_loop_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void LocationUpdateAvailable(const LocationProvider* provider, | 38 void OnLocationUpdate(const LocationProvider* provider, |
| 39 const Geoposition& position) { | 39 const Geoposition& position) { |
| 40 EXPECT_EQ(client_message_loop_, base::MessageLoop::current()); | 40 EXPECT_EQ(client_message_loop_, base::MessageLoop::current()); |
| 41 updated_provider_ = provider; | 41 updated_provider_ = provider; |
| 42 client_message_loop_->Quit(); | 42 client_message_loop_->Quit(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 base::MessageLoop* client_message_loop_; | 45 base::MessageLoop* client_message_loop_; |
| 46 const LocationProvider* updated_provider_; | 46 const LocationProvider* updated_provider_; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // A mock implementation of WifiDataProviderImplBase for testing. Adapted from | 49 // A mock implementation of WifiDataProviderImplBase for testing. Adapted from |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 EXPECT_EQ(-0.1, position.longitude); | 466 EXPECT_EQ(-0.1, position.longitude); |
| 467 EXPECT_TRUE(position.Validate()); | 467 EXPECT_TRUE(position.Validate()); |
| 468 } | 468 } |
| 469 | 469 |
| 470 TEST_F(GeolocationNetworkProviderTest, NoRequestOnStartupUntilWifiData) { | 470 TEST_F(GeolocationNetworkProviderTest, NoRequestOnStartupUntilWifiData) { |
| 471 MessageLoopQuitListener listener; | 471 MessageLoopQuitListener listener; |
| 472 wifi_data_provider_->set_got_data(false); | 472 wifi_data_provider_->set_got_data(false); |
| 473 scoped_ptr<LocationProvider> provider(CreateProvider(true)); | 473 scoped_ptr<LocationProvider> provider(CreateProvider(true)); |
| 474 EXPECT_TRUE(provider->StartProvider(false)); | 474 EXPECT_TRUE(provider->StartProvider(false)); |
| 475 | 475 |
| 476 provider->SetUpdateCallback( | 476 provider->SetUpdateCallback(base::Bind( |
|
timvolodine
2014/08/14 17:32:28
nit: I actually prefer the previous formatting, bu
Michael van Ouwerkerk
2014/08/14 17:36:14
This is what 'git cl format' gave me. I try not to
| |
| 477 base::Bind(&MessageLoopQuitListener::LocationUpdateAvailable, | 477 &MessageLoopQuitListener::OnLocationUpdate, base::Unretained(&listener))); |
| 478 base::Unretained(&listener))); | |
| 479 | 478 |
| 480 main_message_loop_.RunUntilIdle(); | 479 main_message_loop_.RunUntilIdle(); |
| 481 EXPECT_FALSE(get_url_fetcher_and_advance_id()) | 480 EXPECT_FALSE(get_url_fetcher_and_advance_id()) |
| 482 << "Network request should not be created right away on startup when " | 481 << "Network request should not be created right away on startup when " |
| 483 "wifi data has not yet arrived"; | 482 "wifi data has not yet arrived"; |
| 484 | 483 |
| 485 wifi_data_provider_->SetData(CreateReferenceWifiScanData(1)); | 484 wifi_data_provider_->SetData(CreateReferenceWifiScanData(1)); |
| 486 main_message_loop_.RunUntilIdle(); | 485 main_message_loop_.RunUntilIdle(); |
| 487 EXPECT_TRUE(get_url_fetcher_and_advance_id()); | 486 EXPECT_TRUE(get_url_fetcher_and_advance_id()); |
| 488 } | 487 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); | 555 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); |
| 557 } else { | 556 } else { |
| 558 const int evicted = i - kCacheSize; | 557 const int evicted = i - kCacheSize; |
| 559 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); | 558 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); |
| 560 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); | 559 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); |
| 561 } | 560 } |
| 562 } | 561 } |
| 563 } | 562 } |
| 564 | 563 |
| 565 } // namespace content | 564 } // namespace content |
| OLD | NEW |