| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browser_process.h" | |
| 6 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 5 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
| 7 #include "chrome/browser/chromeos/login/mock_login_utils.h" | 6 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 8 #include "chrome/browser/chromeos/login/startup_utils.h" | 7 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 9 #include "chrome/browser/chromeos/login/user_adding_screen.h" | 8 #include "chrome/browser/chromeos/login/user_adding_screen.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" | 9 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
| 12 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chromeos/chromeos_switches.h" | |
| 15 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 14 |
| 18 using namespace testing; | 15 using namespace testing; |
| 19 | 16 |
| 20 namespace { | 17 namespace { |
| 21 | 18 |
| 22 const char* kTestUsers[] = {"test-user@gmail.com", | 19 const char* kTestUsers[] = {"test-user@gmail.com", |
| 23 "test-user1@gmail.com", | 20 "test-user1@gmail.com", |
| 24 "test-user2@gmail.com"}; | 21 "test-user2@gmail.com"}; |
| 25 | 22 |
| 26 } // anonymous namespace | 23 } // anonymous namespace |
| 27 | 24 |
| 28 namespace chromeos { | 25 namespace chromeos { |
| 29 | 26 |
| 30 class UserAddingScreenTest : public InProcessBrowserTest, | 27 class UserAddingScreenTest : public LoginManagerTest, |
| 31 public UserAddingScreen::Observer { | 28 public UserAddingScreen::Observer { |
| 32 public: | 29 public: |
| 33 UserAddingScreenTest() : user_adding_started_(0), user_adding_finished_(0) { | 30 UserAddingScreenTest() : LoginManagerTest(false), |
| 34 set_exit_when_last_browser_closes(false); | 31 user_adding_started_(0), |
| 32 user_adding_finished_(0) { |
| 35 } | 33 } |
| 36 | 34 |
| 37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 36 LoginManagerTest::SetUpCommandLine(command_line); |
| 38 command_line->AppendSwitch(::switches::kMultiProfiles); | 37 command_line->AppendSwitch(::switches::kMultiProfiles); |
| 39 command_line->AppendSwitch(chromeos::switches::kLoginManager); | |
| 40 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | |
| 41 } | 38 } |
| 42 | 39 |
| 43 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 40 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 41 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
| 44 UserAddingScreen::Get()->AddObserver(this); | 42 UserAddingScreen::Get()->AddObserver(this); |
| 45 mock_login_utils_ = new NiceMock<MockLoginUtils>(); | |
| 46 mock_login_utils_->DelegateToFake(); | |
| 47 LoginUtils::Set(mock_login_utils_); | |
| 48 } | 43 } |
| 49 | 44 |
| 50 virtual void OnUserAddingFinished() OVERRIDE { ++user_adding_finished_; } | 45 virtual void OnUserAddingFinished() OVERRIDE { ++user_adding_finished_; } |
| 51 | 46 |
| 52 virtual void OnUserAddingStarted() OVERRIDE { ++user_adding_started_; } | 47 virtual void OnUserAddingStarted() OVERRIDE { ++user_adding_started_; } |
| 53 | 48 |
| 54 void RegisterUser(const std::string& username) { | |
| 55 ListPrefUpdate users_pref(g_browser_process->local_state(), | |
| 56 "LoggedInUsers"); | |
| 57 users_pref->AppendIfNotPresent(new base::StringValue(username)); | |
| 58 } | |
| 59 | |
| 60 void SetExpectedCredentials(const std::string& username, | |
| 61 const std::string& password) { | |
| 62 mock_login_utils_->GetFakeLoginUtils()-> | |
| 63 SetExpectedCredentials(username, password); | |
| 64 } | |
| 65 | |
| 66 bool TryToLogin(const std::string& username, const std::string& password) { | |
| 67 ExistingUserController* controller = | |
| 68 ExistingUserController::current_controller(); | |
| 69 EXPECT_TRUE(controller != NULL); | |
| 70 controller->Login(UserContext(username, password, "")); | |
| 71 content::RunAllPendingInMessageLoop(); | |
| 72 return UserManager::Get()->GetActiveUser()->email() == username; | |
| 73 } | |
| 74 | |
| 75 void LoginUser(const std::string& username) { | |
| 76 SetExpectedCredentials(username, "password"); | |
| 77 EXPECT_TRUE(TryToLogin(username, "password")); | |
| 78 } | |
| 79 | |
| 80 int user_adding_started() { return user_adding_started_; } | 49 int user_adding_started() { return user_adding_started_; } |
| 81 | 50 |
| 82 int user_adding_finished() { return user_adding_finished_; } | 51 int user_adding_finished() { return user_adding_finished_; } |
| 83 | 52 |
| 84 MockLoginUtils& login_utils() { return *mock_login_utils_; } | |
| 85 | |
| 86 private: | 53 private: |
| 87 int user_adding_started_; | 54 int user_adding_started_; |
| 88 int user_adding_finished_; | 55 int user_adding_finished_; |
| 89 MockLoginUtils* mock_login_utils_; | |
| 90 | 56 |
| 91 DISALLOW_COPY_AND_ASSIGN(UserAddingScreenTest); | 57 DISALLOW_COPY_AND_ASSIGN(UserAddingScreenTest); |
| 92 }; | 58 }; |
| 93 | 59 |
| 94 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, PRE_CancelAdding) { | 60 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, PRE_CancelAdding) { |
| 95 RegisterUser(kTestUsers[0]); | 61 RegisterUser(kTestUsers[0]); |
| 96 RegisterUser(kTestUsers[1]); | 62 RegisterUser(kTestUsers[1]); |
| 97 RegisterUser(kTestUsers[2]); | 63 RegisterUser(kTestUsers[2]); |
| 98 StartupUtils::MarkOobeCompleted(); | 64 StartupUtils::MarkOobeCompleted(); |
| 99 } | 65 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 content::RunAllPendingInMessageLoop(); | 100 content::RunAllPendingInMessageLoop(); |
| 135 EXPECT_EQ(user_adding_started(), i); | 101 EXPECT_EQ(user_adding_started(), i); |
| 136 LoginUser(kTestUsers[i]); | 102 LoginUser(kTestUsers[i]); |
| 137 EXPECT_EQ(user_adding_finished(), i); | 103 EXPECT_EQ(user_adding_finished(), i); |
| 138 EXPECT_TRUE(LoginDisplayHostImpl::default_host() == NULL); | 104 EXPECT_TRUE(LoginDisplayHostImpl::default_host() == NULL); |
| 139 EXPECT_EQ(UserManager::Get()->GetLoggedInUsers().size(), unsigned(i + 1)); | 105 EXPECT_EQ(UserManager::Get()->GetLoggedInUsers().size(), unsigned(i + 1)); |
| 140 } | 106 } |
| 141 } | 107 } |
| 142 | 108 |
| 143 } // namespace chromeos | 109 } // namespace chromeos |
| OLD | NEW |