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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/chromeos/cros/cros_network_functions.h" | 8 #include "chrome/browser/chromeos/cros/cros_network_functions.h" |
9 #include "chrome/browser/chromeos/cros/gvalue_util.h" | 9 #include "chrome/browser/chromeos/cros/gvalue_util.h" |
10 #include "chrome/browser/chromeos/cros/mock_chromeos_network.h" | 10 #include "chrome/browser/chromeos/cros/mock_chromeos_network.h" |
11 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
12 #include "chromeos/dbus/mock_flimflam_profile_client.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 using ::testing::_; | 15 using ::testing::_; |
14 using ::testing::Invoke; | 16 using ::testing::Invoke; |
15 | 17 |
16 namespace chromeos { | 18 namespace chromeos { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 const char kExamplePath[] = "/foo/bar/baz"; | 22 const char kExamplePath[] = "/foo/bar/baz"; |
21 | 23 |
22 // Expects path and a dictionary value result. | 24 // A mock to check arguments of NetworkPropertiesCallback and ensure that the |
23 void ExpectPathAndDictionaryValue(const base::DictionaryValue* expected, | 25 // callback is called exactly once. |
24 const char* path, | 26 class MockNetworkPropertiesCallback { |
25 const base::DictionaryValue* result) { | 27 public: |
26 EXPECT_STREQ(kExamplePath, path); | 28 // Creates a NetworkPropertiesCallback with expectations. |
27 EXPECT_TRUE(expected->Equals(result)); | 29 static NetworkPropertiesCallback CreateCallback( |
28 } | 30 const char* expected_path, |
31 const base::DictionaryValue& expected_result) { | |
32 MockNetworkPropertiesCallback* mock_callback = | |
33 new MockNetworkPropertiesCallback(expected_result); | |
34 | |
35 EXPECT_CALL(*mock_callback, Run(expected_path, _)).WillOnce( | |
36 Invoke(mock_callback, &MockNetworkPropertiesCallback::CheckResult)); | |
37 | |
38 return base::Bind(&MockNetworkPropertiesCallback::Run, | |
39 base::Owned(mock_callback)); | |
40 } | |
41 | |
42 private: | |
43 explicit MockNetworkPropertiesCallback( | |
44 const base::DictionaryValue& expected_result) | |
45 : expected_result_(expected_result) {} | |
stevenjb
2012/04/12 17:34:36
indent : 4 spaces
hashimoto
2012/04/13 05:27:22
Done.
| |
46 | |
47 MOCK_METHOD2(Run, void(const char* path, | |
48 const base::DictionaryValue* result)); | |
49 | |
50 void CheckResult(const char* path, const base::DictionaryValue* result) { | |
51 EXPECT_TRUE(expected_result_.Equals(result)); | |
52 } | |
53 | |
54 const base::DictionaryValue& expected_result_; | |
55 }; | |
29 | 56 |
30 } // namespace | 57 } // namespace |
31 | 58 |
32 class CrosNetworkFunctionsTest : public testing::Test { | 59 // Test for cros_network_functions.cc with Libcros. |
60 class CrosNetworkFunctionsLibcrosTest : public testing::Test { | |
33 public: | 61 public: |
34 CrosNetworkFunctionsTest() : argument_ghash_table_(NULL) {} | 62 CrosNetworkFunctionsLibcrosTest() : argument_ghash_table_(NULL) {} |
35 | 63 |
36 virtual void SetUp() { | 64 virtual void SetUp() { |
37 ::g_type_init(); | 65 ::g_type_init(); |
38 MockChromeOSNetwork::Initialize(); | 66 MockChromeOSNetwork::Initialize(); |
67 EnableNonLibcrosNetworkFunctions(false); | |
39 } | 68 } |
40 | 69 |
41 virtual void TearDown() { | 70 virtual void TearDown() { |
42 MockChromeOSNetwork::Shutdown(); | 71 MockChromeOSNetwork::Shutdown(); |
43 } | 72 } |
44 | 73 |
45 // Handles call for SetNetwork*PropertyGValue functions and copies the value. | 74 // Handles call for SetNetwork*PropertyGValue functions and copies the value. |
46 void OnSetNetworkPropertyGValue(const char* path, | 75 void OnSetNetworkPropertyGValue(const char* path, |
47 const char* property, | 76 const char* property, |
48 const GValue* gvalue) { | 77 const GValue* gvalue) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 const char* path, | 133 const char* path, |
105 NetworkMethodErrorType error, | 134 NetworkMethodErrorType error, |
106 const char* error_message) {} | 135 const char* error_message) {} |
107 | 136 |
108 protected: | 137 protected: |
109 ScopedGValue argument_gvalue_; | 138 ScopedGValue argument_gvalue_; |
110 ScopedGHashTable argument_ghash_table_; | 139 ScopedGHashTable argument_ghash_table_; |
111 ScopedGHashTable result_ghash_table_; | 140 ScopedGHashTable result_ghash_table_; |
112 }; | 141 }; |
113 | 142 |
114 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkServiceProperty) { | 143 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkServiceProperty) { |
115 const char service_path[] = "/"; | 144 const char service_path[] = "/"; |
116 const char property[] = "property"; | 145 const char property[] = "property"; |
117 EXPECT_CALL(*MockChromeOSNetwork::Get(), | 146 EXPECT_CALL( |
118 SetNetworkServicePropertyGValue(service_path, property, _)) | 147 *MockChromeOSNetwork::Get(), |
119 .WillOnce(Invoke( | 148 SetNetworkServicePropertyGValue(service_path, property, _)) |
120 this, &CrosNetworkFunctionsTest::OnSetNetworkPropertyGValue)); | 149 .WillOnce(Invoke( |
150 this, &CrosNetworkFunctionsLibcrosTest::OnSetNetworkPropertyGValue)); | |
121 const char key1[] = "key1"; | 151 const char key1[] = "key1"; |
122 const std::string string1 = "string1"; | 152 const std::string string1 = "string1"; |
123 const char key2[] = "key2"; | 153 const char key2[] = "key2"; |
124 const std::string string2 = "string2"; | 154 const std::string string2 = "string2"; |
125 base::DictionaryValue value; | 155 base::DictionaryValue value; |
126 value.SetString(key1, string1); | 156 value.SetString(key1, string1); |
127 value.SetString(key2, string2); | 157 value.SetString(key2, string2); |
128 CrosSetNetworkServiceProperty(service_path, property, value); | 158 CrosSetNetworkServiceProperty(service_path, property, value); |
129 | 159 |
130 // Check the argument GHashTable. | 160 // Check the argument GHashTable. |
131 GHashTable* ghash_table = | 161 GHashTable* ghash_table = |
132 static_cast<GHashTable*>(g_value_get_boxed(argument_gvalue_.get())); | 162 static_cast<GHashTable*>(g_value_get_boxed(argument_gvalue_.get())); |
133 ASSERT_TRUE(ghash_table != NULL); | 163 ASSERT_TRUE(ghash_table != NULL); |
134 EXPECT_EQ(string1, static_cast<const char*>( | 164 EXPECT_EQ(string1, static_cast<const char*>( |
135 g_hash_table_lookup(ghash_table, key1))); | 165 g_hash_table_lookup(ghash_table, key1))); |
136 EXPECT_EQ(string2, static_cast<const char*>( | 166 EXPECT_EQ(string2, static_cast<const char*>( |
137 g_hash_table_lookup(ghash_table, key2))); | 167 g_hash_table_lookup(ghash_table, key2))); |
138 } | 168 } |
139 | 169 |
140 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkDeviceProperty) { | 170 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkDeviceProperty) { |
141 const char device_path[] = "/"; | 171 const char device_path[] = "/"; |
142 const char property[] = "property"; | 172 const char property[] = "property"; |
143 EXPECT_CALL(*MockChromeOSNetwork::Get(), | 173 EXPECT_CALL( |
144 SetNetworkDevicePropertyGValue(device_path, property, _)) | 174 *MockChromeOSNetwork::Get(), |
145 .WillOnce(Invoke( | 175 SetNetworkDevicePropertyGValue(device_path, property, _)) |
146 this, &CrosNetworkFunctionsTest::OnSetNetworkPropertyGValue)); | 176 .WillOnce(Invoke( |
177 this, &CrosNetworkFunctionsLibcrosTest::OnSetNetworkPropertyGValue)); | |
147 const bool kBool = true; | 178 const bool kBool = true; |
148 const base::FundamentalValue value(kBool); | 179 const base::FundamentalValue value(kBool); |
149 CrosSetNetworkDeviceProperty(device_path, property, value); | 180 CrosSetNetworkDeviceProperty(device_path, property, value); |
150 EXPECT_EQ(kBool, g_value_get_boolean(argument_gvalue_.get())); | 181 EXPECT_EQ(kBool, g_value_get_boolean(argument_gvalue_.get())); |
151 } | 182 } |
152 | 183 |
153 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkIPConfigProperty) { | 184 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkIPConfigProperty) { |
154 const char ipconfig_path[] = "/"; | 185 const char ipconfig_path[] = "/"; |
155 const char property[] = "property"; | 186 const char property[] = "property"; |
156 EXPECT_CALL(*MockChromeOSNetwork::Get(), | 187 EXPECT_CALL( |
157 SetNetworkIPConfigPropertyGValue(ipconfig_path, property, _)) | 188 *MockChromeOSNetwork::Get(), |
158 .WillOnce(Invoke( | 189 SetNetworkIPConfigPropertyGValue(ipconfig_path, property, _)) |
159 this, &CrosNetworkFunctionsTest::OnSetNetworkPropertyGValue)); | 190 .WillOnce(Invoke( |
191 this, &CrosNetworkFunctionsLibcrosTest::OnSetNetworkPropertyGValue)); | |
160 const int kInt = 1234; | 192 const int kInt = 1234; |
161 const base::FundamentalValue value(kInt); | 193 const base::FundamentalValue value(kInt); |
162 CrosSetNetworkIPConfigProperty(ipconfig_path, property, value); | 194 CrosSetNetworkIPConfigProperty(ipconfig_path, property, value); |
163 EXPECT_EQ(kInt, g_value_get_int(argument_gvalue_.get())); | 195 EXPECT_EQ(kInt, g_value_get_int(argument_gvalue_.get())); |
164 } | 196 } |
165 | 197 |
166 TEST_F(CrosNetworkFunctionsTest, CrosSetNetworkManagerProperty) { | 198 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosSetNetworkManagerProperty) { |
167 const char property[] = "property"; | 199 const char property[] = "property"; |
168 EXPECT_CALL( | 200 EXPECT_CALL( |
169 *MockChromeOSNetwork::Get(), | 201 *MockChromeOSNetwork::Get(), |
170 SetNetworkManagerPropertyGValue(property, _)) | 202 SetNetworkManagerPropertyGValue(property, _)) |
171 .WillOnce(Invoke( | 203 .WillOnce(Invoke( |
172 this, | 204 this, |
173 &CrosNetworkFunctionsTest::OnSetNetworkManagerPropertyGValue)); | 205 &CrosNetworkFunctionsLibcrosTest::OnSetNetworkManagerPropertyGValue)); |
174 const std::string kString = "string"; | 206 const std::string kString = "string"; |
175 const base::StringValue value(kString); | 207 const base::StringValue value(kString); |
176 CrosSetNetworkManagerProperty(property, value); | 208 CrosSetNetworkManagerProperty(property, value); |
177 EXPECT_EQ(kString, g_value_get_string(argument_gvalue_.get())); | 209 EXPECT_EQ(kString, g_value_get_string(argument_gvalue_.get())); |
178 } | 210 } |
179 | 211 |
180 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkManagerProperties) { | 212 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkManagerProperties) { |
181 const std::string key1 = "key1"; | 213 const std::string key1 = "key1"; |
182 const std::string value1 = "value1"; | 214 const std::string value1 = "value1"; |
183 const std::string key2 = "key.2."; | 215 const std::string key2 = "key.2."; |
184 const std::string value2 = "value2"; | 216 const std::string value2 = "value2"; |
185 // Create result value. | 217 // Create result value. |
186 base::DictionaryValue result; | 218 base::DictionaryValue result; |
187 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | 219 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); |
188 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | 220 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); |
189 result_ghash_table_.reset( | 221 result_ghash_table_.reset( |
190 ConvertDictionaryValueToStringValueGHashTable(result)); | 222 ConvertDictionaryValueToStringValueGHashTable(result)); |
191 // Set expectations. | 223 // Set expectations. |
192 EXPECT_CALL( | 224 EXPECT_CALL( |
193 *MockChromeOSNetwork::Get(), | 225 *MockChromeOSNetwork::Get(), |
194 RequestNetworkManagerProperties(_, _)) | 226 RequestNetworkManagerProperties(_, _)) |
195 .WillOnce(Invoke( | 227 .WillOnce(Invoke( |
196 this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties2)); | 228 this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties2)); |
197 | 229 |
198 CrosRequestNetworkManagerProperties( | 230 CrosRequestNetworkManagerProperties( |
199 base::Bind(&ExpectPathAndDictionaryValue, &result)); | 231 MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result)); |
200 } | 232 } |
201 | 233 |
202 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkServiceProperties) { | 234 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkServiceProperties) { |
203 const std::string service_path = "service path"; | 235 const std::string service_path = "service path"; |
204 const std::string key1 = "key1"; | 236 const std::string key1 = "key1"; |
205 const std::string value1 = "value1"; | 237 const std::string value1 = "value1"; |
206 const std::string key2 = "key.2."; | 238 const std::string key2 = "key.2."; |
207 const std::string value2 = "value2"; | 239 const std::string value2 = "value2"; |
208 // Create result value. | 240 // Create result value. |
209 base::DictionaryValue result; | 241 base::DictionaryValue result; |
210 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | 242 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); |
211 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | 243 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); |
212 result_ghash_table_.reset( | 244 result_ghash_table_.reset( |
213 ConvertDictionaryValueToStringValueGHashTable(result)); | 245 ConvertDictionaryValueToStringValueGHashTable(result)); |
214 // Set expectations. | 246 // Set expectations. |
215 EXPECT_CALL( | 247 EXPECT_CALL( |
216 *MockChromeOSNetwork::Get(), | 248 *MockChromeOSNetwork::Get(), |
217 RequestNetworkServiceProperties(service_path.c_str(), _, _)) | 249 RequestNetworkServiceProperties(service_path.c_str(), _, _)) |
218 .WillOnce(Invoke( | 250 .WillOnce(Invoke( |
219 this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties3)); | 251 this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties3)); |
220 | 252 |
221 CrosRequestNetworkServiceProperties( | 253 CrosRequestNetworkServiceProperties( |
222 service_path.c_str(), base::Bind(&ExpectPathAndDictionaryValue, &result)); | 254 service_path.c_str(), |
255 MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result)); | |
223 } | 256 } |
224 | 257 |
225 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkDeviceProperties) { | 258 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkDeviceProperties) { |
226 const std::string device_path = "device path"; | 259 const std::string device_path = "device path"; |
227 const std::string key1 = "key1"; | 260 const std::string key1 = "key1"; |
228 const std::string value1 = "value1"; | 261 const std::string value1 = "value1"; |
229 const std::string key2 = "key.2."; | 262 const std::string key2 = "key.2."; |
230 const std::string value2 = "value2"; | 263 const std::string value2 = "value2"; |
231 // Create result value. | 264 // Create result value. |
232 base::DictionaryValue result; | 265 base::DictionaryValue result; |
233 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | 266 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); |
234 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | 267 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); |
235 result_ghash_table_.reset( | 268 result_ghash_table_.reset( |
236 ConvertDictionaryValueToStringValueGHashTable(result)); | 269 ConvertDictionaryValueToStringValueGHashTable(result)); |
237 // Set expectations. | 270 // Set expectations. |
238 EXPECT_CALL( | 271 EXPECT_CALL( |
239 *MockChromeOSNetwork::Get(), | 272 *MockChromeOSNetwork::Get(), |
240 RequestNetworkDeviceProperties(device_path.c_str(), _, _)) | 273 RequestNetworkDeviceProperties(device_path.c_str(), _, _)) |
241 .WillOnce(Invoke( | 274 .WillOnce(Invoke( |
242 this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties3)); | 275 this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties3)); |
243 | 276 |
244 CrosRequestNetworkDeviceProperties( | 277 CrosRequestNetworkDeviceProperties( |
245 device_path.c_str(), base::Bind(&ExpectPathAndDictionaryValue, &result)); | 278 device_path.c_str(), |
279 MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result)); | |
246 } | 280 } |
247 | 281 |
248 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileProperties) { | 282 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestNetworkProfileProperties) { |
249 const std::string profile_path = "profile path"; | 283 const std::string profile_path = "profile path"; |
250 const std::string key1 = "key1"; | 284 const std::string key1 = "key1"; |
251 const std::string value1 = "value1"; | 285 const std::string value1 = "value1"; |
252 const std::string key2 = "key.2."; | 286 const std::string key2 = "key.2."; |
253 const std::string value2 = "value2"; | 287 const std::string value2 = "value2"; |
254 // Create result value. | 288 // Create result value. |
255 base::DictionaryValue result; | 289 base::DictionaryValue result; |
256 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | 290 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); |
257 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | 291 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); |
258 result_ghash_table_.reset( | 292 result_ghash_table_.reset( |
259 ConvertDictionaryValueToStringValueGHashTable(result)); | 293 ConvertDictionaryValueToStringValueGHashTable(result)); |
260 // Set expectations. | 294 // Set expectations. |
261 EXPECT_CALL( | 295 EXPECT_CALL( |
262 *MockChromeOSNetwork::Get(), | 296 *MockChromeOSNetwork::Get(), |
263 RequestNetworkProfileProperties(profile_path.c_str(), _, _)) | 297 RequestNetworkProfileProperties(profile_path.c_str(), _, _)) |
264 .WillOnce(Invoke( | 298 .WillOnce(Invoke( |
265 this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties3)); | 299 this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties3)); |
266 | 300 |
267 CrosRequestNetworkProfileProperties( | 301 CrosRequestNetworkProfileProperties( |
268 profile_path.c_str(), | 302 profile_path.c_str(), |
269 base::Bind(&ExpectPathAndDictionaryValue, &result)); | 303 MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result)); |
270 } | 304 } |
271 | 305 |
272 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) { | 306 TEST_F(CrosNetworkFunctionsLibcrosTest, |
307 CrosRequestNetworkProfileEntryProperties) { | |
273 const std::string profile_path = "profile path"; | 308 const std::string profile_path = "profile path"; |
274 const std::string profile_entry_path = "profile entry path"; | 309 const std::string profile_entry_path = "profile entry path"; |
275 const std::string key1 = "key1"; | 310 const std::string key1 = "key1"; |
276 const std::string value1 = "value1"; | 311 const std::string value1 = "value1"; |
277 const std::string key2 = "key.2."; | 312 const std::string key2 = "key.2."; |
278 const std::string value2 = "value2"; | 313 const std::string value2 = "value2"; |
279 // Create result value. | 314 // Create result value. |
280 base::DictionaryValue result; | 315 base::DictionaryValue result; |
281 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | 316 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); |
282 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | 317 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); |
283 result_ghash_table_.reset( | 318 result_ghash_table_.reset( |
284 ConvertDictionaryValueToStringValueGHashTable(result)); | 319 ConvertDictionaryValueToStringValueGHashTable(result)); |
285 // Set expectations. | 320 // Set expectations. |
286 EXPECT_CALL( | 321 EXPECT_CALL( |
287 *MockChromeOSNetwork::Get(), | 322 *MockChromeOSNetwork::Get(), |
288 RequestNetworkProfileEntryProperties(profile_path.c_str(), | 323 RequestNetworkProfileEntryProperties(profile_path.c_str(), |
289 profile_entry_path.c_str(), _, _)) | 324 profile_entry_path.c_str(), _, _)) |
290 .WillOnce(Invoke( | 325 .WillOnce(Invoke( |
291 this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties4)); | 326 this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties4)); |
292 | 327 |
293 CrosRequestNetworkProfileEntryProperties( | 328 CrosRequestNetworkProfileEntryProperties( |
294 profile_path.c_str(), profile_entry_path.c_str(), | 329 profile_path.c_str(), |
295 base::Bind(&ExpectPathAndDictionaryValue, &result)); | 330 profile_entry_path.c_str(), |
331 MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result)); | |
296 } | 332 } |
297 | 333 |
298 TEST_F(CrosNetworkFunctionsTest, CrosRequestHiddenWifiNetworkProperties) { | 334 TEST_F(CrosNetworkFunctionsLibcrosTest, |
335 CrosRequestHiddenWifiNetworkProperties) { | |
299 const std::string ssid = "ssid"; | 336 const std::string ssid = "ssid"; |
300 const std::string security = "security"; | 337 const std::string security = "security"; |
301 const std::string key1 = "key1"; | 338 const std::string key1 = "key1"; |
302 const std::string value1 = "value1"; | 339 const std::string value1 = "value1"; |
303 const std::string key2 = "key.2."; | 340 const std::string key2 = "key.2."; |
304 const std::string value2 = "value2"; | 341 const std::string value2 = "value2"; |
305 // Create result value. | 342 // Create result value. |
306 base::DictionaryValue result; | 343 base::DictionaryValue result; |
307 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | 344 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); |
308 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | 345 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); |
309 result_ghash_table_.reset( | 346 result_ghash_table_.reset( |
310 ConvertDictionaryValueToStringValueGHashTable(result)); | 347 ConvertDictionaryValueToStringValueGHashTable(result)); |
311 // Set expectations. | 348 // Set expectations. |
312 EXPECT_CALL( | 349 EXPECT_CALL( |
313 *MockChromeOSNetwork::Get(), | 350 *MockChromeOSNetwork::Get(), |
314 RequestHiddenWifiNetworkProperties(ssid.c_str(), security.c_str(), _, _)) | 351 RequestHiddenWifiNetworkProperties(ssid.c_str(), security.c_str(), _, _)) |
315 .WillOnce(Invoke( | 352 .WillOnce(Invoke( |
316 this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties4)); | 353 this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties4)); |
317 | 354 |
318 CrosRequestHiddenWifiNetworkProperties( | 355 CrosRequestHiddenWifiNetworkProperties( |
319 ssid.c_str(), security.c_str(), | 356 ssid.c_str(), security.c_str(), |
320 base::Bind(&ExpectPathAndDictionaryValue, &result)); | 357 MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result)); |
321 } | 358 } |
322 | 359 |
323 TEST_F(CrosNetworkFunctionsTest, CrosRequestVirtualNetworkProperties) { | 360 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosRequestVirtualNetworkProperties) { |
324 const std::string service_name = "service name"; | 361 const std::string service_name = "service name"; |
325 const std::string server_hostname = "server hostname"; | 362 const std::string server_hostname = "server hostname"; |
326 const std::string provider_name = "provider name"; | 363 const std::string provider_name = "provider name"; |
327 const std::string key1 = "key1"; | 364 const std::string key1 = "key1"; |
328 const std::string value1 = "value1"; | 365 const std::string value1 = "value1"; |
329 const std::string key2 = "key.2."; | 366 const std::string key2 = "key.2."; |
330 const std::string value2 = "value2"; | 367 const std::string value2 = "value2"; |
331 // Create result value. | 368 // Create result value. |
332 base::DictionaryValue result; | 369 base::DictionaryValue result; |
333 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | 370 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); |
334 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | 371 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); |
335 result_ghash_table_.reset( | 372 result_ghash_table_.reset( |
336 ConvertDictionaryValueToStringValueGHashTable(result)); | 373 ConvertDictionaryValueToStringValueGHashTable(result)); |
337 // Set expectations. | 374 // Set expectations. |
338 EXPECT_CALL(*MockChromeOSNetwork::Get(), | 375 EXPECT_CALL(*MockChromeOSNetwork::Get(), |
339 RequestVirtualNetworkProperties(service_name.c_str(), | 376 RequestVirtualNetworkProperties(service_name.c_str(), |
340 server_hostname.c_str(), | 377 server_hostname.c_str(), |
341 provider_name.c_str(), _, _)) | 378 provider_name.c_str(), _, _)) |
342 .WillOnce(Invoke( | 379 .WillOnce(Invoke( |
343 this, &CrosNetworkFunctionsTest::OnRequestNetworkProperties5)); | 380 this, &CrosNetworkFunctionsLibcrosTest::OnRequestNetworkProperties5)); |
344 | 381 |
345 CrosRequestVirtualNetworkProperties( | 382 CrosRequestVirtualNetworkProperties( |
346 service_name.c_str(), | 383 service_name.c_str(), |
347 server_hostname.c_str(), | 384 server_hostname.c_str(), |
348 provider_name.c_str(), | 385 provider_name.c_str(), |
349 base::Bind(&ExpectPathAndDictionaryValue, &result)); | 386 MockNetworkPropertiesCallback::CreateCallback(kExamplePath, result)); |
350 } | 387 } |
351 | 388 |
352 TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) { | 389 TEST_F(CrosNetworkFunctionsLibcrosTest, CrosConfigureService) { |
353 const char identifier[] = "identifier"; | 390 const char identifier[] = "identifier"; |
354 EXPECT_CALL(*MockChromeOSNetwork::Get(), | 391 EXPECT_CALL(*MockChromeOSNetwork::Get(), |
355 ConfigureService(identifier, _, &OnNetworkAction, this)) | 392 ConfigureService(identifier, _, &OnNetworkAction, this)) |
356 .WillOnce(Invoke( | 393 .WillOnce(Invoke( |
357 this, &CrosNetworkFunctionsTest::OnConfigureService)); | 394 this, &CrosNetworkFunctionsLibcrosTest::OnConfigureService)); |
358 const char key1[] = "key1"; | 395 const char key1[] = "key1"; |
359 const std::string string1 = "string1"; | 396 const std::string string1 = "string1"; |
360 const char key2[] = "key2"; | 397 const char key2[] = "key2"; |
361 const std::string string2 = "string2"; | 398 const std::string string2 = "string2"; |
362 base::DictionaryValue value; | 399 base::DictionaryValue value; |
363 value.SetString(key1, string1); | 400 value.SetString(key1, string1); |
364 value.SetString(key2, string2); | 401 value.SetString(key2, string2); |
365 CrosConfigureService(identifier, value, &OnNetworkAction, this); | 402 CrosConfigureService(identifier, value, &OnNetworkAction, this); |
366 | 403 |
367 // Check the argument GHashTable. | 404 // Check the argument GHashTable. |
368 const GValue* string1_gvalue = static_cast<const GValue*>( | 405 const GValue* string1_gvalue = static_cast<const GValue*>( |
369 g_hash_table_lookup(argument_ghash_table_.get(), key1)); | 406 g_hash_table_lookup(argument_ghash_table_.get(), key1)); |
370 EXPECT_EQ(string1, g_value_get_string(string1_gvalue)); | 407 EXPECT_EQ(string1, g_value_get_string(string1_gvalue)); |
371 const GValue* string2_gvalue = static_cast<const GValue*>( | 408 const GValue* string2_gvalue = static_cast<const GValue*>( |
372 g_hash_table_lookup(argument_ghash_table_.get(), key2)); | 409 g_hash_table_lookup(argument_ghash_table_.get(), key2)); |
373 EXPECT_EQ(string2, g_value_get_string(string2_gvalue)); | 410 EXPECT_EQ(string2, g_value_get_string(string2_gvalue)); |
374 } | 411 } |
375 | 412 |
413 // Test for cros_network_functions.cc without Libcros. | |
414 class CrosNetworkFunctionsTest : public testing::Test { | |
415 public: | |
416 CrosNetworkFunctionsTest() : mock_profile_client_(NULL), | |
417 dictionary_value_result_(NULL) {} | |
418 | |
419 virtual void SetUp() { | |
420 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | |
421 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | |
422 mock_profile_client_ = | |
423 mock_dbus_thread_manager->mock_flimflam_profile_client(); | |
424 EnableNonLibcrosNetworkFunctions(true); | |
425 } | |
426 | |
427 virtual void TearDown() { | |
428 DBusThreadManager::Shutdown(); | |
429 mock_profile_client_ = NULL; | |
430 } | |
431 | |
432 // Handles responses for GetProperties method calls. | |
433 void OnGetProperties( | |
434 const dbus::ObjectPath& profile_path, | |
435 const FlimflamClientHelper::DictionaryValueCallback& callback) { | |
436 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); | |
437 } | |
438 | |
439 // Handles responses for GetEntry method calls. | |
440 void OnGetEntry( | |
441 const dbus::ObjectPath& profile_path, | |
442 const std::string& entry_path, | |
443 const FlimflamClientHelper::DictionaryValueCallback& callback) { | |
444 callback.Run(DBUS_METHOD_CALL_SUCCESS, *dictionary_value_result_); | |
445 } | |
446 | |
447 protected: | |
448 MockFlimflamProfileClient* mock_profile_client_; | |
449 const base::DictionaryValue* dictionary_value_result_; | |
450 }; | |
451 | |
452 TEST_F(CrosNetworkFunctionsTest, CrosDeleteServiceFromProfile) { | |
453 const std::string profile_path("/profile/path"); | |
454 const std::string service_path("/service/path"); | |
455 EXPECT_CALL(*mock_profile_client_, | |
456 DeleteEntry(dbus::ObjectPath(profile_path), service_path, _)) | |
457 .Times(1); | |
458 CrosDeleteServiceFromProfile(profile_path.c_str(), service_path.c_str()); | |
459 } | |
460 | |
461 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileProperties) { | |
462 const std::string profile_path = "profile path"; | |
463 const std::string key1 = "key1"; | |
464 const std::string value1 = "value1"; | |
465 const std::string key2 = "key.2."; | |
466 const std::string value2 = "value2"; | |
467 // Create result value. | |
468 base::DictionaryValue result; | |
469 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | |
470 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | |
471 // Set expectations. | |
472 dictionary_value_result_ = &result; | |
473 EXPECT_CALL(*mock_profile_client_, | |
474 GetProperties(dbus::ObjectPath(profile_path), _)).WillOnce( | |
475 Invoke(this, &CrosNetworkFunctionsTest::OnGetProperties)); | |
476 | |
477 CrosRequestNetworkProfileProperties( | |
478 profile_path.c_str(), | |
479 MockNetworkPropertiesCallback::CreateCallback(profile_path.c_str(), | |
480 result)); | |
481 } | |
482 | |
483 TEST_F(CrosNetworkFunctionsTest, CrosRequestNetworkProfileEntryProperties) { | |
484 const std::string profile_path = "profile path"; | |
485 const std::string profile_entry_path = "profile entry path"; | |
486 const std::string key1 = "key1"; | |
487 const std::string value1 = "value1"; | |
488 const std::string key2 = "key.2."; | |
489 const std::string value2 = "value2"; | |
490 // Create result value. | |
491 base::DictionaryValue result; | |
492 result.SetWithoutPathExpansion(key1, base::Value::CreateStringValue(value1)); | |
493 result.SetWithoutPathExpansion(key2, base::Value::CreateStringValue(value2)); | |
494 // Set expectations. | |
495 dictionary_value_result_ = &result; | |
496 EXPECT_CALL(*mock_profile_client_, | |
497 GetEntry(dbus::ObjectPath(profile_path), profile_entry_path, _)) | |
498 .WillOnce(Invoke(this, &CrosNetworkFunctionsTest::OnGetEntry)); | |
499 | |
500 CrosRequestNetworkProfileEntryProperties( | |
501 profile_path.c_str(), profile_entry_path.c_str(), | |
502 MockNetworkPropertiesCallback::CreateCallback(profile_entry_path.c_str(), | |
503 result)); | |
504 } | |
505 | |
376 } // namespace chromeos | 506 } // namespace chromeos |
OLD | NEW |