| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/chromeos/login/session/chrome_session_manager.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/run_loop.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 15 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 16 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 17 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
| 18 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 19 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" |
| 20 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 21 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 22 #include "chromeos/chromeos_switches.h" |
| 23 #include "content/public/test/test_utils.h" |
| 24 #include "google_apis/gaia/fake_gaia.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 |
| 27 namespace chromeos { |
| 28 |
| 29 namespace { |
| 30 |
| 31 const char* const kTestUsers[] = {"test-user1@consumer.example.com", |
| 32 "test-user2@consumer.example.com", |
| 33 "test-user3@consumer.example.com"}; |
| 34 |
| 35 // Helper class to wait for user adding screen to finish. |
| 36 class UserAddingScreenWaiter : public UserAddingScreen::Observer { |
| 37 public: |
| 38 UserAddingScreenWaiter() { UserAddingScreen::Get()->AddObserver(this); } |
| 39 ~UserAddingScreenWaiter() override { |
| 40 UserAddingScreen::Get()->RemoveObserver(this); |
| 41 } |
| 42 |
| 43 void Wait() { |
| 44 if (!UserAddingScreen::Get()->IsRunning()) |
| 45 return; |
| 46 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 47 run_loop_->Run(); |
| 48 } |
| 49 |
| 50 // UserAddingScreen::Observer: |
| 51 void OnUserAddingFinished() override { |
| 52 if (run_loop_) |
| 53 run_loop_->Quit(); |
| 54 } |
| 55 |
| 56 private: |
| 57 std::unique_ptr<base::RunLoop> run_loop_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(UserAddingScreenWaiter); |
| 60 }; |
| 61 |
| 62 } // anonymous namespace |
| 63 |
| 64 class ChromeSessionManagerTest : public LoginManagerTest { |
| 65 public: |
| 66 ChromeSessionManagerTest() : LoginManagerTest(true) {} |
| 67 ~ChromeSessionManagerTest() override {} |
| 68 |
| 69 // LoginManagerTest: |
| 70 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 71 LoginManagerTest::SetUpCommandLine(command_line); |
| 72 |
| 73 command_line->AppendSwitch(switches::kOobeSkipPostLogin); |
| 74 } |
| 75 |
| 76 void StartSignInScreen() { |
| 77 WizardController* wizard_controller = |
| 78 WizardController::default_controller(); |
| 79 ASSERT_TRUE(wizard_controller); |
| 80 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
| 81 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); |
| 82 } |
| 83 |
| 84 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(ChromeSessionManagerTest); |
| 86 }; |
| 87 |
| 88 IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) { |
| 89 // Verify that session state is OOBE and no user sessions in fresh start. |
| 90 session_manager::SessionManager* manager = |
| 91 session_manager::SessionManager::Get(); |
| 92 EXPECT_EQ(session_manager::SessionState::OOBE, manager->session_state()); |
| 93 EXPECT_EQ(0u, manager->sessions().size()); |
| 94 |
| 95 // Login via fake gaia to add a new user. |
| 96 fake_gaia_.SetFakeMergeSessionParams(kTestUsers[0], "fake_sid", "fake_lsid"); |
| 97 StartSignInScreen(); |
| 98 |
| 99 content::WindowedNotificationObserver session_start_waiter( |
| 100 chrome::NOTIFICATION_SESSION_STARTED, |
| 101 content::NotificationService::AllSources()); |
| 102 |
| 103 WebUILoginDisplay* login_display = static_cast<WebUILoginDisplay*>( |
| 104 ExistingUserController::current_controller()->login_display()); |
| 105 login_display->ShowSigninScreenForCreds(kTestUsers[0], "fake_password"); |
| 106 |
| 107 session_start_waiter.Wait(); |
| 108 |
| 109 // Verify that session state is ACTIVE with one user session. |
| 110 EXPECT_EQ(session_manager::SessionState::ACTIVE, manager->session_state()); |
| 111 EXPECT_EQ(1u, manager->sessions().size()); |
| 112 } |
| 113 |
| 114 IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, PRE_LoginExistingUsers) { |
| 115 for (auto user : kTestUsers) { |
| 116 RegisterUser(user); |
| 117 } |
| 118 StartupUtils::MarkOobeCompleted(); |
| 119 } |
| 120 |
| 121 IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) { |
| 122 // Verify that session state is LOGIN_PRIMARY with existing user data dir. |
| 123 session_manager::SessionManager* manager = |
| 124 session_manager::SessionManager::Get(); |
| 125 EXPECT_EQ(session_manager::SessionState::LOGIN_PRIMARY, |
| 126 manager->session_state()); |
| 127 EXPECT_EQ(0u, manager->sessions().size()); |
| 128 |
| 129 // Verify that session state is ACTIVE with one user session after signing |
| 130 // in a user. |
| 131 LoginUser(kTestUsers[0]); |
| 132 EXPECT_EQ(session_manager::SessionState::ACTIVE, manager->session_state()); |
| 133 EXPECT_EQ(1u, manager->sessions().size()); |
| 134 |
| 135 for (size_t i = 1; i < arraysize(kTestUsers); ++i) { |
| 136 // Verify that session state is LOGIN_SECONDARY during user adding. |
| 137 UserAddingScreen::Get()->Start(); |
| 138 base::RunLoop().RunUntilIdle(); |
| 139 EXPECT_EQ(session_manager::SessionState::LOGIN_SECONDARY, |
| 140 manager->session_state()); |
| 141 |
| 142 // Verify that session state is ACTIVE with 1+i user sessions after user |
| 143 // is added and new user session is started.. |
| 144 UserAddingScreenWaiter waiter; |
| 145 AddUser(kTestUsers[i]); |
| 146 waiter.Wait(); |
| 147 base::RunLoop().RunUntilIdle(); |
| 148 |
| 149 EXPECT_EQ(session_manager::SessionState::ACTIVE, manager->session_state()); |
| 150 EXPECT_EQ(1u + i, manager->sessions().size()); |
| 151 } |
| 152 |
| 153 // Verify that session manager has the correct user session info. |
| 154 ASSERT_EQ(arraysize(kTestUsers), manager->sessions().size()); |
| 155 for (size_t i = 0; i < arraysize(kTestUsers); ++i) { |
| 156 EXPECT_EQ(kTestUsers[i], |
| 157 manager->sessions()[i].user_account_id.GetUserEmail()); |
| 158 } |
| 159 } |
| 160 |
| 161 } // namespace chromeos |
| OLD | NEW |