Android: add UMA instrumentation for inertial sensors.
[chromium-blink-merge.git] / ash / test / test_session_state_delegate.cc
blob5c168078b49e62c6ee3471132db1d80472781b43
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
3 // found in the LICENSE file.
5 #include "ash/test/test_session_state_delegate.h"
7 #include <algorithm>
8 #include <string>
10 #include "ash/shell.h"
11 #include "ash/system/user/login_status.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace {
18 // The the "canonicalized" user ID from a given |email| address.
19 std::string GetUserIDFromEmail(const std::string& email) {
20 std::string user_id = email;
21 std::transform(user_id.begin(), user_id.end(), user_id.begin(), ::tolower);
22 return user_id;
25 } // namespace
27 namespace ash {
28 namespace test {
30 TestSessionStateDelegate::TestSessionStateDelegate()
31 : has_active_user_(false),
32 active_user_session_started_(false),
33 can_lock_screen_(true),
34 should_lock_screen_before_suspending_(false),
35 screen_locked_(false),
36 user_adding_screen_running_(false),
37 logged_in_users_(1),
38 num_transfer_to_desktop_of_user_calls_(0) {
41 TestSessionStateDelegate::~TestSessionStateDelegate() {
44 int TestSessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const {
45 return 3;
48 int TestSessionStateDelegate::NumberOfLoggedInUsers() const {
49 // TODO(skuhne): Add better test framework to test multiple profiles.
50 return has_active_user_ ? logged_in_users_ : 0;
53 bool TestSessionStateDelegate::IsActiveUserSessionStarted() const {
54 return active_user_session_started_;
57 bool TestSessionStateDelegate::CanLockScreen() const {
58 return has_active_user_ && can_lock_screen_;
61 bool TestSessionStateDelegate::IsScreenLocked() const {
62 return screen_locked_;
65 bool TestSessionStateDelegate::ShouldLockScreenBeforeSuspending() const {
66 return should_lock_screen_before_suspending_;
69 void TestSessionStateDelegate::LockScreen() {
70 if (CanLockScreen())
71 screen_locked_ = true;
74 void TestSessionStateDelegate::UnlockScreen() {
75 screen_locked_ = false;
78 bool TestSessionStateDelegate::IsUserSessionBlocked() const {
79 return !IsActiveUserSessionStarted() || IsScreenLocked() ||
80 user_adding_screen_running_;
83 void TestSessionStateDelegate::SetHasActiveUser(bool has_active_user) {
84 has_active_user_ = has_active_user;
85 if (!has_active_user)
86 active_user_session_started_ = false;
87 else
88 Shell::GetInstance()->ShowLauncher();
91 void TestSessionStateDelegate::SetActiveUserSessionStarted(
92 bool active_user_session_started) {
93 active_user_session_started_ = active_user_session_started;
94 if (active_user_session_started) {
95 has_active_user_ = true;
96 Shell::GetInstance()->CreateLauncher();
97 Shell::GetInstance()->UpdateAfterLoginStatusChange(
98 user::LOGGED_IN_USER);
102 void TestSessionStateDelegate::SetCanLockScreen(bool can_lock_screen) {
103 can_lock_screen_ = can_lock_screen;
106 void TestSessionStateDelegate::SetShouldLockScreenBeforeSuspending(
107 bool should_lock) {
108 should_lock_screen_before_suspending_ = should_lock;
111 void TestSessionStateDelegate::SetUserAddingScreenRunning(
112 bool user_adding_screen_running) {
113 user_adding_screen_running_ = user_adding_screen_running;
116 const base::string16 TestSessionStateDelegate::GetUserDisplayName(
117 MultiProfileIndex index) const {
118 return UTF8ToUTF16("Über tray Über tray Über tray Über tray");
121 const std::string TestSessionStateDelegate::GetUserEmail(
122 MultiProfileIndex index) const {
123 switch (index) {
124 case 0: return "First@tray"; // This is intended to be capitalized.
125 case 1: return "Second@tray"; // This is intended to be capitalized.
126 case 2: return "third@tray";
127 default: return "someone@tray";
131 const std::string TestSessionStateDelegate::GetUserID(
132 MultiProfileIndex index) const {
133 return GetUserIDFromEmail(GetUserEmail(index));
136 const gfx::ImageSkia& TestSessionStateDelegate::GetUserImage(
137 MultiProfileIndex index) const {
138 return null_image_;
141 void TestSessionStateDelegate::GetLoggedInUsers(UserIdList* users) {
144 void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) {
145 // Make sure this is a user id and not an email address.
146 EXPECT_EQ(user_id, GetUserIDFromEmail(user_id));
147 activated_user_ = user_id;
150 void TestSessionStateDelegate::CycleActiveUser(CycleUser cycle_user) {
151 activated_user_ = "someone@tray";
154 void TestSessionStateDelegate::AddSessionStateObserver(
155 SessionStateObserver* observer) {
158 void TestSessionStateDelegate::RemoveSessionStateObserver(
159 SessionStateObserver* observer) {
162 bool TestSessionStateDelegate::TransferWindowToDesktopOfUser(
163 aura::Window* window,
164 ash::MultiProfileIndex index) {
165 num_transfer_to_desktop_of_user_calls_++;
166 return false;
169 } // namespace test
170 } // namespace ash