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 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 chrome.test.runTests([ | 10 function connectListener_(network, done) { |
|
not at google - send to devlin
2013/02/12 22:07:25
why the trailing _?
Greg Spencer (Chromium)
2013/02/12 23:11:02
Because I was trying to indicate that these were "
| |
| 11 function getVisibleNetworks() { | 11 var self = this; |
| 12 var collectProperties_ = function(testingConnect, properties) { | |
| 13 var finishTest = function() { | |
|
not at google - send to devlin
2013/02/12 22:07:25
just 2 space indent
Greg Spencer (Chromium)
2013/02/12 23:11:02
Done.
| |
| 14 chrome.networkingPrivate.onNetworksChanged.removeListener( | |
|
not at google - send to devlin
2013/02/12 22:07:25
just 2 space indent
Greg Spencer (Chromium)
2013/02/12 23:11:02
Done.
| |
| 15 self.watchForConnect); | |
| 16 done(); | |
| 17 } | |
|
not at google - send to devlin
2013/02/12 22:07:25
semicolon after all of these
Greg Spencer (Chromium)
2013/02/12 23:11:02
Done.
| |
| 18 var startDisconnect = function() { | |
| 19 chrome.networkingPrivate.startDisconnect( | |
| 20 network, | |
| 21 callbackPass(function() {})); | |
| 22 } | |
| 23 var startConnect = function() { | |
| 24 chrome.networkingPrivate.startConnect( | |
| 25 network, | |
| 26 callbackPass(function() {})); | |
| 27 } | |
| 28 if (properties.ConnectionState == "NotConnected") { | |
| 29 if (testingConnect) | |
|
not at google - send to devlin
2013/02/12 22:07:25
I don't understand what this testingConnect is sup
Greg Spencer (Chromium)
2013/02/12 23:11:02
I'll see if I can change the name to something mor
| |
| 30 finishTest(); | |
| 31 else | |
| 32 startConnect(); | |
| 33 } | |
| 34 if (properties.ConnectionState == "Connected") { | |
| 35 if (testingConnect) | |
| 36 startDisconnect(); | |
| 37 else | |
| 38 finishTest(); | |
| 39 } | |
| 40 } | |
|
not at google - send to devlin
2013/02/12 22:07:25
semicolon, 2 space indent after all of these
Greg Spencer (Chromium)
2013/02/12 23:11:02
Done.
| |
| 41 this.watchForConnect = function(changes) { | |
| 42 assertEq([network], changes); | |
| 43 chrome.networkingPrivate.getProperties( | |
| 44 network, collectProperties_.bind(undefined, true)); | |
| 45 } | |
| 46 this.watchForDisconnect = function(changes) { | |
| 47 assertEq([network], changes); | |
| 48 chrome.networkingPrivate.getProperties( | |
| 49 network, collectProperties_.bind(undefined, false)); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 function listListener_(network, expected, done) { | |
|
not at google - send to devlin
2013/02/12 22:07:25
ditto all the stuff above.
Actually they apply to
| |
| 54 var self = this; | |
| 55 this.listenForChanges = function(list) { | |
| 56 assertEq(expected, list); | |
| 57 chrome.networkingPrivate.onNetworkListChanged.removeListener( | |
| 58 self.listenForChanges); | |
| 59 done(); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 ///////////////////////////////////////////////////// | |
| 64 // Tests | |
| 65 | |
| 66 function startConnect() { | |
| 67 chrome.networkingPrivate.startConnect("stub_wifi2", | |
| 68 callbackPass(function() {})); | |
| 69 } | |
| 70 | |
| 71 function startDisconnect() { | |
| 72 chrome.networkingPrivate.startDisconnect("stub_wifi2", | |
| 73 callbackPass(function() {})); | |
| 74 } | |
| 75 | |
| 76 function startConnectNonexistent() { | |
| 77 // Make sure we get an error when we try to connect to a nonexistent | |
| 78 // network. | |
| 79 chrome.networkingPrivate.startConnect( | |
| 80 "nonexistent_path", | |
| 81 callbackFail("Error.InvalidService", function() {})); | |
| 82 } | |
| 83 | |
| 84 function getVisibleNetworks() { | |
| 12 chrome.networkingPrivate.getVisibleNetworks( | 85 chrome.networkingPrivate.getVisibleNetworks( |
| 13 "All", | 86 "All", |
| 14 callbackPass(function(result) { | 87 callbackPass(function(result) { |
| 15 assertTrue(!!result); | 88 assertTrue(!!result); |
| 16 assertEq(4, result.length); | 89 assertEq(4, result.length); |
| 17 assertEq([{ "Name": "eth0", | 90 assertEq([ |
| 18 "GUID": "stub_ethernet", | 91 { |
| 19 "ConnectionState": "Connected", | 92 "ConnectionState": "Connected", |
| 20 "Type": "Ethernet" | 93 "GUID": "stub_ethernet", |
| 21 }, | 94 "Name": "eth0", |
| 22 { "Name": "wifi1", | 95 "Type": "Ethernet" |
| 23 "GUID": "stub_wifi1", | 96 }, |
| 24 "ConnectionState": "Connected", | 97 { |
| 25 "Type": "WiFi", | 98 "ConnectionState": "Connected", |
| 26 "WiFi": { | 99 "GUID": "stub_wifi1", |
| 100 "Name": "wifi1", | |
| 101 "Type": "WiFi", | |
| 102 "WiFi": { | |
| 27 "SSID": "stub_wifi1", | 103 "SSID": "stub_wifi1", |
| 28 "Type": "WiFi" | 104 "Type": "WiFi" |
| 29 } | 105 } |
| 30 }, | 106 }, |
| 31 { "Name": "wifi2_PSK", | 107 { |
| 32 "GUID": "stub_wifi2", | 108 "ConnectionState": "NotConnected", |
| 33 "ConnectionState": "NotConnected", | 109 "GUID": "stub_wifi2", |
| 34 "Type": "WiFi", | 110 "Name": "wifi2_PSK", |
| 35 "WiFi": { | 111 "Type": "WiFi", |
| 112 "WiFi": { | |
| 36 "SSID": "stub_wifi2", | 113 "SSID": "stub_wifi2", |
| 37 "Type": "WiFi" | 114 "Type": "WiFi" |
| 38 } | 115 } |
| 39 }, | 116 }, |
| 40 { "Name": "cellular1", | 117 { |
| 41 "GUID": "stub_cellular1", | 118 "ConnectionState": "NotConnected", |
| 42 "ConnectionState": "NotConnected", | 119 "GUID": "stub_cellular1", |
| 43 "Type": "Cellular" | 120 "Name": "cellular1", |
| 44 }], result); | 121 "Type": "Cellular" |
| 122 } | |
| 123 ], result); | |
| 45 })); | 124 })); |
| 46 }, | 125 } |
| 47 function getVisibleNetworksWifi() { | 126 |
| 127 function getVisibleNetworksWifi() { | |
| 48 chrome.networkingPrivate.getVisibleNetworks( | 128 chrome.networkingPrivate.getVisibleNetworks( |
| 49 "WiFi", | 129 "WiFi", |
| 50 callbackPass(function(result) { | 130 callbackPass(function(result) { |
| 51 assertTrue(!!result); | 131 assertTrue(!!result); |
| 52 assertEq(2, result.length); | 132 assertEq(2, result.length); |
| 53 assertEq([{ "Name": "wifi1", | 133 assertEq([ |
| 134 { | |
| 135 "ConnectionState": "Connected", | |
| 54 "GUID": "stub_wifi1", | 136 "GUID": "stub_wifi1", |
| 55 "ConnectionState": "Connected", | 137 "Name": "wifi1", |
| 56 "Type": "WiFi", | 138 "Type": "WiFi", |
| 57 "WiFi": { | 139 "WiFi": { |
| 58 "SSID": "stub_wifi1", | 140 "SSID": "stub_wifi1", |
| 59 "Type":"WiFi" | 141 "Type": "WiFi" |
| 60 } | 142 } |
| 61 }, | 143 }, |
| 62 { "Name": "wifi2_PSK", | 144 { |
| 145 "ConnectionState": "NotConnected", | |
| 63 "GUID": "stub_wifi2", | 146 "GUID": "stub_wifi2", |
| 64 "ConnectionState": "NotConnected", | 147 "Name": "wifi2_PSK", |
| 65 "Type": "WiFi", | 148 "Type": "WiFi", |
| 66 "WiFi": { | 149 "WiFi": { |
| 67 "SSID": "stub_wifi2", | 150 "SSID": "stub_wifi2", |
| 68 "Type": "WiFi" | 151 "Type": "WiFi" |
| 69 } | 152 } |
| 70 }], result); | 153 } |
| 71 })); | 154 ], result); |
| 72 }, | 155 })); |
| 73 function getProperties() { | 156 } |
| 157 | |
| 158 function getProperties() { | |
| 74 chrome.networkingPrivate.getProperties( | 159 chrome.networkingPrivate.getProperties( |
| 75 "stub_wifi2", | 160 "stub_wifi2", |
| 76 callbackPass(function(result) { | 161 callbackPass(function(result) { |
| 77 assertTrue(!!result); | 162 assertTrue(!!result); |
| 78 assertEq("wifi2_PSK", result.Name); | 163 assertEq("wifi2_PSK", result.Name); |
| 79 assertEq("NotConnected", result.ConnectionState); | 164 assertEq("NotConnected", result.ConnectionState); |
| 80 assertEq("WiFi", result.Type); | 165 assertEq("WiFi", result.Type); |
| 81 })); | 166 })); |
| 82 }, | 167 } |
| 83 function startConnect() { | 168 |
| 84 chrome.networkingPrivate.startConnect("stub_wifi2", | 169 function onNetworksChangedEvent() { |
| 170 var network = "stub_wifi2"; | |
| 171 var done = chrome.test.callbackAdded(); | |
| 172 var listener = new connectListener_(network, done); | |
| 173 chrome.networkingPrivate.onNetworksChanged.addListener( | |
| 174 listener.watchForConnect); | |
| 175 chrome.networkingPrivate.startConnect(network, | |
| 85 callbackPass(function() {})); | 176 callbackPass(function() {})); |
| 86 }, | 177 } |
| 87 function startDisconnect() { | 178 |
| 88 chrome.networkingPrivate.startDisconnect("stub_wifi2", | 179 function onNetworkListChangedEvent() { |
| 89 callbackPass(function() {})); | 180 var network = "stub_wifi2"; |
| 90 }, | 181 var expected = ["stub_wifi2","stub_ethernet", "stub_wifi1", |
| 91 function startConnectNonexistent() { | 182 "stub_cellular1"]; |
| 92 // Make sure we get an error when we try to connect to a nonexistent | 183 var done = chrome.test.callbackAdded(); |
| 93 // network. | 184 var listener = new listListener_(network, expected, done); |
| 94 chrome.networkingPrivate.startConnect( | 185 chrome.networkingPrivate.onNetworkListChanged.addListener( |
| 95 "nonexistent_path", | 186 listener.listenForChanges); |
| 96 callbackFail("Error.InvalidService", function() {})); | 187 chrome.networkingPrivate.startConnect(network, |
| 97 } | 188 callbackPass(function() {})); |
| 98 ]); | 189 } |
| 190 | |
| 191 var testToRun = window.location.hash.substring(1); | |
|
not at google - send to devlin
2013/02/12 22:07:25
query string seems more idiomatic but it's also mo
Greg Spencer (Chromium)
2013/02/12 23:11:02
Not really. I can switch to query string if you w
not at google - send to devlin
2013/02/12 23:36:09
nah never mind.
| |
| 192 chrome.test.runTests([window[testToRun]]); | |
|
not at google - send to devlin
2013/02/12 22:07:25
prefer to put the tests on a separate object rathe
Greg Spencer (Chromium)
2013/02/12 23:11:02
Yeah, I'd prefer that too, and started off with th
not at google - send to devlin
2013/02/12 23:36:09
I think that window[testToRun] is the greater evil
| |
| OLD | NEW |