Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: chrome/browser/automation/testing_automation_provider_chromeos.cc

Issue 6732040: PyAuto automation hooks: blocking wifi connect, disconnect, and network scan. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial commit. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/automation/automation_provider_json.h" 8 #include "chrome/browser/automation/automation_provider_json.h"
9 #include "chrome/browser/automation/automation_provider_observers.h" 9 #include "chrome/browser/automation/automation_provider_observers.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chrome/browser/chromeos/cros/cros_library.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 item->SetString("roaming_state", 189 item->SetString("roaming_state",
190 cellular_networks[i]->GetRoamingStateString()); 190 cellular_networks[i]->GetRoamingStateString());
191 items->Append(item); 191 items->Append(item);
192 } 192 }
193 return_value->Set("cellular_networks", items); 193 return_value->Set("cellular_networks", items);
194 } 194 }
195 195
196 reply.SendSuccess(return_value.get()); 196 reply.SendSuccess(return_value.get());
197 } 197 }
198 198
199 void TestingAutomationProvider::NetworkScan(DictionaryValue* args,
200 IPC::Message* reply_message) {
201 AutomationJSONReply reply(this, reply_message);
202
203 if (!CrosLibrary::Get()->EnsureLoaded()) {
204 reply.SendError("Could not load cros library.");
205 return;
206 }
207
208 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
dennis_jeffrey 2011/03/24 23:48:54 Are we guaranteed that this variable will be non-N
dtu 2011/03/25 22:22:11 Yes, see stevenjb's comment.
209 network_library->RequestNetworkScan();
210
211 // Set up an observer (it will delete itself).
212 new NetworkScanObserver(this, reply_message);
213 }
214
199 void TestingAutomationProvider::ConnectToWifiNetwork( 215 void TestingAutomationProvider::ConnectToWifiNetwork(
200 DictionaryValue* args, IPC::Message* reply_message) { 216 DictionaryValue* args, IPC::Message* reply_message) {
201 AutomationJSONReply reply(this, reply_message); 217 AutomationJSONReply reply(this, reply_message);
202 std::string service_path, password, identity, certpath; 218 std::string service_path, password, identity, certpath;
203 if (!args->GetString("service_path", &service_path) || 219 if (!args->GetString("service_path", &service_path) ||
204 !args->GetString("password", &password) || 220 !args->GetString("password", &password) ||
205 !args->GetString("identity", &identity) || 221 !args->GetString("identity", &identity) ||
206 !args->GetString("certpath", &certpath)) { 222 !args->GetString("certpath", &certpath)) {
207 reply.SendError("Invalid or missing args"); 223 reply.SendError("Invalid or missing args");
208 return; 224 return;
209 } 225 }
210 226
211 if (!CrosLibrary::Get()->EnsureLoaded()) { 227 if (!CrosLibrary::Get()->EnsureLoaded()) {
212 reply.SendError("Could not load cros library."); 228 reply.SendError("Could not load cros library.");
213 return; 229 return;
214 } 230 }
215 231
216 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); 232 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
217 chromeos::WifiNetwork* wifi = 233 chromeos::WifiNetwork* wifi =
218 network_library->FindWifiNetworkByPath(service_path); 234 network_library->FindWifiNetworkByPath(service_path);
219 if (!wifi) { 235 if (!wifi) {
220 reply.SendError("Failed to connect"); 236 reply.SendError("No network found with specified service path.");
221 return; 237 return;
222 } 238 }
223 if (!password.empty()) 239 if (!password.empty())
224 wifi->SetPassphrase(password); 240 wifi->SetPassphrase(password);
225 if (!identity.empty()) 241 if (!identity.empty())
226 wifi->SetIdentity(identity); 242 wifi->SetIdentity(identity);
227 if (!certpath.empty()) 243 if (!certpath.empty())
228 wifi->SetCertPath(certpath); 244 wifi->SetCertPath(certpath);
245
246 // Set up an observer (it will delete itself).
247 new NetworkConnectObserver(this, reply_message, wifi);
stevenjb 2011/03/25 01:12:22 See my notes in NetworkConnectObserver, but we are
dtu 2011/03/25 22:22:11 Done.
248
229 network_library->ConnectToWifiNetwork(service_path); 249 network_library->ConnectToWifiNetwork(service_path);
stevenjb 2011/03/25 01:12:22 It is now valid and slightly more optimal to pass
dtu 2011/03/25 22:22:11 Done.
250 network_library->RequestNetworkScan();
251 }
230 252
231 // TODO(stevenjb): Observe the network library and check for a successful 253 void TestingAutomationProvider::DisconnectFromWifiNetwork(
232 // connection. 254 DictionaryValue* args, IPC::Message* reply_message) {
255 AutomationJSONReply reply(this, reply_message);
256 std::string service_path;
257 if (!args->GetString("service_path", &service_path)) {
258 reply.SendError("Invalid or missing args");
dennis_jeffrey 2011/03/24 23:48:54 Put period at end of the string sentence (to be co
dtu 2011/03/25 22:22:11 Done.
259 return;
260 }
233 261
262 if (!CrosLibrary::Get()->EnsureLoaded()) {
263 reply.SendError("Could not load cros library.");
264 return;
265 }
266
267 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
dennis_jeffrey 2011/03/24 23:48:54 Same comment as line 208 above.
dtu 2011/03/25 22:22:11 Same reply as line 208 above.
268 chromeos::WifiNetwork* wifi =
269 network_library->FindWifiNetworkByPath(service_path);
270 if (!wifi) {
271 reply.SendError("No network found with specified service path.");
272 return;
273 }
274
275 network_library->DisconnectFromWirelessNetwork(wifi);
234 reply.SendSuccess(NULL); 276 reply.SendSuccess(NULL);
235 } 277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698