| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/shill_manager_client.h" | 11 #include "chromeos/dbus/shill_manager_client.h" |
| 12 #include "chromeos/network/geolocation_handler.h" | 12 #include "chromeos/network/geolocation_handler.h" |
| 13 #include "device/geolocation/wifi_data_provider_chromeos.h" | 13 #include "device/geolocation/wifi_data_provider_chromeos.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 16 |
| 17 namespace device { | 17 namespace device { |
| 18 | 18 |
| 19 class GeolocationChromeOsWifiDataProviderTest : public testing::Test { | 19 class GeolocationChromeOsWifiDataProviderTest : public testing::Test { |
| 20 protected: | 20 protected: |
| 21 GeolocationChromeOsWifiDataProviderTest() { | 21 GeolocationChromeOsWifiDataProviderTest() {} |
| 22 } | |
| 23 | 22 |
| 24 void SetUp() override { | 23 void SetUp() override { |
| 25 chromeos::DBusThreadManager::Initialize(); | 24 chromeos::DBusThreadManager::Initialize(); |
| 26 chromeos::NetworkHandler::Initialize(); | 25 chromeos::NetworkHandler::Initialize(); |
| 27 manager_client_ = | 26 manager_client_ = |
| 28 chromeos::DBusThreadManager::Get()->GetShillManagerClient(); | 27 chromeos::DBusThreadManager::Get()->GetShillManagerClient(); |
| 29 manager_test_ = manager_client_->GetTestInterface(); | 28 manager_test_ = manager_client_->GetTestInterface(); |
| 30 provider_ = new WifiDataProviderChromeOs(); | 29 provider_ = new WifiDataProviderChromeOs(); |
| 31 base::RunLoop().RunUntilIdle(); | 30 base::RunLoop().RunUntilIdle(); |
| 32 } | 31 } |
| 33 | 32 |
| 34 void TearDown() override { | 33 void TearDown() override { |
| 35 provider_ = NULL; | 34 provider_ = NULL; |
| 36 chromeos::NetworkHandler::Shutdown(); | 35 chromeos::NetworkHandler::Shutdown(); |
| 37 chromeos::DBusThreadManager::Shutdown(); | 36 chromeos::DBusThreadManager::Shutdown(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 bool GetAccessPointData() { | 39 bool GetAccessPointData() { return provider_->GetAccessPointData(&ap_data_); } |
| 41 return provider_->GetAccessPointData(&ap_data_); | |
| 42 } | |
| 43 | 40 |
| 44 void AddAccessPoints(int ssids, int aps_per_ssid) { | 41 void AddAccessPoints(int ssids, int aps_per_ssid) { |
| 45 for (int i = 0; i < ssids; ++i) { | 42 for (int i = 0; i < ssids; ++i) { |
| 46 for (int j = 0; j < aps_per_ssid; ++j) { | 43 for (int j = 0; j < aps_per_ssid; ++j) { |
| 47 base::DictionaryValue properties; | 44 base::DictionaryValue properties; |
| 48 std::string mac_address = | 45 std::string mac_address = base::StringPrintf( |
| 49 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", | 46 "%02X:%02X:%02X:%02X:%02X:%02X", i, j, 3, 4, 5, 6); |
| 50 i, j, 3, 4, 5, 6); | |
| 51 std::string channel = base::IntToString(i * 10 + j); | 47 std::string channel = base::IntToString(i * 10 + j); |
| 52 std::string strength = base::IntToString(i * 100 + j); | 48 std::string strength = base::IntToString(i * 100 + j); |
| 53 properties.SetStringWithoutPathExpansion( | 49 properties.SetStringWithoutPathExpansion(shill::kGeoMacAddressProperty, |
| 54 shill::kGeoMacAddressProperty, mac_address); | 50 mac_address); |
| 55 properties.SetStringWithoutPathExpansion( | 51 properties.SetStringWithoutPathExpansion(shill::kGeoChannelProperty, |
| 56 shill::kGeoChannelProperty, channel); | 52 channel); |
| 57 properties.SetStringWithoutPathExpansion( | 53 properties.SetStringWithoutPathExpansion( |
| 58 shill::kGeoSignalStrengthProperty, strength); | 54 shill::kGeoSignalStrengthProperty, strength); |
| 59 manager_test_->AddGeoNetwork(shill::kTypeWifi, properties); | 55 manager_test_->AddGeoNetwork(shill::kTypeWifi, properties); |
| 60 } | 56 } |
| 61 } | 57 } |
| 62 base::RunLoop().RunUntilIdle(); | 58 base::RunLoop().RunUntilIdle(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 base::MessageLoopForUI message_loop_; | 61 base::MessageLoopForUI message_loop_; |
| 66 scoped_refptr<WifiDataProviderChromeOs> provider_; | 62 scoped_refptr<WifiDataProviderChromeOs> provider_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 TEST_F(GeolocationChromeOsWifiDataProviderTest, GetManyAccessPoints) { | 89 TEST_F(GeolocationChromeOsWifiDataProviderTest, GetManyAccessPoints) { |
| 94 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
| 95 EXPECT_FALSE(GetAccessPointData()); | 91 EXPECT_FALSE(GetAccessPointData()); |
| 96 | 92 |
| 97 AddAccessPoints(3, 4); | 93 AddAccessPoints(3, 4); |
| 98 EXPECT_TRUE(GetAccessPointData()); | 94 EXPECT_TRUE(GetAccessPointData()); |
| 99 ASSERT_EQ(12u, ap_data_.size()); | 95 ASSERT_EQ(12u, ap_data_.size()); |
| 100 } | 96 } |
| 101 | 97 |
| 102 } // namespace device | 98 } // namespace device |
| OLD | NEW |