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

Side by Side Diff: chromeos/login/login_state_unittest.cc

Issue 13495003: Add LoginState class to src/chromeos/login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore LOGGED_IN_KIOSK_APP Created 7 years, 8 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
« chromeos/login/login_state.cc ('K') | « chromeos/login/login_state.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chromeos/login/login_state.h"
6
7 #include "base/message_loop.h"
8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/session_manager_client.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace chromeos {
13
14 class LoginStateTest : public testing::Test,
15 public LoginState::Observer {
16 public:
17 LoginStateTest()
18 : login_state_(LoginState::LOGGED_IN_UNKNOWN),
19 session_started_(false) {
20 }
21 virtual ~LoginStateTest() {
22 }
23
24 // testing::Test
25 virtual void SetUp() OVERRIDE {
26 // Initialize DBusThreadManager with a stub implementation.
27 DBusThreadManager::InitializeWithStub();
28 LoginState::Initialize();
29 LoginState::Get()->AddObserver(this);
30 }
31
32 virtual void TearDown() OVERRIDE {
33 LoginState::Get()->RemoveObserver(this);
34 LoginState::Shutdown();
35 DBusThreadManager::Shutdown();
36 }
37
38 // LoginState::Observer
39 virtual void LoginStateChanged(LoginState::State state) OVERRIDE {
40 login_state_ = state;
41 session_started_ = LoginState::Get()->IsSessionStarted();
42 }
43
44 protected:
45 MessageLoopForUI message_loop_;
46 LoginState::State login_state_;
47 bool session_started_;
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(LoginStateTest);
51 };
52
53 TEST_F(LoginStateTest, TestLoginState) {
54 EXPECT_EQ(LoginState::LOGGED_IN_UNKNOWN, login_state_);
55 EXPECT_EQ(LoginState::LOGGED_IN_OOBE, LoginState::Get()->GetLoginState());
56 LoginState::Get()->SetLoginState(LoginState::LOGGED_IN_USER);
57 EXPECT_EQ(LoginState::LOGGED_IN_USER, LoginState::Get()->GetLoginState());
58 EXPECT_TRUE(LoginState::Get()->IsUserLoggedIn());
59 message_loop_.RunUntilIdle();
60 EXPECT_EQ(LoginState::LOGGED_IN_USER, login_state_);
61 // Lock the screen.
62 DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
63 message_loop_.RunUntilIdle();
64 EXPECT_EQ(LoginState::LOGGED_IN_LOCKED, LoginState::Get()->GetLoginState());
65 EXPECT_EQ(LoginState::LOGGED_IN_LOCKED, login_state_);
66 // UnLock the screen.
67 DBusThreadManager::Get()->GetSessionManagerClient()->RequestUnlockScreen();
68 message_loop_.RunUntilIdle();
69 EXPECT_EQ(LoginState::LOGGED_IN_USER, LoginState::Get()->GetLoginState());
70 EXPECT_EQ(LoginState::LOGGED_IN_USER, login_state_);
71 }
72
73 TEST_F(LoginStateTest, TestSessionStarted) {
74 EXPECT_FALSE(LoginState::Get()->IsSessionStarted());
75 EXPECT_FALSE(session_started_);
76 LoginState::Get()->SetSessionStarted(true);
77 message_loop_.RunUntilIdle();
78 EXPECT_TRUE(LoginState::Get()->IsSessionStarted());
79 EXPECT_TRUE(session_started_);
80 }
81
82 } // namespace
OLDNEW
« chromeos/login/login_state.cc ('K') | « chromeos/login/login_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698