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 fd118815b006a17c0030b155b877e05622d0397e..dc73a3638165f5440a21b3fcb994833d2ca68dae 100644 |
--- a/chrome/browser/chromeos/login/kiosk_browsertest.cc |
+++ b/chrome/browser/chromeos/login/kiosk_browsertest.cc |
@@ -10,6 +10,7 @@ |
#include "ash/shell.h" |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
+#include "base/callback.h" |
#include "base/command_line.h" |
#include "base/location.h" |
#include "base/memory/scoped_ptr.h" |
@@ -32,6 +33,7 @@ |
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
#include "chrome/browser/chromeos/login/webui_login_display.h" |
#include "chrome/browser/chromeos/login/wizard_controller.h" |
+#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" |
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
#include "chrome/browser/chromeos/settings/cros_settings.h" |
#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
@@ -102,6 +104,9 @@ const char kTestEnterpriseServiceAccountId[] = "service_account@example.com"; |
const char kTestRefreshToken[] = "fake-refresh-token"; |
const char kTestAccessToken[] = "fake-access-token"; |
+// Note the path name must be the same as in shill stub. |
+const char kStubEthernetServicePath[] = "eth1"; |
+ |
// Helper function for GetConsumerKioskModeStatusCallback. |
void ConsumerKioskModeStatusCheck( |
KioskAppManager::ConsumerKioskModeStatus* out_status, |
@@ -136,58 +141,44 @@ void CopyTokenService(DeviceOAuth2TokenService** out_token_service, |
// Helper functions for CanConfigureNetwork mock. |
class ScopedCanConfigureNetwork { |
public: |
- explicit ScopedCanConfigureNetwork(bool can_configure) |
+ ScopedCanConfigureNetwork(bool can_configure, bool needs_owner_auth) |
: can_configure_(can_configure), |
- callback_(base::Bind(&ScopedCanConfigureNetwork::CanConfigureNetwork, |
- base::Unretained(this))) { |
- AppLaunchController::SetCanConfigureNetworkCallbackForTesting(&callback_); |
+ needs_owner_auth_(needs_owner_auth), |
+ can_configure_network_callback_( |
+ base::Bind(&ScopedCanConfigureNetwork::CanConfigureNetwork, |
+ base::Unretained(this))), |
+ needs_owner_auth_callback_(base::Bind( |
+ &ScopedCanConfigureNetwork::NeedsOwnerAuthToConfigureNetwork, |
+ base::Unretained(this))) { |
+ AppLaunchController::SetCanConfigureNetworkCallbackForTesting( |
+ &can_configure_network_callback_); |
+ AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting( |
+ &needs_owner_auth_callback_); |
} |
~ScopedCanConfigureNetwork() { |
AppLaunchController::SetCanConfigureNetworkCallbackForTesting(NULL); |
+ AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting( |
+ NULL); |
} |
bool CanConfigureNetwork() { |
return can_configure_; |
} |
+ bool NeedsOwnerAuthToConfigureNetwork() { |
+ return needs_owner_auth_; |
+ } |
+ |
private: |
bool can_configure_; |
- AppLaunchController::CanConfigureNetworkCallback callback_; |
+ bool needs_owner_auth_; |
+ AppLaunchController::ReturnBoolCallback can_configure_network_callback_; |
+ AppLaunchController::ReturnBoolCallback needs_owner_auth_callback_; |
DISALLOW_COPY_AND_ASSIGN(ScopedCanConfigureNetwork); |
}; |
} // namespace |
-// Fake NetworkChangeNotifier used to simulate network connectivity. |
-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); |
-}; |
- |
// Helper class that monitors app windows to wait for a window to appear. |
class ShellWindowObserver : public apps::ShellWindowRegistry::Observer { |
public: |
@@ -259,13 +250,14 @@ class KioskTest : public InProcessBrowserTest { |
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
host_resolver()->AddRule("*", "127.0.0.1"); |
+ |
+ network_portal_detector_ = new NetworkPortalDetectorTestImpl(); |
+ NetworkPortalDetector::InitializeForTesting(network_portal_detector_); |
+ network_portal_detector_->SetDefaultNetworkPathForTesting( |
+ kStubEthernetServicePath); |
} |
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); |
- |
AppLaunchController::SetNetworkTimeoutCallbackForTesting(NULL); |
AppLaunchSigninScreen::SetUserManagerForTesting(NULL); |
@@ -323,7 +315,7 @@ class KioskTest : public InProcessBrowserTest { |
KioskAppManager::Get()->SetAutoLaunchApp(kTestKioskApp); |
} |
- void StartAppLaunchFromLoginScreen(bool has_connectivity) { |
+ void StartAppLaunchFromLoginScreen(const base::Closure& network_setup_cb) { |
EnableConsumerKioskMode(); |
// Start UI, find menu entry for this app and launch it. |
@@ -344,8 +336,8 @@ class KioskTest : public InProcessBrowserTest { |
ReloadKioskApps(); |
apps_loaded_signal.Wait(); |
- if (!has_connectivity) |
- SimulateNetworkOffline(); |
+ if (!network_setup_cb.is_null()) |
+ network_setup_cb.Run(); |
GetLoginUI()->CallJavascriptFunction( |
"login.AppsMenuButton.runAppForTesting", |
@@ -402,15 +394,43 @@ class KioskTest : public InProcessBrowserTest { |
} |
void SimulateNetworkOffline() { |
- disable_network_notifier_.reset( |
- new net::NetworkChangeNotifier::DisableForTest); |
+ NetworkPortalDetector::CaptivePortalState offline_state; |
+ offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; |
+ network_portal_detector_->SetDetectionResultsForTesting( |
+ kStubEthernetServicePath, offline_state); |
+ network_portal_detector_->NotifyObserversForTesting(); |
+ } |
- fake_network_notifier_.reset(new FakeNetworkChangeNotifier); |
+ base::Closure SimulateNetworkOfflineClosure() { |
+ return base::Bind(&KioskTest::SimulateNetworkOffline, |
+ base::Unretained(this)); |
} |
void SimulateNetworkOnline() { |
- if (fake_network_notifier_.get()) |
- fake_network_notifier_->GoOnline(); |
+ NetworkPortalDetector::CaptivePortalState online_state; |
+ online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
+ online_state.response_code = 204; |
+ network_portal_detector_->SetDetectionResultsForTesting( |
+ kStubEthernetServicePath, online_state); |
+ network_portal_detector_->NotifyObserversForTesting(); |
+ } |
+ |
+ base::Closure SimulateNetworkOnlineClosure() { |
+ return base::Bind(&KioskTest::SimulateNetworkOnline, |
+ base::Unretained(this)); |
+ } |
+ |
+ void SimulateNetworkPortal() { |
+ NetworkPortalDetector::CaptivePortalState portal_state; |
+ portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; |
+ network_portal_detector_->SetDetectionResultsForTesting( |
+ kStubEthernetServicePath, portal_state); |
+ network_portal_detector_->NotifyObserversForTesting(); |
+ } |
+ |
+ base::Closure SimulateNetworkPortalClosure() { |
+ return base::Bind(&KioskTest::SimulateNetworkPortal, |
+ base::Unretained(this)); |
} |
void WaitForAppLaunchNetworkTimeout() { |
@@ -483,23 +503,21 @@ class KioskTest : public InProcessBrowserTest { |
} |
FakeGaia fake_gaia_; |
- scoped_ptr<net::NetworkChangeNotifier::DisableForTest> |
- disable_network_notifier_; |
- scoped_ptr<FakeNetworkChangeNotifier> fake_network_notifier_; |
scoped_ptr<MockUserManager> mock_user_manager_; |
+ NetworkPortalDetectorTestImpl* network_portal_detector_; |
}; |
IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) { |
- StartAppLaunchFromLoginScreen(true); |
+ StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); |
WaitForAppLaunchSuccess(); |
} |
IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDown) { |
- // Mock network could be configured. |
- ScopedCanConfigureNetwork can_configure_network(true); |
+ // Mock network could be configured with owner's password. |
+ ScopedCanConfigureNetwork can_configure_network(true, true); |
// Start app launch and wait for network connectivity timeout. |
- StartAppLaunchFromLoginScreen(false); |
+ StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
splash_waiter.Wait(); |
WaitForAppLaunchNetworkTimeout(); |
@@ -532,10 +550,10 @@ IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDown) { |
IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDownConfigureNotAllowed) { |
// Mock network could not be configured. |
- ScopedCanConfigureNetwork can_configure_network(false); |
+ ScopedCanConfigureNetwork can_configure_network(false, true); |
// Start app launch and wait for network connectivity timeout. |
- StartAppLaunchFromLoginScreen(false); |
+ StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
splash_waiter.Wait(); |
WaitForAppLaunchNetworkTimeout(); |
@@ -547,8 +565,26 @@ IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkDownConfigureNotAllowed) { |
WaitForAppLaunchSuccess(); |
} |
+IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppNetworkPortal) { |
+ // Mock network could be configured without the owner password. |
+ ScopedCanConfigureNetwork can_configure_network(true, false); |
+ |
+ // Start app launch with network portal state. |
+ StartAppLaunchFromLoginScreen(SimulateNetworkPortalClosure()); |
+ OobeScreenWaiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH) |
+ .WaitNoAssertCurrentScreen(); |
+ WaitForAppLaunchNetworkTimeout(); |
+ |
+ // Network error should show up automatically since this test does not |
+ // require owner auth to configure network. |
+ OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait(); |
+ |
+ ASSERT_TRUE(GetAppLaunchController()->showing_network_dialog()); |
+ WaitForAppLaunchSuccess(); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(KioskTest, LaunchAppUserCancel) { |
- StartAppLaunchFromLoginScreen(false); |
+ StartAppLaunchFromLoginScreen(SimulateNetworkOfflineClosure()); |
OobeScreenWaiter splash_waiter(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH); |
splash_waiter.Wait(); |