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

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

Powered by Google App Engine
This is Rietveld 408576698