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 var callbackPass = chrome.test.callbackPass; | 5 var callbackPass = chrome.test.callbackPass; |
6 var callbackFail = chrome.test.callbackFail; | 6 var callbackFail = chrome.test.callbackFail; |
7 var assertTrue = chrome.test.assertTrue; | 7 var assertTrue = chrome.test.assertTrue; |
8 var assertEq = chrome.test.assertEq; | 8 var assertEq = chrome.test.assertEq; |
9 | 9 |
10 // Test properties for the verification API. | 10 // Test properties for the verification API. |
11 var verificationProperties = { | 11 var verificationProperties = { |
12 "certificate": "certificate", | 12 "certificate": "certificate", |
13 "publicKey": "public_key", | 13 "publicKey": "public_key", |
14 "nonce": "nonce", | 14 "nonce": "nonce", |
15 "signedData": "signed_data", | 15 "signedData": "signed_data", |
16 "deviceSerial": "device_serial" | 16 "deviceSerial": "device_serial" |
17 }; | 17 }; |
18 | 18 |
19 var privateHelpers = { | 19 var privateHelpers = { |
20 // Watches for the states |expectedStates| in reverse order. If all states | 20 // Watches for the states |expectedStates| in reverse order. If all states |
21 // were observed in the right order, succeeds and calls |done|. If any | 21 // were observed in the right order, succeeds and calls |done|. If any |
22 // unexpected state is observed, fails. | 22 // unexpected state is observed, fails. |
23 watchForStateChanges: function(network, expectedStates, done) { | 23 watchForStateChanges: function(network, expectedStates, done) { |
24 var self = this; | 24 var self = this; |
25 var collectProperties = function(properties) { | 25 var collectProperties = function(properties) { |
26 var finishTest = function() { | 26 var finishTest = function() { |
27 chrome.networkingPrivate.onNetworksChanged.removeListener( | 27 chrome.networkingPrivate.onNetworksChanged.removeListener( |
28 self.watchForConnect); | 28 self.onNetworkChange); |
29 done(); | 29 done(); |
30 }; | 30 }; |
31 var expectedState = expectedStates.pop(); | 31 var expectedState = expectedStates.pop(); |
32 assertEq(expectedState, properties.ConnectionState); | 32 assertEq(expectedState, properties.ConnectionState); |
33 if (expectedStates.length == 0) | 33 if (expectedStates.length == 0) |
34 finishTest(); | 34 finishTest(); |
35 }; | 35 }; |
36 this.onNetworkChange = function(changes) { | 36 this.onNetworkChange = function(changes) { |
37 assertEq([network], changes); | 37 assertEq([network], changes); |
38 chrome.networkingPrivate.getProperties(network, | 38 chrome.networkingPrivate.getProperties( |
39 collectProperties.bind(undefined)); | 39 network, |
| 40 callbackPass(collectProperties)); |
40 }; | 41 }; |
41 chrome.networkingPrivate.onNetworksChanged.addListener( | 42 chrome.networkingPrivate.onNetworksChanged.addListener( |
42 this.onNetworkChange); | 43 this.onNetworkChange); |
43 }, | 44 }, |
44 listListener: function(network, expected, done) { | 45 listListener: function(network, expected, done) { |
45 var self = this; | 46 var self = this; |
46 this.listenForChanges = function(list) { | 47 this.listenForChanges = function(list) { |
47 assertEq(expected, list); | 48 assertEq(expected, list); |
48 chrome.networkingPrivate.onNetworkListChanged.removeListener( | 49 chrome.networkingPrivate.onNetworkListChanged.removeListener( |
49 self.listenForChanges); | 50 self.listenForChanges); |
50 done(); | 51 done(); |
51 }; | 52 }; |
52 } | 53 } |
53 }; | 54 }; |
54 | 55 |
55 var availableTests = [ | 56 var availableTests = [ |
56 function startConnect() { | 57 function startConnect() { |
57 chrome.networkingPrivate.startConnect("stub_wifi2", callbackPass()); | 58 chrome.networkingPrivate.startConnect("stub_wifi2", callbackPass()); |
58 }, | 59 }, |
59 function startDisconnect() { | 60 function startDisconnect() { |
(...skipping 11 matching lines...) Expand all Loading... |
71 }, | 72 }, |
72 function startGetPropertiesNonexistent() { | 73 function startGetPropertiesNonexistent() { |
73 chrome.networkingPrivate.getProperties( | 74 chrome.networkingPrivate.getProperties( |
74 "nonexistent_path", | 75 "nonexistent_path", |
75 callbackFail("Error.DBusFailed")); | 76 callbackFail("Error.DBusFailed")); |
76 }, | 77 }, |
77 function getVisibleNetworks() { | 78 function getVisibleNetworks() { |
78 chrome.networkingPrivate.getVisibleNetworks( | 79 chrome.networkingPrivate.getVisibleNetworks( |
79 "All", | 80 "All", |
80 callbackPass(function(result) { | 81 callbackPass(function(result) { |
81 assertTrue(!!result); | |
82 assertEq([{ | 82 assertEq([{ |
83 "ConnectionState": "Connected", | 83 "ConnectionState": "Connected", |
84 "GUID": "stub_ethernet", | 84 "GUID": "stub_ethernet", |
85 "Name": "eth0", | 85 "Name": "eth0", |
86 "Type": "Ethernet" | 86 "Type": "Ethernet" |
87 }, | 87 }, |
88 { | 88 { |
89 "ConnectionState": "Connected", | 89 "ConnectionState": "Connected", |
90 "GUID": "stub_wifi1", | 90 "GUID": "stub_wifi1", |
91 "Name": "wifi1", | 91 "Name": "wifi1", |
(...skipping 10 matching lines...) Expand all Loading... |
102 "Name": "wifi2_PSK", | 102 "Name": "wifi2_PSK", |
103 "Type": "WiFi", | 103 "Type": "WiFi", |
104 "WiFi": { | 104 "WiFi": { |
105 "AutoConnect": false, | 105 "AutoConnect": false, |
106 "Security": "WPA-PSK", | 106 "Security": "WPA-PSK", |
107 "SignalStrength": 80 | 107 "SignalStrength": 80 |
108 } | 108 } |
109 }, | 109 }, |
110 { | 110 { |
111 "Cellular": { | 111 "Cellular": { |
| 112 "ActivateOverNonCellularNetwork": false, |
112 "ActivationState": "not-activated", | 113 "ActivationState": "not-activated", |
113 "NetworkTechnology": "GSM", | 114 "NetworkTechnology": "GSM", |
114 "RoamingState": "home" | 115 "RoamingState": "home" |
115 }, | 116 }, |
116 "ConnectionState": "NotConnected", | 117 "ConnectionState": "NotConnected", |
117 "GUID": "stub_cellular1", | 118 "GUID": "stub_cellular1", |
118 "Name": "cellular1", | 119 "Name": "cellular1", |
119 "Type": "Cellular" | 120 "Type": "Cellular" |
120 }, | 121 }, |
121 { | 122 { |
122 "ConnectionState": "Connected", | 123 "ConnectionState": "Connected", |
123 "GUID": "stub_vpn1", | 124 "GUID": "stub_vpn1", |
124 "Name": "vpn1", | 125 "Name": "vpn1", |
125 "Type": "VPN", | 126 "Type": "VPN", |
126 "VPN": { | 127 "VPN": { |
127 "AutoConnect": false | 128 "AutoConnect": false |
128 } | 129 } |
129 }], result); | 130 }], result); |
130 })); | 131 })); |
131 }, | 132 }, |
132 function getVisibleNetworksWifi() { | 133 function getVisibleNetworksWifi() { |
133 chrome.networkingPrivate.getVisibleNetworks( | 134 chrome.networkingPrivate.getVisibleNetworks( |
134 "WiFi", | 135 "WiFi", |
135 callbackPass(function(result) { | 136 callbackPass(function(result) { |
136 assertTrue(!!result); | |
137 assertEq([{ | 137 assertEq([{ |
138 "ConnectionState": "Connected", | 138 "ConnectionState": "Connected", |
139 "GUID": "stub_wifi1", | 139 "GUID": "stub_wifi1", |
140 "Name": "wifi1", | 140 "Name": "wifi1", |
141 "Type": "WiFi", | 141 "Type": "WiFi", |
142 "WiFi": { | 142 "WiFi": { |
143 "AutoConnect": false, | 143 "AutoConnect": false, |
144 "Security": "WEP-PSK", | 144 "Security": "WEP-PSK", |
145 "SignalStrength": 0 | 145 "SignalStrength": 0 |
146 } | 146 } |
(...skipping 22 matching lines...) Expand all Loading... |
169 var done = chrome.test.callbackAdded(); | 169 var done = chrome.test.callbackAdded(); |
170 var listener = new privateHelpers.listListener(network, expected, done); | 170 var listener = new privateHelpers.listListener(network, expected, done); |
171 chrome.networkingPrivate.onNetworkListChanged.addListener( | 171 chrome.networkingPrivate.onNetworkListChanged.addListener( |
172 listener.listenForChanges); | 172 listener.listenForChanges); |
173 chrome.networkingPrivate.requestNetworkScan(); | 173 chrome.networkingPrivate.requestNetworkScan(); |
174 }, | 174 }, |
175 function getProperties() { | 175 function getProperties() { |
176 chrome.networkingPrivate.getProperties( | 176 chrome.networkingPrivate.getProperties( |
177 "stub_wifi2", | 177 "stub_wifi2", |
178 callbackPass(function(result) { | 178 callbackPass(function(result) { |
179 assertTrue(!!result); | |
180 assertEq({ | 179 assertEq({ |
181 "ConnectionState": "NotConnected", | 180 "ConnectionState": "NotConnected", |
182 "GUID": "stub_wifi2", | 181 "GUID": "stub_wifi2", |
183 "Name": "wifi2_PSK", | 182 "Name": "wifi2_PSK", |
184 "Type": "WiFi", | 183 "Type": "WiFi", |
185 "WiFi": { | 184 "WiFi": { |
186 "SSID": "stub_wifi2", | 185 "SSID": "stub_wifi2", |
187 "Security": "WPA-PSK", | 186 "Security": "WPA-PSK", |
188 "SignalStrength": 80 | 187 "SignalStrength": 80 |
189 } | 188 } |
190 }, result); | 189 }, result); |
191 })); | 190 })); |
192 }, | 191 }, |
| 192 function getManagedProperties() { |
| 193 chrome.networkingPrivate.getManagedProperties( |
| 194 "stub_wifi2", |
| 195 callbackPass(function(result) { |
| 196 assertEq({ |
| 197 "ConnectionState": { |
| 198 "Active": "NotConnected", |
| 199 "Effective": "Unmanaged" |
| 200 }, |
| 201 "GUID": "stub_wifi2", |
| 202 "Name": { |
| 203 "Active": "wifi2_PSK", |
| 204 "Effective": "UserPolicy", |
| 205 "UserPolicy": "My WiFi Network" |
| 206 }, |
| 207 "Type": { |
| 208 "Active": "WiFi", |
| 209 "Effective": "UserPolicy", |
| 210 "UserPolicy": "WiFi" |
| 211 }, |
| 212 "WiFi": { |
| 213 "AutoConnect": { |
| 214 "Active": false, |
| 215 "UserEditable": true |
| 216 }, |
| 217 "Passphrase": { |
| 218 "Effective": "UserSetting", |
| 219 "UserEditable": true, |
| 220 "UserSetting": "FAKE_CREDENTIAL_VPaJDV9x" |
| 221 }, |
| 222 "SSID": { |
| 223 "Active": "stub_wifi2", |
| 224 "Effective": "UserPolicy", |
| 225 "UserPolicy": "stub_wifi2" |
| 226 }, |
| 227 "Security": { |
| 228 "Active": "WPA-PSK", |
| 229 "Effective": "UserPolicy", |
| 230 "UserPolicy": "WPA-PSK" |
| 231 }, |
| 232 "SignalStrength": { |
| 233 "Active": 80, |
| 234 "Effective": "Unmanaged" |
| 235 } |
| 236 } |
| 237 }, result); |
| 238 })); |
| 239 }, |
193 function setProperties() { | 240 function setProperties() { |
194 var done = chrome.test.callbackAdded(); | 241 var done = chrome.test.callbackAdded(); |
195 chrome.networkingPrivate.getProperties( | 242 chrome.networkingPrivate.getProperties( |
196 "stub_wifi2", | 243 "stub_wifi2", |
197 function(result) { | 244 callbackPass(function(result) { |
198 result.WiFi.Security = "WEP-PSK"; | 245 result.WiFi.Security = "WEP-PSK"; |
199 chrome.networkingPrivate.setProperties("stub_wifi2", result, | 246 chrome.networkingPrivate.setProperties("stub_wifi2", result, |
200 function() { | 247 callbackPass(function() { |
201 chrome.networkingPrivate.getProperties( | 248 chrome.networkingPrivate.getProperties( |
202 "stub_wifi2", | 249 "stub_wifi2", |
203 function(result) { | 250 callbackPass(function(result) { |
204 assertEq("WEP-PSK", result.WiFi.Security); | 251 assertEq("WEP-PSK", result.WiFi.Security); |
205 done(); | 252 done(); |
206 }); | 253 })); |
207 }); | 254 })); |
208 }); | 255 })); |
209 }, | 256 }, |
210 function getState() { | 257 function getState() { |
211 chrome.networkingPrivate.getState( | 258 chrome.networkingPrivate.getState( |
212 "stub_wifi2", | 259 "stub_wifi2", |
213 callbackPass(function(result) { | 260 callbackPass(function(result) { |
214 assertEq({ | 261 assertEq({ |
215 "ConnectionState": "NotConnected", | 262 "ConnectionState": "NotConnected", |
216 "GUID": "", | 263 "GUID": "stub_wifi2", |
217 "Name": "wifi2_PSK", | 264 "Name": "wifi2_PSK", |
218 "Type": "WiFi", | 265 "Type": "WiFi", |
219 "WiFi": { | 266 "WiFi": { |
220 "AutoConnect": false, | 267 "AutoConnect": false, |
221 "Security": "WPA-PSK", | 268 "Security": "WPA-PSK", |
222 "SignalStrength": 80 | 269 "SignalStrength": 80 |
223 } | 270 } |
224 }, result); | 271 }, result); |
225 })); | 272 })); |
226 }, | 273 }, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 callbackPass(function(result) { | 322 callbackPass(function(result) { |
276 assertEq("encrypted_data", result); | 323 assertEq("encrypted_data", result); |
277 })); | 324 })); |
278 } | 325 } |
279 ]; | 326 ]; |
280 | 327 |
281 var testToRun = window.location.search.substring(1); | 328 var testToRun = window.location.search.substring(1); |
282 chrome.test.runTests(availableTests.filter(function(op) { | 329 chrome.test.runTests(availableTests.filter(function(op) { |
283 return op.name == testToRun; | 330 return op.name == testToRun; |
284 })); | 331 })); |
OLD | NEW |