Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Unified Diff: chrome/browser/chromeos/login/kiosk_browsertest.cc

Issue 23449023: Add kiosk browser tests for network configuration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/kiosk_browsertest.cc
diff --git a/chrome/browser/chromeos/login/kiosk_browsertest.cc b/chrome/browser/chromeos/login/kiosk_browsertest.cc
index 3c5d1f1310f1b8c7d980d97a9d8473796233ee22..75b13a2728f28c0252f77641834c5595715a2c65 100644
--- a/chrome/browser/chromeos/login/kiosk_browsertest.cc
+++ b/chrome/browser/chromeos/login/kiosk_browsertest.cc
@@ -15,10 +15,14 @@
#include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/login/app_launch_controller.h"
+#include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
+#include "chrome/browser/chromeos/login/mock_user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_display.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
+#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/browser/chromeos/settings/cros_settings_names.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/lifetime/application_lifetime.h"
@@ -39,6 +43,7 @@
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_switches.h"
#include "net/base/host_port_pair.h"
+#include "net/base/network_change_notifier.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
@@ -60,6 +65,12 @@ const base::FilePath kServiceLogin("chromeos/service_login.html");
// detail/ggbflgnkafappblpkiflbgpmkfdpnhhe
const char kTestKioskApp[] = "ggbflgnkafappblpkiflbgpmkfdpnhhe";
+// Timeout while waiting for network connectivity during tests.
+const int kTestNetworkTimeoutSeconds = 1;
+
+// Email of owner account for test.
+const char kTestOwnerEmail[] = "owner@example.com";
+
// Helper function for GetConsumerKioskModeStatusCallback.
void ConsumerKioskModeStatusCheck(
KioskAppManager::ConsumerKioskModeStatus* out_status,
@@ -82,6 +93,35 @@ void ConsumerKioskModeLockCheck(
} // namespace
+class FakeNetworkChangeNotifier : public net::NetworkChangeNotifier {
+ public:
+ FakeNetworkChangeNotifier() : connection_type_(CONNECTION_NONE) {}
+
+ virtual ConnectionType GetCurrentConnectionType() const OVERRIDE {
+ return connection_type_;
+ }
+
+ void GoOnline() {
+ SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET);
+ }
+
+ void GoOffline() {
+ SetConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE);
+ }
+
+ void SetConnectionType(ConnectionType type) {
+ connection_type_ = type;
+ NotifyObserversOfNetworkChange(type);
+ base::RunLoop().RunUntilIdle();
+ }
+
+ virtual ~FakeNetworkChangeNotifier() {}
+
+ private:
+ ConnectionType connection_type_;
+ DISALLOW_COPY_AND_ASSIGN(FakeNetworkChangeNotifier);
+};
+
class KioskTest : public InProcessBrowserTest,
// Param defining is multi-profiles enabled.
public testing::WithParamInterface<bool> {
@@ -105,9 +145,15 @@ class KioskTest : public InProcessBrowserTest,
const GURL gaia_url("http://localhost:" + test_server_->base_url().port());
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
::switches::kGaiaUrl, gaia_url.spec());
+
+ mock_user_manager_.reset(new MockUserManager);
}
virtual void CleanUpOnMainThread() OVERRIDE {
+ // We need to clean up these objects in this specific order.
+ fake_network_notifier_.reset(NULL);
+ disable_network_notifier_.reset(NULL);
+
// If the login display is still showing, exit gracefully.
if (LoginDisplayHostImpl::default_host()) {
base::MessageLoop::current()->PostTask(FROM_HERE,
@@ -196,6 +242,76 @@ class KioskTest : public InProcessBrowserTest,
KioskAppManager::Get()->SetAutoLaunchApp(kTestKioskApp);
}
+ void StartAppLaunchFromLoginScreen(bool has_connectivity) {
+ EnableConsumerKioskMode();
+
+ // Start UI, find menu entry for this app and launch it.
+ content::WindowedNotificationObserver login_signal(
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
+ content::NotificationService::AllSources());
+ chromeos::WizardController::SkipPostLoginScreensForTesting();
+ chromeos::WizardController* wizard_controller =
+ chromeos::WizardController::default_controller();
+ CHECK(wizard_controller);
+ wizard_controller->SkipToLoginForTesting();
+ login_signal.Wait();
+
+ // Wait for the Kiosk App configuration to reload, then launch the app.
+ content::WindowedNotificationObserver apps_loaded_signal(
+ chrome::NOTIFICATION_KIOSK_APPS_LOADED,
+ content::NotificationService::AllSources());
+ ReloadKioskApps();
+ apps_loaded_signal.Wait();
+
+ if (!has_connectivity)
+ SimulateNetworkOffline();
+
+ content::WindowedNotificationObserver screen_change_signal(
+ chrome::NOTIFICATION_CURRENT_SCREEN_CHANGED,
+ content::NotificationService::AllSources());
+ GetLoginUI()->CallJavascriptFunction(
+ "login.AppsMenuButton.runAppForTesting",
+ base::StringValue(kTestKioskApp));
+ screen_change_signal.Wait();
+ ASSERT_EQ(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH, GetCurrentScreen());
+ GetAppLaunchController()->SkipSplashWaitForTesting();
+ }
+
+ void WaitForAppLaunchSuccess() {
+ SimulateNetworkOnline();
+
+ // Wait for the Kiosk App to launch.
+ content::WindowedNotificationObserver(
+ chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
+ content::NotificationService::AllSources()).Wait();
+
+ // Check installer status.
+ EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
+ chromeos::KioskAppLaunchError::Get());
+
+ // Check if the kiosk webapp is really installed for the default profile.
+ ASSERT_TRUE(ProfileManager::GetDefaultProfile());
+ const extensions::Extension* app =
+ extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())->
+ extension_service()->GetInstalledExtension(kTestKioskApp);
+ EXPECT_TRUE(app);
+
+ // Wait until the app terminates.
+ content::RunMessageLoop();
+ }
+
+ void SimulateNetworkOffline() {
+ disable_network_notifier_.reset(
+ new net::NetworkChangeNotifier::DisableForTest);
+
+ fake_network_notifier_.reset(new FakeNetworkChangeNotifier);
+ }
+
+ void SimulateNetworkOnline() {
+ if (fake_network_notifier_.get())
+ fake_network_notifier_->GoOnline();
+ }
+
void EnableConsumerKioskMode() {
scoped_ptr<bool> locked(new bool(false));
scoped_refptr<content::MessageLoopRunner> runner =
@@ -227,47 +343,78 @@ class KioskTest : public InProcessBrowserTest,
chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI()->web_ui();
}
+ OobeDisplay::Screen GetCurrentScreen() {
+ OobeUI* oobe_ui = static_cast<chromeos::LoginDisplayHostImpl*>(
+ chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI();
+ return oobe_ui->current_screen();
+ }
+
+ AppLaunchController* GetAppLaunchController() {
+ return chromeos::LoginDisplayHostImpl::default_host()
+ ->GetAppLaunchController();
+ }
+
std::string service_login_response_;
scoped_ptr<EmbeddedTestServer> test_server_;
+ scoped_ptr<net::NetworkChangeNotifier::DisableForTest>
+ disable_network_notifier_;
+ scoped_ptr<FakeNetworkChangeNotifier> fake_network_notifier_;
+ scoped_ptr<MockUserManager> mock_user_manager_;
};
IN_PROC_BROWSER_TEST_P(KioskTest, InstallAndLaunchApp) {
- EnableConsumerKioskMode();
- chromeos::AppLaunchController::SkipSplashWaitForTesting();
- // Start UI, find menu entry for this app and launch it.
- chromeos::WizardController::SkipPostLoginScreensForTesting();
- chromeos::WizardController* wizard_controller =
- chromeos::WizardController::default_controller();
- CHECK(wizard_controller);
- wizard_controller->SkipToLoginForTesting();
-
- ReloadKioskApps();
-
- // Wait for the Kiosk App configuration to reload, then launch the app.
- content::WindowedNotificationObserver(
- chrome::NOTIFICATION_KIOSK_APPS_LOADED,
- content::NotificationService::AllSources()).Wait();
- GetLoginUI()->CallJavascriptFunction("login.AppsMenuButton.runAppForTesting",
- base::StringValue(kTestKioskApp));
+ StartAppLaunchFromLoginScreen(true);
+ WaitForAppLaunchSuccess();
+}
- // Wait for the Kiosk App to launch.
- content::WindowedNotificationObserver(
- chrome::NOTIFICATION_KIOSK_APP_LAUNCHED,
- content::NotificationService::AllSources()).Wait();
+IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppNetworkDown) {
+ // Start app launch and wait for network connectivity timeout.
+ content::WindowedNotificationObserver network_timeout_signal(
+ chrome::NOTIFICATION_KIOSK_APP_LAUNCH_NO_NETWORK,
+ content::NotificationService::AllSources());
+ StartAppLaunchFromLoginScreen(false);
+ network_timeout_signal.Wait();
+
+ // Set up fake user manager with an owner for the test.
+ mock_user_manager_->SetActiveUser(kTestOwnerEmail);
+ AppLaunchController* controller = GetAppLaunchController();
+ controller->SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds);
+ controller->SetUserManagerForTesting(mock_user_manager_.get());
+ static_cast<LoginDisplayHostImpl*>(LoginDisplayHostImpl::default_host())
+ ->GetOobeUI()->ShowOobeUI(false);
+
+ // Configure network should bring up lock screen for owner.
+ content::WindowedNotificationObserver lock_screen_signal(
+ chrome::NOTIFICATION_CURRENT_SCREEN_CHANGED,
+ content::NotificationService::AllSources());
+ static_cast<AppLaunchSplashScreenActor::Delegate*>(GetAppLaunchController())
+ ->OnConfigureNetwork();
+ lock_screen_signal.Wait();
+ ASSERT_EQ(OobeDisplay::SCREEN_ACCOUNT_PICKER, GetCurrentScreen());
+
+ // A network error screen should be shown after authenticating.
+ content::WindowedNotificationObserver network_error_signal(
+ chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN,
+ content::NotificationService::AllSources());
+ static_cast<AppLaunchSigninScreen::Delegate*>(GetAppLaunchController())
+ ->OnOwnerSigninSuccess();
+ network_error_signal.Wait();
+
+ WaitForAppLaunchSuccess();
+}
- // Check installer status.
- EXPECT_EQ(chromeos::KioskAppLaunchError::NONE,
+IN_PROC_BROWSER_TEST_P(KioskTest, LaunchAppUserCancel) {
+ StartAppLaunchFromLoginScreen(false);
+ CrosSettings::Get()->SetBoolean(
+ kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, true);
+ content::WindowedNotificationObserver signal(
+ chrome::NOTIFICATION_APP_TERMINATING,
+ content::NotificationService::AllSources());
+ GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
+ base::StringValue("app_launch_bailout"));
+ signal.Wait();
+ EXPECT_EQ(chromeos::KioskAppLaunchError::USER_CANCEL,
chromeos::KioskAppLaunchError::Get());
-
- // Check if the kiosk webapp is really installed for the default profile.
- ASSERT_TRUE(ProfileManager::GetDefaultProfile());
- const extensions::Extension* app =
- extensions::ExtensionSystem::Get(ProfileManager::GetDefaultProfile())->
- extension_service()->GetInstalledExtension(kTestKioskApp);
- EXPECT_TRUE(app);
-
- // Wait until the app terminates.
- content::RunMessageLoop();
}
IN_PROC_BROWSER_TEST_P(KioskTest, AutolaunchWarningCancel) {

Powered by Google App Engine
This is Rietveld 408576698