OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/run_loop.h" | |
6 #include "base/strings/string_number_conversions.h" | |
7 #include "base/strings/stringprintf.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "chromeos/dbus/dbus_thread_manager.h" | |
10 #include "chromeos/dbus/shill_manager_client.h" | |
11 #include "chromeos/network/geolocation_handler.h" | |
12 #include "content/browser/geolocation/wifi_data_provider_chromeos.h" | |
13 #include "content/public/test/test_browser_thread_bundle.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | |
16 | |
17 namespace content { | |
18 | |
19 class GeolocationChromeOsWifiDataProviderTest : public testing::Test { | |
20 protected: | |
21 GeolocationChromeOsWifiDataProviderTest() { | |
22 } | |
23 | |
24 void SetUp() override { | |
25 chromeos::DBusThreadManager::Initialize(); | |
26 chromeos::NetworkHandler::Initialize(); | |
27 manager_client_ = | |
28 chromeos::DBusThreadManager::Get()->GetShillManagerClient(); | |
29 manager_test_ = manager_client_->GetTestInterface(); | |
30 provider_ = new WifiDataProviderChromeOs(); | |
31 base::RunLoop().RunUntilIdle(); | |
32 } | |
33 | |
34 void TearDown() override { | |
35 provider_ = NULL; | |
36 chromeos::NetworkHandler::Shutdown(); | |
37 chromeos::DBusThreadManager::Shutdown(); | |
38 } | |
39 | |
40 bool GetAccessPointData() { | |
41 return provider_->GetAccessPointData(&ap_data_); | |
42 } | |
43 | |
44 void AddAccessPoints(int ssids, int aps_per_ssid) { | |
45 for (int i = 0; i < ssids; ++i) { | |
46 for (int j = 0; j < aps_per_ssid; ++j) { | |
47 base::DictionaryValue properties; | |
48 std::string mac_address = | |
49 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", | |
50 i, j, 3, 4, 5, 6); | |
51 std::string channel = base::IntToString(i * 10 + j); | |
52 std::string strength = base::IntToString(i * 100 + j); | |
53 properties.SetStringWithoutPathExpansion( | |
54 shill::kGeoMacAddressProperty, mac_address); | |
55 properties.SetStringWithoutPathExpansion( | |
56 shill::kGeoChannelProperty, channel); | |
57 properties.SetStringWithoutPathExpansion( | |
58 shill::kGeoSignalStrengthProperty, strength); | |
59 manager_test_->AddGeoNetwork(shill::kTypeWifi, properties); | |
60 } | |
61 } | |
62 base::RunLoop().RunUntilIdle(); | |
63 } | |
64 | |
65 TestBrowserThreadBundle thread_bundle_; | |
66 scoped_refptr<WifiDataProviderChromeOs> provider_; | |
67 chromeos::ShillManagerClient* manager_client_; | |
68 chromeos::ShillManagerClient::TestInterface* manager_test_; | |
69 WifiData::AccessPointDataSet ap_data_; | |
70 }; | |
71 | |
72 TEST_F(GeolocationChromeOsWifiDataProviderTest, NoAccessPoints) { | |
73 base::RunLoop().RunUntilIdle(); | |
74 // Initial call to GetAccessPointData requests data and will return false. | |
75 EXPECT_FALSE(GetAccessPointData()); | |
76 base::RunLoop().RunUntilIdle(); | |
77 // Additional call to GetAccessPointData also returns false with no devices. | |
78 EXPECT_FALSE(GetAccessPointData()); | |
79 EXPECT_EQ(0u, ap_data_.size()); | |
80 } | |
81 | |
82 TEST_F(GeolocationChromeOsWifiDataProviderTest, GetOneAccessPoint) { | |
83 base::RunLoop().RunUntilIdle(); | |
84 EXPECT_FALSE(GetAccessPointData()); | |
85 | |
86 AddAccessPoints(1, 1); | |
87 EXPECT_TRUE(GetAccessPointData()); | |
88 ASSERT_EQ(1u, ap_data_.size()); | |
89 EXPECT_EQ("00:00:03:04:05:06", | |
90 base::UTF16ToUTF8(ap_data_.begin()->mac_address)); | |
91 } | |
92 | |
93 TEST_F(GeolocationChromeOsWifiDataProviderTest, GetManyAccessPoints) { | |
94 base::RunLoop().RunUntilIdle(); | |
95 EXPECT_FALSE(GetAccessPointData()); | |
96 | |
97 AddAccessPoints(3, 4); | |
98 EXPECT_TRUE(GetAccessPointData()); | |
99 ASSERT_EQ(12u, ap_data_.size()); | |
100 } | |
101 | |
102 } // namespace content | |
OLD | NEW |