testing_automation_provider_chromeos.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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
3// found in the LICENSE file.
4
5#include "chrome/browser/automation/testing_automation_provider.h"
6
7#include "base/values.h"
8#include "chrome/browser/automation/automation_provider_json.h"
9#include "chrome/browser/automation/automation_provider_observers.h"
10#include "chrome/browser/chromeos/cros/cros_library.h"
11#include "chrome/browser/chromeos/cros/screen_lock_library.h"
12#include "chrome/browser/chromeos/login/existing_user_controller.h"
13
14void TestingAutomationProvider::LoginAsGuest(DictionaryValue* args,
15                                             IPC::Message* reply_message) {
16  chromeos::ExistingUserController* controller =
17      chromeos::ExistingUserController::current_controller();
18  // Set up an observer (it will delete itself).
19  new LoginManagerObserver(this, reply_message);
20  controller->LoginAsGuest();
21}
22
23void TestingAutomationProvider::Login(DictionaryValue* args,
24                                      IPC::Message* reply_message) {
25  std::string username, password;
26  if (!args->GetString("username", &username) ||
27      !args->GetString("password", &password)) {
28    AutomationJSONReply(this, reply_message).SendError(
29        "Invalid or missing args");
30    return;
31  }
32
33  chromeos::ExistingUserController* controller =
34      chromeos::ExistingUserController::current_controller();
35  // Set up an observer (it will delete itself).
36  new LoginManagerObserver(this, reply_message);
37  controller->Login(username, password);
38}
39
40// Logging out could have other undesirable side effects: session_manager is
41// killed, so its children, including chrome and the window manager will also
42// be killed. SSH connections might be closed, the test binary might be killed.
43void TestingAutomationProvider::Logout(DictionaryValue* args,
44                                       IPC::Message* reply_message) {
45  // Send success before stopping session because if we're a child of
46  // session manager then we'll die when the session is stopped.
47  AutomationJSONReply(this, reply_message).SendSuccess(NULL);
48  if (chromeos::CrosLibrary::Get()->EnsureLoaded())
49    chromeos::CrosLibrary::Get()->GetLoginLibrary()->StopSession("");
50}
51
52void TestingAutomationProvider::ScreenLock(DictionaryValue* args,
53                                           IPC::Message* reply_message) {
54  new ScreenLockUnlockObserver(this, reply_message, true);
55  chromeos::CrosLibrary::Get()->GetScreenLockLibrary()->
56      NotifyScreenLockRequested();
57}
58
59void TestingAutomationProvider::ScreenUnlock(DictionaryValue* args,
60                                             IPC::Message* reply_message) {
61  new ScreenLockUnlockObserver(this, reply_message, false);
62  chromeos::CrosLibrary::Get()->GetScreenLockLibrary()->
63      NotifyScreenUnlockRequested();
64}
65