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

Side by Side Diff: chrome/browser/chromeos/login/crash_restore_browsertest.cc

Issue 15929005: [CrOS multi-profiles] Restore user sessions after crash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 7 years, 6 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
(Empty)
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.
4
5 #include <string>
6 #include <vector>
7
8 #include "base/command_line.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h"
11 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
12 #include "chrome/browser/chromeos/login/user.h"
13 #include "chrome/browser/chromeos/login/user_manager.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chromeos/chromeos_switches.h"
16 #include "chromeos/dbus/cryptohome_client.h"
17 #include "chromeos/dbus/fake_session_manager_client.h"
18 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h"
19 #include "chromeos/dbus/session_manager_client.h"
20 #include "content/public/test/test_utils.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h"
23
24 namespace chromeos {
25
26 namespace {
27
28 const char kUserId1[] = "user1@example.com";
29 const char kUserId2[] = "user2@example.com";
30 const char kUserId3[] = "user3@example.com";
31
32 } // namespace
33
34 class CrashRestoreSimpleTest : public CrosInProcessBrowserTest {
35 protected:
36 CrashRestoreSimpleTest() {}
37
38 virtual ~CrashRestoreSimpleTest() {}
39
40 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
41 command_line->AppendSwitch(::switches::kMultiProfiles);
42 command_line->AppendSwitchASCII(switches::kLoginUser, kUserId1);
43 command_line->AppendSwitchASCII(
44 switches::kLoginProfile,
45 CryptohomeClient::GetStubSanitizedUsername(kUserId1));
46 }
47
48 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
49 // Redirect session_manager DBus calls to FakeSessionManagerClient.
50 MockDBusThreadManagerWithoutGMock* dbus_thread_manager =
51 new MockDBusThreadManagerWithoutGMock();
52 session_manager_client_ =
53 dbus_thread_manager->fake_session_manager_client();
54 DBusThreadManager::InitializeForTesting(dbus_thread_manager);
55 session_manager_client_->StartSession(kUserId1);
56 }
57
58 FakeSessionManagerClient* session_manager_client_;
59 };
60
61 IN_PROC_BROWSER_TEST_F(CrashRestoreSimpleTest, RestoreSessionForOneUser) {
62 UserManager* user_manager = UserManager::Get();
63 User* user = user_manager->GetActiveUser();
64 ASSERT_TRUE(user);
65 EXPECT_EQ(kUserId1, user->email());
66 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId1),
67 user->username_hash());
68 EXPECT_EQ(1UL, user_manager->GetLoggedInUsers().size());
69 }
70
71 // Observer that keeps track of user sessions restore event.
72 class UserSessionRestoreObserver :
73 public UserManager::UserSessionStateObserver {
74 public:
75 UserSessionRestoreObserver()
76 : running_loop_(false),
77 user_sessions_restored_(UserManager::Get()->UserSessionsRestored()) {
78 if (!user_sessions_restored_)
79 UserManager::Get()->AddSessionStateObserver(this);
80 }
81 virtual ~UserSessionRestoreObserver() {}
82
83 virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE {
84 }
85 virtual void PendingUserSessionsRestoreFinished() OVERRIDE {
86 user_sessions_restored_ = true;
87 UserManager::Get()->RemoveSessionStateObserver(this);
88 if (!running_loop_)
89 return;
90
91 message_loop_runner_->Quit();
92 running_loop_ = false;
93 }
94
95 // Wait until the user sessions are restored. If that happened between the
96 // construction of this object and this call or even before it was created
97 // then it returns immediately.
98 void Wait() {
99 if (user_sessions_restored_)
100 return;
101
102 running_loop_ = true;
103 message_loop_runner_ = new content::MessageLoopRunner();
104 message_loop_runner_->Run();
105 }
106
107 private:
108 bool running_loop_;
109 bool user_sessions_restored_;
110 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
111
112 DISALLOW_COPY_AND_ASSIGN(UserSessionRestoreObserver);
113 };
114
115 class CrashRestoreComplexTest : public CrashRestoreSimpleTest {
116 protected:
117 CrashRestoreComplexTest() {}
118 virtual ~CrashRestoreComplexTest() {}
119
120 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
121 CrashRestoreSimpleTest::SetUpInProcessBrowserTestFixture();
122 session_manager_client_->StartSession(kUserId2);
123 session_manager_client_->StartSession(kUserId3);
124 }
125 };
126
127 IN_PROC_BROWSER_TEST_F(CrashRestoreComplexTest, RestoreSessionForThreeUsers) {
128 {
129 UserSessionRestoreObserver restore_observer;
130 restore_observer.Wait();
131 }
132
133 UserManager* user_manager = UserManager::Get();
134 DCHECK(user_manager->UserSessionsRestored());
135
136 // User that is last in the user sessions map becomes active. This behavior
137 // will become better defined once each user gets a separate user desktop.
138 User* user = user_manager->GetActiveUser();
139 ASSERT_TRUE(user);
140 EXPECT_EQ(kUserId3, user->email());
141 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId3),
142 user->username_hash());
143 const UserList& users = user_manager->GetLoggedInUsers();
144 ASSERT_EQ(3UL, users.size());
145
146 // User that becomes active moves to the beginning of the list.
147 EXPECT_EQ(kUserId3, users[0]->email());
148 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId3),
149 users[0]->username_hash());
150 EXPECT_EQ(kUserId2, users[1]->email());
151 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId2),
152 users[1]->username_hash());
153 EXPECT_EQ(kUserId1, users[2]->email());
154 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId1),
155 users[2]->username_hash());
156 }
157
158 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/chrome_browser_main_chromeos.cc ('k') | chrome/browser/chromeos/login/existing_user_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698