Commit 123c026c authored by tengs@chromium.org's avatar tengs@chromium.org

Add kiosk browser tests for network configuration.

BUG=242589
TEST=existing kiosk tests pass

Review URL: https://chromiumcodereview.appspot.com/23449023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221848 0039d316-1c4b-4281-b951-d872f2087c98
parent 827d38ae
......@@ -64,6 +64,11 @@ StartupAppLauncher::StartupAppLauncher(Profile* profile,
}
StartupAppLauncher::~StartupAppLauncher() {
// StartupAppLauncher can be deleted at anytime during the launch process
// through a user bailout shortcut.
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
->RemoveObserver(this);
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
}
void StartupAppLauncher::Start() {
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/chromeos/login/app_launch_controller.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h"
#include "base/time/time.h"
......@@ -34,6 +35,9 @@ const int kAppInstallSplashScreenMinTimeMS = 3000;
// static
bool AppLaunchController::skip_splash_wait_ = false;
int AppLaunchController::network_wait_time_ = 10;
base::Closure* AppLaunchController::network_timeout_callback_ = NULL;
UserManager* AppLaunchController::test_user_manager_ = NULL;
AppLaunchController::AppLaunchController(const std::string& app_id,
LoginDisplayHost* host,
......@@ -46,8 +50,11 @@ AppLaunchController::AppLaunchController(const std::string& app_id,
oobe_display_->GetAppLaunchSplashScreenActor()),
error_screen_actor_(oobe_display_->GetErrorScreenActor()),
waiting_for_network_(false),
network_wait_timedout_(false),
showing_network_dialog_(false),
launch_splash_start_time_(0) {
signin_screen_.reset(new AppLaunchSigninScreen(
static_cast<OobeUI*>(oobe_display_), this));
}
AppLaunchController::~AppLaunchController() {
......@@ -66,18 +73,29 @@ void AppLaunchController::StartAppLaunch() {
kiosk_profile_loader_->Start();
}
// static
void AppLaunchController::SkipSplashWaitForTesting() {
skip_splash_wait_ = true;
}
void AppLaunchController::SetNetworkWaitForTesting(int wait_time_secs) {
network_wait_time_ = wait_time_secs;
}
void AppLaunchController::SetNetworkTimeoutCallbackForTesting(
base::Closure* callback) {
network_timeout_callback_ = callback;
}
void AppLaunchController::SetUserManagerForTesting(UserManager* user_manager) {
test_user_manager_ = user_manager;
AppLaunchSigninScreen::SetUserManagerForTesting(user_manager);
}
void AppLaunchController::OnConfigureNetwork() {
DCHECK(profile_);
showing_network_dialog_ = true;
const std::string& owner_email = UserManager::Get()->GetOwnerEmail();
const std::string& owner_email = GetUserManager()->GetOwnerEmail();
if (!owner_email.empty()) {
signin_screen_.reset(new AppLaunchSigninScreen(
static_cast<OobeUI*>(oobe_display_), this));
signin_screen_->Show();
} else {
// If kiosk mode was configured through enterprise policy, we may
......@@ -145,10 +163,9 @@ void AppLaunchController::OnInitializingNetwork() {
// Show the network configration dialog if network is not initialized
// after a brief wait time.
waiting_for_network_ = true;
const int kNetworkConfigWaitSeconds = 10;
network_wait_timer_.Start(
FROM_HERE,
base::TimeDelta::FromSeconds(kNetworkConfigWaitSeconds),
base::TimeDelta::FromSeconds(network_wait_time_),
this, &AppLaunchController::OnNetworkWaitTimedout);
}
......@@ -156,7 +173,10 @@ void AppLaunchController::OnNetworkWaitTimedout() {
DCHECK(waiting_for_network_);
LOG(WARNING) << "OnNetworkWaitTimedout... connection = "
<< net::NetworkChangeNotifier::GetConnectionType();
network_wait_timedout_ = true;
app_launch_splash_screen_actor_->ToggleNetworkConfig(true);
if (network_timeout_callback_)
network_timeout_callback_->Run();
}
void AppLaunchController::OnInstallingApp() {
......@@ -206,4 +226,8 @@ void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) {
Cleanup();
}
UserManager* AppLaunchController::GetUserManager() {
return test_user_manager_ ? test_user_manager_ : UserManager::Get();
}
} // namespace chromeos
......@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
......@@ -24,6 +25,7 @@ namespace chromeos {
class LoginDisplayHost;
class OobeDisplay;
class UserManager;
// Controller for the kiosk app launch process, responsible for
// coordinating loading the kiosk profile, launching the app, and
......@@ -43,11 +45,20 @@ class AppLaunchController
void StartAppLaunch();
bool waiting_for_network() { return waiting_for_network_; }
bool network_wait_timedout() { return network_wait_timedout_; }
bool showing_network_dialog() { return showing_network_dialog_; }
// Customize controller for testing purposes.
static void SkipSplashWaitForTesting();
static void SetNetworkTimeoutCallbackForTesting(base::Closure* callback);
static void SetNetworkWaitForTesting(int wait_time_secs);
static void SetUserManagerForTesting(UserManager* user_manager);
private:
void Cleanup();
void OnNetworkWaitTimedout();
UserManager* GetUserManager();
// KioskProfileLoader::Delegate overrides:
virtual void OnProfileLoaded(Profile* profile) OVERRIDE;
......@@ -80,10 +91,14 @@ class AppLaunchController
base::OneShotTimer<AppLaunchController> network_wait_timer_;
bool waiting_for_network_;
bool network_wait_timedout_;
bool showing_network_dialog_;
int64 launch_splash_start_time_;
static bool skip_splash_wait_;
static int network_wait_time_;
static base::Closure* network_timeout_callback_;
static UserManager* test_user_manager_;
DISALLOW_COPY_AND_ASSIGN(AppLaunchController);
};
......
......@@ -13,6 +13,8 @@
namespace chromeos {
UserManager* AppLaunchSigninScreen::test_user_manager_ = NULL;
AppLaunchSigninScreen::AppLaunchSigninScreen(
OobeUI* oobe_ui, Delegate* delegate)
: oobe_ui_(oobe_ui),
......@@ -30,7 +32,7 @@ void AppLaunchSigninScreen::Show() {
}
void AppLaunchSigninScreen::InitOwnerUserList() {
UserManager* user_manager = UserManager::Get();
UserManager* user_manager = GetUserManager();
const std::string& owner_email = user_manager->GetOwnerEmail();
const UserList& all_users = user_manager->GetUsers();
......@@ -46,6 +48,16 @@ void AppLaunchSigninScreen::InitOwnerUserList() {
}
}
// static
void AppLaunchSigninScreen::SetUserManagerForTesting(
UserManager* user_manager) {
test_user_manager_ = user_manager;
}
UserManager* AppLaunchSigninScreen::GetUserManager() {
return test_user_manager_ ? test_user_manager_ : UserManager::Get();
}
void AppLaunchSigninScreen::CancelPasswordChangedFlow() {
NOTREACHED();
}
......
......@@ -42,8 +42,11 @@ class AppLaunchSigninScreen
void Show();
static void SetUserManagerForTesting(UserManager* user_manager);
private:
void InitOwnerUserList();
UserManager* GetUserManager();
// SigninScreenHandlerDelegate implementation:
virtual void CancelPasswordChangedFlow() OVERRIDE;
......@@ -93,6 +96,8 @@ class AppLaunchSigninScreen
// This list should have at most one user, and that user should be the owner.
UserList owner_user_list_;
static UserManager* test_user_manager_;
DISALLOW_COPY_AND_ASSIGN(AppLaunchSigninScreen);
};
......
......@@ -20,6 +20,7 @@ class Widget;
namespace chromeos {
class AppLaunchController;
class WebUILoginView;
class WizardController;
......@@ -82,6 +83,10 @@ class LoginDisplayHost {
// Result should not be stored.
virtual WizardController* GetWizardController() = 0;
// Returns current AppLaunchController, if it exists.
// Result should not be stored.
virtual AppLaunchController* GetAppLaunchController() = 0;
// Starts screen for adding user into session.
// |completion_callback| called before display host shutdown.
// |completion_callback| can be null.
......
......@@ -410,6 +410,10 @@ WizardController* LoginDisplayHostImpl::GetWizardController() {
return wizard_controller_.get();
}
AppLaunchController* LoginDisplayHostImpl::GetAppLaunchController() {
return app_launch_controller_.get();
}
void LoginDisplayHostImpl::StartUserAdding(
const base::Closure& completion_callback) {
restore_path_ = RESTORE_ADD_USER_INTO_SESSION;
......
......@@ -67,6 +67,7 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
const std::string& first_screen_name,
scoped_ptr<DictionaryValue> screen_parameters) OVERRIDE;
virtual WizardController* GetWizardController() OVERRIDE;
virtual AppLaunchController* GetAppLaunchController() OVERRIDE;
virtual void StartUserAdding(
const base::Closure& completion_callback) OVERRIDE;
virtual void StartSignInScreen() OVERRIDE;
......
......@@ -37,6 +37,7 @@ class MockLoginDisplayHost : public LoginDisplayHost {
virtual void StartWizard(const std::string& name,
scoped_ptr<base::DictionaryValue> value) OVERRIDE;
MOCK_METHOD0(GetWizardController, WizardController*(void));
MOCK_METHOD0(GetAppLaunchController, AppLaunchController*(void));
MOCK_METHOD1(StartUserAdding, void(const base::Closure&));
MOCK_METHOD0(StartSignInScreen, void(void));
MOCK_METHOD0(ResumeSignInScreen, void(void));
......
......@@ -13,6 +13,10 @@ MockUserManager::~MockUserManager() {
delete user_;
}
const UserList& MockUserManager::GetUsers() const {
return user_list_;
}
const User* MockUserManager::GetLoggedInUser() const {
return user_;
}
......@@ -21,6 +25,10 @@ User* MockUserManager::GetLoggedInUser() {
return user_;
}
const std::string& MockUserManager::GetOwnerEmail() {
return user_->email();
}
const User* MockUserManager::GetActiveUser() const {
return user_;
}
......@@ -37,6 +45,8 @@ UserImageManager* MockUserManager::GetUserImageManager() {
void MockUserManager::SetActiveUser(const std::string& email) {
delete user_;
user_ = User::CreateRegularUser(email);
user_list_.clear();
user_list_.push_back(user_);
}
UserFlow* MockUserManager::GetCurrentUserFlow() const {
......@@ -50,6 +60,8 @@ UserFlow* MockUserManager::GetUserFlow(const std::string&) const {
User* MockUserManager::CreatePublicAccountUser(const std::string& email) {
delete user_;
user_ = User::CreatePublicAccountUser(email);
user_list_.clear();
user_list_.push_back(user_);
return user_;
}
......
......@@ -24,11 +24,9 @@ class MockUserManager : public UserManager {
virtual ~MockUserManager();
MOCK_METHOD0(Shutdown, void(void));
MOCK_CONST_METHOD0(GetUsers, const UserList&(void));
MOCK_CONST_METHOD0(GetUsersAdmittedForMultiProfile, UserList(void));
MOCK_CONST_METHOD0(GetLoggedInUsers, const UserList&(void));
MOCK_METHOD0(GetLRULoggedInUsers, const UserList&(void));
MOCK_METHOD0(GetOwnerEmail, const std::string&(void));
MOCK_METHOD3(UserLoggedIn, void(
const std::string&, const std::string&, bool));
MOCK_METHOD1(SwitchActiveUser, void(const std::string& email));
......@@ -103,7 +101,9 @@ class MockUserManager : public UserManager {
// You can't mock these functions easily because nobody can create
// User objects but the UserManagerImpl and us.
virtual const UserList& GetUsers() const OVERRIDE;
virtual const User* GetLoggedInUser() const OVERRIDE;
virtual const std::string& GetOwnerEmail() OVERRIDE;
virtual User* GetLoggedInUser() OVERRIDE;
virtual const User* GetActiveUser() const OVERRIDE;
virtual User* GetActiveUser() OVERRIDE;
......@@ -123,6 +123,7 @@ class MockUserManager : public UserManager {
User* user_;
scoped_ptr<MockUserImageManager> user_image_manager_;
scoped_ptr<UserFlow> user_flow_;
UserList user_list_;
};
} // namespace chromeos
......
......@@ -10,6 +10,7 @@
#include "base/memory/ref_counted_memory.h"
#include "base/values.h"
#include "chrome/browser/browser_about_handler.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
......@@ -459,6 +460,15 @@ void OobeUI::ResetSigninScreenHandlerDelegate() {
signin_screen_handler_->SetNativeWindowDelegate(NULL);
}
void OobeUI::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void OobeUI::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
const std::string& OobeUI::GetScreenName(Screen screen) const {
DCHECK(screen >= 0 && screen < SCREEN_UNKNOWN);
return screen_names_[static_cast<size_t>(screen)];
......@@ -466,7 +476,11 @@ const std::string& OobeUI::GetScreenName(Screen screen) const {
void OobeUI::OnCurrentScreenChanged(const std::string& screen) {
if (screen_ids_.count(screen)) {
current_screen_ = screen_ids_[screen];
Screen new_screen = screen_ids_[screen];
FOR_EACH_OBSERVER(Observer,
observer_list_,
OnCurrentScreenChanged(current_screen_, new_screen));
current_screen_ = new_screen;
} else {
NOTREACHED() << "Screen should be registered in InitializeScreenMaps()";
current_screen_ = SCREEN_UNKNOWN;
......
......@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
#include "chrome/browser/chromeos/login/oobe_display.h"
#include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h"
#include "content/public/browser/web_ui_controller.h"
......@@ -41,6 +42,13 @@ class OobeUI : public OobeDisplay,
public content::WebUIController,
public CoreOobeHandler::Delegate {
public:
class Observer {
public:
virtual ~Observer() {}
virtual void OnCurrentScreenChanged(
Screen current_screen, Screen new_screen) = 0;
};
// JS oobe/login screens names.
static const char kScreenOobeNetwork[];
static const char kScreenOobeEula[];
......@@ -108,6 +116,10 @@ class OobeUI : public OobeDisplay,
// Resets the delegate set in ShowSigninScreen.
void ResetSigninScreenHandlerDelegate();
// Add and remove observers for screen change events.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
Screen current_screen() const { return current_screen_; }
const std::string& GetScreenName(Screen screen) const;
......@@ -179,6 +191,9 @@ class OobeUI : public OobeDisplay,
// Callbacks to notify when JS part is fully loaded and ready to accept calls.
std::vector<base::Closure> ready_callbacks_;
// List of registered observers.
ObserverList<Observer> observer_list_;
DISALLOW_COPY_AND_ASSIGN(OobeUI);
};
......
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