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 "device/geolocation/wifi_data_provider_linux.h" | 5 #include "device/geolocation/wifi_data_provider_linux.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 namespace device { | 28 namespace device { |
29 | 29 |
30 class GeolocationWifiDataProviderLinuxTest : public testing::Test { | 30 class GeolocationWifiDataProviderLinuxTest : public testing::Test { |
31 void SetUp() override { | 31 void SetUp() override { |
32 // Create a mock bus. | 32 // Create a mock bus. |
33 dbus::Bus::Options options; | 33 dbus::Bus::Options options; |
34 options.bus_type = dbus::Bus::SYSTEM; | 34 options.bus_type = dbus::Bus::SYSTEM; |
35 mock_bus_ = new dbus::MockBus(options); | 35 mock_bus_ = new dbus::MockBus(options); |
36 | 36 |
37 // Create a mock proxy that behaves as NetworkManager. | 37 // Create a mock proxy that behaves as NetworkManager. |
38 mock_network_manager_proxy_ = | 38 mock_network_manager_proxy_ = new dbus::MockObjectProxy( |
39 new dbus::MockObjectProxy( | 39 mock_bus_.get(), "org.freedesktop.NetworkManager", |
40 mock_bus_.get(), | 40 dbus::ObjectPath("/org/freedesktop/NetworkManager")); |
41 "org.freedesktop.NetworkManager", | |
42 dbus::ObjectPath("/org/freedesktop/NetworkManager")); | |
43 // Set an expectation so mock_network_manager_proxy_'s | 41 // Set an expectation so mock_network_manager_proxy_'s |
44 // CallMethodAndBlock() will use CreateNetworkManagerProxyResponse() | 42 // CallMethodAndBlock() will use CreateNetworkManagerProxyResponse() |
45 // to return responses. | 43 // to return responses. |
46 EXPECT_CALL(*mock_network_manager_proxy_.get(), | 44 EXPECT_CALL(*mock_network_manager_proxy_.get(), |
47 MockCallMethodAndBlock(_, _)) | 45 MockCallMethodAndBlock(_, _)) |
48 .WillRepeatedly(Invoke(this, | 46 .WillRepeatedly(Invoke(this, &GeolocationWifiDataProviderLinuxTest:: |
49 &GeolocationWifiDataProviderLinuxTest:: | 47 CreateNetworkManagerProxyResponse)); |
50 CreateNetworkManagerProxyResponse)); | |
51 | 48 |
52 // Create a mock proxy that behaves as NetworkManager/Devices/0. | 49 // Create a mock proxy that behaves as NetworkManager/Devices/0. |
53 mock_device_proxy_ = | 50 mock_device_proxy_ = new dbus::MockObjectProxy( |
54 new dbus::MockObjectProxy( | 51 mock_bus_.get(), "org.freedesktop.NetworkManager", |
55 mock_bus_.get(), | 52 dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")); |
56 "org.freedesktop.NetworkManager", | |
57 dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")); | |
58 EXPECT_CALL(*mock_device_proxy_.get(), MockCallMethodAndBlock(_, _)) | 53 EXPECT_CALL(*mock_device_proxy_.get(), MockCallMethodAndBlock(_, _)) |
59 .WillRepeatedly(Invoke( | 54 .WillRepeatedly(Invoke( |
60 this, | 55 this, |
61 &GeolocationWifiDataProviderLinuxTest::CreateDeviceProxyResponse)); | 56 &GeolocationWifiDataProviderLinuxTest::CreateDeviceProxyResponse)); |
62 | 57 |
63 // Create a mock proxy that behaves as NetworkManager/AccessPoint/0. | 58 // Create a mock proxy that behaves as NetworkManager/AccessPoint/0. |
64 mock_access_point_proxy_ = | 59 mock_access_point_proxy_ = new dbus::MockObjectProxy( |
65 new dbus::MockObjectProxy( | 60 mock_bus_.get(), "org.freedesktop.NetworkManager", |
66 mock_bus_.get(), | 61 dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); |
67 "org.freedesktop.NetworkManager", | |
68 dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); | |
69 EXPECT_CALL(*mock_access_point_proxy_.get(), MockCallMethodAndBlock(_, _)) | 62 EXPECT_CALL(*mock_access_point_proxy_.get(), MockCallMethodAndBlock(_, _)) |
70 .WillRepeatedly(Invoke(this, | 63 .WillRepeatedly(Invoke(this, &GeolocationWifiDataProviderLinuxTest:: |
71 &GeolocationWifiDataProviderLinuxTest:: | 64 CreateAccessPointProxyResponse)); |
72 CreateAccessPointProxyResponse)); | |
73 | 65 |
74 // Set an expectation so mock_bus_'s GetObjectProxy() for the given | 66 // Set an expectation so mock_bus_'s GetObjectProxy() for the given |
75 // service name and the object path will return | 67 // service name and the object path will return |
76 // mock_network_manager_proxy_. | 68 // mock_network_manager_proxy_. |
77 EXPECT_CALL( | 69 EXPECT_CALL( |
78 *mock_bus_.get(), | 70 *mock_bus_.get(), |
79 GetObjectProxy("org.freedesktop.NetworkManager", | 71 GetObjectProxy("org.freedesktop.NetworkManager", |
80 dbus::ObjectPath("/org/freedesktop/NetworkManager"))) | 72 dbus::ObjectPath("/org/freedesktop/NetworkManager"))) |
81 .WillOnce(Return(mock_network_manager_proxy_.get())); | 73 .WillOnce(Return(mock_network_manager_proxy_.get())); |
82 // Likewise, set an expectation for mock_device_proxy_. | 74 // Likewise, set an expectation for mock_device_proxy_. |
(...skipping 23 matching lines...) Expand all Loading... |
106 } | 98 } |
107 | 99 |
108 protected: | 100 protected: |
109 // WifiDataProvider requires a task runner to be present. The |message_loop_| | 101 // WifiDataProvider requires a task runner to be present. The |message_loop_| |
110 // is defined here, as it should outlive |wifi_provider_linux_|. | 102 // is defined here, as it should outlive |wifi_provider_linux_|. |
111 base::MessageLoopForUI message_loop_; | 103 base::MessageLoopForUI message_loop_; |
112 scoped_refptr<dbus::MockBus> mock_bus_; | 104 scoped_refptr<dbus::MockBus> mock_bus_; |
113 scoped_refptr<dbus::MockObjectProxy> mock_network_manager_proxy_; | 105 scoped_refptr<dbus::MockObjectProxy> mock_network_manager_proxy_; |
114 scoped_refptr<dbus::MockObjectProxy> mock_access_point_proxy_; | 106 scoped_refptr<dbus::MockObjectProxy> mock_access_point_proxy_; |
115 scoped_refptr<dbus::MockObjectProxy> mock_device_proxy_; | 107 scoped_refptr<dbus::MockObjectProxy> mock_device_proxy_; |
116 scoped_refptr<WifiDataProviderLinux> wifi_provider_linux_; | 108 scoped_refptr<WifiDataProviderLinux> wifi_provider_linux_; |
117 std::unique_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_; | 109 std::unique_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_; |
118 | 110 |
119 private: | 111 private: |
120 // Creates a response for |mock_network_manager_proxy_|. | 112 // Creates a response for |mock_network_manager_proxy_|. |
121 dbus::Response* CreateNetworkManagerProxyResponse( | 113 dbus::Response* CreateNetworkManagerProxyResponse( |
122 dbus::MethodCall* method_call, | 114 dbus::MethodCall* method_call, |
123 Unused) { | 115 Unused) { |
124 if (method_call->GetInterface() == "org.freedesktop.NetworkManager" && | 116 if (method_call->GetInterface() == "org.freedesktop.NetworkManager" && |
125 method_call->GetMember() == "GetDevices") { | 117 method_call->GetMember() == "GetDevices") { |
126 // The list of devices is asked. Return the object path. | 118 // The list of devices is asked. Return the object path. |
(...skipping 24 matching lines...) Expand all Loading... |
151 // The device type is asked. Respond that the device type is wifi. | 143 // The device type is asked. Respond that the device type is wifi. |
152 std::unique_ptr<dbus::Response> response = | 144 std::unique_ptr<dbus::Response> response = |
153 dbus::Response::CreateEmpty(); | 145 dbus::Response::CreateEmpty(); |
154 dbus::MessageWriter writer(response.get()); | 146 dbus::MessageWriter writer(response.get()); |
155 // This matches NM_DEVICE_TYPE_WIFI in wifi_data_provider_linux.cc. | 147 // This matches NM_DEVICE_TYPE_WIFI in wifi_data_provider_linux.cc. |
156 const int kDeviceTypeWifi = 2; | 148 const int kDeviceTypeWifi = 2; |
157 writer.AppendVariantOfUint32(kDeviceTypeWifi); | 149 writer.AppendVariantOfUint32(kDeviceTypeWifi); |
158 return response.release(); | 150 return response.release(); |
159 } | 151 } |
160 } else if (method_call->GetInterface() == | 152 } else if (method_call->GetInterface() == |
161 "org.freedesktop.NetworkManager.Device.Wireless" && | 153 "org.freedesktop.NetworkManager.Device.Wireless" && |
162 method_call->GetMember() == "GetAccessPoints") { | 154 method_call->GetMember() == "GetAccessPoints") { |
163 // The list of access points is asked. Return the object path. | 155 // The list of access points is asked. Return the object path. |
164 std::unique_ptr<dbus::Response> response = dbus::Response::CreateEmpty(); | 156 std::unique_ptr<dbus::Response> response = dbus::Response::CreateEmpty(); |
165 dbus::MessageWriter writer(response.get()); | 157 dbus::MessageWriter writer(response.get()); |
166 std::vector<dbus::ObjectPath> object_paths; | 158 std::vector<dbus::ObjectPath> object_paths; |
167 object_paths.push_back( | 159 object_paths.push_back( |
168 dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); | 160 dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); |
169 writer.AppendArrayOfObjectPaths(object_paths); | 161 writer.AppendArrayOfObjectPaths(object_paths); |
170 return response.release(); | 162 return response.release(); |
171 } | 163 } |
172 | 164 |
173 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); | 165 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); |
174 return NULL; | 166 return NULL; |
175 } | 167 } |
176 | 168 |
177 | |
178 // Creates a response for |mock_access_point_proxy_|. | 169 // Creates a response for |mock_access_point_proxy_|. |
179 dbus::Response* CreateAccessPointProxyResponse(dbus::MethodCall* method_call, | 170 dbus::Response* CreateAccessPointProxyResponse(dbus::MethodCall* method_call, |
180 Unused) { | 171 Unused) { |
181 if (method_call->GetInterface() == DBUS_INTERFACE_PROPERTIES && | 172 if (method_call->GetInterface() == DBUS_INTERFACE_PROPERTIES && |
182 method_call->GetMember() == "Get") { | 173 method_call->GetMember() == "Get") { |
183 dbus::MessageReader reader(method_call); | 174 dbus::MessageReader reader(method_call); |
184 | 175 |
185 std::string interface_name; | 176 std::string interface_name; |
186 std::string property_name; | 177 std::string property_name; |
187 if (reader.PopString(&interface_name) && | 178 if (reader.PopString(&interface_name) && |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // Check the contents of the access point data. | 219 // Check the contents of the access point data. |
229 // The expected values come from CreateAccessPointProxyResponse() above. | 220 // The expected values come from CreateAccessPointProxyResponse() above. |
230 EXPECT_EQ("test", base::UTF16ToUTF8(access_point_data.ssid)); | 221 EXPECT_EQ("test", base::UTF16ToUTF8(access_point_data.ssid)); |
231 EXPECT_EQ("00-11-22-33-44-55", | 222 EXPECT_EQ("00-11-22-33-44-55", |
232 base::UTF16ToUTF8(access_point_data.mac_address)); | 223 base::UTF16ToUTF8(access_point_data.mac_address)); |
233 EXPECT_EQ(-50, access_point_data.radio_signal_strength); | 224 EXPECT_EQ(-50, access_point_data.radio_signal_strength); |
234 EXPECT_EQ(4, access_point_data.channel); | 225 EXPECT_EQ(4, access_point_data.channel); |
235 } | 226 } |
236 | 227 |
237 } // namespace device | 228 } // namespace device |
OLD | NEW |