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

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

Issue 79113002: kiosk: Network connectivity test during launch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years 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 fd65deba40f9e3bfd9891197374380dcdf7580b8..acdab07bccdae8f4b8b8aad109fc14dc43430b7e 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:
@@ -262,6 +253,11 @@ 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 SetUpOnMainThread() OVERRIDE {
@@ -270,10 +266,6 @@ class KioskTest : public InProcessBrowserTest {
}
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);
@@ -331,7 +323,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.
@@ -352,8 +344,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",
@@ -410,15 +402,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() {
@@ -491,23 +511,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();
@@ -540,10 +558,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();
@@ -555,8 +573,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();

Powered by Google App Engine
This is Rietveld 408576698