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

Side by Side Diff: content/browser/geolocation/wifi_data_provider_linux_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698