Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 // The expectations in this test for the Chrome OS implementation. See | 5 // The expectations in this test for the Chrome OS implementation. See |
| 6 // networking_private_chromeos_apitest.cc for more info. | 6 // networking_private_chromeos_apitest.cc for more info. |
| 7 | 7 |
| 8 var callbackPass = chrome.test.callbackPass; | 8 var callbackPass = chrome.test.callbackPass; |
| 9 var callbackFail = chrome.test.callbackFail; | 9 var callbackFail = chrome.test.callbackFail; |
| 10 var assertTrue = chrome.test.assertTrue; | 10 var assertTrue = chrome.test.assertTrue; |
| 11 var assertFalse = chrome.test.assertFalse; | 11 var assertFalse = chrome.test.assertFalse; |
| 12 var assertEq = chrome.test.assertEq; | 12 var assertEq = chrome.test.assertEq; |
| 13 | 13 |
| 14 var ActivationStateType = chrome.networkingPrivate.ActivationStateType; | 14 var NETWORKING_API = null; |
| 15 var ConnectionStateType = chrome.networkingPrivate.ConnectionStateType; | |
| 16 var NetworkType = chrome.networkingPrivate.NetworkType; | |
| 17 | 15 |
| 18 var kCellularGuid = 'stub_cellular1_guid'; | 16 var kCellularGuid = 'stub_cellular1_guid'; |
| 19 var kDefaultPin = '1111'; | 17 var kDefaultPin = '1111'; |
| 20 var kDefaultPuk = '12345678'; | 18 var kDefaultPuk = '12345678'; |
| 21 | 19 |
| 22 // Test properties for the verification API. | 20 // Test properties for the verification API. |
| 23 var verificationProperties = { | 21 var verificationProperties = { |
| 24 certificate: 'certificate', | 22 certificate: 'certificate', |
| 25 intermediateCertificates: ['ica1', 'ica2', 'ica3'], | 23 intermediateCertificates: ['ica1', 'ica2', 'ica3'], |
| 26 publicKey: 'cHVibGljX2tleQ==', // Base64('public_key') | 24 publicKey: 'cHVibGljX2tleQ==', // Base64('public_key') |
| 27 nonce: 'nonce', | 25 nonce: 'nonce', |
| 28 signedData: 'c2lnbmVkX2RhdGE=', // Base64('signed_data') | 26 signedData: 'c2lnbmVkX2RhdGE=', // Base64('signed_data') |
| 29 deviceSerial: 'device_serial', | 27 deviceSerial: 'device_serial', |
| 30 deviceSsid: 'Device 0123', | 28 deviceSsid: 'Device 0123', |
| 31 deviceBssid: '00:01:02:03:04:05' | 29 deviceBssid: '00:01:02:03:04:05' |
| 32 }; | 30 }; |
| 33 | 31 |
| 34 var privateHelpers = { | 32 var privateHelpers = { |
| 35 // Watches for the states |expectedStates| in reverse order. If all states | 33 // Watches for the states |expectedStates| in reverse order. If all states |
| 36 // were observed in the right order, succeeds and calls |done|. If any | 34 // were observed in the right order, succeeds and calls |done|. If any |
| 37 // unexpected state is observed, fails. | 35 // unexpected state is observed, fails. |
| 38 watchForStateChanges: function(network, expectedStates, done) { | 36 watchForStateChanges: function(network, expectedStates, done) { |
| 39 var self = this; | 37 var self = this; |
| 40 var collectProperties = function(properties) { | 38 var collectProperties = function(properties) { |
| 41 var finishTest = function() { | 39 var finishTest = function() { |
| 42 chrome.networkingPrivate.onNetworksChanged.removeListener( | 40 NETWORKING_API.onNetworksChanged.removeListener( |
| 43 self.onNetworkChange); | 41 self.onNetworkChange); |
| 44 done(); | 42 done(); |
| 45 }; | 43 }; |
| 46 if (expectedStates.length > 0) { | 44 if (expectedStates.length > 0) { |
| 47 var expectedState = expectedStates.pop(); | 45 var expectedState = expectedStates.pop(); |
| 48 assertEq(expectedState, properties.ConnectionState); | 46 assertEq(expectedState, properties.ConnectionState); |
| 49 if (expectedStates.length == 0) | 47 if (expectedStates.length == 0) |
| 50 finishTest(); | 48 finishTest(); |
| 51 } | 49 } |
| 52 }; | 50 }; |
| 53 this.onNetworkChange = function(changes) { | 51 this.onNetworkChange = function(changes) { |
| 54 assertEq([network], changes); | 52 assertEq([network], changes); |
| 55 chrome.networkingPrivate.getProperties( | 53 NETWORKING_API.getProperties( |
| 56 network, | 54 network, |
| 57 callbackPass(collectProperties)); | 55 callbackPass(collectProperties)); |
| 58 }; | 56 }; |
| 59 chrome.networkingPrivate.onNetworksChanged.addListener( | 57 NETWORKING_API.onNetworksChanged.addListener( |
| 60 this.onNetworkChange); | 58 this.onNetworkChange); |
| 61 }, | 59 }, |
| 62 listListener: function(expected, done) { | 60 listListener: function(expected, done) { |
| 63 var self = this; | 61 var self = this; |
| 64 this.listenForChanges = function(list) { | 62 this.listenForChanges = function(list) { |
| 65 assertEq(expected, list); | 63 assertEq(expected, list); |
| 66 chrome.networkingPrivate.onNetworkListChanged.removeListener( | 64 NETWORKING_API.onNetworkListChanged.removeListener( |
| 67 self.listenForChanges); | 65 self.listenForChanges); |
| 68 done(); | 66 done(); |
| 69 }; | 67 }; |
| 70 }, | 68 }, |
| 71 watchForCaptivePortalState: function(expectedGuid, | 69 watchForCaptivePortalState: function(expectedGuid, |
| 72 expectedState, | 70 expectedState, |
| 73 done) { | 71 done) { |
| 74 var self = this; | 72 var self = this; |
| 75 this.onPortalDetectionCompleted = function(guid, state) { | 73 this.onPortalDetectionCompleted = function(guid, state) { |
| 76 assertEq(expectedGuid, guid); | 74 assertEq(expectedGuid, guid); |
| 77 assertEq(expectedState, state); | 75 assertEq(expectedState, state); |
| 78 chrome.networkingPrivate.onPortalDetectionCompleted.removeListener( | 76 NETWORKING_API.onPortalDetectionCompleted.removeListener( |
| 79 self.onPortalDetectionCompleted); | 77 self.onPortalDetectionCompleted); |
| 80 done(); | 78 done(); |
| 81 }; | 79 }; |
| 82 chrome.networkingPrivate.onPortalDetectionCompleted.addListener( | 80 NETWORKING_API.onPortalDetectionCompleted.addListener( |
| 83 self.onPortalDetectionCompleted); | 81 self.onPortalDetectionCompleted); |
| 84 } | 82 } |
| 85 }; | 83 }; |
| 86 | 84 |
| 87 var kFailure = 'Failure'; | 85 var kFailure = 'Failure'; |
| 88 | 86 |
| 89 function networkCallbackPass() { | 87 function networkCallbackPass() { |
| 90 var callbackCompleted = chrome.test.callbackAdded(); | 88 var callbackCompleted = chrome.test.callbackAdded(); |
| 91 return function(result) { | 89 return function(result) { |
| 92 chrome.test.assertNoLastError(); | 90 chrome.test.assertNoLastError(); |
| 93 if (result === false || result === kFailure) | 91 if (result === false || result === kFailure) |
| 94 chrome.test.fail('Failed: ' + result); | 92 chrome.test.fail('Failed: ' + result); |
| 95 callbackCompleted(); | 93 callbackCompleted(); |
| 96 }; | 94 }; |
| 97 } | 95 } |
| 98 | 96 |
| 99 var availableTests = [ | 97 var availableTests = [ |
| 100 function startConnect() { | 98 function startConnect() { |
| 101 chrome.networkingPrivate.startConnect('stub_wifi2_guid', | 99 NETWORKING_API.startConnect('stub_wifi2_guid', |
| 102 networkCallbackPass()); | 100 networkCallbackPass()); |
| 103 }, | 101 }, |
| 104 function startDisconnect() { | 102 function startDisconnect() { |
| 105 // Must connect to a network before we can disconnect from it. | 103 // Must connect to a network before we can disconnect from it. |
| 106 chrome.networkingPrivate.startConnect( | 104 NETWORKING_API.startConnect( |
| 107 'stub_wifi2_guid', | 105 'stub_wifi2_guid', |
| 108 callbackPass(function() { | 106 callbackPass(function() { |
| 109 chrome.networkingPrivate.startDisconnect( | 107 NETWORKING_API.startDisconnect( |
| 110 'stub_wifi2_guid', networkCallbackPass()); | 108 'stub_wifi2_guid', networkCallbackPass()); |
| 111 })); | 109 })); |
| 112 }, | 110 }, |
| 113 function startActivate() { | 111 function startActivate() { |
| 114 // Must connect to a network before we can activate it. | 112 // Must connect to a network before we can activate it. |
| 115 chrome.networkingPrivate.startConnect( | 113 NETWORKING_API.startConnect( |
| 116 kCellularGuid, callbackPass(function() { | 114 kCellularGuid, callbackPass(function() { |
| 117 chrome.networkingPrivate.startActivate( | 115 NETWORKING_API.startActivate( |
| 118 kCellularGuid, callbackPass(function() { | 116 kCellularGuid, callbackPass(function() { |
| 119 // For non Sprint networks, startActivate will delegate | 117 // For non Sprint networks, startActivate will delegate |
| 120 // showing the activation UI to the browser host and not | 118 // showing the activation UI to the browser host and not |
| 121 // immediately activate the network. | 119 // immediately activate the network. |
| 122 chrome.networkingPrivate.getState( | 120 NETWORKING_API.getState( |
| 123 kCellularGuid, callbackPass(function(state) { | 121 kCellularGuid, callbackPass(function(state) { |
| 124 assertEq(ActivationStateType.NOT_ACTIVATED, | 122 assertEq(NETWORKING_API.ActivationStateType.NOT_ACTIVATED, |
| 125 state.Cellular.ActivationState); | 123 state.Cellular.ActivationState); |
| 126 })); | 124 })); |
| 127 })); | 125 })); |
| 128 })); | 126 })); |
| 129 }, | 127 }, |
| 130 function startActivateSprint() { | 128 function startActivateSprint() { |
| 131 // Must connect to a network before we can activate it. | 129 // Must connect to a network before we can activate it. |
| 132 chrome.networkingPrivate.startConnect( | 130 NETWORKING_API.startConnect( |
| 133 kCellularGuid, callbackPass(function() { | 131 kCellularGuid, callbackPass(function() { |
| 134 chrome.networkingPrivate.startActivate( | 132 NETWORKING_API.startActivate( |
| 135 kCellularGuid, callbackPass(function() { | 133 kCellularGuid, callbackPass(function() { |
| 136 chrome.networkingPrivate.getState( | 134 NETWORKING_API.getState( |
| 137 kCellularGuid, callbackPass(function(state) { | 135 kCellularGuid, callbackPass(function(state) { |
| 138 assertEq(ActivationStateType.ACTIVATED, | 136 assertEq(NETWORKING_API.ActivationStateType.ACTIVATED, |
| 139 state.Cellular.ActivationState); | 137 state.Cellular.ActivationState); |
| 140 })); | 138 })); |
| 141 })); | 139 })); |
| 142 })); | 140 })); |
| 143 }, | 141 }, |
| 144 function startConnectNonexistent() { | 142 function startConnectNonexistent() { |
| 145 chrome.networkingPrivate.startConnect( | 143 NETWORKING_API.startConnect( |
| 146 'nonexistent_path', | 144 'nonexistent_path', |
| 147 callbackFail('Error.InvalidNetworkGuid')); | 145 callbackFail('Error.InvalidNetworkGuid')); |
| 148 }, | 146 }, |
| 149 function startDisconnectNonexistent() { | 147 function startDisconnectNonexistent() { |
| 150 chrome.networkingPrivate.startDisconnect( | 148 NETWORKING_API.startDisconnect( |
| 151 'nonexistent_path', | 149 'nonexistent_path', |
| 152 callbackFail('Error.InvalidNetworkGuid')); | 150 callbackFail('Error.InvalidNetworkGuid')); |
| 153 }, | 151 }, |
| 154 function startGetPropertiesNonexistent() { | 152 function startGetPropertiesNonexistent() { |
| 155 chrome.networkingPrivate.getProperties( | 153 NETWORKING_API.getProperties( |
| 156 'nonexistent_path', | 154 'nonexistent_path', |
| 157 callbackFail('Error.InvalidNetworkGuid')); | 155 callbackFail('Error.InvalidNetworkGuid')); |
| 158 }, | 156 }, |
| 159 function createNetwork() { | 157 function createNetwork() { |
| 160 chrome.networkingPrivate.createNetwork( | 158 NETWORKING_API.createNetwork( |
| 161 false, // shared | 159 false, // shared |
| 162 { Type: NetworkType.WI_FI, | 160 { Type: NETWORKING_API.NetworkType.WI_FI, |
| 163 GUID: 'ignored_guid', | 161 GUID: 'ignored_guid', |
| 164 WiFi: { | 162 WiFi: { |
| 165 SSID: 'wifi_created', | 163 SSID: 'wifi_created', |
| 166 Security: 'WEP-PSK' | 164 Security: 'WEP-PSK' |
| 167 } | 165 } |
| 168 }, | 166 }, |
| 169 callbackPass(function(guid) { | 167 callbackPass(function(guid) { |
| 170 assertFalse(guid == ''); | 168 assertFalse(guid == ''); |
| 171 assertFalse(guid == 'ignored_guid'); | 169 assertFalse(guid == 'ignored_guid'); |
| 172 chrome.networkingPrivate.getProperties( | 170 NETWORKING_API.getProperties( |
| 173 guid, callbackPass(function(properties) { | 171 guid, callbackPass(function(properties) { |
| 174 assertEq(NetworkType.WI_FI, properties.Type); | 172 assertEq(NETWORKING_API.NetworkType.WI_FI, properties.Type); |
| 175 assertEq(guid, properties.GUID); | 173 assertEq(guid, properties.GUID); |
| 176 assertEq('wifi_created', properties.WiFi.SSID); | 174 assertEq('wifi_created', properties.WiFi.SSID); |
| 177 assertEq('WEP-PSK', properties.WiFi.Security); | 175 assertEq('WEP-PSK', properties.WiFi.Security); |
| 178 })); | 176 })); |
| 179 })); | 177 })); |
| 180 }, | 178 }, |
| 181 function forgetNetwork() { | 179 function forgetNetwork() { |
| 182 var kNumNetworks = 2; | 180 var kNumNetworks = 2; |
| 183 var kTestNetworkGuid = 'stub_wifi1_guid'; | 181 var kTestNetworkGuid = 'stub_wifi1_guid'; |
| 184 function guidExists(networks, guid) { | 182 function guidExists(networks, guid) { |
| 185 for (var n of networks) { | 183 for (var n of networks) { |
| 186 if (n.GUID == kTestNetworkGuid) | 184 if (n.GUID == kTestNetworkGuid) |
| 187 return true; | 185 return true; |
| 188 } | 186 } |
| 189 return false; | 187 return false; |
| 190 } | 188 } |
| 191 var filter = { | 189 var filter = { |
| 192 networkType: NetworkType.WI_FI, | 190 networkType: NETWORKING_API.NetworkType.WI_FI, |
| 193 visible: true, | 191 visible: true, |
| 194 configured: true | 192 configured: true |
| 195 }; | 193 }; |
| 196 chrome.networkingPrivate.getNetworks( | 194 NETWORKING_API.getNetworks( |
| 197 filter, callbackPass(function(networks) { | 195 filter, callbackPass(function(networks) { |
| 198 assertEq(kNumNetworks, networks.length); | 196 assertEq(kNumNetworks, networks.length); |
| 199 assertTrue(guidExists(networks, kTestNetworkGuid)); | 197 assertTrue(guidExists(networks, kTestNetworkGuid)); |
| 200 chrome.networkingPrivate.forgetNetwork( | 198 NETWORKING_API.forgetNetwork( |
| 201 kTestNetworkGuid, callbackPass(function() { | 199 kTestNetworkGuid, callbackPass(function() { |
| 202 chrome.networkingPrivate.getNetworks( | 200 NETWORKING_API.getNetworks( |
| 203 filter, callbackPass(function(networks) { | 201 filter, callbackPass(function(networks) { |
| 204 assertEq(kNumNetworks - 1, networks.length); | 202 assertEq(kNumNetworks - 1, networks.length); |
| 205 assertFalse(guidExists(networks, kTestNetworkGuid)); | 203 assertFalse(guidExists(networks, kTestNetworkGuid)); |
| 206 })); | 204 })); |
| 207 })); | 205 })); |
| 208 })); | 206 })); |
| 209 }, | 207 }, |
| 210 function getNetworks() { | 208 function getNetworks() { |
| 211 // Test 'type' and 'configured'. | 209 // Test 'type' and 'configured'. |
| 212 var filter = { | 210 var filter = { |
| 213 networkType: NetworkType.WI_FI, | 211 networkType: NETWORKING_API.NetworkType.WI_FI, |
| 214 configured: true | 212 configured: true |
| 215 }; | 213 }; |
| 216 chrome.networkingPrivate.getNetworks( | 214 NETWORKING_API.getNetworks( |
| 217 filter, | 215 filter, |
| 218 callbackPass(function(result) { | 216 callbackPass(function(result) { |
| 219 assertEq([{ | 217 assertEq([{ |
| 220 Connectable: true, | 218 Connectable: true, |
| 221 ConnectionState: ConnectionStateType.CONNECTED, | 219 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 222 GUID: 'stub_wifi1_guid', | 220 GUID: 'stub_wifi1_guid', |
| 223 Name: 'wifi1', | 221 Name: 'wifi1', |
| 224 Priority: 0, | 222 Priority: 0, |
| 225 Source: 'User', | 223 Source: 'User', |
| 226 Type: NetworkType.WI_FI, | 224 Type: NETWORKING_API.NetworkType.WI_FI, |
| 227 WiFi: { | 225 WiFi: { |
| 228 BSSID: '00:01:02:03:04:05', | 226 BSSID: '00:01:02:03:04:05', |
| 229 Frequency: 2400, | 227 Frequency: 2400, |
| 230 Security: 'WEP-PSK', | 228 Security: 'WEP-PSK', |
| 231 SignalStrength: 40 | 229 SignalStrength: 40 |
| 232 } | 230 } |
| 233 }, { | 231 }, { |
| 234 GUID: 'stub_wifi2_guid', | 232 GUID: 'stub_wifi2_guid', |
| 235 Name: 'wifi2_PSK', | 233 Name: 'wifi2_PSK', |
| 236 Priority: 0, | 234 Priority: 0, |
| 237 Source: 'User', | 235 Source: 'User', |
| 238 Type: NetworkType.WI_FI, | 236 Type: NETWORKING_API.NetworkType.WI_FI, |
| 239 WiFi: { | 237 WiFi: { |
| 240 BSSID: '', | 238 BSSID: '', |
| 241 Frequency: 5000, | 239 Frequency: 5000, |
| 242 Security: 'WPA-PSK', | 240 Security: 'WPA-PSK', |
| 243 } | 241 } |
| 244 }], result); | 242 }], result); |
| 245 | 243 |
| 246 // Test 'visible' (and 'configured'). | 244 // Test 'visible' (and 'configured'). |
| 247 filter.visible = true; | 245 filter.visible = true; |
| 248 chrome.networkingPrivate.getNetworks( | 246 NETWORKING_API.getNetworks( |
| 249 filter, | 247 filter, |
| 250 callbackPass(function(result) { | 248 callbackPass(function(result) { |
| 251 assertEq([{ | 249 assertEq([{ |
| 252 Connectable: true, | 250 Connectable: true, |
| 253 ConnectionState: ConnectionStateType.CONNECTED, | 251 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 254 GUID: 'stub_wifi1_guid', | 252 GUID: 'stub_wifi1_guid', |
| 255 Name: 'wifi1', | 253 Name: 'wifi1', |
| 256 Priority: 0, | 254 Priority: 0, |
| 257 Source: 'User', | 255 Source: 'User', |
| 258 Type: NetworkType.WI_FI, | 256 Type: NETWORKING_API.NetworkType.WI_FI, |
| 259 WiFi: { | 257 WiFi: { |
| 260 BSSID: '00:01:02:03:04:05', | 258 BSSID: '00:01:02:03:04:05', |
| 261 Frequency: 2400, | 259 Frequency: 2400, |
| 262 Security: 'WEP-PSK', | 260 Security: 'WEP-PSK', |
| 263 SignalStrength: 40 | 261 SignalStrength: 40 |
| 264 } | 262 } |
| 265 }], result); | 263 }], result); |
| 266 | 264 |
| 267 // Test 'limit'. | 265 // Test 'limit'. |
| 268 filter = { | 266 filter = { |
| 269 networkType: NetworkType.ALL, | 267 networkType: NETWORKING_API.NetworkType.ALL, |
| 270 limit: 1 | 268 limit: 1 |
| 271 }; | 269 }; |
| 272 chrome.networkingPrivate.getNetworks( | 270 NETWORKING_API.getNetworks( |
| 273 filter, | 271 filter, |
| 274 callbackPass(function(result) { | 272 callbackPass(function(result) { |
| 275 assertEq([{ | 273 assertEq([{ |
| 276 ConnectionState: ConnectionStateType.CONNECTED, | 274 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 277 Ethernet: { | 275 Ethernet: { |
| 278 Authentication: 'None' | 276 Authentication: 'None' |
| 279 }, | 277 }, |
| 280 GUID: 'stub_ethernet_guid', | 278 GUID: 'stub_ethernet_guid', |
| 281 Name: 'eth0', | 279 Name: 'eth0', |
| 282 Priority: 0, | 280 Priority: 0, |
| 283 Source: 'Device', | 281 Source: 'Device', |
| 284 Type: NetworkType.ETHERNET | 282 Type: NETWORKING_API.NetworkType.ETHERNET |
| 285 }], result); | 283 }], result); |
| 286 })); | 284 })); |
| 287 })); | 285 })); |
| 288 })); | 286 })); |
| 289 }, | 287 }, |
| 290 function getVisibleNetworks() { | 288 function getVisibleNetworks() { |
| 291 chrome.networkingPrivate.getVisibleNetworks( | 289 NETWORKING_API.getVisibleNetworks( |
| 292 NetworkType.ALL, | 290 NETWORKING_API.NetworkType.ALL, |
| 293 callbackPass(function(result) { | 291 callbackPass(function(result) { |
| 294 assertEq([{ | 292 assertEq([{ |
| 295 ConnectionState: ConnectionStateType.CONNECTED, | 293 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 296 Ethernet: { | 294 Ethernet: { |
| 297 Authentication: 'None' | 295 Authentication: 'None' |
| 298 }, | 296 }, |
| 299 GUID: 'stub_ethernet_guid', | 297 GUID: 'stub_ethernet_guid', |
| 300 Name: 'eth0', | 298 Name: 'eth0', |
| 301 Priority: 0, | 299 Priority: 0, |
| 302 Source: 'Device', | 300 Source: 'Device', |
| 303 Type: NetworkType.ETHERNET | 301 Type: NETWORKING_API.NetworkType.ETHERNET |
| 304 }, { | 302 }, { |
| 305 Connectable: true, | 303 Connectable: true, |
| 306 ConnectionState: ConnectionStateType.CONNECTED, | 304 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 307 GUID: 'stub_wifi1_guid', | 305 GUID: 'stub_wifi1_guid', |
| 308 Name: 'wifi1', | 306 Name: 'wifi1', |
| 309 Priority: 0, | 307 Priority: 0, |
| 310 Source: 'User', | 308 Source: 'User', |
| 311 Type: NetworkType.WI_FI, | 309 Type: NETWORKING_API.NetworkType.WI_FI, |
| 312 WiFi: { | 310 WiFi: { |
| 313 BSSID: '00:01:02:03:04:05', | 311 BSSID: '00:01:02:03:04:05', |
| 314 Frequency: 2400, | 312 Frequency: 2400, |
| 315 Security: 'WEP-PSK', | 313 Security: 'WEP-PSK', |
| 316 SignalStrength: 40 | 314 SignalStrength: 40 |
| 317 } | 315 } |
| 318 }, { | 316 }, { |
| 319 Connectable: true, | 317 Connectable: true, |
| 320 ConnectionState: ConnectionStateType.CONNECTED, | 318 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 321 GUID: 'stub_wimax_guid', | 319 GUID: 'stub_wimax_guid', |
| 322 Name: 'wimax', | 320 Name: 'wimax', |
| 323 Priority: 0, | 321 Priority: 0, |
| 324 Source: 'User', | 322 Source: 'User', |
| 325 Type: NetworkType.WI_MAX, | 323 Type: NETWORKING_API.NetworkType.WI_MAX, |
| 326 WiMAX: { | 324 WiMAX: { |
| 327 SignalStrength: 40 | 325 SignalStrength: 40 |
| 328 } | 326 } |
| 329 }, { | 327 }, { |
| 330 ConnectionState: ConnectionStateType.CONNECTED, | 328 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 331 GUID: 'stub_vpn1_guid', | 329 GUID: 'stub_vpn1_guid', |
| 332 Name: 'vpn1', | 330 Name: 'vpn1', |
| 333 Priority: 0, | 331 Priority: 0, |
| 334 Source: 'User', | 332 Source: 'User', |
| 335 Type: NetworkType.VPN, | 333 Type: NETWORKING_API.NetworkType.VPN, |
| 336 VPN: { | 334 VPN: { |
| 337 Type: 'OpenVPN' | 335 Type: 'OpenVPN' |
| 338 } | 336 } |
| 339 }, { | 337 }, { |
| 340 ConnectionState: ConnectionStateType.NOT_CONNECTED, | 338 ConnectionState: NETWORKING_API.ConnectionStateType.NOT_CONNECTED, |
| 341 GUID: 'stub_vpn2_guid', | 339 GUID: 'stub_vpn2_guid', |
| 342 Name: 'vpn2', | 340 Name: 'vpn2', |
| 343 Priority: 0, | 341 Priority: 0, |
| 344 Source: 'User', | 342 Source: 'User', |
| 345 Type: NetworkType.VPN, | 343 Type: NETWORKING_API.NetworkType.VPN, |
| 346 VPN: { | 344 VPN: { |
| 347 ThirdPartyVPN: { | 345 ThirdPartyVPN: { |
| 348 ExtensionID: 'third_party_provider_extension_id' | 346 ExtensionID: 'third_party_provider_extension_id' |
| 349 }, | 347 }, |
| 350 Type: 'ThirdPartyVPN' | 348 Type: 'ThirdPartyVPN' |
| 351 } | 349 } |
| 352 }, { | 350 }, { |
| 353 Connectable: true, | 351 Connectable: true, |
| 354 ConnectionState: ConnectionStateType.NOT_CONNECTED, | 352 ConnectionState: NETWORKING_API.ConnectionStateType.NOT_CONNECTED, |
| 355 GUID: 'stub_wifi2_guid', | 353 GUID: 'stub_wifi2_guid', |
| 356 Name: 'wifi2_PSK', | 354 Name: 'wifi2_PSK', |
| 357 Priority: 0, | 355 Priority: 0, |
| 358 Source: 'User', | 356 Source: 'User', |
| 359 Type: NetworkType.WI_FI, | 357 Type: NETWORKING_API.NetworkType.WI_FI, |
| 360 WiFi: { | 358 WiFi: { |
| 361 BSSID: '', | 359 BSSID: '', |
| 362 Frequency: 5000, | 360 Frequency: 5000, |
| 363 Security: 'WPA-PSK', | 361 Security: 'WPA-PSK', |
| 364 SignalStrength: 80 | 362 SignalStrength: 80 |
| 365 } | 363 } |
| 366 }], result); | 364 }], result); |
| 367 })); | 365 })); |
| 368 }, | 366 }, |
| 369 function getVisibleNetworksWifi() { | 367 function getVisibleNetworksWifi() { |
| 370 chrome.networkingPrivate.getVisibleNetworks( | 368 NETWORKING_API.getVisibleNetworks( |
| 371 NetworkType.WI_FI, | 369 NETWORKING_API.NetworkType.WI_FI, |
| 372 callbackPass(function(result) { | 370 callbackPass(function(result) { |
| 373 assertEq([{ | 371 assertEq([{ |
| 374 Connectable: true, | 372 Connectable: true, |
| 375 ConnectionState: ConnectionStateType.CONNECTED, | 373 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 376 GUID: 'stub_wifi1_guid', | 374 GUID: 'stub_wifi1_guid', |
| 377 Name: 'wifi1', | 375 Name: 'wifi1', |
| 378 Priority: 0, | 376 Priority: 0, |
| 379 Source: 'User', | 377 Source: 'User', |
| 380 Type: NetworkType.WI_FI, | 378 Type: NETWORKING_API.NetworkType.WI_FI, |
| 381 WiFi: { | 379 WiFi: { |
| 382 BSSID: '00:01:02:03:04:05', | 380 BSSID: '00:01:02:03:04:05', |
| 383 Frequency: 2400, | 381 Frequency: 2400, |
| 384 Security: 'WEP-PSK', | 382 Security: 'WEP-PSK', |
| 385 SignalStrength: 40 | 383 SignalStrength: 40 |
| 386 } | 384 } |
| 387 }, { | 385 }, { |
| 388 Connectable: true, | 386 Connectable: true, |
| 389 ConnectionState: ConnectionStateType.NOT_CONNECTED, | 387 ConnectionState: NETWORKING_API.ConnectionStateType.NOT_CONNECTED, |
| 390 GUID: 'stub_wifi2_guid', | 388 GUID: 'stub_wifi2_guid', |
| 391 Name: 'wifi2_PSK', | 389 Name: 'wifi2_PSK', |
| 392 Priority: 0, | 390 Priority: 0, |
| 393 Source: 'User', | 391 Source: 'User', |
| 394 Type: NetworkType.WI_FI, | 392 Type: NETWORKING_API.NetworkType.WI_FI, |
| 395 WiFi: { | 393 WiFi: { |
| 396 BSSID: '', | 394 BSSID: '', |
| 397 Frequency: 5000, | 395 Frequency: 5000, |
| 398 Security: 'WPA-PSK', | 396 Security: 'WPA-PSK', |
| 399 SignalStrength: 80 | 397 SignalStrength: 80 |
| 400 } | 398 } |
| 401 }], result); | 399 }], result); |
| 402 })); | 400 })); |
| 403 }, | 401 }, |
| 404 function enabledNetworkTypes() { | 402 function enabledNetworkTypes() { |
| 405 // Note: We call getEnabledNetworkTypes twice after each enable/dsiable | 403 // Note: We call getEnabledNetworkTypes twice after each enable/dsiable |
| 406 // to ensure that Chrome has processed the command (since enable/disable | 404 // to ensure that Chrome has processed the command (since enable/disable |
| 407 // are 'synchronous' even though the action of enabling/disabling is not). | 405 // are 'synchronous' even though the action of enabling/disabling is not). |
| 408 chrome.networkingPrivate.getEnabledNetworkTypes( | 406 NETWORKING_API.getEnabledNetworkTypes( |
| 409 callbackPass(function(types) { | 407 callbackPass(function(types) { |
| 410 assertTrue(types.indexOf('WiFi') >= 0); | 408 assertTrue(types.indexOf('WiFi') >= 0); |
| 411 chrome.networkingPrivate.disableNetworkType('WiFi'); | 409 NETWORKING_API.disableNetworkType('WiFi'); |
| 412 chrome.networkingPrivate.getEnabledNetworkTypes( | 410 NETWORKING_API.getEnabledNetworkTypes( |
| 413 callbackPass(function(types) { | 411 callbackPass(function(types) { |
| 414 chrome.networkingPrivate.getEnabledNetworkTypes( | 412 NETWORKING_API.getEnabledNetworkTypes( |
| 415 callbackPass(function(types) { | 413 callbackPass(function(types) { |
| 416 assertFalse(types.indexOf('WiFi') >= 0); | 414 assertFalse(types.indexOf('WiFi') >= 0); |
| 417 chrome.networkingPrivate.enableNetworkType('WiFi'); | 415 NETWORKING_API.enableNetworkType('WiFi'); |
| 418 chrome.networkingPrivate.getEnabledNetworkTypes( | 416 NETWORKING_API.getEnabledNetworkTypes( |
| 419 callbackPass(function(types) { | 417 callbackPass(function(types) { |
| 420 chrome.networkingPrivate.getEnabledNetworkTypes( | 418 NETWORKING_API.getEnabledNetworkTypes( |
| 421 callbackPass(function(types) { | 419 callbackPass(function(types) { |
| 422 assertTrue(types.indexOf('WiFi') >= 0); | 420 assertTrue(types.indexOf('WiFi') >= 0); |
| 423 })); | 421 })); |
| 424 })); | 422 })); |
| 425 })); | 423 })); |
| 426 })); | 424 })); |
| 427 })); | 425 })); |
| 428 }, | 426 }, |
| 429 function getDeviceStates() { | 427 function getDeviceStates() { |
| 430 chrome.networkingPrivate.getDeviceStates(callbackPass(function(result) { | 428 NETWORKING_API.getDeviceStates(callbackPass(function(result) { |
| 431 assertEq([ | 429 assertEq([ |
| 432 {Scanning: false, State: 'Enabled', Type: 'Ethernet'}, | 430 {Scanning: false, State: 'Enabled', Type: 'Ethernet'}, |
| 433 {Scanning: false, State: 'Enabled', Type: 'WiFi'}, | 431 {Scanning: false, State: 'Enabled', Type: 'WiFi'}, |
| 434 {State: 'Uninitialized', Type: 'Cellular', SimPresent: true}, | 432 {State: 'Uninitialized', Type: 'Cellular', SimPresent: true}, |
| 435 {State: 'Disabled', Type: 'WiMAX'}, | 433 {State: 'Disabled', Type: 'WiMAX'}, |
| 436 ], | 434 ], |
| 437 result); | 435 result); |
| 438 })); | 436 })); |
| 439 }, | 437 }, |
| 440 function requestNetworkScan() { | 438 function requestNetworkScan() { |
| 441 // Connected or Connecting networks should be listed first, sorted by type. | 439 // Connected or Connecting networks should be listed first, sorted by type. |
| 442 var expected = ['stub_ethernet_guid', | 440 var expected = ['stub_ethernet_guid', |
| 443 'stub_wifi1_guid', | 441 'stub_wifi1_guid', |
| 444 'stub_wimax_guid', | 442 'stub_wimax_guid', |
| 445 'stub_vpn1_guid', | 443 'stub_vpn1_guid', |
| 446 'stub_vpn2_guid', | 444 'stub_vpn2_guid', |
| 447 'stub_wifi2_guid']; | 445 'stub_wifi2_guid']; |
| 448 var done = chrome.test.callbackAdded(); | 446 var done = chrome.test.callbackAdded(); |
| 449 var listener = new privateHelpers.listListener(expected, done); | 447 var listener = new privateHelpers.listListener(expected, done); |
| 450 chrome.networkingPrivate.onNetworkListChanged.addListener( | 448 NETWORKING_API.onNetworkListChanged.addListener( |
| 451 listener.listenForChanges); | 449 listener.listenForChanges); |
| 452 chrome.networkingPrivate.requestNetworkScan(); | 450 NETWORKING_API.requestNetworkScan(); |
| 453 }, | 451 }, |
| 454 function getProperties() { | 452 function getProperties() { |
| 455 chrome.networkingPrivate.getProperties( | 453 NETWORKING_API.getProperties( |
| 456 'stub_wifi1_guid', | 454 'stub_wifi1_guid', |
| 457 callbackPass(function(result) { | 455 callbackPass(function(result) { |
| 458 assertEq({ | 456 assertEq({ |
| 459 Connectable: true, | 457 Connectable: true, |
| 460 ConnectionState: ConnectionStateType.CONNECTED, | 458 ConnectionState: NETWORKING_API.ConnectionStateType.CONNECTED, |
| 461 GUID: 'stub_wifi1_guid', | 459 GUID: 'stub_wifi1_guid', |
| 462 IPAddressConfigType: chrome.networkingPrivate.IPConfigType.STATIC, | 460 IPAddressConfigType: NETWORKING_API.IPConfigType.STATIC, |
| 463 IPConfigs: [{ | 461 IPConfigs: [{ |
| 464 Gateway: '0.0.0.1', | 462 Gateway: '0.0.0.1', |
| 465 IPAddress: '0.0.0.0', | 463 IPAddress: '0.0.0.0', |
| 466 RoutingPrefix: 0, | 464 RoutingPrefix: 0, |
| 467 Type: 'IPv4' | 465 Type: 'IPv4' |
| 468 }], | 466 }], |
| 469 MacAddress: '00:11:22:AA:BB:CC', | 467 MacAddress: '00:11:22:AA:BB:CC', |
| 470 Name: 'wifi1', | 468 Name: 'wifi1', |
| 471 Source: 'User', | 469 Source: 'User', |
| 472 StaticIPConfig: { | 470 StaticIPConfig: { |
| 473 IPAddress: '1.2.3.4', | 471 IPAddress: '1.2.3.4', |
| 474 Type: 'IPv4' | 472 Type: 'IPv4' |
| 475 }, | 473 }, |
| 476 Type: NetworkType.WI_FI, | 474 Type: NETWORKING_API.NetworkType.WI_FI, |
| 477 WiFi: { | 475 WiFi: { |
| 478 BSSID: '00:01:02:03:04:05', | 476 BSSID: '00:01:02:03:04:05', |
| 479 HexSSID: '7769666931', // 'wifi1' | 477 HexSSID: '7769666931', // 'wifi1' |
| 480 Frequency: 2400, | 478 Frequency: 2400, |
| 481 FrequencyList: [2400], | 479 FrequencyList: [2400], |
| 482 SSID: 'wifi1', | 480 SSID: 'wifi1', |
| 483 Security: 'WEP-PSK', | 481 Security: 'WEP-PSK', |
| 484 SignalStrength: 40 | 482 SignalStrength: 40 |
| 485 } | 483 } |
| 486 }, result); | 484 }, result); |
| 487 })); | 485 })); |
| 488 }, | 486 }, |
| 489 function getPropertiesCellular() { | 487 function getPropertiesCellular() { |
| 490 chrome.networkingPrivate.getProperties( | 488 NETWORKING_API.getProperties( |
| 491 kCellularGuid, | 489 kCellularGuid, |
| 492 callbackPass(function(result) { | 490 callbackPass(function(result) { |
| 493 assertEq({ | 491 assertEq({ |
| 494 Cellular: { | 492 Cellular: { |
| 495 ActivationState: ActivationStateType.NOT_ACTIVATED, | 493 ActivationState: NETWORKING_API.ActivationStateType.NOT_ACTIVATED, |
| 496 AllowRoaming: false, | 494 AllowRoaming: false, |
| 497 AutoConnect: true, | 495 AutoConnect: true, |
| 498 Carrier: 'Cellular1_Carrier', | 496 Carrier: 'Cellular1_Carrier', |
| 499 Family: 'GSM', | 497 Family: 'GSM', |
| 500 HomeProvider: { | 498 HomeProvider: { |
| 501 Code: '000000', | 499 Code: '000000', |
| 502 Country: 'us', | 500 Country: 'us', |
| 503 Name: 'Cellular1_Provider' | 501 Name: 'Cellular1_Provider' |
| 504 }, | 502 }, |
| 505 NetworkTechnology: 'GSM', | 503 NetworkTechnology: 'GSM', |
| 506 RoamingState: 'Home', | 504 RoamingState: 'Home', |
| 507 SIMLockStatus: {LockEnabled: true, LockType: '', RetriesLeft: 3} | 505 SIMLockStatus: {LockEnabled: true, LockType: '', RetriesLeft: 3} |
| 508 }, | 506 }, |
| 509 ConnectionState: ConnectionStateType.NOT_CONNECTED, | 507 ConnectionState: NETWORKING_API.ConnectionStateType.NOT_CONNECTED, |
| 510 GUID: kCellularGuid, | 508 GUID: kCellularGuid, |
| 511 Name: 'cellular1', | 509 Name: 'cellular1', |
| 512 Source: 'User', | 510 Source: 'User', |
| 513 Type: NetworkType.CELLULAR, | 511 Type: NETWORKING_API.NetworkType.CELLULAR, |
| 514 }, result); | 512 }, result); |
| 515 })); | 513 })); |
| 516 }, | 514 }, |
| 517 function getManagedProperties() { | 515 function getManagedProperties() { |
| 518 chrome.networkingPrivate.getManagedProperties( | 516 NETWORKING_API.getManagedProperties( |
| 519 'stub_wifi2', | 517 'stub_wifi2', |
| 520 callbackPass(function(result) { | 518 callbackPass(function(result) { |
| 521 assertEq({ | 519 assertEq({ |
| 522 Connectable: true, | 520 Connectable: true, |
| 523 ConnectionState: ConnectionStateType.NOT_CONNECTED, | 521 ConnectionState: NETWORKING_API.ConnectionStateType.NOT_CONNECTED, |
| 524 GUID: 'stub_wifi2', | 522 GUID: 'stub_wifi2', |
| 525 Name: { | 523 Name: { |
| 526 Active: 'wifi2_PSK', | 524 Active: 'wifi2_PSK', |
| 527 Effective: 'UserPolicy', | 525 Effective: 'UserPolicy', |
| 528 UserPolicy: 'My WiFi Network' | 526 UserPolicy: 'My WiFi Network' |
| 529 }, | 527 }, |
| 530 ProxySettings: { | 528 ProxySettings: { |
| 531 Type: { | 529 Type: { |
| 532 Active: 'Direct', | 530 Active: 'Direct', |
| 533 Effective: 'UserPolicy', | 531 Effective: 'UserPolicy', |
| 534 UserEditable: false, | 532 UserEditable: false, |
| 535 UserPolicy: 'Direct' | 533 UserPolicy: 'Direct' |
| 536 } | 534 } |
| 537 }, | 535 }, |
| 538 Source: 'UserPolicy', | 536 Source: 'UserPolicy', |
| 539 Type: NetworkType.WI_FI, | 537 Type: NETWORKING_API.NetworkType.WI_FI, |
| 540 WiFi: { | 538 WiFi: { |
| 541 AutoConnect: { | 539 AutoConnect: { |
| 542 Active: false, | 540 Active: false, |
| 543 UserEditable: true | 541 UserEditable: true |
| 544 }, | 542 }, |
| 545 HexSSID: { | 543 HexSSID: { |
| 546 Active: '77696669325F50534B', // 'wifi2_PSK' | 544 Active: '77696669325F50534B', // 'wifi2_PSK' |
| 547 Effective: 'UserPolicy', | 545 Effective: 'UserPolicy', |
| 548 UserPolicy: '77696669325F50534B' | 546 UserPolicy: '77696669325F50534B' |
| 549 }, | 547 }, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 566 SignalStrength: 80, | 564 SignalStrength: 80, |
| 567 } | 565 } |
| 568 }, result); | 566 }, result); |
| 569 })); | 567 })); |
| 570 }, | 568 }, |
| 571 function setCellularProperties() { | 569 function setCellularProperties() { |
| 572 var network_guid = kCellularGuid; | 570 var network_guid = kCellularGuid; |
| 573 // Make sure we test Cellular.Carrier since it requires a special call | 571 // Make sure we test Cellular.Carrier since it requires a special call |
| 574 // to Shill.Device.SetCarrier. | 572 // to Shill.Device.SetCarrier. |
| 575 var newCarrier = 'new_carrier'; | 573 var newCarrier = 'new_carrier'; |
| 576 chrome.networkingPrivate.getProperties( | 574 NETWORKING_API.getProperties( |
| 577 network_guid, | 575 network_guid, |
| 578 callbackPass(function(result) { | 576 callbackPass(function(result) { |
| 579 assertEq(network_guid, result.GUID); | 577 assertEq(network_guid, result.GUID); |
| 580 assertTrue(!result.Cellular || result.Cellular.Carrier != newCarrier); | 578 assertTrue(!result.Cellular || result.Cellular.Carrier != newCarrier); |
| 581 var new_properties = { | 579 var new_properties = { |
| 582 Priority: 1, | 580 Priority: 1, |
| 583 Cellular: { | 581 Cellular: { |
| 584 Carrier: newCarrier, | 582 Carrier: newCarrier, |
| 585 }, | 583 }, |
| 586 }; | 584 }; |
| 587 chrome.networkingPrivate.setProperties( | 585 NETWORKING_API.setProperties( |
| 588 network_guid, | 586 network_guid, |
| 589 new_properties, | 587 new_properties, |
| 590 callbackPass(function() { | 588 callbackPass(function() { |
| 591 chrome.networkingPrivate.getProperties( | 589 NETWORKING_API.getProperties( |
| 592 network_guid, | 590 network_guid, |
| 593 callbackPass(function(result) { | 591 callbackPass(function(result) { |
| 594 // Ensure that the GUID doesn't change. | 592 // Ensure that the GUID doesn't change. |
| 595 assertEq(network_guid, result.GUID); | 593 assertEq(network_guid, result.GUID); |
| 596 // Ensure that the properties were set. | 594 // Ensure that the properties were set. |
| 597 assertEq(1, result['Priority']); | 595 assertEq(1, result['Priority']); |
| 598 assertTrue('Cellular' in result); | 596 assertTrue('Cellular' in result); |
| 599 assertEq(newCarrier, result.Cellular.Carrier); | 597 assertEq(newCarrier, result.Cellular.Carrier); |
| 600 })); | 598 })); |
| 601 })); | 599 })); |
| 602 })); | 600 })); |
| 603 }, | 601 }, |
| 604 function setWiFiProperties() { | 602 function setWiFiProperties() { |
| 605 var network_guid = 'stub_wifi1_guid'; | 603 var network_guid = 'stub_wifi1_guid'; |
| 606 chrome.networkingPrivate.getProperties( | 604 NETWORKING_API.getProperties( |
| 607 network_guid, | 605 network_guid, |
| 608 callbackPass(function(result) { | 606 callbackPass(function(result) { |
| 609 assertEq(network_guid, result.GUID); | 607 assertEq(network_guid, result.GUID); |
| 610 var new_properties = { | 608 var new_properties = { |
| 611 Priority: 1, | 609 Priority: 1, |
| 612 WiFi: { | 610 WiFi: { |
| 613 AutoConnect: true | 611 AutoConnect: true |
| 614 }, | 612 }, |
| 615 IPAddressConfigType: 'Static', | 613 IPAddressConfigType: 'Static', |
| 616 StaticIPConfig: { | 614 StaticIPConfig: { |
| 617 IPAddress: '1.2.3.4' | 615 IPAddress: '1.2.3.4' |
| 618 } | 616 } |
| 619 }; | 617 }; |
| 620 chrome.networkingPrivate.setProperties( | 618 NETWORKING_API.setProperties( |
| 621 network_guid, | 619 network_guid, |
| 622 new_properties, | 620 new_properties, |
| 623 callbackPass(function() { | 621 callbackPass(function() { |
| 624 chrome.networkingPrivate.getProperties( | 622 NETWORKING_API.getProperties( |
| 625 network_guid, | 623 network_guid, |
| 626 callbackPass(function(result) { | 624 callbackPass(function(result) { |
| 627 // Ensure that the GUID doesn't change. | 625 // Ensure that the GUID doesn't change. |
| 628 assertEq(network_guid, result.GUID); | 626 assertEq(network_guid, result.GUID); |
| 629 // Ensure that the properties were set. | 627 // Ensure that the properties were set. |
| 630 assertEq(1, result['Priority']); | 628 assertEq(1, result['Priority']); |
| 631 assertTrue('WiFi' in result); | 629 assertTrue('WiFi' in result); |
| 632 assertTrue('AutoConnect' in result['WiFi']); | 630 assertTrue('AutoConnect' in result['WiFi']); |
| 633 assertEq(true, result['WiFi']['AutoConnect']); | 631 assertEq(true, result['WiFi']['AutoConnect']); |
| 634 assertTrue('StaticIPConfig' in result); | 632 assertTrue('StaticIPConfig' in result); |
| 635 assertEq('1.2.3.4', | 633 assertEq('1.2.3.4', |
| 636 result['StaticIPConfig']['IPAddress']); | 634 result['StaticIPConfig']['IPAddress']); |
| 637 })); | 635 })); |
| 638 })); | 636 })); |
| 639 })); | 637 })); |
| 640 }, | 638 }, |
| 641 function setVPNProperties() { | 639 function setVPNProperties() { |
| 642 var network_guid = 'stub_vpn1_guid'; | 640 var network_guid = 'stub_vpn1_guid'; |
| 643 chrome.networkingPrivate.getProperties( | 641 NETWORKING_API.getProperties( |
| 644 network_guid, | 642 network_guid, |
| 645 callbackPass(function(result) { | 643 callbackPass(function(result) { |
| 646 assertEq(network_guid, result.GUID); | 644 assertEq(network_guid, result.GUID); |
| 647 var new_properties = { | 645 var new_properties = { |
| 648 Priority: 1, | 646 Priority: 1, |
| 649 VPN: { | 647 VPN: { |
| 650 Host: 'vpn.host1' | 648 Host: 'vpn.host1' |
| 651 } | 649 } |
| 652 }; | 650 }; |
| 653 chrome.networkingPrivate.setProperties( | 651 NETWORKING_API.setProperties( |
| 654 network_guid, | 652 network_guid, |
| 655 new_properties, | 653 new_properties, |
| 656 callbackPass(function() { | 654 callbackPass(function() { |
| 657 chrome.networkingPrivate.getProperties( | 655 NETWORKING_API.getProperties( |
| 658 network_guid, | 656 network_guid, |
| 659 callbackPass(function(result) { | 657 callbackPass(function(result) { |
| 660 // Ensure that the properties were set. | 658 // Ensure that the properties were set. |
| 661 assertEq(1, result['Priority']); | 659 assertEq(1, result['Priority']); |
| 662 assertTrue('VPN' in result); | 660 assertTrue('VPN' in result); |
| 663 assertTrue('Host' in result['VPN']); | 661 assertTrue('Host' in result['VPN']); |
| 664 assertEq('vpn.host1', result['VPN']['Host']); | 662 assertEq('vpn.host1', result['VPN']['Host']); |
| 665 // Ensure that the GUID doesn't change. | 663 // Ensure that the GUID doesn't change. |
| 666 assertEq(network_guid, result.GUID); | 664 assertEq(network_guid, result.GUID); |
| 667 })); | 665 })); |
| 668 })); | 666 })); |
| 669 })); | 667 })); |
| 670 }, | 668 }, |
| 671 function getState() { | 669 function getState() { |
| 672 chrome.networkingPrivate.getState( | 670 NETWORKING_API.getState( |
| 673 'stub_wifi2_guid', | 671 'stub_wifi2_guid', |
| 674 callbackPass(function(result) { | 672 callbackPass(function(result) { |
| 675 assertEq({ | 673 assertEq({ |
| 676 Connectable: true, | 674 Connectable: true, |
| 677 ConnectionState: ConnectionStateType.NOT_CONNECTED, | 675 ConnectionState: NETWORKING_API.ConnectionStateType.NOT_CONNECTED, |
| 678 GUID: 'stub_wifi2_guid', | 676 GUID: 'stub_wifi2_guid', |
| 679 Name: 'wifi2_PSK', | 677 Name: 'wifi2_PSK', |
| 680 Priority: 0, | 678 Priority: 0, |
| 681 Source: 'User', | 679 Source: 'User', |
| 682 Type: NetworkType.WI_FI, | 680 Type: NETWORKING_API.NetworkType.WI_FI, |
| 683 WiFi: { | 681 WiFi: { |
| 684 BSSID: '', | 682 BSSID: '', |
| 685 Frequency: 5000, | 683 Frequency: 5000, |
| 686 Security: 'WPA-PSK', | 684 Security: 'WPA-PSK', |
| 687 SignalStrength: 80 | 685 SignalStrength: 80 |
| 688 } | 686 } |
| 689 }, result); | 687 }, result); |
| 690 })); | 688 })); |
| 691 }, | 689 }, |
| 692 function getStateNonExistent() { | 690 function getStateNonExistent() { |
| 693 chrome.networkingPrivate.getState( | 691 NETWORKING_API.getState( |
| 694 'non_existent', | 692 'non_existent', |
| 695 callbackFail('Error.InvalidNetworkGuid')); | 693 callbackFail('Error.InvalidNetworkGuid')); |
| 696 }, | 694 }, |
| 697 function getErrorState() { | 695 function getErrorState() { |
| 698 // Both getState and getProperties should have ErrorState set. | 696 // Both getState and getProperties should have ErrorState set. |
| 699 chrome.networkingPrivate.getState( | 697 NETWORKING_API.getState( |
| 700 'stub_wifi1_guid', callbackPass(function(result) { | 698 'stub_wifi1_guid', callbackPass(function(result) { |
| 701 assertEq('TestErrorState', result.ErrorState); | 699 assertEq('TestErrorState', result.ErrorState); |
| 702 chrome.networkingPrivate.getProperties( | 700 NETWORKING_API.getProperties( |
| 703 'stub_wifi1_guid', callbackPass(function(result2) { | 701 'stub_wifi1_guid', callbackPass(function(result2) { |
| 704 assertEq('TestErrorState', result2.ErrorState); | 702 assertEq('TestErrorState', result2.ErrorState); |
| 705 })); | 703 })); |
| 706 })); | 704 })); |
| 707 }, | 705 }, |
| 708 function onNetworksChangedEventConnect() { | 706 function onNetworksChangedEventConnect() { |
| 709 var network = 'stub_wifi2_guid'; | 707 var network = 'stub_wifi2_guid'; |
| 710 var done = chrome.test.callbackAdded(); | 708 var done = chrome.test.callbackAdded(); |
| 711 var expectedStates = [ConnectionStateType.CONNECTED]; | 709 var expectedStates = [NETWORKING_API.ConnectionStateType.CONNECTED]; |
| 712 var listener = | 710 var listener = |
| 713 new privateHelpers.watchForStateChanges(network, expectedStates, done); | 711 new privateHelpers.watchForStateChanges(network, expectedStates, done); |
| 714 chrome.networkingPrivate.startConnect(network, | 712 NETWORKING_API.startConnect(network, |
| 715 networkCallbackPass()); | 713 networkCallbackPass()); |
| 716 }, | 714 }, |
| 717 function onNetworksChangedEventDisconnect() { | 715 function onNetworksChangedEventDisconnect() { |
| 718 var network = 'stub_wifi1_guid'; | 716 var network = 'stub_wifi1_guid'; |
| 719 var done = chrome.test.callbackAdded(); | 717 var done = chrome.test.callbackAdded(); |
| 720 var expectedStates = [ConnectionStateType.NOT_CONNECTED]; | 718 var expectedStates = [NETWORKING_API.ConnectionStateType.NOT_CONNECTED]; |
| 721 var listener = | 719 var listener = |
| 722 new privateHelpers.watchForStateChanges(network, expectedStates, done); | 720 new privateHelpers.watchForStateChanges(network, expectedStates, done); |
| 723 chrome.networkingPrivate.startDisconnect(network, | 721 NETWORKING_API.startDisconnect(network, |
| 724 networkCallbackPass()); | 722 networkCallbackPass()); |
| 725 }, | 723 }, |
| 726 function onNetworkListChangedEvent() { | 724 function onNetworkListChangedEvent() { |
| 727 // Connecting to wifi2 should set wifi1 to offline. Connected or Connecting | 725 // Connecting to wifi2 should set wifi1 to offline. Connected or Connecting |
| 728 // networks should be listed first, sorted by type. | 726 // networks should be listed first, sorted by type. |
| 729 var expected = ['stub_ethernet_guid', | 727 var expected = ['stub_ethernet_guid', |
| 730 'stub_wifi2_guid', | 728 'stub_wifi2_guid', |
| 731 'stub_wimax_guid', | 729 'stub_wimax_guid', |
| 732 'stub_vpn1_guid', | 730 'stub_vpn1_guid', |
| 733 'stub_wifi1_guid', | 731 'stub_wifi1_guid', |
| 734 'stub_vpn2_guid']; | 732 'stub_vpn2_guid']; |
| 735 var done = chrome.test.callbackAdded(); | 733 var done = chrome.test.callbackAdded(); |
| 736 var listener = new privateHelpers.listListener(expected, done); | 734 var listener = new privateHelpers.listListener(expected, done); |
| 737 chrome.networkingPrivate.onNetworkListChanged.addListener( | 735 NETWORKING_API.onNetworkListChanged.addListener( |
| 738 listener.listenForChanges); | 736 listener.listenForChanges); |
| 739 var network = 'stub_wifi2_guid'; | 737 var network = 'stub_wifi2_guid'; |
| 740 chrome.networkingPrivate.startConnect(network, | 738 NETWORKING_API.startConnect(network, |
| 741 networkCallbackPass()); | 739 networkCallbackPass()); |
| 742 }, | 740 }, |
| 743 function onDeviceStateListChangedEvent() { | 741 function onDeviceStateListChangedEvent() { |
| 744 var listener = callbackPass(function() { | 742 var listener = callbackPass(function() { |
| 745 chrome.networkingPrivate.onDeviceStateListChanged.removeListener( | 743 NETWORKING_API.onDeviceStateListChanged.removeListener( |
| 746 listener); | 744 listener); |
| 747 }); | 745 }); |
| 748 chrome.networkingPrivate.onDeviceStateListChanged.addListener(listener); | 746 NETWORKING_API.onDeviceStateListChanged.addListener(listener); |
| 749 chrome.networkingPrivate.disableNetworkType('WiFi'); | 747 NETWORKING_API.disableNetworkType('WiFi'); |
| 750 }, | 748 }, |
| 751 function verifyDestination() { | 749 function verifyDestination() { |
| 752 chrome.networkingPrivate.verifyDestination( | 750 NETWORKING_API.verifyDestination( |
| 753 verificationProperties, | 751 verificationProperties, |
| 754 callbackPass(function(isValid) { | 752 callbackPass(function(isValid) { |
| 755 assertTrue(isValid); | 753 assertTrue(isValid); |
| 756 })); | 754 })); |
| 757 }, | 755 }, |
| 758 function verifyAndEncryptCredentials() { | 756 function verifyAndEncryptCredentials() { |
| 759 var network_guid = 'stub_wifi2_guid'; | 757 var network_guid = 'stub_wifi2_guid'; |
| 760 chrome.networkingPrivate.verifyAndEncryptCredentials( | 758 NETWORKING_API.verifyAndEncryptCredentials( |
| 761 verificationProperties, | 759 verificationProperties, |
| 762 network_guid, | 760 network_guid, |
| 763 callbackPass(function(result) { | 761 callbackPass(function(result) { |
| 764 assertEq('encrypted_credentials', result); | 762 assertEq('encrypted_credentials', result); |
| 765 })); | 763 })); |
| 766 }, | 764 }, |
| 767 function verifyAndEncryptData() { | 765 function verifyAndEncryptData() { |
| 768 chrome.networkingPrivate.verifyAndEncryptData( | 766 NETWORKING_API.verifyAndEncryptData( |
| 769 verificationProperties, | 767 verificationProperties, |
| 770 'data', | 768 'data', |
| 771 callbackPass(function(result) { | 769 callbackPass(function(result) { |
| 772 assertEq('encrypted_data', result); | 770 assertEq('encrypted_data', result); |
| 773 })); | 771 })); |
| 774 }, | 772 }, |
| 775 function setWifiTDLSEnabledState() { | 773 function setWifiTDLSEnabledState() { |
| 776 chrome.networkingPrivate.setWifiTDLSEnabledState( | 774 NETWORKING_API.setWifiTDLSEnabledState( |
| 777 'aa:bb:cc:dd:ee:ff', true, callbackPass(function(result) { | 775 'aa:bb:cc:dd:ee:ff', true, callbackPass(function(result) { |
| 778 assertEq(ConnectionStateType.CONNECTED, result); | 776 assertEq(NETWORKING_API.ConnectionStateType.CONNECTED, result); |
| 779 })); | 777 })); |
| 780 }, | 778 }, |
| 781 function getWifiTDLSStatus() { | 779 function getWifiTDLSStatus() { |
| 782 chrome.networkingPrivate.getWifiTDLSStatus( | 780 NETWORKING_API.getWifiTDLSStatus( |
| 783 'aa:bb:cc:dd:ee:ff', callbackPass(function(result) { | 781 'aa:bb:cc:dd:ee:ff', callbackPass(function(result) { |
| 784 assertEq(ConnectionStateType.CONNECTED, result); | 782 assertEq(NETWORKING_API.ConnectionStateType.CONNECTED, result); |
| 785 })); | 783 })); |
| 786 }, | 784 }, |
| 787 function getCaptivePortalStatus() { | 785 function getCaptivePortalStatus() { |
| 788 var networks = [['stub_ethernet_guid', 'Online'], | 786 var networks = [['stub_ethernet_guid', 'Online'], |
| 789 ['stub_wifi1_guid', 'Offline'], | 787 ['stub_wifi1_guid', 'Offline'], |
| 790 ['stub_wifi2_guid', 'Portal'], | 788 ['stub_wifi2_guid', 'Portal'], |
| 791 ['stub_cellular1_guid', 'ProxyAuthRequired'], | 789 ['stub_cellular1_guid', 'ProxyAuthRequired'], |
| 792 ['stub_vpn1_guid', 'Unknown']]; | 790 ['stub_vpn1_guid', 'Unknown']]; |
| 793 networks.forEach(function(network) { | 791 networks.forEach(function(network) { |
| 794 var guid = network[0]; | 792 var guid = network[0]; |
| 795 var expectedStatus = network[1]; | 793 var expectedStatus = network[1]; |
| 796 chrome.networkingPrivate.getCaptivePortalStatus( | 794 NETWORKING_API.getCaptivePortalStatus( |
| 797 guid, | 795 guid, |
| 798 callbackPass(function(status) { | 796 callbackPass(function(status) { |
| 799 assertEq(expectedStatus, status); | 797 assertEq(expectedStatus, status); |
| 800 })); | 798 })); |
| 801 }); | 799 }); |
| 802 }, | 800 }, |
| 803 function captivePortalNotification() { | 801 function captivePortalNotification() { |
| 804 var done = chrome.test.callbackAdded(); | 802 var done = chrome.test.callbackAdded(); |
| 805 var listener = | 803 var listener = |
| 806 new privateHelpers.watchForCaptivePortalState( | 804 new privateHelpers.watchForCaptivePortalState( |
| 807 'wifi_guid', 'Online', done); | 805 'wifi_guid', 'Online', done); |
| 808 chrome.test.sendMessage('notifyPortalDetectorObservers'); | 806 chrome.test.sendMessage('notifyPortalDetectorObservers'); |
| 809 }, | 807 }, |
| 810 function unlockCellularSim() { | 808 function unlockCellularSim() { |
| 811 var incorrectPin = '2222'; | 809 var incorrectPin = '2222'; |
| 812 // Try with incorrect PIN, expect failure. | 810 // Try with incorrect PIN, expect failure. |
| 813 chrome.networkingPrivate.unlockCellularSim( | 811 NETWORKING_API.unlockCellularSim( |
| 814 kCellularGuid, incorrectPin, '', | 812 kCellularGuid, incorrectPin, '', |
| 815 callbackFail('incorrect-pin', function() { | 813 callbackFail('incorrect-pin', function() { |
| 816 // Try with correct PIN, expect success. | 814 // Try with correct PIN, expect success. |
| 817 chrome.networkingPrivate.unlockCellularSim( | 815 NETWORKING_API.unlockCellularSim( |
| 818 kCellularGuid, kDefaultPin, '', networkCallbackPass()); | 816 kCellularGuid, kDefaultPin, '', networkCallbackPass()); |
| 819 })); | 817 })); |
| 820 }, | 818 }, |
| 821 function setCellularSimState() { | 819 function setCellularSimState() { |
| 822 var newPin = '6666'; | 820 var newPin = '6666'; |
| 823 var simState = {requirePin: true, currentPin: kDefaultPin, newPin: newPin}; | 821 var simState = {requirePin: true, currentPin: kDefaultPin, newPin: newPin}; |
| 824 // Test setting 'requirePin' and 'newPin'. | 822 // Test setting 'requirePin' and 'newPin'. |
| 825 chrome.networkingPrivate.getProperties( | 823 NETWORKING_API.getProperties( |
| 826 kCellularGuid, callbackPass(function(result) { | 824 kCellularGuid, callbackPass(function(result) { |
| 827 // Ensure the SIM is initially unlocked. | 825 // Ensure the SIM is initially unlocked. |
| 828 assertTrue(result.Cellular.SIMLockStatus == undefined || | 826 assertTrue(result.Cellular.SIMLockStatus == undefined || |
| 829 result.Cellular.SIMLockStatus.LockType == ''); | 827 result.Cellular.SIMLockStatus.LockType == ''); |
| 830 chrome.networkingPrivate.setCellularSimState( | 828 NETWORKING_API.setCellularSimState( |
| 831 kCellularGuid, simState, callbackPass(function() { | 829 kCellularGuid, simState, callbackPass(function() { |
| 832 chrome.networkingPrivate.getProperties( | 830 NETWORKING_API.getProperties( |
| 833 kCellularGuid, callbackPass(function(result) { | 831 kCellularGuid, callbackPass(function(result) { |
| 834 // The SIM should still be unlocked. | 832 // The SIM should still be unlocked. |
| 835 assertEq('', result.Cellular.SIMLockStatus.LockType); | 833 assertEq('', result.Cellular.SIMLockStatus.LockType); |
| 836 // Ensure SIM locking is enabled. | 834 // Ensure SIM locking is enabled. |
| 837 assertTrue(result.Cellular.SIMLockStatus.LockEnabled); | 835 assertTrue(result.Cellular.SIMLockStatus.LockEnabled); |
| 838 // Ensure the new pin is set by using the new PIN | 836 // Ensure the new pin is set by using the new PIN |
| 839 // to change the PIN back. | 837 // to change the PIN back. |
| 840 simState.currentPin = newPin; | 838 simState.currentPin = newPin; |
| 841 simState.newPin = kDefaultPin; | 839 simState.newPin = kDefaultPin; |
| 842 chrome.networkingPrivate.setCellularSimState( | 840 NETWORKING_API.setCellularSimState( |
| 843 kCellularGuid, simState, networkCallbackPass()); | 841 kCellularGuid, simState, networkCallbackPass()); |
| 844 })); | 842 })); |
| 845 })); | 843 })); |
| 846 })); | 844 })); |
| 847 }, | 845 }, |
| 848 function cellularSimPuk() { | 846 function cellularSimPuk() { |
| 849 var newPin = '6666'; | 847 var newPin = '6666'; |
| 850 var incorrectPin = '2222'; | 848 var incorrectPin = '2222'; |
| 851 var incorrectPuk = '22222222'; | 849 var incorrectPuk = '22222222'; |
| 852 var unlockFailFunc = function(nextFunc) { | 850 var unlockFailFunc = function(nextFunc) { |
| 853 chrome.networkingPrivate.unlockCellularSim( | 851 NETWORKING_API.unlockCellularSim( |
| 854 kCellularGuid, incorrectPin, '', | 852 kCellularGuid, incorrectPin, '', |
| 855 callbackFail('incorrect-pin', nextFunc)); | 853 callbackFail('incorrect-pin', nextFunc)); |
| 856 }; | 854 }; |
| 857 // Try with incorrect PIN three times, SIM should become PUK locked. | 855 // Try with incorrect PIN three times, SIM should become PUK locked. |
| 858 unlockFailFunc(unlockFailFunc(unlockFailFunc(function() { | 856 unlockFailFunc(unlockFailFunc(unlockFailFunc(function() { |
| 859 // Ensure the SIM is PUK locked. | 857 // Ensure the SIM is PUK locked. |
| 860 chrome.networkingPrivate.getProperties( | 858 NETWORKING_API.getProperties( |
| 861 kCellularGuid, callbackPass(function(result) { | 859 kCellularGuid, callbackPass(function(result) { |
| 862 assertEq('sim-puk', result.Cellular.SIMLockStatus.LockType); | 860 assertEq('sim-puk', result.Cellular.SIMLockStatus.LockType); |
| 863 // Try to unlock with an incorrect PUK, expect failure. | 861 // Try to unlock with an incorrect PUK, expect failure. |
| 864 chrome.networkingPrivate.unlockCellularSim( | 862 NETWORKING_API.unlockCellularSim( |
| 865 kCellularGuid, newPin, incorrectPuk, | 863 kCellularGuid, newPin, incorrectPuk, |
| 866 callbackFail('incorrect-pin', function() { | 864 callbackFail('incorrect-pin', function() { |
| 867 // Try with the correct PUK, expect success. | 865 // Try with the correct PUK, expect success. |
| 868 chrome.networkingPrivate.unlockCellularSim( | 866 NETWORKING_API.unlockCellularSim( |
| 869 kCellularGuid, newPin, kDefaultPuk, | 867 kCellularGuid, newPin, kDefaultPuk, |
| 870 callbackPass(function() { | 868 callbackPass(function() { |
| 871 // Set state with the new PIN, expect success. | 869 // Set state with the new PIN, expect success. |
| 872 var simState = {requirePin: true, currentPin: newPin}; | 870 var simState = {requirePin: true, currentPin: newPin}; |
| 873 chrome.networkingPrivate.setCellularSimState( | 871 NETWORKING_API.setCellularSimState( |
| 874 kCellularGuid, simState, networkCallbackPass()); | 872 kCellularGuid, simState, networkCallbackPass()); |
| 875 })); | 873 })); |
| 876 })); | 874 })); |
| 877 })); | 875 })); |
| 878 }))); | 876 }))); |
| 879 } | 877 } |
| 880 ]; | 878 ]; |
| 881 | 879 |
| 882 var testToRun = window.location.search.substring(1); | 880 // Finds chrome API object for api named |apiName|. |
| 883 chrome.test.runTests(availableTests.filter(function(op) { | 881 // If the object is not defined, returns null. |
| 884 return op.name == testToRun; | 882 // |checkedComponents| will contain all API path components that have been |
| 885 })); | 883 // checked - in case of the failure it will contain components of the APi |
|
stevenjb
2016/12/09 23:29:04
s/the failure/failure/
tbarzic
2016/12/10 02:04:49
Done.
| |
| 884 // name up to the one that could not be found. | |
| 885 function getApiObject(apiName, checkedComponents) { | |
| 886 var apiComponents = apiName.split('.'); | |
| 887 | |
| 888 checkedComponents.push('chrome'); | |
| 889 var apiObject = chrome; | |
| 890 for (var i = 0; i < apiComponents.length; i++) { | |
| 891 var component = apiComponents[i]; | |
| 892 checkedComponents.push(component); | |
| 893 if (!apiObject[component]) { | |
| 894 return null; | |
| 895 } | |
| 896 apiObject = apiObject[component]; | |
| 897 } | |
| 898 return apiObject; | |
| 899 } | |
| 900 | |
| 901 chrome.test.getConfig(function(config) { | |
| 902 console.error(config.customArg); | |
|
stevenjb
2016/12/09 23:29:04
Debugging?
tbarzic
2016/12/10 02:04:49
Done.
| |
| 903 var args = JSON.parse(config.customArg); | |
| 904 // Used for better error message in case API is not defined. | |
| 905 var checkedComponents = []; | |
| 906 NETWORKING_API = getApiObject(args.api, checkedComponents); | |
| 907 if (!NETWORKING_API) { | |
| 908 chrome.test.notifyFail('API not defined: ' + checkedComponents.join('.')); | |
| 909 return; | |
| 910 } | |
| 911 chrome.test.runTests(availableTests.filter(function(op) { | |
| 912 return args.tests.indexOf(op.name) > -1; | |
| 913 })); | |
| 914 }); | |
| OLD | NEW |