OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // The expectations in this test for the Chrome OS implementation. See | |
6 // networking_private_chromeos_apitest.cc for more info. | |
7 | |
8 var callbackPass = chrome.test.callbackPass; | |
9 var callbackFail = chrome.test.callbackFail; | |
10 var assertTrue = chrome.test.assertTrue; | |
11 var assertFalse = chrome.test.assertFalse; | |
12 var assertEq = chrome.test.assertEq; | |
13 | |
14 // Test properties for the verification API. | |
15 var verificationProperties = { | |
16 "certificate": "certificate", | |
17 "intermediateCertificates": ["ica1", "ica2", "ica3"], | |
18 "publicKey": "cHVibGljX2tleQ==", // Base64("public_key") | |
19 "nonce": "nonce", | |
20 "signedData": "c2lnbmVkX2RhdGE=", // Base64("signed_data") | |
21 "deviceSerial": "device_serial", | |
22 "deviceSsid": "Device 0123", | |
23 "deviceBssid": "00:01:02:03:04:05" | |
24 }; | |
25 | |
26 var privateHelpers = { | |
27 // Watches for the states |expectedStates| in reverse order. If all states | |
28 // were observed in the right order, succeeds and calls |done|. If any | |
29 // unexpected state is observed, fails. | |
30 watchForStateChanges: function(network, expectedStates, done) { | |
31 var self = this; | |
32 var collectProperties = function(properties) { | |
33 var finishTest = function() { | |
34 chrome.networkingPrivate.onNetworksChanged.removeListener( | |
35 self.onNetworkChange); | |
36 done(); | |
37 }; | |
38 if (expectedStates.length > 0) { | |
39 var expectedState = expectedStates.pop(); | |
40 assertEq(expectedState, properties.ConnectionState); | |
41 if (expectedStates.length == 0) | |
42 finishTest(); | |
43 } | |
44 }; | |
45 this.onNetworkChange = function(changes) { | |
46 assertEq([network], changes); | |
47 chrome.networkingPrivate.getProperties( | |
48 network, | |
49 callbackPass(collectProperties)); | |
50 }; | |
51 chrome.networkingPrivate.onNetworksChanged.addListener( | |
52 this.onNetworkChange); | |
53 }, | |
54 listListener: function(expected, done) { | |
55 var self = this; | |
56 this.listenForChanges = function(list) { | |
57 assertEq(expected, list); | |
58 chrome.networkingPrivate.onNetworkListChanged.removeListener( | |
59 self.listenForChanges); | |
60 done(); | |
61 }; | |
62 }, | |
63 watchForCaptivePortalState: function(expectedGuid, | |
64 expectedState, | |
65 done) { | |
66 var self = this; | |
67 this.onPortalDetectionCompleted = function(guid, state) { | |
68 assertEq(expectedGuid, guid); | |
69 assertEq(expectedState, state); | |
70 chrome.networkingPrivate.onPortalDetectionCompleted.removeListener( | |
71 self.onPortalDetectionCompleted); | |
72 done(); | |
73 }; | |
74 chrome.networkingPrivate.onPortalDetectionCompleted.addListener( | |
75 self.onPortalDetectionCompleted); | |
76 } | |
77 }; | |
78 | |
79 var availableTests = [ | |
80 function startConnect() { | |
81 chrome.networkingPrivate.startConnect("stub_wifi2_guid", callbackPass()); | |
82 }, | |
83 function startDisconnect() { | |
84 // Must connect to a network before we can disconnect from it. | |
85 chrome.networkingPrivate.startConnect( | |
86 "stub_wifi2_guid", callbackPass(function() { | |
87 chrome.networkingPrivate.startDisconnect("stub_wifi2_guid", | |
88 callbackPass()); | |
89 })); | |
90 }, | |
91 function startActivate() { | |
92 // Must connect to a network before we can activate it. | |
93 chrome.networkingPrivate.startConnect( | |
94 "stub_cellular1_guid", callbackPass(function() { | |
95 chrome.networkingPrivate.startActivate( | |
96 "stub_cellular1_guid", callbackPass(function() { | |
97 chrome.networkingPrivate.getState( | |
98 "stub_cellular1_guid", callbackPass(function(state) { | |
99 assertEq("Activated", state.Cellular.ActivationState); | |
100 })); | |
101 })); | |
102 })); | |
103 }, | |
104 function startConnectNonexistent() { | |
105 chrome.networkingPrivate.startConnect( | |
106 "nonexistent_path", | |
107 callbackFail("Error.InvalidNetworkGuid")); | |
108 }, | |
109 function startDisconnectNonexistent() { | |
110 chrome.networkingPrivate.startDisconnect( | |
111 "nonexistent_path", | |
112 callbackFail("Error.InvalidNetworkGuid")); | |
113 }, | |
114 function startGetPropertiesNonexistent() { | |
115 chrome.networkingPrivate.getProperties( | |
116 "nonexistent_path", | |
117 callbackFail("Error.InvalidNetworkGuid")); | |
118 }, | |
119 function createNetwork() { | |
120 chrome.networkingPrivate.createNetwork( | |
121 false, // shared | |
122 { "Type": "WiFi", | |
123 "GUID": "ignored_guid", | |
124 "WiFi": { | |
125 "SSID": "wifi_created", | |
126 "Security": "WEP-PSK" | |
127 } | |
128 }, | |
129 callbackPass(function(guid) { | |
130 assertFalse(guid == ""); | |
131 assertFalse(guid == "ignored_guid"); | |
132 chrome.networkingPrivate.getProperties( | |
133 guid, | |
134 callbackPass(function(properties) { | |
135 assertEq("WiFi", properties.Type); | |
136 assertEq(guid, properties.GUID); | |
137 assertEq("wifi_created", properties.WiFi.SSID); | |
138 assertEq("WEP-PSK", properties.WiFi.Security); | |
139 })); | |
140 })); | |
141 }, | |
142 function getNetworks() { | |
143 // Test 'type' and 'configured'. | |
144 chrome.networkingPrivate.getNetworks( | |
145 { "networkType": "WiFi", "configured": true }, | |
146 callbackPass(function(result) { | |
147 assertEq([{ | |
148 "Connectable": true, | |
149 "ConnectionState": "Connected", | |
150 "GUID": "stub_wifi1_guid", | |
151 "Name": "wifi1", | |
152 "Type": "WiFi", | |
153 "Source":"User", | |
154 "WiFi": { | |
155 "Security": "WEP-PSK", | |
156 "SignalStrength": 40 | |
157 } | |
158 }, { | |
159 "GUID": "stub_wifi2_guid", | |
160 "Name": "wifi2_PSK", | |
161 "Type": "WiFi", | |
162 "Source":"User", | |
163 "WiFi": { | |
164 "Security": "WPA-PSK", | |
165 } | |
166 }], result); | |
167 | |
168 // Test 'visible' (and 'configured'). | |
169 chrome.networkingPrivate.getNetworks( | |
170 { "networkType": "WiFi", "visible": true, "configured": true }, | |
171 callbackPass(function(result) { | |
172 assertEq([{ | |
173 "Connectable": true, | |
174 "ConnectionState": "Connected", | |
175 "GUID": "stub_wifi1_guid", | |
176 "Name": "wifi1", | |
177 "Source":"User", | |
178 "Type": "WiFi", | |
179 "WiFi": { | |
180 "Security": "WEP-PSK", | |
181 "SignalStrength": 40 | |
182 } | |
183 }], result); | |
184 | |
185 // Test 'limit'. | |
186 chrome.networkingPrivate.getNetworks( | |
187 { "networkType": "All", "limit": 1 }, | |
188 callbackPass(function(result) { | |
189 assertEq([{ | |
190 "ConnectionState": "Connected", | |
191 "Ethernet": { | |
192 "Authentication": "None" | |
193 }, | |
194 "GUID": "stub_ethernet_guid", | |
195 "Name": "eth0", | |
196 "Source":"Device", | |
197 "Type": "Ethernet" | |
198 }], result); | |
199 })); | |
200 })); | |
201 })); | |
202 }, | |
203 function getVisibleNetworks() { | |
204 chrome.networkingPrivate.getVisibleNetworks( | |
205 "All", | |
206 callbackPass(function(result) { | |
207 assertEq([{ | |
208 "ConnectionState": "Connected", | |
209 "Ethernet": { | |
210 "Authentication": "None" | |
211 }, | |
212 "GUID": "stub_ethernet_guid", | |
213 "Name": "eth0", | |
214 "Source":"Device", | |
215 "Type": "Ethernet" | |
216 }, | |
217 { | |
218 "Connectable": true, | |
219 "ConnectionState": "Connected", | |
220 "GUID": "stub_wifi1_guid", | |
221 "Name": "wifi1", | |
222 "Source": "User", | |
223 "Type": "WiFi", | |
224 "WiFi": { | |
225 "Security": "WEP-PSK", | |
226 "SignalStrength": 40 | |
227 } | |
228 }, | |
229 { | |
230 "Connectable": true, | |
231 "ConnectionState": "Connected", | |
232 "GUID": "stub_wimax_guid", | |
233 "Name": "wimax", | |
234 "Source": "User", | |
235 "Type": "WiMAX", | |
236 "WiMAX": { | |
237 "SignalStrength": 40 | |
238 } | |
239 }, | |
240 { | |
241 "ConnectionState": "Connected", | |
242 "GUID": "stub_vpn1_guid", | |
243 "Name": "vpn1", | |
244 "Source": "User", | |
245 "Type": "VPN", | |
246 "VPN": { | |
247 "Type":"OpenVPN" | |
248 } | |
249 }, | |
250 { | |
251 "ConnectionState": "NotConnected", | |
252 "GUID": "stub_vpn2_guid", | |
253 "Name": "vpn2", | |
254 "Source": "User", | |
255 "Type": "VPN", | |
256 "VPN": { | |
257 "ThirdPartyVPN": { | |
258 "ExtensionID": "third_party_provider_extension_id" | |
259 }, | |
260 "Type": "ThirdPartyVPN" | |
261 } | |
262 }, | |
263 { | |
264 "Connectable": true, | |
265 "ConnectionState": "NotConnected", | |
266 "GUID": "stub_wifi2_guid", | |
267 "Name": "wifi2_PSK", | |
268 "Source": "User", | |
269 "Type": "WiFi", | |
270 "WiFi": { | |
271 "Security": "WPA-PSK", | |
272 "SignalStrength": 80 | |
273 } | |
274 }], result); | |
275 })); | |
276 }, | |
277 function getVisibleNetworksWifi() { | |
278 chrome.networkingPrivate.getVisibleNetworks( | |
279 "WiFi", | |
280 callbackPass(function(result) { | |
281 assertEq([{ | |
282 "Connectable": true, | |
283 "ConnectionState": "Connected", | |
284 "GUID": "stub_wifi1_guid", | |
285 "Name": "wifi1", | |
286 "Source": "User", | |
287 "Type": "WiFi", | |
288 "WiFi": { | |
289 "Security": "WEP-PSK", | |
290 "SignalStrength": 40 | |
291 } | |
292 }, | |
293 { | |
294 "Connectable": true, | |
295 "ConnectionState": "NotConnected", | |
296 "GUID": "stub_wifi2_guid", | |
297 "Name": "wifi2_PSK", | |
298 "Source": "User", | |
299 "Type": "WiFi", | |
300 "WiFi": { | |
301 "Security": "WPA-PSK", | |
302 "SignalStrength": 80 | |
303 } | |
304 } | |
305 ], result); | |
306 })); | |
307 }, | |
308 function requestNetworkScan() { | |
309 // Connected or Connecting networks should be listed first, sorted by type. | |
310 var expected = ["stub_ethernet_guid", | |
311 "stub_wifi1_guid", | |
312 "stub_wimax_guid", | |
313 "stub_vpn1_guid", | |
314 "stub_vpn2_guid", | |
315 "stub_wifi2_guid"]; | |
316 var done = chrome.test.callbackAdded(); | |
317 var listener = new privateHelpers.listListener(expected, done); | |
318 chrome.networkingPrivate.onNetworkListChanged.addListener( | |
319 listener.listenForChanges); | |
320 chrome.networkingPrivate.requestNetworkScan(); | |
321 }, | |
322 function getProperties() { | |
323 chrome.networkingPrivate.getProperties( | |
324 "stub_wifi1_guid", | |
325 callbackPass(function(result) { | |
326 assertEq({ "Connectable": true, | |
327 "ConnectionState": "Connected", | |
328 "GUID": "stub_wifi1_guid", | |
329 "IPAddressConfigType": "Static", | |
330 "IPConfigs": [{ | |
331 "Gateway": "0.0.0.1", | |
332 "IPAddress": "0.0.0.0", | |
333 "RoutingPrefix": 0, | |
334 "Type": "IPv4" | |
335 }], | |
336 "MacAddress": "00:11:22:AA:BB:CC", | |
337 "Name": "wifi1", | |
338 "StaticIPConfig": { | |
339 "IPAddress": "1.2.3.4", | |
340 "Type": "IPv4" | |
341 }, | |
342 "Type": "WiFi", | |
343 "WiFi": { | |
344 "HexSSID": "7769666931", // "wifi1" | |
345 "Frequency": 2400, | |
346 "FrequencyList": [2400], | |
347 "SSID": "wifi1", | |
348 "Security": "WEP-PSK", | |
349 "SignalStrength": 40 | |
350 } | |
351 }, result); | |
352 })); | |
353 }, | |
354 function getPropertiesCellular() { | |
355 chrome.networkingPrivate.getProperties( | |
356 "stub_cellular1_guid", | |
357 callbackPass(function(result) { | |
358 assertEq({ "Cellular": { | |
359 "ActivationState": "NotActivated", | |
360 "AllowRoaming": false, | |
361 "AutoConnect": true, | |
362 "Carrier": "Cellular1_Carrier", | |
363 "HomeProvider": { | |
364 "Country": "us", | |
365 "Name": "Cellular1_Provider" | |
366 }, | |
367 "NetworkTechnology": "GSM", | |
368 "RoamingState": "Home" | |
369 }, | |
370 "ConnectionState": "NotConnected", | |
371 "GUID": "stub_cellular1_guid", | |
372 "Name": "cellular1", | |
373 "Type": "Cellular" | |
374 }, result); | |
375 })); | |
376 }, | |
377 function getManagedProperties() { | |
378 chrome.networkingPrivate.getManagedProperties( | |
379 "stub_wifi2", | |
380 callbackPass(function(result) { | |
381 assertEq({ | |
382 "Connectable": true, | |
383 "ConnectionState": "NotConnected", | |
384 "GUID": "stub_wifi2", | |
385 "Name": { | |
386 "Active": "wifi2_PSK", | |
387 "Effective": "UserPolicy", | |
388 "UserPolicy": "My WiFi Network" | |
389 }, | |
390 "Source": "UserPolicy", | |
391 "Type": { | |
392 "Active": "WiFi", | |
393 "Effective": "UserPolicy", | |
394 "UserPolicy": "WiFi" | |
395 }, | |
396 "WiFi": { | |
397 "AutoConnect": { | |
398 "Active": false, | |
399 "UserEditable": true | |
400 }, | |
401 "HexSSID": { | |
402 "Active": "77696669325F50534B", // "wifi2_PSK" | |
403 "Effective": "UserPolicy", | |
404 "UserPolicy": "77696669325F50534B" | |
405 }, | |
406 "Frequency" : 5000, | |
407 "FrequencyList" : [2400, 5000], | |
408 "Passphrase": { | |
409 "Effective": "UserSetting", | |
410 "UserEditable": true, | |
411 "UserSetting": "FAKE_CREDENTIAL_VPaJDV9x" | |
412 }, | |
413 "SSID": { | |
414 "Active": "wifi2_PSK", | |
415 "Effective": "UserPolicy", | |
416 }, | |
417 "Security": { | |
418 "Active": "WPA-PSK", | |
419 "Effective": "UserPolicy", | |
420 "UserPolicy": "WPA-PSK" | |
421 }, | |
422 "SignalStrength": 80, | |
423 } | |
424 }, result); | |
425 })); | |
426 }, | |
427 function setWiFiProperties() { | |
428 var done = chrome.test.callbackAdded(); | |
429 var network_guid = "stub_wifi1_guid"; | |
430 chrome.networkingPrivate.getProperties( | |
431 network_guid, | |
432 callbackPass(function(result) { | |
433 assertEq(network_guid, result.GUID); | |
434 var new_properties = { | |
435 Priority: 1, | |
436 WiFi: { | |
437 AutoConnect: true | |
438 }, | |
439 IPAddressConfigType: 'Static', | |
440 StaticIPConfig: { | |
441 IPAddress: '1.2.3.4' | |
442 } | |
443 }; | |
444 chrome.networkingPrivate.setProperties( | |
445 network_guid, | |
446 new_properties, | |
447 callbackPass(function() { | |
448 chrome.networkingPrivate.getProperties( | |
449 network_guid, | |
450 callbackPass(function(result) { | |
451 // Ensure that the GUID doesn't change. | |
452 assertEq(network_guid, result.GUID); | |
453 // Ensure that the properties were set. | |
454 assertEq(1, result['Priority']); | |
455 assertTrue('WiFi' in result); | |
456 assertTrue('AutoConnect' in result['WiFi']); | |
457 assertEq(true, result['WiFi']['AutoConnect']); | |
458 assertTrue('StaticIPConfig' in result); | |
459 assertEq('1.2.3.4', | |
460 result['StaticIPConfig']['IPAddress']); | |
461 done(); | |
462 })); | |
463 })); | |
464 })); | |
465 }, | |
466 function setVPNProperties() { | |
467 var done = chrome.test.callbackAdded(); | |
468 var network_guid = "stub_vpn1_guid"; | |
469 chrome.networkingPrivate.getProperties( | |
470 network_guid, | |
471 callbackPass(function(result) { | |
472 assertEq(network_guid, result.GUID); | |
473 var new_properties = { | |
474 Priority: 1, | |
475 VPN: { | |
476 Host: 'vpn.host1' | |
477 } | |
478 }; | |
479 chrome.networkingPrivate.setProperties( | |
480 network_guid, | |
481 new_properties, | |
482 callbackPass(function() { | |
483 chrome.networkingPrivate.getProperties( | |
484 network_guid, | |
485 callbackPass(function(result) { | |
486 // Ensure that the properties were set. | |
487 assertEq(1, result['Priority']); | |
488 assertTrue('VPN' in result); | |
489 assertTrue('Host' in result['VPN']); | |
490 assertEq('vpn.host1', result['VPN']['Host']); | |
491 // Ensure that the GUID doesn't change. | |
492 assertEq(network_guid, result.GUID); | |
493 done(); | |
494 })); | |
495 })); | |
496 })); | |
497 }, | |
498 function getState() { | |
499 chrome.networkingPrivate.getState( | |
500 "stub_wifi2_guid", | |
501 callbackPass(function(result) { | |
502 assertEq({ | |
503 "Connectable": true, | |
504 "ConnectionState": "NotConnected", | |
505 "GUID": "stub_wifi2_guid", | |
506 "Name": "wifi2_PSK", | |
507 "Source": "User", | |
508 "Type": "WiFi", | |
509 "WiFi": { | |
510 "Security": "WPA-PSK", | |
511 "SignalStrength": 80 | |
512 } | |
513 }, result); | |
514 })); | |
515 }, | |
516 function getStateNonExistent() { | |
517 chrome.networkingPrivate.getState( | |
518 'non_existent', | |
519 callbackFail('Error.InvalidNetworkGuid')); | |
520 }, | |
521 function onNetworksChangedEventConnect() { | |
522 var network = "stub_wifi2_guid"; | |
523 var done = chrome.test.callbackAdded(); | |
524 var expectedStates = ["Connected"]; | |
525 var listener = | |
526 new privateHelpers.watchForStateChanges(network, expectedStates, done); | |
527 chrome.networkingPrivate.startConnect(network, callbackPass()); | |
528 }, | |
529 function onNetworksChangedEventDisconnect() { | |
530 var network = "stub_wifi1_guid"; | |
531 var done = chrome.test.callbackAdded(); | |
532 var expectedStates = ["NotConnected"]; | |
533 var listener = | |
534 new privateHelpers.watchForStateChanges(network, expectedStates, done); | |
535 chrome.networkingPrivate.startDisconnect(network, callbackPass()); | |
536 }, | |
537 function onNetworkListChangedEvent() { | |
538 // Connecting to wifi2 should set wifi1 to offline. Connected or Connecting | |
539 // networks should be listed first, sorted by type. | |
540 var expected = ["stub_ethernet_guid", | |
541 "stub_wifi2_guid", | |
542 "stub_wimax_guid", | |
543 "stub_vpn1_guid", | |
544 "stub_wifi1_guid", | |
545 "stub_vpn2_guid"]; | |
546 var done = chrome.test.callbackAdded(); | |
547 var listener = new privateHelpers.listListener(expected, done); | |
548 chrome.networkingPrivate.onNetworkListChanged.addListener( | |
549 listener.listenForChanges); | |
550 var network = "stub_wifi2_guid"; | |
551 chrome.networkingPrivate.startConnect(network, callbackPass()); | |
552 }, | |
553 function verifyDestination() { | |
554 chrome.networkingPrivate.verifyDestination( | |
555 verificationProperties, | |
556 callbackPass(function(isValid) { | |
557 assertTrue(isValid); | |
558 })); | |
559 }, | |
560 function verifyAndEncryptCredentials() { | |
561 var network_guid = "stub_wifi2_guid"; | |
562 chrome.networkingPrivate.verifyAndEncryptCredentials( | |
563 verificationProperties, | |
564 network_guid, | |
565 callbackPass(function(result) { | |
566 assertEq("encrypted_credentials", result); | |
567 })); | |
568 }, | |
569 function verifyAndEncryptData() { | |
570 chrome.networkingPrivate.verifyAndEncryptData( | |
571 verificationProperties, | |
572 "data", | |
573 callbackPass(function(result) { | |
574 assertEq("encrypted_data", result); | |
575 })); | |
576 }, | |
577 function setWifiTDLSEnabledState() { | |
578 chrome.networkingPrivate.setWifiTDLSEnabledState( | |
579 "aa:bb:cc:dd:ee:ff", | |
580 true, | |
581 callbackPass(function(result) { | |
582 assertEq("Connected", result); | |
583 })); | |
584 }, | |
585 function getWifiTDLSStatus() { | |
586 chrome.networkingPrivate.getWifiTDLSStatus( | |
587 "aa:bb:cc:dd:ee:ff", | |
588 callbackPass(function(result) { | |
589 assertEq("Connected", result); | |
590 })); | |
591 }, | |
592 function getCaptivePortalStatus() { | |
593 var networks = [['stub_ethernet_guid', 'Online'], | |
594 ['stub_wifi1_guid', 'Offline'], | |
595 ['stub_wifi2_guid', 'Portal'], | |
596 ['stub_cellular1_guid', 'ProxyAuthRequired'], | |
597 ['stub_vpn1_guid', 'Unknown']]; | |
598 networks.forEach(function(network) { | |
599 var guid = network[0]; | |
600 var expectedStatus = network[1]; | |
601 chrome.networkingPrivate.getCaptivePortalStatus( | |
602 guid, | |
603 callbackPass(function(status) { | |
604 assertEq(expectedStatus, status); | |
605 })); | |
606 }); | |
607 }, | |
608 function captivePortalNotification() { | |
609 var done = chrome.test.callbackAdded(); | |
610 var listener = | |
611 new privateHelpers.watchForCaptivePortalState( | |
612 'wifi_guid', 'Online', done); | |
613 chrome.test.sendMessage('notifyPortalDetectorObservers'); | |
614 }, | |
615 ]; | |
616 | |
617 var testToRun = window.location.search.substring(1); | |
618 chrome.test.runTests(availableTests.filter(function(op) { | |
619 return op.name == testToRun; | |
620 })); | |
OLD | NEW |