Fix build break
[chromium-blink-merge.git] / chrome / browser / automation / testing_automation_provider_chromeos.cc
blobce7d871d9f406836d8e4eb792834176ac23b1644
1 // Copyright (c) 2012 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 #include "chrome/browser/automation/testing_automation_provider.h"
7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h"
9 #include "ash/system/tray/system_tray_delegate.h"
10 #include "base/command_line.h"
11 #include "base/i18n/time_formatting.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/stringprintf.h"
14 #include "base/time.h"
15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/automation/automation_provider_json.h"
17 #include "chrome/browser/automation/automation_provider_observers.h"
18 #include "chrome/browser/automation/automation_util.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
21 #include "chrome/browser/chromeos/audio/audio_handler.h"
22 #include "chrome/browser/chromeos/cros/cros_library.h"
23 #include "chrome/browser/chromeos/cros/network_library.h"
24 #include "chrome/browser/chromeos/login/default_user_images.h"
25 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen.h"
26 #include "chrome/browser/chromeos/login/existing_user_controller.h"
27 #include "chrome/browser/chromeos/login/login_display.h"
28 #include "chrome/browser/chromeos/login/login_display_host.h"
29 #include "chrome/browser/chromeos/login/screen_locker.h"
30 #include "chrome/browser/chromeos/login/screens/eula_screen.h"
31 #include "chrome/browser/chromeos/login/screens/network_screen.h"
32 #include "chrome/browser/chromeos/login/screens/update_screen.h"
33 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
34 #include "chrome/browser/chromeos/login/webui_login_display.h"
35 #include "chrome/browser/chromeos/login/webui_login_display_host.h"
36 #include "chrome/browser/chromeos/login/wizard_controller.h"
37 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
38 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
39 #include "chrome/browser/chromeos/settings/cros_settings.h"
40 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
41 #include "chrome/browser/chromeos/system/timezone_settings.h"
42 #include "chrome/browser/ui/browser.h"
43 #include "chrome/browser/ui/browser_window.h"
44 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
45 #include "chrome/common/pref_names.h"
46 #include "chromeos/dbus/dbus_thread_manager.h"
47 #include "chromeos/dbus/power_manager_client.h"
48 #include "chromeos/dbus/session_manager_client.h"
49 #include "chromeos/dbus/update_engine_client.h"
50 #include "content/public/browser/web_contents.h"
51 #include "net/base/network_change_notifier.h"
52 #include "policy/policy_constants.h"
53 #include "ui/views/widget/widget.h"
55 using chromeos::CrosLibrary;
56 using chromeos::DBusThreadManager;
57 using chromeos::ExistingUserController;
58 using chromeos::NetworkLibrary;
59 using chromeos::UpdateEngineClient;
60 using chromeos::User;
61 using chromeos::UserManager;
62 using chromeos::WizardController;
64 namespace {
66 DictionaryValue* GetNetworkInfoDict(const chromeos::Network* network) {
67 DictionaryValue* item = new DictionaryValue;
68 item->SetString("name", network->name());
69 item->SetString("device_path", network->device_path());
70 item->SetString("ip_address", network->ip_address());
71 item->SetString("status", network->GetStateString());
72 return item;
75 DictionaryValue* GetWifiInfoDict(const chromeos::WifiNetwork* wifi) {
76 DictionaryValue* item = GetNetworkInfoDict(wifi);
77 item->SetInteger("strength", wifi->strength());
78 item->SetBoolean("encrypted", wifi->encrypted());
79 item->SetString("encryption", wifi->GetEncryptionString());
80 return item;
83 base::Value* GetProxySetting(const std::string& setting_name,
84 Profile* profile) {
85 std::string setting_path = "cros.session.proxy.";
86 setting_path.append(setting_name);
87 base::Value* setting;
88 if (chromeos::proxy_cros_settings_parser::GetProxyPrefValue(
89 profile, setting_path, &setting)) {
90 scoped_ptr<DictionaryValue> setting_dict(
91 static_cast<DictionaryValue*>(setting));
92 base::Value* value;
93 if (setting_dict->Remove("value", &value))
94 return value;
97 return NULL;
100 const char* UpdateStatusToString(
101 UpdateEngineClient::UpdateStatusOperation status) {
102 switch (status) {
103 case UpdateEngineClient::UPDATE_STATUS_IDLE:
104 return "idle";
105 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE:
106 return "checking for update";
107 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE:
108 return "update available";
109 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING:
110 return "downloading";
111 case UpdateEngineClient::UPDATE_STATUS_VERIFYING:
112 return "verifying";
113 case UpdateEngineClient::UPDATE_STATUS_FINALIZING:
114 return "finalizing";
115 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT:
116 return "updated need reboot";
117 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT:
118 return "reporting error event";
119 default:
120 return "unknown";
124 void GetReleaseTrackCallback(AutomationJSONReply* reply,
125 const std::string& track) {
126 if (track.empty()) {
127 reply->SendError("Unable to get release track.");
128 delete reply;
129 return;
132 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
133 return_value->SetString("release_track", track);
135 const UpdateEngineClient::Status& status =
136 DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus();
137 UpdateEngineClient::UpdateStatusOperation update_status =
138 status.status;
139 return_value->SetString("status", UpdateStatusToString(update_status));
140 if (update_status == UpdateEngineClient::UPDATE_STATUS_DOWNLOADING)
141 return_value->SetDouble("download_progress", status.download_progress);
142 if (status.last_checked_time > 0)
143 return_value->SetInteger("last_checked_time", status.last_checked_time);
144 if (status.new_size > 0)
145 return_value->SetInteger("new_size", status.new_size);
147 reply->SendSuccess(return_value.get());
148 delete reply;
151 void UpdateCheckCallback(AutomationJSONReply* reply,
152 UpdateEngineClient::UpdateCheckResult result) {
153 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS)
154 reply->SendSuccess(NULL);
155 else
156 reply->SendError("update check failed");
157 delete reply;
160 const std::string VPNProviderTypeToString(
161 chromeos::ProviderType provider_type) {
162 switch (provider_type) {
163 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK:
164 return std::string("L2TP_IPSEC_PSK");
165 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT:
166 return std::string("L2TP_IPSEC_USER_CERT");
167 case chromeos::PROVIDER_TYPE_OPEN_VPN:
168 return std::string("OPEN_VPN");
169 default:
170 return std::string("UNSUPPORTED_PROVIDER_TYPE");
174 // Last reported power status.
175 chromeos::PowerSupplyStatus global_power_status;
177 } // namespace
179 class PowerManagerClientObserverForTesting
180 : public chromeos::PowerManagerClient::Observer {
181 public:
182 virtual ~PowerManagerClientObserverForTesting() {}
184 virtual void PowerChanged(const chromeos::PowerSupplyStatus& status)
185 OVERRIDE {
186 global_power_status = status;
190 void TestingAutomationProvider::AcceptOOBENetworkScreen(
191 DictionaryValue* args,
192 IPC::Message* reply_message) {
193 WizardController* wizard_controller = WizardController::default_controller();
194 if (!wizard_controller || wizard_controller->current_screen()->GetName() !=
195 WizardController::kNetworkScreenName) {
196 AutomationJSONReply(this, reply_message).SendError(
197 "Network screen not active.");
198 return;
200 // Observer will delete itself.
201 new WizardControllerObserver(wizard_controller, this, reply_message);
202 wizard_controller->GetNetworkScreen()->OnContinuePressed();
205 void TestingAutomationProvider::AcceptOOBEEula(DictionaryValue* args,
206 IPC::Message* reply_message) {
207 bool accepted;
208 bool usage_stats_reporting;
209 if (!args->GetBoolean("accepted", &accepted) ||
210 !args->GetBoolean("usage_stats_reporting", &usage_stats_reporting)) {
211 AutomationJSONReply(this, reply_message).SendError(
212 "Invalid or missing args.");
213 return;
216 WizardController* wizard_controller = WizardController::default_controller();
217 if (!wizard_controller || wizard_controller->current_screen()->GetName() !=
218 WizardController::kEulaScreenName) {
219 AutomationJSONReply(this, reply_message).SendError(
220 "EULA screen not active.");
221 return;
223 // Observer will delete itself.
224 new WizardControllerObserver(wizard_controller, this, reply_message);
225 wizard_controller->GetEulaScreen()->OnExit(accepted, usage_stats_reporting);
228 void TestingAutomationProvider::CancelOOBEUpdate(DictionaryValue* args,
229 IPC::Message* reply_message) {
230 WizardController* wizard_controller = WizardController::default_controller();
231 if (wizard_controller && wizard_controller->IsOobeCompleted()) {
232 // Update already finished.
233 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
234 return_value->SetString("next_screen",
235 WizardController::kLoginScreenName);
236 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
237 return;
239 if (!wizard_controller || wizard_controller->current_screen()->GetName() !=
240 WizardController::kUpdateScreenName) {
241 AutomationJSONReply(this, reply_message).SendError(
242 "Update screen not active.");
243 return;
245 // Observer will delete itself.
246 new WizardControllerObserver(wizard_controller, this, reply_message);
247 wizard_controller->GetUpdateScreen()->CancelUpdate();
250 void TestingAutomationProvider::GetLoginInfo(DictionaryValue* args,
251 IPC::Message* reply_message) {
252 AutomationJSONReply reply(this, reply_message);
253 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
255 const UserManager* user_manager = UserManager::Get();
256 if (!user_manager)
257 reply.SendError("No user manager!");
258 const chromeos::ScreenLocker* screen_locker =
259 chromeos::ScreenLocker::default_screen_locker();
261 return_value->SetString("login_ui_type", "webui");
262 return_value->SetBoolean("is_owner", user_manager->IsCurrentUserOwner());
263 return_value->SetBoolean("is_logged_in", user_manager->IsUserLoggedIn());
264 return_value->SetBoolean("is_screen_locked", screen_locker);
265 if (user_manager->IsUserLoggedIn()) {
266 const User* user = user_manager->GetLoggedInUser();
267 return_value->SetBoolean("is_guest", user_manager->IsLoggedInAsGuest());
268 return_value->SetString("email", user->email());
269 return_value->SetString("display_email", user->display_email());
270 switch (user->image_index()) {
271 case User::kExternalImageIndex:
272 return_value->SetString("user_image", "file");
273 break;
275 case User::kProfileImageIndex:
276 return_value->SetString("user_image", "profile");
277 break;
279 default:
280 return_value->SetInteger("user_image", user->image_index());
281 break;
285 reply.SendSuccess(return_value.get());
288 // See the note under LoginAsGuest(). CreateAccount() causes a login as guest.
289 void TestingAutomationProvider::ShowCreateAccountUI(
290 DictionaryValue* args, IPC::Message* reply_message) {
291 ExistingUserController* controller =
292 ExistingUserController::current_controller();
293 // Return immediately, since we're going to die before the login is finished.
294 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
295 controller->CreateAccount();
298 // Logging in as guest will cause session_manager to restart Chrome with new
299 // flags. If you used EnableChromeTesting, you will have to call it again.
300 void TestingAutomationProvider::LoginAsGuest(DictionaryValue* args,
301 IPC::Message* reply_message) {
302 ExistingUserController* controller =
303 ExistingUserController::current_controller();
304 // Return immediately, since we're going to die before the login is finished.
305 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
306 controller->LoginAsGuest();
309 void TestingAutomationProvider::SubmitLoginForm(DictionaryValue* args,
310 IPC::Message* reply_message) {
311 AutomationJSONReply reply(this, reply_message);
313 std::string username, password;
314 if (!args->GetString("username", &username) ||
315 !args->GetString("password", &password)) {
316 reply.SendError("Invalid or missing args.");
317 return;
320 chromeos::ExistingUserController* controller =
321 chromeos::ExistingUserController::current_controller();
322 if (!controller) {
323 reply.SendError("Unable to access ExistingUserController");
324 return;
327 // WebUI login.
328 chromeos::WebUILoginDisplay* webui_login_display =
329 static_cast<chromeos::WebUILoginDisplay*>(controller->login_display());
330 VLOG(2) << "TestingAutomationProvider::SubmitLoginForm "
331 << "ShowSigninScreenForCreds(" << username << ", " << password << ")";
333 webui_login_display->ShowSigninScreenForCreds(username, password);
334 reply.SendSuccess(NULL);
337 void TestingAutomationProvider::AddLoginEventObserver(
338 DictionaryValue* args, IPC::Message* reply_message) {
339 ExistingUserController* controller =
340 ExistingUserController::current_controller();
341 AutomationJSONReply reply(this, reply_message);
342 if (!controller) {
343 // This may happen due to SkipToLogin not being called.
344 reply.SendError("Unable to access ExistingUserController");
345 return;
348 if (!automation_event_queue_.get())
349 automation_event_queue_.reset(new AutomationEventQueue);
351 int observer_id = automation_event_queue_->AddObserver(
352 new LoginEventObserver(automation_event_queue_.get(), this));
354 // Return the observer's id.
355 DictionaryValue return_value;
356 return_value.SetInteger("observer_id", observer_id);
357 reply.SendSuccess(&return_value);
360 void TestingAutomationProvider::SignOut(DictionaryValue* args,
361 IPC::Message* reply_message) {
362 ash::Shell::GetInstance()->system_tray_delegate()->SignOut();
363 // Sign out has the side effect of restarting the session_manager
364 // and chrome, thereby severing the automation channel, so it's
365 // not really necessary to send a reply back. The next line is
366 // for consistency with other methods.
367 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
370 void TestingAutomationProvider::PickUserImage(DictionaryValue* args,
371 IPC::Message* reply_message) {
372 std::string image_type;
373 int image_number = -1;
374 if (!args->GetString("image", &image_type)
375 && !args->GetInteger("image", &image_number)) {
376 AutomationJSONReply(this, reply_message).SendError(
377 "Invalid or missing args.");
378 return;
380 WizardController* wizard_controller = WizardController::default_controller();
381 if (!wizard_controller || wizard_controller->current_screen()->GetName() !=
382 WizardController::kUserImageScreenName) {
383 AutomationJSONReply(this, reply_message).SendError(
384 "User image screen not active.");
385 return;
387 chromeos::UserImageScreen* image_screen =
388 wizard_controller->GetUserImageScreen();
389 // Observer will delete itself unless error is returned.
390 WizardControllerObserver* observer =
391 new WizardControllerObserver(wizard_controller, this, reply_message);
392 if (image_type == "profile") {
393 image_screen->OnProfileImageSelected();
394 } else if (image_type.empty() && image_number >= 0 &&
395 image_number < chromeos::kDefaultImagesCount) {
396 image_screen->OnDefaultImageSelected(image_number);
397 } else {
398 AutomationJSONReply(this, reply_message).SendError(
399 "Invalid or missing args.");
400 delete observer;
401 return;
405 void TestingAutomationProvider::SkipToLogin(DictionaryValue* args,
406 IPC::Message* reply_message) {
407 bool skip_post_login_screens;
408 // The argument name is a legacy. If set to |true|, this argument causes any
409 // screens that may otherwise be shown after login (registration, Terms of
410 // Service, user image selection) to be skipped.
411 if (!args->GetBoolean("skip_image_selection", &skip_post_login_screens)) {
412 AutomationJSONReply reply(this, reply_message);
413 reply.SendError("Invalid or missing args.");
414 return;
416 if (skip_post_login_screens)
417 WizardController::SkipPostLoginScreensForTesting();
419 WizardController* wizard_controller = WizardController::default_controller();
420 if (!wizard_controller) {
421 AutomationJSONReply reply(this, reply_message);
422 if (ExistingUserController::current_controller()) {
423 // Already at login screen.
424 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
425 return_value->SetString("next_screen",
426 WizardController::kLoginScreenName);
427 reply.SendSuccess(return_value.get());
428 } else {
429 reply.SendError("OOBE not active.");
431 return;
434 // Observer will delete itself.
435 WizardControllerObserver* observer =
436 new WizardControllerObserver(wizard_controller, this, reply_message);
437 observer->set_screen_to_wait_for(WizardController::kLoginScreenName);
438 wizard_controller->SkipToLoginForTesting();
441 void TestingAutomationProvider::GetOOBEScreenInfo(DictionaryValue* args,
442 IPC::Message* reply_message) {
443 static const char kScreenNameKey[] = "screen_name";
444 AutomationJSONReply reply(this, reply_message);
445 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
447 WizardController* wizard_controller = WizardController::default_controller();
448 if (wizard_controller) {
449 if (wizard_controller->login_screen_started()) {
450 return_value->SetString(kScreenNameKey,
451 WizardController::kLoginScreenName);
452 } else {
453 return_value->SetString(kScreenNameKey,
454 wizard_controller->current_screen()->GetName());
456 } else if (ExistingUserController::current_controller()) {
457 return_value->SetString(kScreenNameKey, WizardController::kLoginScreenName);
458 } else {
459 // Already logged in.
460 reply.SendSuccess(NULL);
461 return;
463 reply.SendSuccess(return_value.get());
466 void TestingAutomationProvider::LockScreen(DictionaryValue* args,
467 IPC::Message* reply_message) {
468 new ScreenLockUnlockObserver(this, reply_message, true);
469 DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
472 void TestingAutomationProvider::UnlockScreen(DictionaryValue* args,
473 IPC::Message* reply_message) {
474 std::string password;
475 if (!args->GetString("password", &password)) {
476 AutomationJSONReply(this, reply_message).SendError(
477 "Invalid or missing args.");
478 return;
481 chromeos::ScreenLocker* screen_locker =
482 chromeos::ScreenLocker::default_screen_locker();
483 if (!screen_locker) {
484 AutomationJSONReply(this, reply_message).SendError(
485 "No default screen locker. Are you sure the screen is locked?");
486 return;
489 new ScreenUnlockObserver(this, reply_message);
490 screen_locker->Authenticate(ASCIIToUTF16(password));
493 // Signing out could have undesirable side effects: session_manager is
494 // killed, so its children, including chrome and the window manager, will
495 // also be killed. Anything owned by chronos will probably be killed.
496 void TestingAutomationProvider::SignoutInScreenLocker(
497 DictionaryValue* args, IPC::Message* reply_message) {
498 AutomationJSONReply reply(this, reply_message);
499 chromeos::ScreenLocker* screen_locker =
500 chromeos::ScreenLocker::default_screen_locker();
501 if (!screen_locker) {
502 reply.SendError(
503 "No default screen locker. Are you sure the screen is locked?");
504 return;
507 // Send success before stopping session because if we're a child of
508 // session manager then we'll die when the session is stopped.
509 reply.SendSuccess(NULL);
510 screen_locker->Signout();
513 void TestingAutomationProvider::GetBatteryInfo(DictionaryValue* args,
514 IPC::Message* reply_message) {
515 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
517 return_value->SetBoolean("battery_is_present",
518 global_power_status.battery_is_present);
519 return_value->SetBoolean("line_power_on", global_power_status.line_power_on);
520 if (global_power_status.battery_is_present) {
521 return_value->SetBoolean("battery_fully_charged",
522 global_power_status.battery_is_full);
523 return_value->SetDouble("battery_percentage",
524 global_power_status.battery_percentage);
525 if (global_power_status.line_power_on) {
526 int64 time = global_power_status.battery_seconds_to_full;
527 if (time > 0 || global_power_status.battery_is_full)
528 return_value->SetInteger("battery_seconds_to_full", time);
529 } else {
530 int64 time = global_power_status.battery_seconds_to_empty;
531 if (time > 0)
532 return_value->SetInteger("battery_seconds_to_empty", time);
536 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
539 void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args,
540 IPC::Message* reply_message) {
541 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
542 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
544 return_value->SetBoolean("offline_mode",
545 net::NetworkChangeNotifier::IsOffline());
547 // IP address.
548 return_value->SetString("ip_address", network_library->IPAddress());
550 // Currently connected networks.
551 if (network_library->ethernet_network())
552 return_value->SetString(
553 "connected_ethernet",
554 network_library->ethernet_network()->service_path());
555 if (network_library->wifi_network())
556 return_value->SetString("connected_wifi",
557 network_library->wifi_network()->service_path());
558 if (network_library->cellular_network())
559 return_value->SetString(
560 "connected_cellular",
561 network_library->cellular_network()->service_path());
563 // Ethernet network.
564 bool ethernet_available = network_library->ethernet_available();
565 bool ethernet_enabled = network_library->ethernet_enabled();
566 return_value->SetBoolean("ethernet_available", ethernet_available);
567 return_value->SetBoolean("ethernet_enabled", ethernet_enabled);
568 if (ethernet_available && ethernet_enabled) {
569 const chromeos::EthernetNetwork* ethernet_network =
570 network_library->ethernet_network();
571 if (ethernet_network) {
572 DictionaryValue* items = new DictionaryValue;
573 DictionaryValue* item = GetNetworkInfoDict(ethernet_network);
574 items->Set(ethernet_network->service_path(), item);
575 items->SetInteger("network_type", chromeos::TYPE_ETHERNET);
576 return_value->Set("ethernet_networks", items);
580 // Wi-fi networks.
581 bool wifi_available = network_library->wifi_available();
582 bool wifi_enabled = network_library->wifi_enabled();
583 return_value->SetBoolean("wifi_available", wifi_available);
584 return_value->SetBoolean("wifi_enabled", wifi_enabled);
585 if (wifi_available && wifi_enabled) {
586 const chromeos::WifiNetworkVector& wifi_networks =
587 network_library->wifi_networks();
588 DictionaryValue* items = new DictionaryValue;
589 for (chromeos::WifiNetworkVector::const_iterator iter =
590 wifi_networks.begin(); iter != wifi_networks.end(); ++iter) {
591 const chromeos::WifiNetwork* wifi = *iter;
592 DictionaryValue* item = GetWifiInfoDict(wifi);
593 items->Set(wifi->service_path(), item);
595 items->SetInteger("network_type", chromeos::TYPE_WIFI);
596 return_value->Set("wifi_networks", items);
599 // Cellular networks.
600 bool cellular_available = network_library->cellular_available();
601 bool cellular_enabled = network_library->cellular_enabled();
602 return_value->SetBoolean("cellular_available", cellular_available);
603 return_value->SetBoolean("cellular_enabled", cellular_enabled);
604 if (cellular_available && cellular_enabled) {
605 const chromeos::CellularNetworkVector& cellular_networks =
606 network_library->cellular_networks();
607 DictionaryValue* items = new DictionaryValue;
608 for (size_t i = 0; i < cellular_networks.size(); ++i) {
609 DictionaryValue* item = GetNetworkInfoDict(cellular_networks[i]);
610 item->SetInteger("strength", cellular_networks[i]->strength());
611 item->SetString("operator_name", cellular_networks[i]->operator_name());
612 item->SetString("operator_code", cellular_networks[i]->operator_code());
613 item->SetString("payment_url", cellular_networks[i]->payment_url());
614 item->SetString("usage_url", cellular_networks[i]->usage_url());
615 item->SetString("network_technology",
616 cellular_networks[i]->GetNetworkTechnologyString());
617 item->SetString("activation_state",
618 cellular_networks[i]->GetActivationStateString());
619 item->SetString("roaming_state",
620 cellular_networks[i]->GetRoamingStateString());
621 items->Set(cellular_networks[i]->service_path(), item);
623 items->SetInteger("network_type", chromeos::TYPE_CELLULAR);
624 return_value->Set("cellular_networks", items);
627 // Remembered Wifi Networks.
628 const chromeos::WifiNetworkVector& remembered_wifi =
629 network_library->remembered_wifi_networks();
630 DictionaryValue* remembered_wifi_items = new DictionaryValue;
631 for (chromeos::WifiNetworkVector::const_iterator iter =
632 remembered_wifi.begin(); iter != remembered_wifi.end();
633 ++iter) {
634 const chromeos::WifiNetwork* wifi = *iter;
635 DictionaryValue* item = GetWifiInfoDict(wifi);
636 remembered_wifi_items->Set(wifi->service_path(), item);
638 remembered_wifi_items->SetInteger("network_type", chromeos::TYPE_WIFI);
639 return_value->Set("remembered_wifi", remembered_wifi_items);
641 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
644 void TestingAutomationProvider::NetworkScan(DictionaryValue* args,
645 IPC::Message* reply_message) {
646 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
647 network_library->RequestNetworkScan();
649 // Set up an observer (it will delete itself).
650 new NetworkScanObserver(this, reply_message);
653 void TestingAutomationProvider::ToggleNetworkDevice(
654 DictionaryValue* args, IPC::Message* reply_message) {
655 AutomationJSONReply reply(this, reply_message);
656 std::string device;
657 bool enable;
658 if (!args->GetString("device", &device) ||
659 !args->GetBoolean("enable", &enable)) {
660 reply.SendError("Invalid or missing args.");
661 return;
664 // Set up an observer (it will delete itself).
665 new ToggleNetworkDeviceObserver(this, reply_message, device, enable);
667 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
668 if (device == "ethernet") {
669 network_library->EnableEthernetNetworkDevice(enable);
670 } else if (device == "wifi") {
671 network_library->EnableWifiNetworkDevice(enable);
672 } else if (device == "cellular") {
673 network_library->EnableCellularNetworkDevice(enable);
674 } else {
675 reply.SendError(
676 "Unknown device. Valid devices are ethernet, wifi, cellular.");
677 return;
681 void TestingAutomationProvider::GetProxySettings(DictionaryValue* args,
682 IPC::Message* reply_message) {
683 const char* settings[] = { "pacurl", "singlehttp", "singlehttpport",
684 "httpurl", "httpport", "httpsurl", "httpsport",
685 "type", "single", "ftpurl", "ftpport",
686 "socks", "socksport", "ignorelist" };
687 AutomationJSONReply reply(this, reply_message);
688 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
690 std::string error_message;
691 Profile* profile =
692 automation_util::GetCurrentProfileOnChromeOS(&error_message);
693 if (!profile) {
694 reply.SendError(error_message);
695 return;
697 for (size_t i = 0; i < arraysize(settings); ++i) {
698 base::Value* setting =
699 GetProxySetting(settings[i], profile);
700 if (setting)
701 return_value->Set(settings[i], setting);
703 reply.SendSuccess(return_value.get());
706 void TestingAutomationProvider::SetSharedProxies(
707 DictionaryValue* args,
708 IPC::Message* reply_message) {
710 AutomationJSONReply reply(this, reply_message);
711 base::Value* value;
712 if (!args->Get("value", &value)) {
713 reply.SendError("Invalid or missing value argument.");
714 return;
716 std::string proxy_setting_type;
717 std::string setting_path = prefs::kUseSharedProxies;
718 std::string error_message;
719 Profile* profile =
720 automation_util::GetCurrentProfileOnChromeOS(&error_message);
721 if (!profile) {
722 reply.SendError(error_message);
723 return;
725 PrefService* pref_service = profile->GetPrefs();
726 pref_service->Set(setting_path.c_str(), *value);
727 reply.SendSuccess(NULL);
730 void TestingAutomationProvider::RefreshInternetDetails(
731 DictionaryValue* args,
732 IPC::Message* reply_message) {
734 AutomationJSONReply reply(this, reply_message);
735 std::string service_path;
736 if (!args->GetString("service path", &service_path)) {
737 reply.SendError("missing service path.");
738 return;
740 std::string error_message;
741 Profile* profile =
742 automation_util::GetCurrentProfileOnChromeOS(&error_message);
743 if (!profile) {
744 reply.SendError(error_message);
745 return;
747 chromeos::ProxyConfigServiceImpl* config_service =
748 profile->GetProxyConfigTracker();
749 if (!config_service) {
750 reply.SendError("Unable to get proxy configuration.");
751 return;
753 config_service->UISetCurrentNetwork(service_path);
754 reply.SendSuccess(NULL);
757 void TestingAutomationProvider::SetProxySettings(DictionaryValue* args,
758 IPC::Message* reply_message) {
759 AutomationJSONReply reply(this, reply_message);
760 std::string key;
761 base::Value* value;
762 if (!args->GetString("key", &key) || !args->Get("value", &value)) {
763 reply.SendError("Invalid or missing args.");
764 return;
766 std::string error_message;
767 Profile* profile =
768 automation_util::GetCurrentProfileOnChromeOS(&error_message);
769 if (!profile) {
770 reply.SendError(error_message);
771 return;
773 // ProxyCrosSettingsProvider will own the Value* passed to Set().
774 std::string setting_path = "cros.session.proxy.";
775 setting_path.append(key);
776 chromeos::proxy_cros_settings_parser::SetProxyPrefValue(
777 profile, setting_path, value);
778 reply.SendSuccess(NULL);
781 void TestingAutomationProvider::ConnectToCellularNetwork(
782 DictionaryValue* args, IPC::Message* reply_message) {
783 std::string service_path;
784 if (!args->GetString("service_path", &service_path)) {
785 AutomationJSONReply(this, reply_message).SendError(
786 "Invalid or missing args.");
787 return;
790 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
791 chromeos::CellularNetwork* cellular =
792 network_library->FindCellularNetworkByPath(service_path);
793 if (!cellular) {
794 AutomationJSONReply(this, reply_message).SendError(
795 "No network found with specified service path.");
796 return;
799 // Set up an observer (it will delete itself).
800 new ServicePathConnectObserver(this, reply_message, service_path);
802 network_library->ConnectToCellularNetwork(cellular);
803 network_library->RequestNetworkScan();
806 void TestingAutomationProvider::DisconnectFromCellularNetwork(
807 DictionaryValue* args, IPC::Message* reply_message) {
808 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
809 const chromeos::CellularNetwork* cellular =
810 network_library->cellular_network();
811 if (!cellular) {
812 AutomationJSONReply(this, reply_message).SendError(
813 "Not connected to any cellular network.");
814 return;
817 // Set up an observer (it will delete itself).
818 new NetworkDisconnectObserver(this, reply_message, cellular->service_path());
820 network_library->DisconnectFromNetwork(cellular);
823 void TestingAutomationProvider::ConnectToWifiNetwork(
824 DictionaryValue* args, IPC::Message* reply_message) {
825 AutomationJSONReply reply(this, reply_message);
826 std::string service_path, password;
827 bool shared;
828 if (!args->GetString("service_path", &service_path) ||
829 !args->GetString("password", &password) ||
830 !args->GetBoolean("shared", &shared)) {
831 reply.SendError("Invalid or missing args.");
832 return;
835 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
836 chromeos::WifiNetwork* wifi =
837 network_library->FindWifiNetworkByPath(service_path);
838 if (!wifi) {
839 reply.SendError("No network found with specified service path.");
840 return;
842 if (!password.empty())
843 wifi->SetPassphrase(password);
845 // Regardless of what was passed, if the network is open and visible,
846 // the network must be shared because of a UI restriction.
847 if (wifi->encryption() == chromeos::SECURITY_NONE)
848 shared = true;
850 // Set up an observer (it will delete itself).
851 new ServicePathConnectObserver(this, reply_message, service_path);
853 network_library->ConnectToWifiNetwork(wifi, shared);
854 network_library->RequestNetworkScan();
857 void TestingAutomationProvider::ForgetWifiNetwork(
858 DictionaryValue* args, IPC::Message* reply_message) {
859 std::string service_path;
860 if (!args->GetString("service_path", &service_path)) {
861 AutomationJSONReply(this, reply_message).SendError(
862 "Invalid or missing args.");
863 return;
866 CrosLibrary::Get()->GetNetworkLibrary()->ForgetNetwork(service_path);
867 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
870 void TestingAutomationProvider::ConnectToHiddenWifiNetwork(
871 DictionaryValue* args, IPC::Message* reply_message) {
872 std::string ssid, security, password;
873 bool shared;
874 if (!args->GetString("ssid", &ssid) ||
875 !args->GetString("security", &security) ||
876 !args->GetString("password", &password) ||
877 !args->GetBoolean("shared", &shared)) {
878 AutomationJSONReply(this, reply_message).SendError(
879 "Invalid or missing args.");
880 return;
883 std::map<std::string, chromeos::ConnectionSecurity> connection_security_map;
884 connection_security_map["SECURITY_NONE"] = chromeos::SECURITY_NONE;
885 connection_security_map["SECURITY_WEP"] = chromeos::SECURITY_WEP;
886 connection_security_map["SECURITY_WPA"] = chromeos::SECURITY_WPA;
887 connection_security_map["SECURITY_RSN"] = chromeos::SECURITY_RSN;
888 connection_security_map["SECURITY_8021X"] = chromeos::SECURITY_8021X;
890 if (connection_security_map.find(security) == connection_security_map.end()) {
891 AutomationJSONReply(this, reply_message).SendError(
892 "Unknown security type.");
893 return;
895 chromeos::ConnectionSecurity connection_security =
896 connection_security_map[security];
898 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
900 // Set up an observer (it will delete itself).
901 new SSIDConnectObserver(this, reply_message, ssid);
903 bool save_credentials = false;
905 if (connection_security == chromeos::SECURITY_8021X) {
906 chromeos::NetworkLibrary::EAPConfigData config_data;
907 std::string eap_method, eap_auth, eap_identity;
908 if (!args->GetString("eap_method", &eap_method) ||
909 !args->GetString("eap_auth", &eap_auth) ||
910 !args->GetString("eap_identity", &eap_identity) ||
911 !args->GetBoolean("save_credentials", &save_credentials)) {
912 AutomationJSONReply(this, reply_message).SendError(
913 "Invalid or missing EAP args.");
914 return;
917 std::map<std::string, chromeos::EAPMethod> eap_method_map;
918 eap_method_map["EAP_METHOD_NONE"] = chromeos::EAP_METHOD_UNKNOWN;
919 eap_method_map["EAP_METHOD_PEAP"] = chromeos::EAP_METHOD_PEAP;
920 eap_method_map["EAP_METHOD_TLS"] = chromeos::EAP_METHOD_TLS;
921 eap_method_map["EAP_METHOD_TTLS"] = chromeos::EAP_METHOD_TTLS;
922 eap_method_map["EAP_METHOD_LEAP"] = chromeos::EAP_METHOD_LEAP;
923 if (eap_method_map.find(eap_method) == eap_method_map.end()) {
924 AutomationJSONReply(this, reply_message).SendError(
925 "Unknown EAP Method type.");
926 return;
928 config_data.method = eap_method_map[eap_method];
930 std::map<std::string, chromeos::EAPPhase2Auth> eap_auth_map;
931 eap_auth_map["EAP_PHASE_2_AUTH_AUTO"] = chromeos::EAP_PHASE_2_AUTH_AUTO;
932 eap_auth_map["EAP_PHASE_2_AUTH_MD5"] = chromeos::EAP_PHASE_2_AUTH_MD5;
933 eap_auth_map["EAP_PHASE_2_AUTH_MSCHAP"] =
934 chromeos::EAP_PHASE_2_AUTH_MSCHAP;
935 eap_auth_map["EAP_PHASE_2_AUTH_MSCHAPV2"] =
936 chromeos::EAP_PHASE_2_AUTH_MSCHAPV2;
937 eap_auth_map["EAP_PHASE_2_AUTH_PAP"] = chromeos::EAP_PHASE_2_AUTH_PAP;
938 eap_auth_map["EAP_PHASE_2_AUTH_CHAP"] = chromeos::EAP_PHASE_2_AUTH_CHAP;
939 if (eap_auth_map.find(eap_auth) == eap_auth_map.end()) {
940 AutomationJSONReply(this, reply_message).SendError(
941 "Unknown EAP Phase2 Auth type.");
942 return;
944 config_data.auth = eap_auth_map[eap_auth];
946 config_data.identity = eap_identity;
948 // TODO(stevenjb): Parse cert values?
949 config_data.server_ca_cert_nss_nickname = "";
950 config_data.use_system_cas = false;
951 config_data.client_cert_pkcs11_id = "";
953 network_library->ConnectToUnconfiguredWifiNetwork(
954 ssid, chromeos::SECURITY_8021X, password, &config_data,
955 save_credentials, shared);
956 } else {
957 network_library->ConnectToUnconfiguredWifiNetwork(
958 ssid, connection_security, password, NULL,
959 save_credentials, shared);
963 void TestingAutomationProvider::DisconnectFromWifiNetwork(
964 DictionaryValue* args, IPC::Message* reply_message) {
965 AutomationJSONReply reply(this, reply_message);
966 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
967 const chromeos::WifiNetwork* wifi = network_library->wifi_network();
968 if (!wifi) {
969 reply.SendError("Not connected to any wifi network.");
970 return;
973 network_library->DisconnectFromNetwork(wifi);
974 reply.SendSuccess(NULL);
977 void TestingAutomationProvider::AddPrivateNetwork(
978 DictionaryValue* args, IPC::Message* reply_message) {
979 std::string hostname, service_name, provider_type, key, cert_id, cert_nss,
980 username, password;
981 if (!args->GetString("hostname", &hostname) ||
982 !args->GetString("service_name", &service_name) ||
983 !args->GetString("provider_type", &provider_type) ||
984 !args->GetString("username", &username) ||
985 !args->GetString("password", &password)) {
986 AutomationJSONReply(this, reply_message)
987 .SendError("Invalid or missing args.");
988 return;
991 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
993 // Attempt to connect to the VPN based on the provider type.
994 if (provider_type == VPNProviderTypeToString(
995 chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK)) {
996 if (!args->GetString("key", &key)) {
997 AutomationJSONReply(this, reply_message)
998 .SendError("Missing key arg.");
999 return;
1001 new VirtualConnectObserver(this, reply_message, service_name);
1002 // Connect using a pre-shared key.
1003 chromeos::NetworkLibrary::VPNConfigData config_data;
1004 config_data.psk = key;
1005 config_data.username = username;
1006 config_data.user_passphrase = password;
1007 network_library->ConnectToUnconfiguredVirtualNetwork(
1008 service_name,
1009 hostname,
1010 chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK,
1011 config_data);
1012 } else if (provider_type == VPNProviderTypeToString(
1013 chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT)) {
1014 if (!args->GetString("cert_id", &cert_id) ||
1015 !args->GetString("cert_nss", &cert_nss)) {
1016 AutomationJSONReply(this, reply_message)
1017 .SendError("Missing a certificate arg.");
1018 return;
1020 new VirtualConnectObserver(this, reply_message, service_name);
1021 // Connect using a user certificate.
1022 chromeos::NetworkLibrary::VPNConfigData config_data;
1023 config_data.server_ca_cert_nss_nickname = cert_nss;
1024 config_data.client_cert_pkcs11_id = cert_id;
1025 config_data.username = username;
1026 config_data.user_passphrase = password;
1027 network_library->ConnectToUnconfiguredVirtualNetwork(
1028 service_name,
1029 hostname,
1030 chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT,
1031 config_data);
1032 } else if (provider_type == VPNProviderTypeToString(
1033 chromeos::PROVIDER_TYPE_OPEN_VPN)) {
1034 std::string otp;
1035 args->GetString("otp", &otp);
1036 // Connect using OPEN_VPN.
1037 chromeos::NetworkLibrary::VPNConfigData config_data;
1038 config_data.server_ca_cert_nss_nickname = cert_nss;
1039 config_data.client_cert_pkcs11_id = cert_id;
1040 config_data.username = username;
1041 config_data.user_passphrase = password;
1042 config_data.otp = otp;
1043 network_library->ConnectToUnconfiguredVirtualNetwork(
1044 service_name,
1045 hostname,
1046 chromeos::PROVIDER_TYPE_OPEN_VPN,
1047 config_data);
1048 } else {
1049 AutomationJSONReply(this, reply_message)
1050 .SendError("Unsupported provider type.");
1051 return;
1055 void TestingAutomationProvider::ConnectToPrivateNetwork(
1056 DictionaryValue* args, IPC::Message* reply_message) {
1057 AutomationJSONReply reply(this, reply_message);
1058 std::string service_path;
1059 if (!args->GetString("service_path", &service_path)) {
1060 reply.SendError("Invalid or missing args.");
1061 return;
1064 // Connect to a remembered VPN by its service_path. Valid service_paths
1065 // can be found in the dictionary returned by GetPrivateNetworkInfo.
1066 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
1067 chromeos::VirtualNetwork* network =
1068 network_library->FindVirtualNetworkByPath(service_path);
1069 if (!network) {
1070 reply.SendError(base::StringPrintf("No virtual network found: %s",
1071 service_path.c_str()));
1072 return;
1074 if (network->NeedMoreInfoToConnect()) {
1075 reply.SendError("Virtual network is missing info required to connect.");
1076 return;
1079 // Set up an observer (it will delete itself).
1080 new VirtualConnectObserver(this, reply_message, network->name());
1081 network_library->ConnectToVirtualNetwork(network);
1084 void TestingAutomationProvider::GetPrivateNetworkInfo(
1085 DictionaryValue* args, IPC::Message* reply_message) {
1086 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1087 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
1088 const chromeos::VirtualNetworkVector& virtual_networks =
1089 network_library->virtual_networks();
1091 // Construct a dictionary of fields describing remembered VPNs. Also list
1092 // the currently active VPN, if any.
1093 if (network_library->virtual_network())
1094 return_value->SetString("connected",
1095 network_library->virtual_network()->service_path());
1096 for (chromeos::VirtualNetworkVector::const_iterator iter =
1097 virtual_networks.begin(); iter != virtual_networks.end(); ++iter) {
1098 const chromeos::VirtualNetwork* virt = *iter;
1099 DictionaryValue* item = new DictionaryValue;
1100 item->SetString("name", virt->name());
1101 item->SetString("provider_type",
1102 VPNProviderTypeToString(virt->provider_type()));
1103 item->SetString("hostname", virt->server_hostname());
1104 item->SetString("key", virt->psk_passphrase());
1105 item->SetString("cert_nss", virt->ca_cert_nss());
1106 item->SetString("cert_id", virt->client_cert_id());
1107 item->SetString("username", virt->username());
1108 item->SetString("password", virt->user_passphrase());
1109 return_value->Set(virt->service_path(), item);
1112 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
1115 void TestingAutomationProvider::DisconnectFromPrivateNetwork(
1116 DictionaryValue* args, IPC::Message* reply_message) {
1117 AutomationJSONReply reply(this, reply_message);
1118 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
1119 const chromeos::VirtualNetwork* virt = network_library->virtual_network();
1120 if (!virt) {
1121 reply.SendError("Not connected to any virtual network.");
1122 return;
1125 network_library->DisconnectFromNetwork(virt);
1126 reply.SendSuccess(NULL);
1129 void TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI(
1130 DictionaryValue* args, IPC::Message* reply_message) {
1131 std::string javascript, frame_xpath;
1132 if (!args->GetString("javascript", &javascript)) {
1133 AutomationJSONReply(this, reply_message)
1134 .SendError("'javascript' missing or invalid");
1135 return;
1137 if (!args->GetString("frame_xpath", &frame_xpath)) {
1138 AutomationJSONReply(this, reply_message)
1139 .SendError("'frame_xpath' missing or invalid");
1140 return;
1142 const UserManager* user_manager = UserManager::Get();
1143 if (!user_manager) {
1144 AutomationJSONReply(this, reply_message).SendError(
1145 "No user manager!");
1146 return;
1148 if (user_manager->IsUserLoggedIn()) {
1149 AutomationJSONReply(this, reply_message).SendError(
1150 "User is already logged in.");
1151 return;
1153 ExistingUserController* controller =
1154 ExistingUserController::current_controller();
1155 if (!controller) {
1156 AutomationJSONReply(this, reply_message).SendError(
1157 "Unable to access ExistingUserController");
1158 return;
1160 chromeos::WebUILoginDisplayHost* webui_login_display_host =
1161 static_cast<chromeos::WebUILoginDisplayHost*>(
1162 controller->login_display_host());
1163 content::WebContents* web_contents =
1164 webui_login_display_host->GetOobeUI()->web_ui()->GetWebContents();
1166 new DomOperationMessageSender(this, reply_message, true);
1167 ExecuteJavascriptInRenderViewFrame(ASCIIToUTF16(frame_xpath),
1168 ASCIIToUTF16(javascript),
1169 reply_message,
1170 web_contents->GetRenderViewHost());
1173 void TestingAutomationProvider::EnableSpokenFeedback(
1174 DictionaryValue* args, IPC::Message* reply_message) {
1175 AutomationJSONReply reply(this, reply_message);
1176 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1177 bool enabled;
1178 if (!args->GetBoolean("enabled", &enabled)) {
1179 reply.SendError("Invalid or missing args.");
1180 return;
1182 const UserManager* user_manager = UserManager::Get();
1183 if (!user_manager) {
1184 reply.SendError("No user manager!");
1185 return;
1188 if (user_manager->IsUserLoggedIn()) {
1189 chromeos::accessibility::EnableSpokenFeedback(
1190 enabled, NULL, ash::A11Y_NOTIFICATION_NONE);
1191 } else {
1192 ExistingUserController* controller =
1193 ExistingUserController::current_controller();
1194 chromeos::WebUILoginDisplayHost* webui_login_display_host =
1195 static_cast<chromeos::WebUILoginDisplayHost*>(
1196 controller->login_display_host());
1197 chromeos::accessibility::EnableSpokenFeedback(
1198 enabled,
1199 webui_login_display_host->GetOobeUI()->web_ui(),
1200 ash::A11Y_NOTIFICATION_NONE);
1203 reply.SendSuccess(return_value.get());
1206 void TestingAutomationProvider::IsSpokenFeedbackEnabled(
1207 DictionaryValue* args, IPC::Message* reply_message) {
1208 AutomationJSONReply reply(this, reply_message);
1209 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1210 return_value->SetBoolean("spoken_feedback",
1211 chromeos::accessibility::IsSpokenFeedbackEnabled());
1212 reply.SendSuccess(return_value.get());
1215 void TestingAutomationProvider::GetTimeInfo(Browser* browser,
1216 DictionaryValue* args,
1217 IPC::Message* reply_message) {
1218 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1219 base::Time time(base::Time::Now());
1220 bool use_24hour_clock = browser && browser->profile()->GetPrefs()->GetBoolean(
1221 prefs::kUse24HourClock);
1222 base::HourClockType hour_clock_type =
1223 use_24hour_clock ? base::k24HourClock : base::k12HourClock;
1224 string16 display_time = base::TimeFormatTimeOfDayWithHourClockType(
1225 time, hour_clock_type, base::kDropAmPm);
1226 string16 timezone =
1227 chromeos::system::TimezoneSettings::GetInstance()->GetCurrentTimezoneID();
1228 return_value->SetString("display_time", display_time);
1229 return_value->SetString("display_date", base::TimeFormatFriendlyDate(time));
1230 return_value->SetString("timezone", timezone);
1231 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
1234 void TestingAutomationProvider::GetTimeInfo(DictionaryValue* args,
1235 IPC::Message* reply_message) {
1236 GetTimeInfo(NULL, args, reply_message);
1239 void TestingAutomationProvider::SetTimezone(DictionaryValue* args,
1240 IPC::Message* reply_message) {
1241 AutomationJSONReply reply(this, reply_message);
1242 std::string timezone_id;
1243 if (!args->GetString("timezone", &timezone_id)) {
1244 reply.SendError("Invalid or missing args.");
1245 return;
1247 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get();
1248 settings->SetString(chromeos::kSystemTimezone, timezone_id);
1249 reply.SendSuccess(NULL);
1252 void TestingAutomationProvider::GetUpdateInfo(DictionaryValue* args,
1253 IPC::Message* reply_message) {
1254 AutomationJSONReply* reply = new AutomationJSONReply(this, reply_message);
1255 DBusThreadManager::Get()->GetUpdateEngineClient()
1256 ->GetReleaseTrack(base::Bind(GetReleaseTrackCallback, reply));
1259 void TestingAutomationProvider::UpdateCheck(
1260 DictionaryValue* args,
1261 IPC::Message* reply_message) {
1262 AutomationJSONReply* reply = new AutomationJSONReply(this, reply_message);
1263 DBusThreadManager::Get()->GetUpdateEngineClient()
1264 ->RequestUpdateCheck(base::Bind(UpdateCheckCallback, reply));
1267 void TestingAutomationProvider::SetReleaseTrack(DictionaryValue* args,
1268 IPC::Message* reply_message) {
1269 AutomationJSONReply reply(this, reply_message);
1270 std::string track;
1271 if (!args->GetString("track", &track)) {
1272 reply.SendError("Invalid or missing args.");
1273 return;
1276 DBusThreadManager::Get()->GetUpdateEngineClient()->SetReleaseTrack(track);
1277 reply.SendSuccess(NULL);
1280 void TestingAutomationProvider::GetVolumeInfo(DictionaryValue* args,
1281 IPC::Message* reply_message) {
1282 AutomationJSONReply reply(this, reply_message);
1283 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1284 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
1285 if (!audio_handler) {
1286 reply.SendError("AudioHandler not initialized.");
1287 return;
1289 return_value->SetDouble("volume", audio_handler->GetVolumePercent());
1290 return_value->SetBoolean("is_mute", audio_handler->IsMuted());
1291 reply.SendSuccess(return_value.get());
1294 void TestingAutomationProvider::SetVolume(DictionaryValue* args,
1295 IPC::Message* reply_message) {
1296 AutomationJSONReply reply(this, reply_message);
1297 double volume_percent;
1298 if (!args->GetDouble("volume", &volume_percent)) {
1299 reply.SendError("Invalid or missing args.");
1300 return;
1302 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
1303 if (!audio_handler) {
1304 reply.SendError("AudioHandler not initialized.");
1305 return;
1307 audio_handler->SetVolumePercent(volume_percent);
1308 reply.SendSuccess(NULL);
1311 void TestingAutomationProvider::SetMute(DictionaryValue* args,
1312 IPC::Message* reply_message) {
1313 AutomationJSONReply reply(this, reply_message);
1314 bool mute;
1315 if (!args->GetBoolean("mute", &mute)) {
1316 reply.SendError("Invalid or missing args.");
1317 return;
1319 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
1320 if (!audio_handler) {
1321 reply.SendError("AudioHandler not initialized.");
1322 return;
1324 audio_handler->SetMuted(mute);
1325 reply.SendSuccess(NULL);
1328 void TestingAutomationProvider::OpenCrosh(DictionaryValue* args,
1329 IPC::Message* reply_message) {
1330 new NavigationNotificationObserver(
1331 NULL, this, reply_message, 1, false, true);
1332 ash::Shell::GetInstance()->delegate()->OpenCrosh();
1335 void TestingAutomationProvider::AddChromeosObservers() {
1336 power_manager_observer_ = new PowerManagerClientObserverForTesting;
1337 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
1338 AddObserver(power_manager_observer_);
1341 void TestingAutomationProvider::RemoveChromeosObservers() {
1342 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
1343 RemoveObserver(power_manager_observer_);
1344 delete power_manager_observer_;
1345 power_manager_observer_ = NULL;