| Index: chrome/browser/chromeos/login/login_manager_test.cc
|
| diff --git a/chrome/browser/chromeos/login/login_manager_test.cc b/chrome/browser/chromeos/login/login_manager_test.cc
|
| index 3066bed910c41e125d64db05b798a80d65212304..cfede81f2a1b4fe0e7d924761e0d0a8be70d2fee 100644
|
| --- a/chrome/browser/chromeos/login/login_manager_test.cc
|
| +++ b/chrome/browser/chromeos/login/login_manager_test.cc
|
| @@ -4,22 +4,9 @@
|
|
|
| #include "chrome/browser/chromeos/login/login_manager_test.h"
|
|
|
| -#include "base/prefs/scoped_user_pref_update.h"
|
| -#include "chrome/browser/browser_process.h"
|
| -#include "chrome/browser/chrome_notification_types.h"
|
| -#include "chrome/browser/chromeos/login/auth/user_context.h"
|
| -#include "chrome/browser/chromeos/login/existing_user_controller.h"
|
| #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
|
| #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
|
| -#include "chrome/browser/chromeos/login/users/user.h"
|
| -#include "chrome/browser/chromeos/login/users/user_manager.h"
|
| -#include "chrome/common/chrome_switches.h"
|
| -#include "chromeos/chromeos_switches.h"
|
| -#include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/web_contents.h"
|
| -#include "content/public/test/browser_test_utils.h"
|
| -#include "content/public/test/test_utils.h"
|
| -#include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace chromeos {
|
|
|
| @@ -27,100 +14,72 @@ LoginManagerTest::LoginManagerTest(bool should_launch_browser)
|
| : should_launch_browser_(should_launch_browser),
|
| web_contents_(NULL) {
|
| set_exit_when_last_browser_closes(false);
|
| + login_manager_test_helper_.reset(new LoginManagerTestHelper);
|
| +}
|
| +
|
| +LoginManagerTest::~LoginManagerTest() {}
|
| +
|
| +void LoginManagerTest::SetUpOnMainThread() {
|
| + login_manager_test_helper_->WaitForLoginWebUI();
|
| + InitializeWebContents();
|
| }
|
|
|
| void LoginManagerTest::CleanUpOnMainThread() {
|
| - if (LoginDisplayHostImpl::default_host())
|
| - LoginDisplayHostImpl::default_host()->Finalize();
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + login_manager_test_helper_->CloseLoginWebUI();
|
| }
|
|
|
| void LoginManagerTest::SetUpCommandLine(CommandLine* command_line) {
|
| - command_line->AppendSwitch(chromeos::switches::kLoginManager);
|
| - command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
|
| - command_line->AppendSwitch(::switches::kMultiProfiles);
|
| + login_manager_test_helper_->SetUpCommandLine(command_line);
|
| }
|
|
|
| void LoginManagerTest::SetUpInProcessBrowserTestFixture() {
|
| - mock_login_utils_ = new testing::NiceMock<MockLoginUtils>();
|
| - mock_login_utils_->DelegateToFake();
|
| - mock_login_utils_->GetFakeLoginUtils()->set_should_launch_browser(
|
| - should_launch_browser_);
|
| - LoginUtils::Set(mock_login_utils_);
|
| -}
|
| -
|
| -void LoginManagerTest::SetUpOnMainThread() {
|
| - content::WindowedNotificationObserver(
|
| - chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
|
| - content::NotificationService::AllSources()).Wait();
|
| - InitializeWebContents();
|
| + login_manager_test_helper_->SetUpLoginUtils(should_launch_browser_);
|
| }
|
|
|
| void LoginManagerTest::RegisterUser(const std::string& username) {
|
| - ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers");
|
| - users_pref->AppendIfNotPresent(new base::StringValue(username));
|
| + login_manager_test_helper_->RegisterUser(username);
|
| }
|
|
|
| void LoginManagerTest::SetExpectedCredentials(const std::string& username,
|
| const std::string& password) {
|
| - login_utils().GetFakeLoginUtils()->SetExpectedCredentials(username, password);
|
| + login_manager_test_helper_->SetExpectedCredentials(username, password);
|
| }
|
|
|
| bool LoginManagerTest::TryToLogin(const std::string& username,
|
| const std::string& password) {
|
| - if (!AddUserToSession(username, password))
|
| - return false;
|
| - if (const User* active_user = UserManager::Get()->GetActiveUser())
|
| - return active_user->email() == username;
|
| - return false;
|
| + return login_manager_test_helper_->TryToLogIn(username, password);
|
| }
|
|
|
| bool LoginManagerTest::AddUserToSession(const std::string& username,
|
| const std::string& password) {
|
| - ExistingUserController* controller =
|
| - ExistingUserController::current_controller();
|
| - if (!controller) {
|
| - ADD_FAILURE();
|
| - return false;
|
| - }
|
| - UserContext user_context(username);
|
| - user_context.SetPassword(password);
|
| - controller->Login(user_context);
|
| - content::WindowedNotificationObserver(
|
| - chrome::NOTIFICATION_SESSION_STARTED,
|
| - content::NotificationService::AllSources()).Wait();
|
| - const UserList& logged_users = UserManager::Get()->GetLoggedInUsers();
|
| - for (UserList::const_iterator it = logged_users.begin();
|
| - it != logged_users.end(); ++it) {
|
| - if ((*it)->email() == username)
|
| - return true;
|
| - }
|
| - return false;
|
| + return login_manager_test_helper_->AddUserToSession(username, password);
|
| }
|
|
|
| void LoginManagerTest::LoginUser(const std::string& username) {
|
| - SetExpectedCredentials(username, "password");
|
| - EXPECT_TRUE(TryToLogin(username, "password"));
|
| + login_manager_test_helper_->LogInUser(username);
|
| }
|
|
|
| void LoginManagerTest::AddUser(const std::string& username) {
|
| - SetExpectedCredentials(username, "password");
|
| - EXPECT_TRUE(AddUserToSession(username, "password"));
|
| + login_manager_test_helper_->AddUser(username);
|
| }
|
|
|
| void LoginManagerTest::JSExpect(const std::string& expression) {
|
| js_checker_.ExpectTrue(expression);
|
| }
|
|
|
| +MockLoginUtils& LoginManagerTest::login_utils() {
|
| + return login_manager_test_helper_->mock_login_utils();
|
| +}
|
| +
|
| void LoginManagerTest::InitializeWebContents() {
|
| - LoginDisplayHost* host = LoginDisplayHostImpl::default_host();
|
| - EXPECT_TRUE(host != NULL);
|
| -
|
| - content::WebContents* web_contents =
|
| - host->GetWebUILoginView()->GetWebContents();
|
| - EXPECT_TRUE(web_contents != NULL);
|
| - set_web_contents(web_contents);
|
| - js_checker_.set_web_contents(web_contents);
|
| - }
|
| + LoginDisplayHost* host = LoginDisplayHostImpl::default_host();
|
| + EXPECT_TRUE(host != NULL);
|
| +
|
| + content::WebContents* web_contents =
|
| + host->GetWebUILoginView()->GetWebContents();
|
| + EXPECT_TRUE(web_contents != NULL);
|
| + set_web_contents(web_contents);
|
| + js_checker_.set_web_contents(web_contents);
|
| +}
|
|
|
| } // namespace chromeos
|
|
|