Commit 879528db authored by avayvod@chromium.org's avatar avayvod@chromium.org

Added browser test for existing user controller (new user login).

BUG=None
TEST=Run browser_tests --gtest_filter=ExistingUserControllerTest.*

Review URL: http://codereview.chromium.org/6360006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71953 0039d316-1c4b-4281-b951-d872f2087c98
parent 0e22fde2
......@@ -117,7 +117,7 @@ void EnableTooltipsIfNeeded(const std::vector<UserController*>& controllers) {
} // namespace
ExistingUserController*
ExistingUserController::delete_scheduled_instance_ = NULL;
ExistingUserController::current_controller_ = NULL;
// TODO(xiyuan): Wait for the cached settings update before using them.
ExistingUserController::ExistingUserController(
......@@ -131,8 +131,9 @@ ExistingUserController::ExistingUserController(
bubble_(NULL),
user_settings_(new UserCrosSettingsProvider),
method_factory_(this) {
if (delete_scheduled_instance_)
delete_scheduled_instance_->Delete();
if (current_controller_)
current_controller_->Delete();
current_controller_ = this;
// Calculate the max number of users from available screen size.
bool show_guest = UserCrosSettingsProvider::cached_allow_guest();
......@@ -247,10 +248,11 @@ ExistingUserController::~ExistingUserController() {
STLDeleteElements(&controllers_);
STLDeleteElements(&invisible_controllers_);
DCHECK(current_controller_ != NULL);
current_controller_ = NULL;
}
void ExistingUserController::Delete() {
delete_scheduled_instance_ = NULL;
delete this;
}
......@@ -288,7 +290,10 @@ void ExistingUserController::Login(UserController* source,
// Use the same LoginPerformer for subsequent login as it has state
// such as CAPTCHA challenge token & corresponding user input.
if (!login_performer_.get() || num_login_attempts_ <= 1) {
login_performer_.reset(new LoginPerformer(this));
LoginPerformer::Delegate* delegate = this;
if (login_performer_delegate_.get())
delegate = login_performer_delegate_.get();
login_performer_.reset(new LoginPerformer(delegate));
}
login_performer_->Login(controllers_[selected_view_index_]->user().email(),
UTF16ToUTF8(password));
......@@ -361,11 +366,6 @@ void ExistingUserController::ActivateWizard(const std::string& screen_name) {
controller->set_start_url(start_url_);
controller->Show();
// And schedule us for deletion. We delay for a second as the window manager
// is doing an animation with our windows.
DCHECK(!delete_scheduled_instance_);
delete_scheduled_instance_ = this;
delete_timer_.Start(base::TimeDelta::FromSeconds(1), this,
&ExistingUserController::Delete);
}
......
......@@ -21,6 +21,7 @@
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/wm_message_listener.h"
#include "gfx/size.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
namespace chromeos {
......@@ -50,6 +51,11 @@ class ExistingUserController : public WmMessageListener::Observer,
ExistingUserController(const std::vector<UserManager::User>& users,
const gfx::Rect& background_bounds);
// Returns the current existing user controller if it has been created.
static ExistingUserController* current_controller() {
return current_controller_;
}
// Creates and shows the appropriate set of windows.
void Init();
......@@ -66,6 +72,7 @@ class ExistingUserController : public WmMessageListener::Observer,
private:
friend class DeleteTask<ExistingUserController>;
friend class MockLoginPerformerDelegate;
~ExistingUserController();
......@@ -129,6 +136,10 @@ class ExistingUserController : public WmMessageListener::Observer,
// Send message to window manager to enable/disable click on other windows.
void SendSetLoginState(bool is_login);
void set_login_performer_delegate(LoginPerformer::Delegate* d) {
login_performer_delegate_.reset(d);
}
// Bounds of the background window.
const gfx::Rect background_bounds_;
......@@ -145,6 +156,10 @@ class ExistingUserController : public WmMessageListener::Observer,
// Used to execute login operations.
scoped_ptr<LoginPerformer> login_performer_;
// Delegate for login performer to be overridden by tests.
// |this| is used if |login_performer_delegate_| is NULL.
scoped_ptr<LoginPerformer::Delegate> login_performer_delegate_;
// Index of selected view (user).
size_t selected_view_index_;
......@@ -155,9 +170,9 @@ class ExistingUserController : public WmMessageListener::Observer,
// See comment in ProcessWmMessage.
base::OneShotTimer<ExistingUserController> delete_timer_;
// Pointer to the instance that was scheduled to be deleted soon or NULL
// if there is no such instance.
static ExistingUserController* delete_scheduled_instance_;
// Pointer to the current instance of the controller to be used by
// automation tests.
static ExistingUserController* current_controller_;
// Pointer to shown message bubble. We don't need to delete it because
// it will be deleted on bubble closing.
......@@ -175,6 +190,8 @@ class ExistingUserController : public WmMessageListener::Observer,
// Factory of callbacks.
ScopedRunnableMethodFactory<ExistingUserController> method_factory_;
FRIEND_TEST_ALL_PREFIXES(ExistingUserControllerTest, NewUserLogin);
DISALLOW_COPY_AND_ASSIGN(ExistingUserController);
};
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "app/l10n_util.h"
#include "base/message_loop.h"
#include "chrome/browser/chromeos/cros/cros_mock.h"
#include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
#include "chrome/browser/chromeos/cros/mock_login_library.h"
#include "chrome/browser/chromeos/cros/mock_network_library.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/login_performer.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/login/mock_authenticator.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h"
#include "grit/generated_resources.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
using ::testing::AnyNumber;
using ::testing::InvokeWithoutArgs;
using ::testing::Return;
const char kUsername[] = "test_user@gmail.com";
const char kPassword[] = "test_password";
class MockLoginPerformerDelegate : public LoginPerformer::Delegate {
public:
explicit MockLoginPerformerDelegate(ExistingUserController* controller)
: controller_(controller) {
}
void OnLoginSuccess(const std::string&,
const std::string&,
const GaiaAuthConsumer::ClientLoginResult&,
bool) {
LoginPerformer* login_performer = controller_->login_performer_.release();
login_performer = NULL;
controller_->ActivateWizard(WizardController::kUserImageScreenName);
delete WizardController::default_controller();
}
MOCK_METHOD1(OnLoginFailure, void(const LoginFailure&));
MOCK_METHOD1(WhiteListCheckFailed, void(const std::string&));
private:
ExistingUserController* controller_;
DISALLOW_COPY_AND_ASSIGN(MockLoginPerformerDelegate);
};
class ExistingUserControllerTest : public WizardInProcessBrowserTest {
protected:
ExistingUserControllerTest()
: chromeos::WizardInProcessBrowserTest(""),
mock_cryptohome_library_(NULL),
mock_login_library_(NULL),
mock_network_library_(NULL) {
}
virtual void SetUpWizard() {
gfx::Rect background_bounds(login::kWizardScreenWidth,
login::kWizardScreenHeight);
ExistingUserController* controller =
new ExistingUserController(std::vector<UserManager::User>(),
background_bounds);
controller->Init();
}
ExistingUserController* existing_user_controller() {
return ExistingUserController::current_controller();
}
virtual void SetUpInProcessBrowserTestFixture() {
WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
cros_mock_->InitStatusAreaMocks();
cros_mock_->SetStatusAreaMocksExpectations();
mock_network_library_ = cros_mock_->mock_network_library();
mock_login_library_ = new MockLoginLibrary();
EXPECT_CALL(*mock_login_library_, EmitLoginPromptReady())
.Times(1);
EXPECT_CALL(*mock_login_library_, RetrieveProperty(_, _, _))
.Times(AnyNumber())
.WillRepeatedly((Return(true)));
cros_mock_->test_api()->SetLoginLibrary(mock_login_library_, true);
cros_mock_->InitMockCryptohomeLibrary();
mock_cryptohome_library_ = cros_mock_->mock_cryptohome_library();
EXPECT_CALL(*mock_cryptohome_library_, IsMounted())
.Times(AnyNumber())
.WillRepeatedly((Return(true)));
LoginUtils::Set(new MockLoginUtils(kUsername, kPassword));
}
virtual void TearDownInProcessBrowserTestFixture() {
WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
cros_mock_->test_api()->SetLoginLibrary(NULL, false);
}
MockCryptohomeLibrary* mock_cryptohome_library_;
MockLoginLibrary* mock_login_library_;
MockNetworkLibrary* mock_network_library_;
private:
DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest);
};
IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, NewUserLogin) {
MockLoginPerformerDelegate* mock_delegate =
new MockLoginPerformerDelegate(existing_user_controller());
existing_user_controller()->set_login_performer_delegate(mock_delegate);
existing_user_controller()->LoginNewUser(kUsername, kPassword);
}
} // namespace chromeos
......@@ -24,7 +24,7 @@ class MockUserManager : public UserManager {
MOCK_METHOD1(UserLoggedIn, void(const std::string&));
MOCK_METHOD1(RemoveUser, void(const std::string&));
MOCK_METHOD1(IsKnownUser, bool(const std::string&));
MOCK_METHOD0(logged_in_user, const User&());
MOCK_CONST_METHOD0(logged_in_user, User());
MOCK_METHOD0(current_user_is_owner, bool());
MOCK_METHOD1(set_current_user_is_owner, void(bool));
};
......
......@@ -74,7 +74,7 @@ class UserManager : public UserImageLoader::Delegate,
virtual bool IsKnownUser(const std::string& email);
// Returns the logged-in user.
virtual const User& logged_in_user() {
virtual User logged_in_user() const {
return logged_in_user_;
}
......
......@@ -20,8 +20,10 @@ WizardInProcessBrowserTest::WizardInProcessBrowserTest(const char* screen_name)
Browser* WizardInProcessBrowserTest::CreateBrowser(Profile* profile) {
SetUpWizard();
browser::ShowLoginWizard(screen_name_.c_str(), gfx::Size(1024, 600));
controller_ = WizardController::default_controller();
if (!screen_name_.empty()) {
browser::ShowLoginWizard(screen_name_.c_str(), gfx::Size(1024, 600));
controller_ = WizardController::default_controller();
}
return NULL;
}
......
......@@ -34,6 +34,9 @@ class WizardInProcessBrowserTest : public CrosInProcessBrowserTest {
virtual void CleanUpOnMainThread();
WizardController* controller() const { return controller_; }
void set_controller(WizardController* controller) {
controller_ = controller;
}
private:
std::string screen_name_;
......
......@@ -2011,6 +2011,7 @@
'browser/chromeos/cros/mock_system_library.h',
'browser/chromeos/cros/mock_touchpad_library.h',
'browser/chromeos/login/account_screen_browsertest.cc',
'browser/chromeos/login/existing_user_controller_browsertest.cc',
'browser/chromeos/login/login_browsertest.cc',
'browser/chromeos/login/login_screen_browsertest.cc',
'browser/chromeos/login/mock_authenticator.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment