Revert "Only store leading 13 bits of password hash."
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / networking / test.js
blob6bd2292cfebdc8a41315cc2acadf71cfb52efd6d
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.
5 // Note: the expectations in this test are shared by both the Chrome OS and
6 // Win/Mac (ServiceClient) implementations. TODO(stevenjb): Set up a way for
7 // the test code to specify the correct expectations.
9 var callbackPass = chrome.test.callbackPass;
10 var callbackFail = chrome.test.callbackFail;
11 var assertTrue = chrome.test.assertTrue;
12 var assertFalse = chrome.test.assertFalse;
13 var assertEq = chrome.test.assertEq;
15 // Test properties for the verification API.
16 var verificationProperties = {
17 "certificate": "certificate",
18 "intermediateCertificates": ["ica1", "ica2", "ica3"],
19 "publicKey": "cHVibGljX2tleQ==", // Base64("public_key")
20 "nonce": "nonce",
21 "signedData": "c2lnbmVkX2RhdGE=", // Base64("signed_data")
22 "deviceSerial": "device_serial",
23 "deviceSsid": "Device 0123",
24 "deviceBssid": "00:01:02:03:04:05"
27 var privateHelpers = {
28 // Watches for the states |expectedStates| in reverse order. If all states
29 // were observed in the right order, succeeds and calls |done|. If any
30 // unexpected state is observed, fails.
31 watchForStateChanges: function(network, expectedStates, done) {
32 var self = this;
33 var collectProperties = function(properties) {
34 var finishTest = function() {
35 chrome.networkingPrivate.onNetworksChanged.removeListener(
36 self.onNetworkChange);
37 done();
39 if (expectedStates.length > 0) {
40 var expectedState = expectedStates.pop();
41 assertEq(expectedState, properties.ConnectionState);
42 if (expectedStates.length == 0)
43 finishTest();
46 this.onNetworkChange = function(changes) {
47 assertEq([network], changes);
48 chrome.networkingPrivate.getProperties(
49 network,
50 callbackPass(collectProperties));
52 chrome.networkingPrivate.onNetworksChanged.addListener(
53 this.onNetworkChange);
55 listListener: function(expected, done) {
56 var self = this;
57 this.listenForChanges = function(list) {
58 assertEq(expected, list);
59 chrome.networkingPrivate.onNetworkListChanged.removeListener(
60 self.listenForChanges);
61 done();
64 watchForCaptivePortalState: function(expectedGuid,
65 expectedState,
66 done) {
67 var self = this;
68 this.onPortalDetectionCompleted = function(guid, state) {
69 assertEq(expectedGuid, guid);
70 assertEq(expectedState, state);
71 chrome.networkingPrivate.onPortalDetectionCompleted.removeListener(
72 self.onPortalDetectionCompleted);
73 done();
75 chrome.networkingPrivate.onPortalDetectionCompleted.addListener(
76 self.onPortalDetectionCompleted);
80 var availableTests = [
81 function startConnect() {
82 chrome.networkingPrivate.startConnect("stub_wifi2_guid", callbackPass());
84 function startDisconnect() {
85 // Must connect to a network before we can disconnect from it.
86 chrome.networkingPrivate.startConnect("stub_wifi2_guid", callbackPass(
87 function() {
88 chrome.networkingPrivate.startDisconnect("stub_wifi2_guid",
89 callbackPass());
90 }));
92 function startConnectNonexistent() {
93 chrome.networkingPrivate.startConnect(
94 "nonexistent_path",
95 callbackFail("Error.InvalidNetworkGuid"));
97 function startDisconnectNonexistent() {
98 chrome.networkingPrivate.startDisconnect(
99 "nonexistent_path",
100 callbackFail("Error.InvalidNetworkGuid"));
102 function startGetPropertiesNonexistent() {
103 chrome.networkingPrivate.getProperties(
104 "nonexistent_path",
105 callbackFail("Error.InvalidNetworkGuid"));
107 function createNetwork() {
108 chrome.networkingPrivate.createNetwork(
109 false, // shared
110 { "Type": "WiFi",
111 "GUID": "ignored_guid",
112 "WiFi": {
113 "SSID": "wifi_created",
114 "Security": "WEP-PSK"
117 callbackPass(function(guid) {
118 assertFalse(guid == "");
119 assertFalse(guid == "ignored_guid");
120 chrome.networkingPrivate.getProperties(
121 guid,
122 callbackPass(function(properties) {
123 assertEq("WiFi", properties.Type);
124 assertEq(guid, properties.GUID);
125 assertEq("wifi_created", properties.WiFi.SSID);
126 assertEq("WEP-PSK", properties.WiFi.Security);
127 }));
128 }));
130 function getNetworks() {
131 // Test 'type' and 'configured'.
132 chrome.networkingPrivate.getNetworks(
133 { "networkType": "WiFi", "configured": true },
134 callbackPass(function(result) {
135 assertEq([{
136 "Connectable": true,
137 "ConnectionState": "Connected",
138 "GUID": "stub_wifi1_guid",
139 "Name": "wifi1",
140 "Type": "WiFi",
141 "WiFi": {
142 "Security": "WEP-PSK",
143 "SignalStrength": 40
145 }, {
146 "GUID": "stub_wifi2_guid",
147 "Name": "wifi2_PSK",
148 "Type": "WiFi",
149 "WiFi": {
150 "Security": "WPA-PSK",
152 }], result);
154 // Test 'visible' (and 'configured').
155 chrome.networkingPrivate.getNetworks(
156 { "networkType": "WiFi", "visible": true, "configured": true },
157 callbackPass(function(result) {
158 assertEq([{
159 "Connectable": true,
160 "ConnectionState": "Connected",
161 "GUID": "stub_wifi1_guid",
162 "Name": "wifi1",
163 "Type": "WiFi",
164 "WiFi": {
165 "Security": "WEP-PSK",
166 "SignalStrength": 40
168 }], result);
170 // Test 'limit'.
171 chrome.networkingPrivate.getNetworks(
172 { "networkType": "All", "limit": 1 },
173 callbackPass(function(result) {
174 assertEq([{
175 "ConnectionState": "Connected",
176 "Ethernet": {
177 "Authentication": "None"
179 "GUID": "stub_ethernet_guid",
180 "Name": "eth0",
181 "Type": "Ethernet"
182 }], result);
183 }));
184 }));
185 }));
187 function getVisibleNetworks() {
188 chrome.networkingPrivate.getVisibleNetworks(
189 "All",
190 callbackPass(function(result) {
191 assertEq([{
192 "ConnectionState": "Connected",
193 "Ethernet": {
194 "Authentication": "None"
196 "GUID": "stub_ethernet_guid",
197 "Name": "eth0",
198 "Type": "Ethernet"
201 "Connectable": true,
202 "ConnectionState": "Connected",
203 "GUID": "stub_wifi1_guid",
204 "Name": "wifi1",
205 "Type": "WiFi",
206 "WiFi": {
207 "Security": "WEP-PSK",
208 "SignalStrength": 40
212 "Connectable": true,
213 "ConnectionState": "Connected",
214 "GUID": "stub_wimax_guid",
215 "Name": "wimax",
216 "Type": "WiMAX",
217 "WiMAX": {
218 "SignalStrength": 40
222 "ConnectionState": "Connected",
223 "GUID": "stub_vpn1_guid",
224 "Name": "vpn1",
225 "Type": "VPN"
228 "Connectable": true,
229 "ConnectionState": "NotConnected",
230 "GUID": "stub_wifi2_guid",
231 "Name": "wifi2_PSK",
232 "Type": "WiFi",
233 "WiFi": {
234 "Security": "WPA-PSK",
235 "SignalStrength": 80
237 }], result);
238 }));
240 function getVisibleNetworksWifi() {
241 chrome.networkingPrivate.getVisibleNetworks(
242 "WiFi",
243 callbackPass(function(result) {
244 assertEq([{
245 "Connectable": true,
246 "ConnectionState": "Connected",
247 "GUID": "stub_wifi1_guid",
248 "Name": "wifi1",
249 "Type": "WiFi",
250 "WiFi": {
251 "Security": "WEP-PSK",
252 "SignalStrength": 40
256 "Connectable": true,
257 "ConnectionState": "NotConnected",
258 "GUID": "stub_wifi2_guid",
259 "Name": "wifi2_PSK",
260 "Type": "WiFi",
261 "WiFi": {
262 "Security": "WPA-PSK",
263 "SignalStrength": 80
266 ], result);
267 }));
269 function requestNetworkScan() {
270 // Connected or Connecting networks should be listed first, sorted by type.
271 var expected = ["stub_ethernet_guid",
272 "stub_wifi1_guid",
273 "stub_wimax_guid",
274 "stub_vpn1_guid",
275 "stub_wifi2_guid"];
276 var done = chrome.test.callbackAdded();
277 var listener = new privateHelpers.listListener(expected, done);
278 chrome.networkingPrivate.onNetworkListChanged.addListener(
279 listener.listenForChanges);
280 chrome.networkingPrivate.requestNetworkScan();
282 function getProperties() {
283 chrome.networkingPrivate.getProperties(
284 "stub_wifi1_guid",
285 callbackPass(function(result) {
286 assertEq({ "Connectable": true,
287 "ConnectionState": "Connected",
288 "GUID": "stub_wifi1_guid",
289 "IPAddressConfigType": "Static",
290 "IPConfigs": [{
291 "Gateway": "0.0.0.1",
292 "IPAddress": "0.0.0.0",
293 "RoutingPrefix": 0,
294 "Type": "IPv4"
296 "MacAddress": "00:11:22:AA:BB:CC",
297 "Name": "wifi1",
298 "StaticIPConfig": {
299 "IPAddress": "1.2.3.4",
300 "Type": "IPv4"
302 "Type": "WiFi",
303 "WiFi": {
304 "HexSSID": "7769666931", // "wifi1"
305 "Frequency": 2400,
306 "FrequencyList": [2400],
307 "SSID": "wifi1",
308 "Security": "WEP-PSK",
309 "SignalStrength": 40
311 }, result);
312 }));
314 function getPropertiesCellular() {
315 chrome.networkingPrivate.getProperties(
316 "stub_cellular1_guid",
317 callbackPass(function(result) {
318 assertEq({ "Cellular": {
319 "ActivationState": "NotActivated",
320 "AllowRoaming": false,
321 "AutoConnect": true,
322 "Carrier": "Cellular1_Carrier",
323 "HomeProvider": {
324 "country": "us",
325 "name": "Cellular1_Provider"
327 "NetworkTechnology": "GSM",
328 "RoamingState": "Home"
330 "ConnectionState": "NotConnected",
331 "GUID": "stub_cellular1_guid",
332 "Name": "cellular1",
333 "Type": "Cellular"
334 }, result);
335 }));
337 function getManagedProperties() {
338 chrome.networkingPrivate.getManagedProperties(
339 "stub_wifi2",
340 callbackPass(function(result) {
341 assertEq({
342 "Connectable": true,
343 "ConnectionState": "NotConnected",
344 "GUID": "stub_wifi2",
345 "Name": {
346 "Active": "wifi2_PSK",
347 "Effective": "UserPolicy",
348 "UserPolicy": "My WiFi Network"
350 "Source": "UserPolicy",
351 "Type": {
352 "Active": "WiFi",
353 "Effective": "UserPolicy",
354 "UserPolicy": "WiFi"
356 "WiFi": {
357 "AutoConnect": {
358 "Active": false,
359 "UserEditable": true
361 "HexSSID": {
362 "Active": "77696669325F50534B", // "wifi2_PSK"
363 "Effective": "UserPolicy",
364 "UserPolicy": "77696669325F50534B"
366 "Frequency" : 5000,
367 "FrequencyList" : [2400, 5000],
368 "Passphrase": {
369 "Effective": "UserSetting",
370 "UserEditable": true,
371 "UserSetting": "FAKE_CREDENTIAL_VPaJDV9x"
373 "SSID": {
374 "Active": "wifi2_PSK",
375 "Effective": "UserPolicy",
377 "Security": {
378 "Active": "WPA-PSK",
379 "Effective": "UserPolicy",
380 "UserPolicy": "WPA-PSK"
382 "SignalStrength": 80,
384 }, result);
385 }));
387 function setWiFiProperties() {
388 var done = chrome.test.callbackAdded();
389 var network_guid = "stub_wifi1_guid";
390 chrome.networkingPrivate.getProperties(
391 network_guid,
392 callbackPass(function(result) {
393 assertEq(network_guid, result.GUID);
394 var new_properties = {
395 Priority: 1,
396 WiFi: {
397 AutoConnect: true
399 IPAddressConfigType: 'Static',
400 StaticIPConfig: {
401 IPAddress: '1.2.3.4'
404 chrome.networkingPrivate.setProperties(
405 network_guid,
406 new_properties,
407 callbackPass(function() {
408 chrome.networkingPrivate.getProperties(
409 network_guid,
410 callbackPass(function(result) {
411 // Ensure that the GUID doesn't change.
412 assertEq(network_guid, result.GUID);
413 // Ensure that the properties were set.
414 assertEq(1, result['Priority']);
415 assertTrue('WiFi' in result);
416 assertTrue('AutoConnect' in result['WiFi']);
417 assertEq(true, result['WiFi']['AutoConnect']);
418 assertTrue('StaticIPConfig' in result);
419 assertEq('1.2.3.4',
420 result['StaticIPConfig']['IPAddress']);
421 done();
422 }));
423 }));
424 }));
426 function setVPNProperties() {
427 var done = chrome.test.callbackAdded();
428 var network_guid = "stub_vpn1_guid";
429 chrome.networkingPrivate.getProperties(
430 network_guid,
431 callbackPass(function(result) {
432 assertEq(network_guid, result.GUID);
433 var new_properties = {
434 Priority: 1,
435 VPN: {
436 Host: 'vpn.host1'
439 chrome.networkingPrivate.setProperties(
440 network_guid,
441 new_properties,
442 callbackPass(function() {
443 chrome.networkingPrivate.getProperties(
444 network_guid,
445 callbackPass(function(result) {
446 // Ensure that the properties were set.
447 assertEq(1, result['Priority']);
448 assertTrue('VPN' in result);
449 assertTrue('Host' in result['VPN']);
450 assertEq('vpn.host1', result['VPN']['Host']);
451 // Ensure that the GUID doesn't change.
452 assertEq(network_guid, result.GUID);
453 done();
454 }));
455 }));
456 }));
458 function getState() {
459 chrome.networkingPrivate.getState(
460 "stub_wifi2_guid",
461 callbackPass(function(result) {
462 assertEq({
463 "Connectable": true,
464 "ConnectionState": "NotConnected",
465 "GUID": "stub_wifi2_guid",
466 "Name": "wifi2_PSK",
467 "Type": "WiFi",
468 "WiFi": {
469 "Security": "WPA-PSK",
470 "SignalStrength": 80
472 }, result);
473 }));
475 function getStateNonExistent() {
476 chrome.networkingPrivate.getState(
477 'non_existent',
478 callbackFail('Error.InvalidNetworkGuid'));
480 function onNetworksChangedEventConnect() {
481 var network = "stub_wifi2_guid";
482 var done = chrome.test.callbackAdded();
483 var expectedStates = ["Connected"];
484 var listener =
485 new privateHelpers.watchForStateChanges(network, expectedStates, done);
486 chrome.networkingPrivate.startConnect(network, callbackPass());
488 function onNetworksChangedEventDisconnect() {
489 var network = "stub_wifi1_guid";
490 var done = chrome.test.callbackAdded();
491 var expectedStates = ["NotConnected"];
492 var listener =
493 new privateHelpers.watchForStateChanges(network, expectedStates, done);
494 chrome.networkingPrivate.startDisconnect(network, callbackPass());
496 function onNetworkListChangedEvent() {
497 // Connecting to wifi2 should set wifi1 to offline. Connected or Connecting
498 // networks should be listed first, sorted by type.
499 var expected = ["stub_ethernet_guid",
500 "stub_wifi2_guid",
501 "stub_wimax_guid",
502 "stub_vpn1_guid",
503 "stub_wifi1_guid"];
504 var done = chrome.test.callbackAdded();
505 var listener = new privateHelpers.listListener(expected, done);
506 chrome.networkingPrivate.onNetworkListChanged.addListener(
507 listener.listenForChanges);
508 var network = "stub_wifi2_guid";
509 chrome.networkingPrivate.startConnect(network, callbackPass());
511 function verifyDestination() {
512 chrome.networkingPrivate.verifyDestination(
513 verificationProperties,
514 callbackPass(function(isValid) {
515 assertTrue(isValid);
516 }));
518 function verifyAndEncryptCredentials() {
519 var network_guid = "stub_wifi2_guid";
520 chrome.networkingPrivate.verifyAndEncryptCredentials(
521 verificationProperties,
522 network_guid,
523 callbackPass(function(result) {
524 assertEq("encrypted_credentials", result);
525 }));
527 function verifyAndEncryptData() {
528 chrome.networkingPrivate.verifyAndEncryptData(
529 verificationProperties,
530 "data",
531 callbackPass(function(result) {
532 assertEq("encrypted_data", result);
533 }));
535 function setWifiTDLSEnabledState() {
536 chrome.networkingPrivate.setWifiTDLSEnabledState(
537 "aa:bb:cc:dd:ee:ff",
538 true,
539 callbackPass(function(result) {
540 assertEq("Connected", result);
541 }));
543 function getWifiTDLSStatus() {
544 chrome.networkingPrivate.getWifiTDLSStatus(
545 "aa:bb:cc:dd:ee:ff",
546 callbackPass(function(result) {
547 assertEq("Connected", result);
548 }));
550 function getCaptivePortalStatus() {
551 var networks = [['stub_ethernet_guid', 'Online'],
552 ['stub_wifi1_guid', 'Offline'],
553 ['stub_wifi2_guid', 'Portal'],
554 ['stub_cellular1_guid', 'ProxyAuthRequired'],
555 ['stub_vpn1_guid', 'Unknown']];
556 networks.forEach(function(network) {
557 var guid = network[0];
558 var expectedStatus = network[1];
559 chrome.networkingPrivate.getCaptivePortalStatus(
560 guid,
561 callbackPass(function(status) {
562 assertEq(expectedStatus, status);
563 }));
566 function captivePortalNotification() {
567 var done = chrome.test.callbackAdded();
568 var listener =
569 new privateHelpers.watchForCaptivePortalState(
570 'wifi_guid', 'Online', done);
571 chrome.test.sendMessage('notifyPortalDetectorObservers');
575 var testToRun = window.location.search.substring(1);
576 chrome.test.runTests(availableTests.filter(function(op) {
577 return op.name == testToRun;
578 }));