Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chromeos/geolocation/simple_geolocation_unittest.cc

Issue 2314853004: Remove calls to deprecated MessageLoop methods in chromeos. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 180
181 const Geoposition& position() const { return position_; } 181 const Geoposition& position() const { return position_; }
182 bool server_error() const { return server_error_; } 182 bool server_error() const { return server_error_; }
183 base::TimeDelta elapsed() const { return elapsed_; } 183 base::TimeDelta elapsed() const { return elapsed_; }
184 184
185 private: 185 private:
186 Geoposition position_; 186 Geoposition position_;
187 bool server_error_; 187 bool server_error_;
188 base::TimeDelta elapsed_; 188 base::TimeDelta elapsed_;
189 std::unique_ptr<base::RunLoop> message_loop_runner_; 189 std::unique_ptr<base::RunLoop> message_loop_runner_;
oshima 2016/09/13 01:36:05 can you clean up this too? (and one in timezone_u
fdoray 2016/09/13 13:12:49 Still used at lines 173, 177, 178. Same thing in t
190 }; 190 };
191 191
192 class WiFiTestMonitor : public SimpleGeolocationRequestTestMonitor { 192 class WiFiTestMonitor : public SimpleGeolocationRequestTestMonitor {
193 public: 193 public:
194 WiFiTestMonitor() {} 194 WiFiTestMonitor() {}
195 195
196 void OnRequestCreated(SimpleGeolocationRequest* request) override {} 196 void OnRequestCreated(SimpleGeolocationRequest* request) override {}
197 void OnStart(SimpleGeolocationRequest* request) override { 197 void OnStart(SimpleGeolocationRequest* request) override {
198 last_request_body_ = request->FormatRequestBodyForTesting(); 198 last_request_body_ = request->FormatRequestBodyForTesting();
199 } 199 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 334
335 void SetUp() override { 335 void SetUp() override {
336 // This initializes DBusThreadManager and markes it "for tests only". 336 // This initializes DBusThreadManager and markes it "for tests only".
337 DBusThreadManager::GetSetterForTesting(); 337 DBusThreadManager::GetSetterForTesting();
338 // Get the test interface for manager / device. 338 // Get the test interface for manager / device.
339 manager_test_ = 339 manager_test_ =
340 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); 340 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
341 ASSERT_TRUE(manager_test_); 341 ASSERT_TRUE(manager_test_);
342 geolocation_handler_.reset(new GeolocationHandler()); 342 geolocation_handler_.reset(new GeolocationHandler());
343 geolocation_handler_->Init(); 343 geolocation_handler_->Init();
344 message_loop_.RunUntilIdle(); 344 base::RunLoop().RunUntilIdle();
345 } 345 }
346 346
347 void TearDown() override { 347 void TearDown() override {
348 geolocation_handler_.reset(); 348 geolocation_handler_.reset();
349 DBusThreadManager::Shutdown(); 349 DBusThreadManager::Shutdown();
350 } 350 }
351 351
352 bool GetWifiAccessPoints() { 352 bool GetWifiAccessPoints() {
353 return geolocation_handler_->GetWifiAccessPoints(&wifi_access_points_, 353 return geolocation_handler_->GetWifiAccessPoints(&wifi_access_points_,
354 nullptr); 354 nullptr);
355 } 355 }
356 356
357 void AddAccessPoint(int idx) { 357 void AddAccessPoint(int idx) {
358 base::DictionaryValue properties; 358 base::DictionaryValue properties;
359 std::string mac_address = 359 std::string mac_address =
360 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", idx, 0, 0, 0, 0, 0); 360 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", idx, 0, 0, 0, 0, 0);
361 std::string channel = base::IntToString(idx); 361 std::string channel = base::IntToString(idx);
362 std::string strength = base::IntToString(idx * 10); 362 std::string strength = base::IntToString(idx * 10);
363 properties.SetStringWithoutPathExpansion(shill::kGeoMacAddressProperty, 363 properties.SetStringWithoutPathExpansion(shill::kGeoMacAddressProperty,
364 mac_address); 364 mac_address);
365 properties.SetStringWithoutPathExpansion(shill::kGeoChannelProperty, 365 properties.SetStringWithoutPathExpansion(shill::kGeoChannelProperty,
366 channel); 366 channel);
367 properties.SetStringWithoutPathExpansion(shill::kGeoSignalStrengthProperty, 367 properties.SetStringWithoutPathExpansion(shill::kGeoSignalStrengthProperty,
368 strength); 368 strength);
369 manager_test_->AddGeoNetwork(shill::kTypeWifi, properties); 369 manager_test_->AddGeoNetwork(shill::kTypeWifi, properties);
370 message_loop_.RunUntilIdle(); 370 base::RunLoop().RunUntilIdle();
371 } 371 }
372 372
373 protected: 373 protected:
374 base::MessageLoopForUI message_loop_; 374 base::MessageLoopForUI message_loop_;
375 std::unique_ptr<GeolocationHandler> geolocation_handler_; 375 std::unique_ptr<GeolocationHandler> geolocation_handler_;
376 ShillManagerClient::TestInterface* manager_test_; 376 ShillManagerClient::TestInterface* manager_test_;
377 WifiAccessPointVector wifi_access_points_; 377 WifiAccessPointVector wifi_access_points_;
378 378
379 private: 379 private:
380 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationWiFiTest); 380 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationWiFiTest);
(...skipping 20 matching lines...) Expand all
401 receiver.WaitUntilRequestDone(); 401 receiver.WaitUntilRequestDone();
402 EXPECT_EQ(kIPOnlyRequestBody, requests_monitor.last_request_body()); 402 EXPECT_EQ(kIPOnlyRequestBody, requests_monitor.last_request_body());
403 403
404 EXPECT_EQ(kExpectedPosition, receiver.position().ToString()); 404 EXPECT_EQ(kExpectedPosition, receiver.position().ToString());
405 EXPECT_FALSE(receiver.server_error()); 405 EXPECT_FALSE(receiver.server_error());
406 EXPECT_EQ(1U, url_factory.attempts()); 406 EXPECT_EQ(1U, url_factory.attempts());
407 } 407 }
408 408
409 // Add an acces point. 409 // Add an acces point.
410 AddAccessPoint(1); 410 AddAccessPoint(1);
411 message_loop_.RunUntilIdle(); 411 base::RunLoop().RunUntilIdle();
412 // Inititial call should return false and request access points. 412 // Inititial call should return false and request access points.
413 EXPECT_FALSE(GetWifiAccessPoints()); 413 EXPECT_FALSE(GetWifiAccessPoints());
414 message_loop_.RunUntilIdle(); 414 base::RunLoop().RunUntilIdle();
415 // Second call should return true since we have an access point. 415 // Second call should return true since we have an access point.
416 EXPECT_TRUE(GetWifiAccessPoints()); 416 EXPECT_TRUE(GetWifiAccessPoints());
417 ASSERT_EQ(1u, wifi_access_points_.size()); 417 ASSERT_EQ(1u, wifi_access_points_.size());
418 EXPECT_EQ(kWiFiAP1MacAddress, wifi_access_points_[0].mac_address); 418 EXPECT_EQ(kWiFiAP1MacAddress, wifi_access_points_[0].mac_address);
419 EXPECT_EQ(1, wifi_access_points_[0].channel); 419 EXPECT_EQ(1, wifi_access_points_[0].channel);
420 420
421 { 421 {
422 GeolocationReceiver receiver; 422 GeolocationReceiver receiver;
423 provider.RequestGeolocation(base::TimeDelta::FromSeconds(1), GetParam(), 423 provider.RequestGeolocation(base::TimeDelta::FromSeconds(1), GetParam(),
424 base::Bind(&GeolocationReceiver::OnRequestDone, 424 base::Bind(&GeolocationReceiver::OnRequestDone,
(...skipping 14 matching lines...) Expand all
439 } 439 }
440 NetworkHandler::Shutdown(); 440 NetworkHandler::Shutdown();
441 } 441 }
442 442
443 // This test verifies that WiFi data is sent only if sending was requested. 443 // This test verifies that WiFi data is sent only if sending was requested.
444 INSTANTIATE_TEST_CASE_P(EnableDisableSendingWifiData, 444 INSTANTIATE_TEST_CASE_P(EnableDisableSendingWifiData,
445 SimpleGeolocationWiFiTest, 445 SimpleGeolocationWiFiTest,
446 testing::Bool()); 446 testing::Bool());
447 447
448 } // namespace chromeos 448 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698