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

Side by Side Diff: chromeos/network/network_configuration_handler_unittest.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Add NetworkConnectionHandler to NetworkHandler Created 7 years, 7 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) 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/json/json_writer.h" 6 #include "base/json/json_writer.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chromeos/dbus/dbus_thread_manager.h" 10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/mock_dbus_thread_manager.h" 11 #include "chromeos/dbus/mock_dbus_thread_manager.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 virtual void SetUp() OVERRIDE { 80 virtual void SetUp() OVERRIDE {
81 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; 81 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
82 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) 82 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
83 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); 83 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
84 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); 84 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
85 mock_manager_client_ = 85 mock_manager_client_ =
86 mock_dbus_thread_manager->mock_shill_manager_client(); 86 mock_dbus_thread_manager->mock_shill_manager_client();
87 mock_service_client_ = 87 mock_service_client_ =
88 mock_dbus_thread_manager->mock_shill_service_client(); 88 mock_dbus_thread_manager->mock_shill_service_client();
89 89
90 // Initialize DBusThreadManager with a stub implementation. 90 network_configuration_handler_.reset(new NetworkConfigurationHandler());
91 NetworkConfigurationHandler::Initialize();
92 message_loop_.RunUntilIdle(); 91 message_loop_.RunUntilIdle();
93 } 92 }
94 93
95 virtual void TearDown() OVERRIDE { 94 virtual void TearDown() OVERRIDE {
96 NetworkConfigurationHandler::Shutdown(); 95 network_configuration_handler_.reset();
97 DBusThreadManager::Shutdown(); 96 DBusThreadManager::Shutdown();
98 } 97 }
99 98
100 // Handles responses for GetProperties method calls. 99 // Handles responses for GetProperties method calls.
101 void OnGetProperties( 100 void OnGetProperties(
102 const dbus::ObjectPath& path, 101 const dbus::ObjectPath& path,
103 const ShillClientHelper::DictionaryValueCallback& callback) { 102 const ShillClientHelper::DictionaryValueCallback& callback) {
104 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); 103 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_);
105 } 104 }
106 105
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 141
143 void OnRemove(const dbus::ObjectPath& service_path, 142 void OnRemove(const dbus::ObjectPath& service_path,
144 const base::Closure& callback, 143 const base::Closure& callback,
145 const ShillClientHelper::ErrorCallback& error_callback) { 144 const ShillClientHelper::ErrorCallback& error_callback) {
146 callback.Run(); 145 callback.Run();
147 } 146 }
148 147
149 protected: 148 protected:
150 MockShillManagerClient* mock_manager_client_; 149 MockShillManagerClient* mock_manager_client_;
151 MockShillServiceClient* mock_service_client_; 150 MockShillServiceClient* mock_service_client_;
151 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_;
152 MessageLoop message_loop_; 152 MessageLoop message_loop_;
153 base::DictionaryValue* dictionary_value_result_; 153 base::DictionaryValue* dictionary_value_result_;
154 }; 154 };
155 155
156 TEST_F(NetworkConfigurationHandlerTest, GetProperties) { 156 TEST_F(NetworkConfigurationHandlerTest, GetProperties) {
157 std::string service_path = "/service/1"; 157 std::string service_path = "/service/1";
158 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; 158 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n";
159 std::string networkName = "MyNetwork"; 159 std::string networkName = "MyNetwork";
160 std::string key = "SSID"; 160 std::string key = "SSID";
161 scoped_ptr<base::StringValue> networkNameValue( 161 scoped_ptr<base::StringValue> networkNameValue(
162 base::Value::CreateStringValue(networkName)); 162 base::Value::CreateStringValue(networkName));
163 163
164 base::DictionaryValue value; 164 base::DictionaryValue value;
165 value.Set(key, base::Value::CreateStringValue(networkName)); 165 value.Set(key, base::Value::CreateStringValue(networkName));
166 dictionary_value_result_ = &value; 166 dictionary_value_result_ = &value;
167 EXPECT_CALL(*mock_service_client_, 167 EXPECT_CALL(*mock_service_client_,
168 SetProperty(dbus::ObjectPath(service_path), key, 168 SetProperty(dbus::ObjectPath(service_path), key,
169 IsEqualTo(networkNameValue.get()), _, _)).Times(1); 169 IsEqualTo(networkNameValue.get()), _, _)).Times(1);
170 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 170 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
171 dbus::ObjectPath(service_path), key, *networkNameValue, 171 dbus::ObjectPath(service_path), key, *networkNameValue,
172 base::Bind(&base::DoNothing), 172 base::Bind(&base::DoNothing),
173 base::Bind(&DBusErrorCallback)); 173 base::Bind(&DBusErrorCallback));
174 message_loop_.RunUntilIdle(); 174 message_loop_.RunUntilIdle();
175 175
176 ShillServiceClient::DictionaryValueCallback get_properties_callback; 176 ShillServiceClient::DictionaryValueCallback get_properties_callback;
177 EXPECT_CALL(*mock_service_client_, 177 EXPECT_CALL(*mock_service_client_,
178 GetProperties(_, _)).WillOnce( 178 GetProperties(_, _)).WillOnce(
179 Invoke(this, 179 Invoke(this,
180 &NetworkConfigurationHandlerTest::OnGetProperties)); 180 &NetworkConfigurationHandlerTest::OnGetProperties));
181 NetworkConfigurationHandler::Get()->GetProperties( 181 network_configuration_handler_->GetProperties(
182 service_path, 182 service_path,
183 base::Bind(&DictionaryValueCallback, 183 base::Bind(&DictionaryValueCallback,
184 service_path, 184 service_path,
185 expected_json), 185 expected_json),
186 base::Bind(&ErrorCallback, false, service_path)); 186 base::Bind(&ErrorCallback, false, service_path));
187 message_loop_.RunUntilIdle(); 187 message_loop_.RunUntilIdle();
188 } 188 }
189 189
190 TEST_F(NetworkConfigurationHandlerTest, SetProperties) { 190 TEST_F(NetworkConfigurationHandlerTest, SetProperties) {
191 std::string service_path = "/service/1"; 191 std::string service_path = "/service/1";
192 std::string networkName = "MyNetwork"; 192 std::string networkName = "MyNetwork";
193 std::string key = "SSID"; 193 std::string key = "SSID";
194 scoped_ptr<base::StringValue> networkNameValue( 194 scoped_ptr<base::StringValue> networkNameValue(
195 base::Value::CreateStringValue(networkName)); 195 base::Value::CreateStringValue(networkName));
196 196
197 base::DictionaryValue value; 197 base::DictionaryValue value;
198 value.Set(key, base::Value::CreateStringValue(networkName)); 198 value.Set(key, base::Value::CreateStringValue(networkName));
199 dictionary_value_result_ = &value; 199 dictionary_value_result_ = &value;
200 EXPECT_CALL(*mock_manager_client_, 200 EXPECT_CALL(*mock_manager_client_,
201 ConfigureService(_, _, _)).WillOnce( 201 ConfigureService(_, _, _)).WillOnce(
202 Invoke(this, 202 Invoke(this,
203 &NetworkConfigurationHandlerTest::OnSetProperties)); 203 &NetworkConfigurationHandlerTest::OnSetProperties));
204 NetworkConfigurationHandler::Get()->SetProperties( 204 network_configuration_handler_->SetProperties(
205 service_path, 205 service_path,
206 value, 206 value,
207 base::Bind(&base::DoNothing), 207 base::Bind(&base::DoNothing),
208 base::Bind(&ErrorCallback, false, service_path)); 208 base::Bind(&ErrorCallback, false, service_path));
209 message_loop_.RunUntilIdle(); 209 message_loop_.RunUntilIdle();
210 } 210 }
211 211
212 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) { 212 TEST_F(NetworkConfigurationHandlerTest, ClearProperties) {
213 std::string service_path = "/service/1"; 213 std::string service_path = "/service/1";
214 std::string networkName = "MyNetwork"; 214 std::string networkName = "MyNetwork";
215 std::string key = "SSID"; 215 std::string key = "SSID";
216 scoped_ptr<base::StringValue> networkNameValue( 216 scoped_ptr<base::StringValue> networkNameValue(
217 base::Value::CreateStringValue(networkName)); 217 base::Value::CreateStringValue(networkName));
218 218
219 // First set up a value to clear. 219 // First set up a value to clear.
220 base::DictionaryValue value; 220 base::DictionaryValue value;
221 value.Set(key, base::Value::CreateStringValue(networkName)); 221 value.Set(key, base::Value::CreateStringValue(networkName));
222 dictionary_value_result_ = &value; 222 dictionary_value_result_ = &value;
223 EXPECT_CALL(*mock_manager_client_, 223 EXPECT_CALL(*mock_manager_client_,
224 ConfigureService(_, _, _)).WillOnce( 224 ConfigureService(_, _, _)).WillOnce(
225 Invoke(this, 225 Invoke(this,
226 &NetworkConfigurationHandlerTest::OnSetProperties)); 226 &NetworkConfigurationHandlerTest::OnSetProperties));
227 NetworkConfigurationHandler::Get()->SetProperties( 227 network_configuration_handler_->SetProperties(
228 service_path, 228 service_path,
229 value, 229 value,
230 base::Bind(&base::DoNothing), 230 base::Bind(&base::DoNothing),
231 base::Bind(&ErrorCallback, false, service_path)); 231 base::Bind(&ErrorCallback, false, service_path));
232 message_loop_.RunUntilIdle(); 232 message_loop_.RunUntilIdle();
233 233
234 // Now clear it. 234 // Now clear it.
235 std::vector<std::string> values_to_clear; 235 std::vector<std::string> values_to_clear;
236 values_to_clear.push_back(key); 236 values_to_clear.push_back(key);
237 EXPECT_CALL(*mock_service_client_, 237 EXPECT_CALL(*mock_service_client_,
238 ClearProperties(_, _, _, _)).WillOnce( 238 ClearProperties(_, _, _, _)).WillOnce(
239 Invoke(this, 239 Invoke(this,
240 &NetworkConfigurationHandlerTest::OnClearProperties)); 240 &NetworkConfigurationHandlerTest::OnClearProperties));
241 NetworkConfigurationHandler::Get()->ClearProperties( 241 network_configuration_handler_->ClearProperties(
242 service_path, 242 service_path,
243 values_to_clear, 243 values_to_clear,
244 base::Bind(&base::DoNothing), 244 base::Bind(&base::DoNothing),
245 base::Bind(&ErrorCallback, false, service_path)); 245 base::Bind(&ErrorCallback, false, service_path));
246 message_loop_.RunUntilIdle(); 246 message_loop_.RunUntilIdle();
247 } 247 }
248 248
249 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) { 249 TEST_F(NetworkConfigurationHandlerTest, ClearPropertiesError) {
250 std::string service_path = "/service/1"; 250 std::string service_path = "/service/1";
251 std::string networkName = "MyNetwork"; 251 std::string networkName = "MyNetwork";
252 std::string key = "SSID"; 252 std::string key = "SSID";
253 scoped_ptr<base::StringValue> networkNameValue( 253 scoped_ptr<base::StringValue> networkNameValue(
254 base::Value::CreateStringValue(networkName)); 254 base::Value::CreateStringValue(networkName));
255 255
256 // First set up a value to clear. 256 // First set up a value to clear.
257 base::DictionaryValue value; 257 base::DictionaryValue value;
258 value.Set(key, base::Value::CreateStringValue(networkName)); 258 value.Set(key, base::Value::CreateStringValue(networkName));
259 dictionary_value_result_ = &value; 259 dictionary_value_result_ = &value;
260 EXPECT_CALL(*mock_manager_client_, 260 EXPECT_CALL(*mock_manager_client_,
261 ConfigureService(_, _, _)).WillOnce( 261 ConfigureService(_, _, _)).WillOnce(
262 Invoke(this, 262 Invoke(this,
263 &NetworkConfigurationHandlerTest::OnSetProperties)); 263 &NetworkConfigurationHandlerTest::OnSetProperties));
264 NetworkConfigurationHandler::Get()->SetProperties( 264 network_configuration_handler_->SetProperties(
265 service_path, 265 service_path,
266 value, 266 value,
267 base::Bind(&base::DoNothing), 267 base::Bind(&base::DoNothing),
268 base::Bind(&ErrorCallback, false, service_path)); 268 base::Bind(&ErrorCallback, false, service_path));
269 message_loop_.RunUntilIdle(); 269 message_loop_.RunUntilIdle();
270 270
271 // Now clear it. 271 // Now clear it.
272 std::vector<std::string> values_to_clear; 272 std::vector<std::string> values_to_clear;
273 values_to_clear.push_back(key); 273 values_to_clear.push_back(key);
274 EXPECT_CALL( 274 EXPECT_CALL(
275 *mock_service_client_, 275 *mock_service_client_,
276 ClearProperties(_, _, _, _)).WillOnce( 276 ClearProperties(_, _, _, _)).WillOnce(
277 Invoke(this, 277 Invoke(this,
278 &NetworkConfigurationHandlerTest::OnClearPropertiesError)); 278 &NetworkConfigurationHandlerTest::OnClearPropertiesError));
279 NetworkConfigurationHandler::Get()->ClearProperties( 279 network_configuration_handler_->ClearProperties(
280 service_path, 280 service_path,
281 values_to_clear, 281 values_to_clear,
282 base::Bind(&base::DoNothing), 282 base::Bind(&base::DoNothing),
283 base::Bind(&ErrorCallback, true, service_path)); 283 base::Bind(&ErrorCallback, true, service_path));
284 message_loop_.RunUntilIdle(); 284 message_loop_.RunUntilIdle();
285 } 285 }
286 286
287 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) { 287 TEST_F(NetworkConfigurationHandlerTest, CreateConfiguration) {
288 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n"; 288 std::string expected_json = "{\n \"SSID\": \"MyNetwork\"\n}\n";
289 std::string networkName = "MyNetwork"; 289 std::string networkName = "MyNetwork";
290 std::string key = "SSID"; 290 std::string key = "SSID";
291 scoped_ptr<base::StringValue> networkNameValue( 291 scoped_ptr<base::StringValue> networkNameValue(
292 base::Value::CreateStringValue(networkName)); 292 base::Value::CreateStringValue(networkName));
293 base::DictionaryValue value; 293 base::DictionaryValue value;
294 value.Set(key, base::Value::CreateStringValue(networkName)); 294 value.Set(key, base::Value::CreateStringValue(networkName));
295 295
296 EXPECT_CALL( 296 EXPECT_CALL(
297 *mock_manager_client_, 297 *mock_manager_client_,
298 GetService(_, _, _)).WillOnce( 298 GetService(_, _, _)).WillOnce(
299 Invoke(this, 299 Invoke(this,
300 &NetworkConfigurationHandlerTest::OnGetService)); 300 &NetworkConfigurationHandlerTest::OnGetService));
301 NetworkConfigurationHandler::Get()->CreateConfiguration( 301 network_configuration_handler_->CreateConfiguration(
302 value, 302 value,
303 base::Bind(&StringResultCallback, std::string("/service/2")), 303 base::Bind(&StringResultCallback, std::string("/service/2")),
304 base::Bind(&ErrorCallback, false, std::string(""))); 304 base::Bind(&ErrorCallback, false, std::string("")));
305 message_loop_.RunUntilIdle(); 305 message_loop_.RunUntilIdle();
306 } 306 }
307 307
308 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) { 308 TEST_F(NetworkConfigurationHandlerTest, RemoveConfiguration) {
309 std::string service_path = "/service/1"; 309 std::string service_path = "/service/1";
310 310
311 EXPECT_CALL( 311 EXPECT_CALL(
312 *mock_service_client_, 312 *mock_service_client_,
313 Remove(_, _, _)).WillOnce( 313 Remove(_, _, _)).WillOnce(
314 Invoke(this, 314 Invoke(this,
315 &NetworkConfigurationHandlerTest::OnRemove)); 315 &NetworkConfigurationHandlerTest::OnRemove));
316 NetworkConfigurationHandler::Get()->RemoveConfiguration( 316 network_configuration_handler_->RemoveConfiguration(
317 service_path, 317 service_path,
318 base::Bind(&base::DoNothing), 318 base::Bind(&base::DoNothing),
319 base::Bind(&ErrorCallback, false, service_path)); 319 base::Bind(&ErrorCallback, false, service_path));
320 message_loop_.RunUntilIdle(); 320 message_loop_.RunUntilIdle();
321 } 321 }
322 322
323 } // namespace chromeos 323 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698