OLD | NEW |
1 // Copyright (c) 2011 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 "content/browser/geolocation/wifi_data_provider_linux.h" | 5 #include "content/browser/geolocation/wifi_data_provider_linux.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "dbus/message.h" | 11 #include "dbus/message.h" |
12 #include "dbus/mock_bus.h" | 12 #include "dbus/mock_bus.h" |
13 #include "dbus/mock_object_proxy.h" | 13 #include "dbus/mock_object_proxy.h" |
| 14 #include "dbus/object_path.h" |
14 #include "dbus/object_proxy.h" | 15 #include "dbus/object_proxy.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using ::testing::_; | 19 using ::testing::_; |
19 using ::testing::Invoke; | 20 using ::testing::Invoke; |
20 using ::testing::Return; | 21 using ::testing::Return; |
21 using ::testing::Unused; | 22 using ::testing::Unused; |
22 | 23 |
23 class GeolocationWifiDataProviderLinuxTest : public testing::Test { | 24 class GeolocationWifiDataProviderLinuxTest : public testing::Test { |
24 void SetUp() { | 25 void SetUp() { |
25 // Create a mock bus. | 26 // Create a mock bus. |
26 dbus::Bus::Options options; | 27 dbus::Bus::Options options; |
27 options.bus_type = dbus::Bus::SYSTEM; | 28 options.bus_type = dbus::Bus::SYSTEM; |
28 mock_bus_ = new dbus::MockBus(options); | 29 mock_bus_ = new dbus::MockBus(options); |
29 | 30 |
30 // Create a mock proxy that behaves as NetworkManager. | 31 // Create a mock proxy that behaves as NetworkManager. |
31 mock_network_manager_proxy_ = | 32 mock_network_manager_proxy_ = |
32 new dbus::MockObjectProxy(mock_bus_.get(), | 33 new dbus::MockObjectProxy( |
33 "org.freedesktop.NetworkManager", | 34 mock_bus_.get(), |
34 "/org/freedesktop/NetworkManager"); | 35 "org.freedesktop.NetworkManager", |
| 36 dbus::ObjectPath("/org/freedesktop/NetworkManager")); |
35 // Set an expectation so mock_network_manager_proxy_'s | 37 // Set an expectation so mock_network_manager_proxy_'s |
36 // CallMethodAndBlock() will use CreateNetowrkManagerProxyResponse() | 38 // CallMethodAndBlock() will use CreateNetowrkManagerProxyResponse() |
37 // to return responses. | 39 // to return responses. |
38 EXPECT_CALL(*mock_network_manager_proxy_, | 40 EXPECT_CALL(*mock_network_manager_proxy_, |
39 CallMethodAndBlock(_, _)) | 41 CallMethodAndBlock(_, _)) |
40 .WillRepeatedly(Invoke( | 42 .WillRepeatedly(Invoke( |
41 this, | 43 this, |
42 &GeolocationWifiDataProviderLinuxTest:: | 44 &GeolocationWifiDataProviderLinuxTest:: |
43 CreateNetowrkManagerProxyResponse)); | 45 CreateNetowrkManagerProxyResponse)); |
44 | 46 |
45 // Create a mock proxy that behaves as NetworkManager/Devices/0. | 47 // Create a mock proxy that behaves as NetworkManager/Devices/0. |
46 mock_device_proxy_ = | 48 mock_device_proxy_ = |
47 new dbus::MockObjectProxy(mock_bus_.get(), | 49 new dbus::MockObjectProxy( |
48 "org.freedesktop.NetworkManager", | 50 mock_bus_.get(), |
49 "/org/freedesktop/NetworkManager/Devices/0"); | 51 "org.freedesktop.NetworkManager", |
| 52 dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")); |
50 EXPECT_CALL(*mock_device_proxy_, | 53 EXPECT_CALL(*mock_device_proxy_, |
51 CallMethodAndBlock(_, _)) | 54 CallMethodAndBlock(_, _)) |
52 .WillRepeatedly(Invoke( | 55 .WillRepeatedly(Invoke( |
53 this, | 56 this, |
54 &GeolocationWifiDataProviderLinuxTest::CreateDeviceProxyResponse)); | 57 &GeolocationWifiDataProviderLinuxTest::CreateDeviceProxyResponse)); |
55 | 58 |
56 // Create a mock proxy that behaves as NetworkManager/AccessPoint/0. | 59 // Create a mock proxy that behaves as NetworkManager/AccessPoint/0. |
57 mock_access_point_proxy_ = | 60 mock_access_point_proxy_ = |
58 new dbus::MockObjectProxy( | 61 new dbus::MockObjectProxy( |
59 mock_bus_.get(), | 62 mock_bus_.get(), |
60 "org.freedesktop.NetworkManager", | 63 "org.freedesktop.NetworkManager", |
61 "/org/freedesktop/NetworkManager/AccessPoint/0"); | 64 dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); |
62 EXPECT_CALL(*mock_access_point_proxy_, | 65 EXPECT_CALL(*mock_access_point_proxy_, |
63 CallMethodAndBlock(_, _)) | 66 CallMethodAndBlock(_, _)) |
64 .WillRepeatedly(Invoke( | 67 .WillRepeatedly(Invoke( |
65 this, | 68 this, |
66 &GeolocationWifiDataProviderLinuxTest:: | 69 &GeolocationWifiDataProviderLinuxTest:: |
67 CreateAccessPointProxyResponse)); | 70 CreateAccessPointProxyResponse)); |
68 | 71 |
69 // Set an expectation so mock_bus_'s GetObjectProxy() for the given | 72 // Set an expectation so mock_bus_'s GetObjectProxy() for the given |
70 // service name and the object path will return | 73 // service name and the object path will return |
71 // mock_network_manager_proxy_. | 74 // mock_network_manager_proxy_. |
72 EXPECT_CALL(*mock_bus_, GetObjectProxy( | 75 EXPECT_CALL(*mock_bus_, GetObjectProxy( |
73 "org.freedesktop.NetworkManager", | 76 "org.freedesktop.NetworkManager", |
74 "/org/freedesktop/NetworkManager")) | 77 dbus::ObjectPath("/org/freedesktop/NetworkManager"))) |
75 .WillOnce(Return(mock_network_manager_proxy_.get())); | 78 .WillOnce(Return(mock_network_manager_proxy_.get())); |
76 // Likewise, set an expectation for mock_device_proxy_. | 79 // Likewise, set an expectation for mock_device_proxy_. |
77 EXPECT_CALL(*mock_bus_, GetObjectProxy( | 80 EXPECT_CALL(*mock_bus_, GetObjectProxy( |
78 "org.freedesktop.NetworkManager", | 81 "org.freedesktop.NetworkManager", |
79 "/org/freedesktop/NetworkManager/Devices/0")) | 82 dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0"))) |
80 .WillOnce(Return(mock_device_proxy_.get())) | 83 .WillOnce(Return(mock_device_proxy_.get())) |
81 .WillOnce(Return(mock_device_proxy_.get())); | 84 .WillOnce(Return(mock_device_proxy_.get())); |
82 // Likewise, set an expectation for mock_access_point_proxy_. | 85 // Likewise, set an expectation for mock_access_point_proxy_. |
83 EXPECT_CALL(*mock_bus_, GetObjectProxy( | 86 EXPECT_CALL(*mock_bus_, GetObjectProxy( |
84 "org.freedesktop.NetworkManager", | 87 "org.freedesktop.NetworkManager", |
85 "/org/freedesktop/NetworkManager/AccessPoint/0")) | 88 dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0"))) |
86 .WillOnce(Return(mock_access_point_proxy_.get())); | 89 .WillOnce(Return(mock_access_point_proxy_.get())); |
87 | 90 |
88 // ShutdownAndBlock() should be called. | 91 // ShutdownAndBlock() should be called. |
89 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); | 92 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); |
90 | 93 |
91 // Create the wlan API with the mock bus object injected. | 94 // Create the wlan API with the mock bus object injected. |
92 wifi_provider_linux_ = new WifiDataProviderLinux; | 95 wifi_provider_linux_ = new WifiDataProviderLinux; |
93 wlan_api_.reset( | 96 wlan_api_.reset( |
94 wifi_provider_linux_->NewWlanApiForTesting(mock_bus_.get())); | 97 wifi_provider_linux_->NewWlanApiForTesting(mock_bus_.get())); |
95 ASSERT_TRUE(wlan_api_.get()); | 98 ASSERT_TRUE(wlan_api_.get()); |
(...skipping 12 matching lines...) Expand all Loading... |
108 scoped_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_; | 111 scoped_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_; |
109 | 112 |
110 private: | 113 private: |
111 // Creates a response for |mock_network_manager_proxy_|. | 114 // Creates a response for |mock_network_manager_proxy_|. |
112 dbus::Response* CreateNetowrkManagerProxyResponse( | 115 dbus::Response* CreateNetowrkManagerProxyResponse( |
113 dbus::MethodCall* method_call, | 116 dbus::MethodCall* method_call, |
114 Unused) { | 117 Unused) { |
115 if (method_call->GetInterface() == "org.freedesktop.NetworkManager" && | 118 if (method_call->GetInterface() == "org.freedesktop.NetworkManager" && |
116 method_call->GetMember() == "GetDevices") { | 119 method_call->GetMember() == "GetDevices") { |
117 // The list of devices is asked. Return the object path. | 120 // The list of devices is asked. Return the object path. |
118 std::vector<std::string> object_paths; | 121 std::vector<dbus::ObjectPath> object_paths; |
119 object_paths.push_back("/org/freedesktop/NetworkManager/Devices/0"); | 122 object_paths.push_back( |
| 123 dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")); |
120 | 124 |
121 dbus::Response* response = dbus::Response::CreateEmpty(); | 125 dbus::Response* response = dbus::Response::CreateEmpty(); |
122 dbus::MessageWriter writer(response); | 126 dbus::MessageWriter writer(response); |
123 writer.AppendArrayOfObjectPaths(object_paths); | 127 writer.AppendArrayOfObjectPaths(object_paths); |
124 return response; | 128 return response; |
125 } | 129 } |
126 | 130 |
127 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); | 131 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); |
128 return NULL; | 132 return NULL; |
129 } | 133 } |
(...skipping 15 matching lines...) Expand all Loading... |
145 const int kDeviceTypeWifi = 2; | 149 const int kDeviceTypeWifi = 2; |
146 writer.AppendVariantOfUint32(kDeviceTypeWifi); | 150 writer.AppendVariantOfUint32(kDeviceTypeWifi); |
147 return response; | 151 return response; |
148 } | 152 } |
149 } else if (method_call->GetInterface() == | 153 } else if (method_call->GetInterface() == |
150 "org.freedesktop.NetworkManager.Device.Wireless" && | 154 "org.freedesktop.NetworkManager.Device.Wireless" && |
151 method_call->GetMember() == "GetAccessPoints") { | 155 method_call->GetMember() == "GetAccessPoints") { |
152 // The list of access points is asked. Return the object path. | 156 // The list of access points is asked. Return the object path. |
153 dbus::Response* response = dbus::Response::CreateEmpty(); | 157 dbus::Response* response = dbus::Response::CreateEmpty(); |
154 dbus::MessageWriter writer(response); | 158 dbus::MessageWriter writer(response); |
155 std::vector<std::string> object_paths; | 159 std::vector<dbus::ObjectPath> object_paths; |
156 object_paths.push_back("/org/freedesktop/NetworkManager/AccessPoint/0"); | 160 object_paths.push_back( |
| 161 dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); |
157 writer.AppendArrayOfObjectPaths(object_paths); | 162 writer.AppendArrayOfObjectPaths(object_paths); |
158 return response; | 163 return response; |
159 } | 164 } |
160 | 165 |
161 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); | 166 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); |
162 return NULL; | 167 return NULL; |
163 } | 168 } |
164 | 169 |
165 | 170 |
166 // Creates a response for |mock_access_point_proxy_|. | 171 // Creates a response for |mock_access_point_proxy_|. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 ASSERT_EQ(1U, access_point_data_set.size()); | 217 ASSERT_EQ(1U, access_point_data_set.size()); |
213 AccessPointData access_point_data = *access_point_data_set.begin(); | 218 AccessPointData access_point_data = *access_point_data_set.begin(); |
214 | 219 |
215 // Check the contents of the access point data. | 220 // Check the contents of the access point data. |
216 // The expected values come from CreateAccessPointProxyResponse() above. | 221 // The expected values come from CreateAccessPointProxyResponse() above. |
217 EXPECT_EQ("test", UTF16ToUTF8(access_point_data.ssid)); | 222 EXPECT_EQ("test", UTF16ToUTF8(access_point_data.ssid)); |
218 EXPECT_EQ("00-11-22-33-44-55", UTF16ToUTF8(access_point_data.mac_address)); | 223 EXPECT_EQ("00-11-22-33-44-55", UTF16ToUTF8(access_point_data.mac_address)); |
219 EXPECT_EQ(-50, access_point_data.radio_signal_strength); | 224 EXPECT_EQ(-50, access_point_data.radio_signal_strength); |
220 EXPECT_EQ(4, access_point_data.channel); | 225 EXPECT_EQ(4, access_point_data.channel); |
221 } | 226 } |
OLD | NEW |