diff options
author | nkostylev <nkostylev@chromium.org> | 2015-04-15 14:19:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-15 21:19:47 +0000 |
commit | 29061783f8b59f1e78286a87a3bb7d18129f639a (patch) | |
tree | f90a87d5f08545ebd9bd00941c7a257bd05d49aa | |
parent | 45a3c93f745eabf6c1b1cbdac87ed4350a919e76 (diff) | |
download | chromium_src-29061783f8b59f1e78286a87a3bb7d18129f639a.zip chromium_src-29061783f8b59f1e78286a87a3bb7d18129f639a.tar.gz chromium_src-29061783f8b59f1e78286a87a3bb7d18129f639a.tar.bz2 |
[cros New-GAIA] Webview login and new GAIA endpoint enabled by default
For devices with Remora/Shark requisition webview is still disabled (http://crbug.com/464049)
webview is disabled for these tests:
* WizardControllerProxyAuthOnSigninTest* (http://crbug.com/452452)
* ProxyAuthOnUserBoardScreenTest* (http://crbug.com/452452)
* Tests that are based on LoginManagerTest/OobeBaseTest and are not yet parametrized (http://crbug.com/477402)
BUG=475529, 452452, 472664, 464049, 477402
TBR=jhawkins@chromium.org
Review URL: https://codereview.chromium.org/1079083002
Cr-Commit-Position: refs/heads/master@{#325307}
20 files changed, 377 insertions, 196 deletions
diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index afe1bf4..f949875 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -153,8 +153,20 @@ content::StoragePartition* GetSigninPartition() { } net::URLRequestContextGetter* GetSigninContext() { - if (StartupUtils::IsWebviewSigninEnabled()) - return GetSigninPartition()->GetURLRequestContext(); + if (StartupUtils::IsWebviewSigninEnabled()) { + content::StoragePartition* signin_partition = GetSigninPartition(); + + // Special case for unit tests. There's no LoginDisplayHost thus no + // webview instance. TODO(nkostylev): Investigate if there's a better + // place to address this like dependency injection. http://crbug.com/477402 + if (!signin_partition && !LoginDisplayHostImpl::default_host()) + return ProfileHelper::GetSigninProfile()->GetRequestContext(); + + if (!signin_partition) + return nullptr; + + return signin_partition->GetURLRequestContext(); + } return ProfileHelper::GetSigninProfile()->GetRequestContext(); } diff --git a/chrome/browser/chromeos/login/hid_detection_browsertest.cc b/chrome/browser/chromeos/login/hid_detection_browsertest.cc index ebb23d2..d4e31b2 100644 --- a/chrome/browser/chromeos/login/hid_detection_browsertest.cc +++ b/chrome/browser/chromeos/login/hid_detection_browsertest.cc @@ -43,11 +43,15 @@ void SetUpBluetoothMock( namespace chromeos { -class HidDetectionTest : public OobeBaseTest { +// Boolean parameter is used to run this test for webview (true) and for +// iframe (false) GAIA sign in. +class HidDetectionTest : public OobeBaseTest, + public testing::WithParamInterface<bool> { public: typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; HidDetectionTest() : weak_ptr_factory_(this) { + set_use_webview(GetParam()); InputServiceProxy::SetThreadIdForTesting(content::BrowserThread::UI); HidDetectionTest::InitInputService(); } @@ -112,13 +116,17 @@ class HidDetectionSkipTest : public HidDetectionTest { } }; -IN_PROC_BROWSER_TEST_F(HidDetectionTest, NoDevicesConnected) { +IN_PROC_BROWSER_TEST_P(HidDetectionTest, NoDevicesConnected) { OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_HID_DETECTION).Wait(); } -IN_PROC_BROWSER_TEST_F(HidDetectionSkipTest, BothDevicesPreConnected) { +IN_PROC_BROWSER_TEST_P(HidDetectionSkipTest, BothDevicesPreConnected) { OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_NETWORK).Wait(); - } +INSTANTIATE_TEST_CASE_P(HidDetectionSuite, HidDetectionTest, testing::Bool()); +INSTANTIATE_TEST_CASE_P(HidDetectionSkipSuite, + HidDetectionSkipTest, + testing::Bool()); + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc index 85880b1..5d1cffa 100644 --- a/chrome/browser/chromeos/login/login_browsertest.cc +++ b/chrome/browser/chromeos/login/login_browsertest.cc @@ -5,6 +5,8 @@ #include "ash/shell.h" #include "ash/system/tray/system_tray.h" #include "base/command_line.h" +#include "base/json/json_file_value_serializer.h" +#include "base/path_service.h" #include "base/strings/string_util.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/login_manager_test.h" @@ -17,7 +19,9 @@ #include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/tracing.h" @@ -143,6 +147,33 @@ class LoginTest : public chromeos::LoginManagerTest { } }; +class LoginOfflineTest : public LoginTest { + public: + LoginOfflineTest() {} + ~LoginOfflineTest() override {} + + bool SetUpUserDataDirectory() override { + base::FilePath user_data_dir; + CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); + base::FilePath local_state_path = + user_data_dir.Append(chrome::kLocalStateFilename); + base::DictionaryValue local_state_dict; + + // Set webview disabled flag only when local state file does not exist. + // Otherwise, we break PRE tests that leave state in it. + if (!base::PathExists(local_state_path)) { + // TODO(rsorokin): Fix offline test for webview signin. + // http://crbug.com/475569 + local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); + + CHECK(JSONFileValueSerializer(local_state_path) + .Serialize(local_state_dict)); + } + + return LoginTest::SetUpUserDataDirectory(); + } +}; + // Used to make sure that the system tray is visible and within the screen // bounds after login. void TestSystemTrayIsVisible() { @@ -215,14 +246,14 @@ IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) { ASSERT_TRUE(tracing::EndTracing(&json_events)); } -IN_PROC_BROWSER_TEST_F(LoginTest, PRE_GaiaAuthOffline) { +IN_PROC_BROWSER_TEST_F(LoginOfflineTest, PRE_GaiaAuthOffline) { RegisterUser(kTestUser); chromeos::StartupUtils::MarkOobeCompleted(); chromeos::CrosSettings::Get()->SetBoolean( chromeos::kAccountsPrefShowUserNamesOnSignIn, false); } -IN_PROC_BROWSER_TEST_F(LoginTest, GaiaAuthOffline) { +IN_PROC_BROWSER_TEST_F(LoginOfflineTest, GaiaAuthOffline) { bool show_user; ASSERT_TRUE(chromeos::CrosSettings::Get()->GetBoolean( chromeos::kAccountsPrefShowUserNamesOnSignIn, &show_user)); diff --git a/chrome/browser/chromeos/login/login_manager_test.cc b/chrome/browser/chromeos/login/login_manager_test.cc index 45a6101..bd44832 100644 --- a/chrome/browser/chromeos/login/login_manager_test.cc +++ b/chrome/browser/chromeos/login/login_manager_test.cc @@ -5,14 +5,20 @@ #include "chrome/browser/chromeos/login/login_manager_test.h" #include "base/command_line.h" +#include "base/json/json_file_value_serializer.h" +#include "base/path_service.h" #include "base/prefs/scoped_user_pref_update.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" #include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" +#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" #include "chrome/browser/chromeos/login/ui/webui_login_view.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/pref_names.h" #include "chromeos/chromeos_switches.h" #include "chromeos/login/auth/key.h" #include "chromeos/login/auth/user_context.h" @@ -27,7 +33,8 @@ namespace chromeos { LoginManagerTest::LoginManagerTest(bool should_launch_browser) - : should_launch_browser_(should_launch_browser), + : use_webview_(false), + should_launch_browser_(should_launch_browser), web_contents_(NULL) { set_exit_when_last_browser_closes(false); } @@ -61,6 +68,29 @@ void LoginManagerTest::SetUpOnMainThread() { should_launch_browser_); } +bool LoginManagerTest::SetUpUserDataDirectory() { + base::FilePath user_data_dir; + CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); + base::FilePath local_state_path = + user_data_dir.Append(chrome::kLocalStateFilename); + + if (!use_webview()) { + // Set webview disabled flag only when local state file does not exist. + // Otherwise, we break PRE tests that leave state in it. + if (!base::PathExists(local_state_path)) { + base::DictionaryValue local_state_dict; + + // TODO(nkostylev): Fix tests that fail with webview signin. + local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); + + CHECK(JSONFileValueSerializer(local_state_path) + .Serialize(local_state_dict)); + } + } + + return MixinBasedBrowserTest::SetUpUserDataDirectory(); +} + void LoginManagerTest::RegisterUser(const std::string& user_id) { ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers"); users_pref->AppendIfNotPresent(new base::StringValue(user_id)); diff --git a/chrome/browser/chromeos/login/login_manager_test.h b/chrome/browser/chromeos/login/login_manager_test.h index e2b6921..ff4a6dd 100644 --- a/chrome/browser/chromeos/login/login_manager_test.h +++ b/chrome/browser/chromeos/login/login_manager_test.h @@ -33,6 +33,7 @@ class LoginManagerTest : public MixinBasedBrowserTest { void SetUpCommandLine(base::CommandLine* command_line) override; void SetUpInProcessBrowserTestFixture() override; void SetUpOnMainThread() override; + bool SetUpUserDataDirectory() override; // Registers the user with the given |user_id| on the device. // This method should be called in PRE_* test. @@ -66,6 +67,12 @@ class LoginManagerTest : public MixinBasedBrowserTest { test::JSChecker& js_checker() { return js_checker_; } + protected: + bool use_webview() { return use_webview_; } + void set_use_webview(bool use_webview) { use_webview_ = use_webview; } + + bool use_webview_; + private: void InitializeWebContents(); diff --git a/chrome/browser/chromeos/login/oobe_browsertest.cc b/chrome/browser/chromeos/login/oobe_browsertest.cc index da7e596..2f13bd1 100644 --- a/chrome/browser/chromeos/login/oobe_browsertest.cc +++ b/chrome/browser/chromeos/login/oobe_browsertest.cc @@ -5,6 +5,7 @@ #include "base/command_line.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" +#include "chrome/browser/chromeos/login/test/oobe_base_test.h" #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" #include "chrome/browser/chromeos/login/ui/webui_login_display.h" @@ -14,8 +15,8 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/base/in_process_browser_test.h" #include "chromeos/chromeos_switches.h" +#include "content/public/test/browser_test_utils.h" #include "content/public/test/test_utils.h" -#include "google_apis/gaia/fake_gaia.h" #include "google_apis/gaia/gaia_switches.h" #include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/http_response.h" @@ -27,28 +28,17 @@ using namespace net::test_server; namespace chromeos { -class OobeTest : public InProcessBrowserTest { +// Boolean parameter is used to run this test for webview (true) and for +// iframe (false) GAIA sign in. +class OobeTest : public OobeBaseTest, public testing::WithParamInterface<bool> { public: - OobeTest() {} + OobeTest() { set_use_webview(GetParam()); } ~OobeTest() override {} void SetUpCommandLine(base::CommandLine* command_line) override { - command_line->AppendSwitch(chromeos::switches::kLoginManager); - command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); - command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); - command_line->AppendSwitchASCII( - ::switches::kAuthExtensionPath, "gaia_auth"); - fake_gaia_.Initialize(); - } - - void SetUpOnMainThread() override { - CHECK(embedded_test_server()->InitializeAndWaitUntilReady()); - embedded_test_server()->RegisterRequestHandler( - base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); - LOG(INFO) << "Set up http server at " << embedded_test_server()->base_url(); + command_line->AppendSwitch(switches::kOobeSkipPostLogin); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - ::switches::kGaiaUrl, embedded_test_server()->base_url().spec()); + OobeBaseTest::SetUpCommandLine(command_line); } void TearDownOnMainThread() override { @@ -58,6 +48,8 @@ class OobeTest : public InProcessBrowserTest { base::Bind(&chrome::AttemptExit)); content::RunMessageLoop(); } + + OobeBaseTest::TearDownOnMainThread(); } chromeos::WebUILoginDisplay* GetLoginDisplay() { @@ -75,40 +67,24 @@ class OobeTest : public InProcessBrowserTest { } private: - FakeGaia fake_gaia_; DISALLOW_COPY_AND_ASSIGN(OobeTest); }; -IN_PROC_BROWSER_TEST_F(OobeTest, NewUser) { - chromeos::WizardController::SkipPostLoginScreensForTesting(); - chromeos::WizardController* wizard_controller = - chromeos::WizardController::default_controller(); - CHECK(wizard_controller); - wizard_controller->SkipToLoginForTesting(LoginScreenContext()); +IN_PROC_BROWSER_TEST_P(OobeTest, NewUser) { + WaitForGaiaPageLoad(); - content::WindowedNotificationObserver( - chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, - content::NotificationService::AllSources()).Wait(); + content::WindowedNotificationObserver session_start_waiter( + chrome::NOTIFICATION_SESSION_STARTED, + content::NotificationService::AllSources()); - // TODO(glotov): mock GAIA server (test_server()) should support - // username/password configuration. - GetLoginDisplay()->ShowSigninScreenForCreds("username", "password"); + GetLoginDisplay()->ShowSigninScreenForCreds(OobeBaseTest::kFakeUserEmail, + OobeBaseTest::kFakeUserPassword); - content::WindowedNotificationObserver( - chrome::NOTIFICATION_SESSION_STARTED, - content::NotificationService::AllSources()).Wait(); + session_start_waiter.Wait(); } -IN_PROC_BROWSER_TEST_F(OobeTest, Accelerator) { - chromeos::WizardController::SkipPostLoginScreensForTesting(); - chromeos::WizardController* wizard_controller = - chromeos::WizardController::default_controller(); - CHECK(wizard_controller); - wizard_controller->SkipToLoginForTesting(LoginScreenContext()); - - content::WindowedNotificationObserver( - chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, - content::NotificationService::AllSources()).Wait(); +IN_PROC_BROWSER_TEST_P(OobeTest, Accelerator) { + WaitForGaiaPageLoad(); gfx::NativeWindow login_window = GetLoginWindowWidget()->GetNativeWindow(); @@ -121,4 +97,6 @@ IN_PROC_BROWSER_TEST_F(OobeTest, Accelerator) { OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_ENROLLMENT).Wait(); } +INSTANTIATE_TEST_CASE_P(OobeSuite, OobeTest, testing::Bool()); + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/proxy_auth_dialog_browsertest.cc b/chrome/browser/chromeos/login/proxy_auth_dialog_browsertest.cc index eca6b5c..3eef72f 100644 --- a/chrome/browser/chromeos/login/proxy_auth_dialog_browsertest.cc +++ b/chrome/browser/chromeos/login/proxy_auth_dialog_browsertest.cc @@ -57,13 +57,21 @@ class ProxyAuthDialogWaiter : public content::WindowedNotificationObserver { } // namespace -class ProxyAuthOnUserBoardScreenTest : public LoginManagerTest { +// Boolean parameter is used to run this test for webview (true) and for +// iframe (false) GAIA sign in. +class ProxyAuthOnUserBoardScreenTest + : public LoginManagerTest, + public testing::WithParamInterface<bool> { public: ProxyAuthOnUserBoardScreenTest() : LoginManagerTest(true /* should_launch_browser */), proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, net::SpawnedTestServer::kLocalhost, - base::FilePath()) {} + base::FilePath()) { + // TODO(paulmeyer): Re-enable webview version of this test + // (uncomment this line) once http://crbug.com/452452 is fixed. + // set_use_webview(GetParam()); + } ~ProxyAuthOnUserBoardScreenTest() override {} @@ -84,13 +92,13 @@ class ProxyAuthOnUserBoardScreenTest : public LoginManagerTest { DISALLOW_COPY_AND_ASSIGN(ProxyAuthOnUserBoardScreenTest); }; -IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest, +IN_PROC_BROWSER_TEST_P(ProxyAuthOnUserBoardScreenTest, PRE_ProxyAuthDialogOnUserBoardScreen) { RegisterUser("test-user@gmail.com"); StartupUtils::MarkOobeCompleted(); } -IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest, +IN_PROC_BROWSER_TEST_P(ProxyAuthOnUserBoardScreenTest, ProxyAuthDialogOnUserBoardScreen) { LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host(); WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView(); @@ -120,4 +128,8 @@ IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest, } } +INSTANTIATE_TEST_CASE_P(ProxyAuthOnUserBoardScreenTestSuite, + ProxyAuthOnUserBoardScreenTest, + testing::Bool()); + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/saml/saml_browsertest.cc b/chrome/browser/chromeos/login/saml/saml_browsertest.cc index 0a11e4c..ce4d3c0 100644 --- a/chrome/browser/chromeos/login/saml/saml_browsertest.cc +++ b/chrome/browser/chromeos/login/saml/saml_browsertest.cc @@ -170,7 +170,7 @@ void FakeSamlIdp::SetUp(const std::string& base_path, const GURL& gaia_url) { ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); html_template_dir_ = test_data_dir.Append("login"); - login_path_= base_path; + login_path_ = base_path; login_auth_path_ = base_path + "Auth"; gaia_assertion_url_ = gaia_url.Resolve("/SSO"); } @@ -259,9 +259,14 @@ scoped_ptr<HttpResponse> FakeSamlIdp::BuildHTMLResponse( } // namespace +// Boolean parameter is used to run this test for webview (true) and for +// iframe (false) GAIA sign in. class SamlTest : public OobeBaseTest, public testing::WithParamInterface<bool> { public: - SamlTest() : saml_load_injected_(false) { use_webview_ = GetParam(); } + SamlTest() : saml_load_injected_(false) { + set_use_webview(GetParam()); + set_initialize_fake_merge_session(false); + } ~SamlTest() override {} void SetUpCommandLine(base::CommandLine* command_line) override { @@ -365,13 +370,13 @@ IN_PROC_BROWSER_TEST_P(SamlTest, SamlUI) { // Saml flow UI expectations. JsExpect("$('gaia-signin').classList.contains('full-width')"); - if (!use_webview_) { + if (!use_webview()) { JsExpect("!$('cancel-add-user-button').hidden"); } // Click on 'cancel'. content::DOMMessageQueue message_queue; // Observe before 'cancel'. - if (use_webview_) { + if (use_webview()) { ASSERT_TRUE(content::ExecuteScript( GetLoginUI()->GetWebContents(), "$('close-button-item').click();")); @@ -397,7 +402,7 @@ IN_PROC_BROWSER_TEST_P(SamlTest, CredentialPassingAPI) { // webview.executeScript and there is no way to control the injection time. // As a result, this test is flaky and fails about 20% of the time. // TODO(xiyuan): Re-enable when webview.addContentScript API is ready. - if (use_webview_) + if (use_webview()) return; fake_saml_idp()->SetLoginHTMLTemplate("saml_api_login.html"); diff --git a/chrome/browser/chromeos/login/session/user_session_manager.cc b/chrome/browser/chromeos/login/session/user_session_manager.cc index 31395c2..50f75fb 100644 --- a/chrome/browser/chromeos/login/session/user_session_manager.cc +++ b/chrome/browser/chromeos/login/session/user_session_manager.cc @@ -997,14 +997,29 @@ void UserSessionManager::UserProfileInitialized(Profile* profile, // empty if |transfer_saml_auth_cookies_on_subsequent_login| is true. const bool transfer_auth_cookies_and_channel_ids_on_first_login = has_auth_cookies_; - ProfileAuthData::Transfer( - GetAuthRequestContext(), - profile->GetRequestContext(), - transfer_auth_cookies_and_channel_ids_on_first_login, - transfer_saml_auth_cookies_on_subsequent_login, - base::Bind(&UserSessionManager::CompleteProfileCreateAfterAuthTransfer, - AsWeakPtr(), - profile)); + + net::URLRequestContextGetter* auth_request_context = + GetAuthRequestContext(); + + // Authentication request context may be missing especially if user didn't + // sign in using GAIA (webview) and webview didn't yet initialize. + if (auth_request_context) { + ProfileAuthData::Transfer( + auth_request_context, profile->GetRequestContext(), + transfer_auth_cookies_and_channel_ids_on_first_login, + transfer_saml_auth_cookies_on_subsequent_login, + base::Bind( + &UserSessionManager::CompleteProfileCreateAfterAuthTransfer, + AsWeakPtr(), profile)); + } else { + // We need to post task so that OnProfileCreated() caller sends out + // NOTIFICATION_PROFILE_CREATED which marks user profile as initialized. + base::MessageLoopProxy::current()->PostTask( + FROM_HERE, + base::Bind( + &UserSessionManager::CompleteProfileCreateAfterAuthTransfer, + AsWeakPtr(), profile)); + } return; } @@ -1231,9 +1246,18 @@ void UserSessionManager::RestoreAuthSessionImpl( OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile); login_manager->AddObserver(this); - login_manager->RestoreSession( - GetAuthRequestContext(), session_restore_strategy_, - user_context_.GetRefreshToken(), user_context_.GetAuthCode()); + net::URLRequestContextGetter* auth_request_context = GetAuthRequestContext(); + + // Authentication request context may not be available if user was not + // signing in with GAIA webview (i.e. webview instance hasn't been + // initialized at all). Use fallback request context. + if (!auth_request_context) { + auth_request_context = + authenticator_->authentication_context()->GetRequestContext(); + } + login_manager->RestoreSession(auth_request_context, session_restore_strategy_, + user_context_.GetRefreshToken(), + user_context_.GetAuthCode()); } void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) { @@ -1422,13 +1446,15 @@ void UserSessionManager::UpdateEasyUnlockKeys(const UserContext& user_context) { net::URLRequestContextGetter* UserSessionManager::GetAuthRequestContext() const { - net::URLRequestContextGetter* auth_request_context = NULL; + net::URLRequestContextGetter* auth_request_context = nullptr; if (StartupUtils::IsWebviewSigninEnabled()) { // Webview uses different partition storage than iframe. We need to get // cookies from the right storage for url request to get auth token into // session. - auth_request_context = login::GetSigninPartition()->GetURLRequestContext(); + content::StoragePartition* signin_partition = login::GetSigninPartition(); + if (signin_partition) + auth_request_context = signin_partition->GetURLRequestContext(); } else if (authenticator_.get() && authenticator_->authentication_context()) { auth_request_context = authenticator_->authentication_context()->GetRequestContext(); diff --git a/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc b/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc index 48bdb7b..c09e3a7 100644 --- a/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc +++ b/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc @@ -13,6 +13,7 @@ #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" #include "chrome/browser/chromeos/login/signin_specifics.h" +#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/test/oobe_base_test.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/profiles/profile_manager.h" @@ -130,9 +131,12 @@ class OAuth2LoginManagerStateWaiter : public OAuth2LoginManager::Observer { } // namespace -class OAuth2Test : public OobeBaseTest { +// Boolean parameter is used to run this test for webview (true) and for +// iframe (false) GAIA sign in. +class OAuth2Test : public OobeBaseTest, + public testing::WithParamInterface<bool> { protected: - OAuth2Test() {} + OAuth2Test() { set_use_webview(GetParam()); } void SetUpCommandLine(base::CommandLine* command_line) override { OobeBaseTest::SetUpCommandLine(command_line); @@ -327,23 +331,17 @@ class OAuth2Test : public OobeBaseTest { void StartNewUserSession(bool wait_for_merge) { SetupGaiaServerForNewAccount(); SimulateNetworkOnline(); - chromeos::WizardController::SkipPostLoginScreensForTesting(); - chromeos::WizardController* wizard_controller = - chromeos::WizardController::default_controller(); - wizard_controller->SkipToLoginForTesting(LoginScreenContext()); + WaitForGaiaPageLoad(); - content::WindowedNotificationObserver( - chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, - content::NotificationService::AllSources()).Wait(); + content::WindowedNotificationObserver session_start_waiter( + chrome::NOTIFICATION_SESSION_STARTED, + content::NotificationService::AllSources()); // Use capitalized and dotted user name on purpose to make sure // our email normalization kicks in. GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawAccountId, kTestAccountPassword); - - content::WindowedNotificationObserver( - chrome::NOTIFICATION_SESSION_STARTED, - content::NotificationService::AllSources()).Wait(); + session_start_waiter.Wait(); if (wait_for_merge) { // Wait for the session merge to finish. @@ -414,7 +412,7 @@ class CookieReader : public base::RefCountedThreadSafe<CookieReader> { }; // PRE_MergeSession is testing merge session for a new profile. -IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) { +IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_PRE_PRE_MergeSession) { StartNewUserSession(true); // Check for existance of refresh token. ProfileOAuth2TokenService* token_service = @@ -424,7 +422,6 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) { EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), user_manager::User::OAUTH2_TOKEN_STATUS_VALID); - scoped_refptr<CookieReader> cookie_reader(new CookieReader()); cookie_reader->ReadCookies(profile()); EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); @@ -435,7 +432,7 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) { // that was generated in PRE_PRE_PRE_MergeSession test. In this test, we // are not running /MergeSession process since the /ListAccounts call confirms // that the session is not stale. -IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_MergeSession) { +IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_PRE_MergeSession) { SetupGaiaServerForUnexpiredAccount(); SimulateNetworkOnline(); LoginAsExistingUser(); @@ -449,7 +446,7 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_MergeSession) { // MergeSession test is running merge session process for an existing profile // that was generated in PRE_PRE_MergeSession test. -IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_MergeSession) { +IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_MergeSession) { SetupGaiaServerForExpiredAccount(); SimulateNetworkOnline(); LoginAsExistingUser(); @@ -465,7 +462,7 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_MergeSession) { // MergeSession test is attempting to merge session for an existing profile // that was generated in PRE_PRE_MergeSession test. This attempt should fail // since FakeGaia instance isn't configured to return relevant tokens/cookies. -IN_PROC_BROWSER_TEST_F(OAuth2Test, MergeSession) { +IN_PROC_BROWSER_TEST_P(OAuth2Test, MergeSession) { SimulateNetworkOnline(); content::WindowedNotificationObserver( @@ -535,9 +532,7 @@ class FakeGoogle { } // True if we have already served the test page. - bool IsPageRequested () { - return start_event_.IsSignaled(); - } + bool IsPageRequested() { return start_event_.IsSignaled(); } // Waits until we receive a request to serve the test page. void WaitForPageRequest() { @@ -699,7 +694,7 @@ Browser* FindOrCreateVisibleBrowser(Profile* profile) { return browser; } -IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) { +IN_PROC_BROWSER_TEST_P(MergeSessionTest, PageThrottle) { StartNewUserSession(false); // Try to open a page from google.com. @@ -742,7 +737,7 @@ IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) { DVLOG(1) << "Loaded page at the end : " << title; } -IN_PROC_BROWSER_TEST_F(MergeSessionTest, XHRThrottle) { +IN_PROC_BROWSER_TEST_P(MergeSessionTest, XHRThrottle) { StartNewUserSession(false); // Wait until we get send merge session request. @@ -796,4 +791,7 @@ IN_PROC_BROWSER_TEST_F(MergeSessionTest, XHRThrottle) { EXPECT_TRUE(fake_google_.IsPageRequested()); } +INSTANTIATE_TEST_CASE_P(OAuth2Suite, OAuth2Test, testing::Bool()); +INSTANTIATE_TEST_CASE_P(MergeSessionSuite, MergeSessionTest, testing::Bool()); + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/startup_utils.cc b/chrome/browser/chromeos/login/startup_utils.cc index 1a0d47f..c136ea3 100644 --- a/chrome/browser/chromeos/login/startup_utils.cc +++ b/chrome/browser/chromeos/login/startup_utils.cc @@ -13,6 +13,7 @@ #include "base/sys_info.h" #include "base/threading/thread_restrictions.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/features/feature_channel.h" #include "chrome/common/pref_names.h" @@ -59,7 +60,7 @@ void StartupUtils::RegisterPrefs(PrefRegistrySimple* registry) { registry->RegisterBooleanPref(prefs::kEnrollmentRecoveryRequired, false); registry->RegisterStringPref(prefs::kInitialLocale, "en-US"); registry->RegisterBooleanPref(prefs::kNewOobe, false); - registry->RegisterBooleanPref(prefs::kWebviewSigninEnabled, false); + registry->RegisterBooleanPref(prefs::kWebviewSigninDisabled, false); } // static @@ -179,25 +180,41 @@ std::string StartupUtils::GetInitialLocale() { // static bool StartupUtils::IsWebviewSigninAllowed() { - return extensions::GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV && - !base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableWebviewSigninFlow); + return !base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableWebviewSigninFlow); } // static bool StartupUtils::IsWebviewSigninEnabled() { - return IsWebviewSigninAllowed() && - g_browser_process->local_state()->GetBoolean( - prefs::kWebviewSigninEnabled); + policy::DeviceCloudPolicyManagerChromeOS* policy_manager = + g_browser_process + ? g_browser_process->platform_part() + ->browser_policy_connector_chromeos() + ->GetDeviceCloudPolicyManager() + : nullptr; + + bool is_remora_or_shark_requisition = + policy_manager + ? policy_manager->IsRemoraRequisition() || + policy_manager->IsSharkRequisition() + : false; + + bool is_webview_disabled_pref = g_browser_process->local_state()->GetBoolean( + prefs::kWebviewSigninDisabled); + + // TODO(dzhioev): Re-enable webview signin for remora/shark requisition + // http://crbug.com/464049 + return !is_remora_or_shark_requisition && IsWebviewSigninAllowed() && + !is_webview_disabled_pref; } // static bool StartupUtils::EnableWebviewSignin(bool is_enabled) { - if (!IsWebviewSigninAllowed()) + if (is_enabled && !IsWebviewSigninAllowed()) return false; - g_browser_process->local_state()->SetBoolean(prefs::kWebviewSigninEnabled, - is_enabled); + g_browser_process->local_state()->SetBoolean(prefs::kWebviewSigninDisabled, + !is_enabled); return true; } diff --git a/chrome/browser/chromeos/login/test/oobe_base_test.cc b/chrome/browser/chromeos/login/test/oobe_base_test.cc index 5dcc635..5aa0eff 100644 --- a/chrome/browser/chromeos/login/test/oobe_base_test.cc +++ b/chrome/browser/chromeos/login/test/oobe_base_test.cc @@ -20,6 +20,7 @@ #include "chrome/common/pref_names.h" #include "chromeos/chromeos_switches.h" #include "chromeos/dbus/fake_shill_manager_client.h" +#include "components/policy/core/common/policy_switches.h" #include "components/user_manager/fake_user_manager.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -32,12 +33,19 @@ namespace chromeos { +// static +const char OobeBaseTest::kFakeUserEmail[] = "fake-email@gmail.com"; +const char OobeBaseTest::kFakeUserPassword[] = "fake-password"; +const char OobeBaseTest::kFakeSIDCookie[] = "fake-SID-cookie"; +const char OobeBaseTest::kFakeLSIDCookie[] = "fake-LSID-cookie"; + OobeBaseTest::OobeBaseTest() : fake_gaia_(new FakeGaia()), network_portal_detector_(NULL), needs_background_networking_(false), gaia_frame_parent_("signin-frame"), - use_webview_(false) { + use_webview_(false), + initialize_fake_merge_session_(true) { set_exit_when_last_browser_closes(false); set_chromeos_user_ = false; } @@ -50,6 +58,8 @@ void OobeBaseTest::SetUp() { PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); embedded_test_server()->ServeFilesFromDirectory(test_data_dir); + RegisterAdditionalRequestHandlers(); + embedded_test_server()->RegisterRequestHandler( base::Bind(&FakeGaia::HandleRequest, base::Unretained(fake_gaia_.get()))); @@ -67,25 +77,19 @@ void OobeBaseTest::SetUp() { } bool OobeBaseTest::SetUpUserDataDirectory() { - if (use_webview_) { - // Fake Dev channel to enable webview signin. - scoped_channel_.reset( - new extensions::ScopedCurrentChannel(chrome::VersionInfo::CHANNEL_DEV)); + base::FilePath user_data_dir; + CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); + base::FilePath local_state_path = + user_data_dir.Append(chrome::kLocalStateFilename); - base::FilePath user_data_dir; - CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); - base::FilePath local_state_path = - user_data_dir.Append(chrome::kLocalStateFilename); - - // Set webview enabled flag only when local state file does not exist. + if (!use_webview()) { + // Set webview disabled flag only when local state file does not exist. // Otherwise, we break PRE tests that leave state in it. if (!base::PathExists(local_state_path)) { base::DictionaryValue local_state_dict; - local_state_dict.SetBoolean(prefs::kWebviewSigninEnabled, true); - // OobeCompleted to skip controller-pairing-screen which still uses - // iframe and ends up in a JS error in oobe page init. - // See http://crbug.com/467147 - local_state_dict.SetBoolean(prefs::kOobeComplete, true); + + // TODO(nkostylev): Fix tests that fail with webview signin. + local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); CHECK(JSONFileValueSerializer(local_state_path) .Serialize(local_state_dict)); @@ -106,6 +110,11 @@ void OobeBaseTest::SetUpInProcessBrowserTestFixture() { } void OobeBaseTest::SetUpOnMainThread() { + if (initialize_fake_merge_session()) { + fake_gaia_->SetFakeMergeSessionParams(kFakeUserEmail, kFakeSIDCookie, + kFakeLSIDCookie); + } + // Restart the thread as the sandbox host process has already been spawned. embedded_test_server()->RestartThreadAndListen(); @@ -123,6 +132,7 @@ void OobeBaseTest::TearDownOnMainThread() { base::Bind(&chrome::AttemptExit)); content::RunMessageLoop(); } + EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); ExtensionApiTest::TearDownOnMainThread(); } @@ -136,14 +146,14 @@ void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) { command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); - GURL gaia_url = gaia_https_forwarder_->GetURL(""); + GURL gaia_url = gaia_https_forwarder_->GetURL(std::string()); command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, gaia_url.spec()); fake_gaia_->Initialize(); - fake_gaia_->set_issue_oauth_code_cookie(use_webview_); + fake_gaia_->set_issue_oauth_code_cookie(use_webview()); } void OobeBaseTest::InitHttpsForwarders() { @@ -152,6 +162,9 @@ void OobeBaseTest::InitHttpsForwarders() { ASSERT_TRUE(gaia_https_forwarder_->Start()); } +void OobeBaseTest::RegisterAdditionalRequestHandlers() { +} + void OobeBaseTest::SimulateNetworkOffline() { NetworkPortalDetector::CaptivePortalState offline_state; offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; @@ -217,11 +230,32 @@ WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() { controller->login_display()); } +void OobeBaseTest::WaitForGaiaPageLoad() { + WaitForSigninScreen(); + + if (!use_webview()) + return; + + ASSERT_TRUE(content::ExecuteScript( + GetLoginUI()->GetWebContents(), + "$('gaia-signin').gaiaAuthHost_.addEventListener('ready'," + "function() {" + "window.domAutomationController.setAutomationId(0);" + "window.domAutomationController.send('GaiaReady');" + "});")); + + content::DOMMessageQueue message_queue; + std::string message; + do { + ASSERT_TRUE(message_queue.WaitForMessage(&message)); + } while (message != "\"GaiaReady\""); +} + void OobeBaseTest::WaitForSigninScreen() { WizardController* wizard_controller = WizardController::default_controller(); - if (wizard_controller) { + if (wizard_controller) wizard_controller->SkipToLoginForTesting(LoginScreenContext()); - } + WizardController::SkipPostLoginScreensForTesting(); login_screen_load_observer_->Wait(); diff --git a/chrome/browser/chromeos/login/test/oobe_base_test.h b/chrome/browser/chromeos/login/test/oobe_base_test.h index 6933a01..7c2f592 100644 --- a/chrome/browser/chromeos/login/test/oobe_base_test.h +++ b/chrome/browser/chromeos/login/test/oobe_base_test.h @@ -34,9 +34,22 @@ class NetworkPortalDetectorTestImpl; // Base class for OOBE, login, SAML and Kiosk tests. class OobeBaseTest : public ExtensionApiTest { public: + // Default fake user email and password, may be used by tests. + + static const char kFakeUserEmail[]; + static const char kFakeUserPassword[]; + + // FakeGaia is configured to return these cookies for kFakeUserEmail. + static const char kFakeSIDCookie[]; + static const char kFakeLSIDCookie[]; + OobeBaseTest(); ~OobeBaseTest() override; + // Subclasses may register their own custom request handlers that will + // process requests prior it gets handled by FakeGaia instance. + virtual void RegisterAdditionalRequestHandlers(); + protected: // InProcessBrowserTest overrides. void SetUp() override; @@ -60,12 +73,23 @@ class OobeBaseTest : public ExtensionApiTest { // Checks JavaScript |expression| in login screen. void JsExpect(const std::string& expression); + bool use_webview() { return use_webview_; } + void set_use_webview(bool use_webview) { use_webview_ = use_webview; } + + bool initialize_fake_merge_session() { + return initialize_fake_merge_session_; + } + void set_initialize_fake_merge_session(bool value) { + initialize_fake_merge_session_ = value; + } + // Returns chrome://oobe WebUI. content::WebUI* GetLoginUI(); // Returns login display. WebUILoginDisplay* GetLoginDisplay(); + void WaitForGaiaPageLoad(); void WaitForSigninScreen(); void ExecuteJsInSigninFrame(const std::string& js); void SetSignFormField(const std::string& field_id, @@ -83,6 +107,7 @@ class OobeBaseTest : public ExtensionApiTest { scoped_ptr<HTTPSForwarder> gaia_https_forwarder_; std::string gaia_frame_parent_; bool use_webview_; + bool initialize_fake_merge_session_; DISALLOW_COPY_AND_ASSIGN(OobeBaseTest); }; diff --git a/chrome/browser/chromeos/login/webview_login_browsertest.cc b/chrome/browser/chromeos/login/webview_login_browsertest.cc index c3163b2..b7d3caa 100644 --- a/chrome/browser/chromeos/login/webview_login_browsertest.cc +++ b/chrome/browser/chromeos/login/webview_login_browsertest.cc @@ -10,57 +10,27 @@ #include "content/public/test/test_utils.h" namespace chromeos { -namespace { -const char kFakeUserEmail[] = "fake-email@gmail.com"; -const char kFakeUserPassword[] = "fake-password"; -const char kFakeSIDCookie[] = "fake-SID-cookie"; -const char kFakeLSIDCookie[] = "fake-LSID-cookie"; -} class WebviewLoginTest : public OobeBaseTest { public: - WebviewLoginTest() { use_webview_ = true; } + WebviewLoginTest() { set_use_webview(true); } ~WebviewLoginTest() override {} - void SetUpOnMainThread() override { - fake_gaia_->SetFakeMergeSessionParams(kFakeUserEmail, kFakeSIDCookie, - kFakeLSIDCookie); - - OobeBaseTest::SetUpOnMainThread(); - } - void SetUpCommandLine(base::CommandLine* command_line) override { command_line->AppendSwitch(switches::kOobeSkipPostLogin); OobeBaseTest::SetUpCommandLine(command_line); } - void WaitForGaiaPageLoaded() { - WaitForSigninScreen(); - - ASSERT_TRUE(content::ExecuteScript( - GetLoginUI()->GetWebContents(), - "$('gaia-signin').gaiaAuthHost_.addEventListener('ready'," - "function() {" - "window.domAutomationController.setAutomationId(0);" - "window.domAutomationController.send('GaiaReady');" - "});")); - - content::DOMMessageQueue message_queue; - std::string message; - ASSERT_TRUE(message_queue.WaitForMessage(&message)); - EXPECT_EQ("\"GaiaReady\"", message); - } - private: DISALLOW_COPY_AND_ASSIGN(WebviewLoginTest); }; IN_PROC_BROWSER_TEST_F(WebviewLoginTest, Basic) { - WaitForGaiaPageLoaded(); + WaitForGaiaPageLoad(); JsExpect("$('close-button-item').hidden"); - SetSignFormField("identifier", kFakeUserEmail); + SetSignFormField("identifier", OobeBaseTest::kFakeUserEmail); ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); JsExpect("$('close-button-item').hidden"); @@ -69,21 +39,21 @@ IN_PROC_BROWSER_TEST_F(WebviewLoginTest, Basic) { chrome::NOTIFICATION_SESSION_STARTED, content::NotificationService::AllSources()); - SetSignFormField("password", kFakeUserPassword); + SetSignFormField("password", OobeBaseTest::kFakeUserPassword); ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); session_start_waiter.Wait(); } IN_PROC_BROWSER_TEST_F(WebviewLoginTest, BackButton) { - WaitForGaiaPageLoaded(); + WaitForGaiaPageLoad(); // Start: no back button, first page. JsExpect("$('back-button-item').hidden"); JsExpect("$('signin-frame').src.indexOf('#identifier') != -1"); // Next step: back button active, second page. - SetSignFormField("identifier", kFakeUserEmail); + SetSignFormField("identifier", OobeBaseTest::kFakeUserEmail); ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); JsExpect("!$('back-button-item').hidden"); JsExpect("$('signin-frame').src.indexOf('#challengepassword') != -1"); @@ -103,7 +73,7 @@ IN_PROC_BROWSER_TEST_F(WebviewLoginTest, BackButton) { chrome::NOTIFICATION_SESSION_STARTED, content::NotificationService::AllSources()); - SetSignFormField("password", kFakeUserPassword); + SetSignFormField("password", OobeBaseTest::kFakeUserPassword); ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); session_start_waiter.Wait(); diff --git a/chrome/browser/chromeos/login/wizard_controller_browsertest.cc b/chrome/browser/chromeos/login/wizard_controller_browsertest.cc index 658a78a..3b71746 100644 --- a/chrome/browser/chromeos/login/wizard_controller_browsertest.cc +++ b/chrome/browser/chromeos/login/wizard_controller_browsertest.cc @@ -7,6 +7,8 @@ #include "base/basictypes.h" #include "base/command_line.h" #include "base/compiler_specific.h" +#include "base/json/json_file_value_serializer.h" +#include "base/path_service.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/prefs/pref_service_factory.h" @@ -48,6 +50,7 @@ #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" +#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" @@ -965,7 +968,11 @@ IN_PROC_BROWSER_TEST_F(WizardControllerBrokenLocalStateTest, ASSERT_EQ(1, fake_session_manager_client()->start_device_wipe_call_count()); } -class WizardControllerProxyAuthOnSigninTest : public WizardControllerTest { +// Boolean parameter is used to run this test for webview (true) and for +// iframe (false) GAIA sign in. +class WizardControllerProxyAuthOnSigninTest + : public WizardControllerTest, + public testing::WithParamInterface<bool> { protected: WizardControllerProxyAuthOnSigninTest() : proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, @@ -991,6 +998,32 @@ class WizardControllerProxyAuthOnSigninTest : public WizardControllerTest { proxy_server_.host_port_pair().ToString()); } + bool SetUpUserDataDirectory() override { + base::FilePath user_data_dir; + CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); + base::FilePath local_state_path = + user_data_dir.Append(chrome::kLocalStateFilename); + + // Set webview disabled flag only when local state file does not exist. + // Otherwise, we break PRE tests that leave state in it. + if (!base::PathExists(local_state_path)) { + base::DictionaryValue local_state_dict; + + if (!GetParam()) + local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); + + // TODO(paulmeyer): Re-enable webview version of this test + // (drop this condition) once http://crbug.com/452452 is fixed. + if (GetParam()) + local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); + + CHECK(JSONFileValueSerializer(local_state_path) + .Serialize(local_state_dict)); + } + + return WizardControllerTest::SetUpUserDataDirectory(); + } + net::SpawnedTestServer& proxy_server() { return proxy_server_; } private: @@ -999,7 +1032,7 @@ class WizardControllerProxyAuthOnSigninTest : public WizardControllerTest { DISALLOW_COPY_AND_ASSIGN(WizardControllerProxyAuthOnSigninTest); }; -IN_PROC_BROWSER_TEST_F(WizardControllerProxyAuthOnSigninTest, +IN_PROC_BROWSER_TEST_P(WizardControllerProxyAuthOnSigninTest, ProxyAuthDialogOnSigninScreen) { content::WindowedNotificationObserver auth_needed_waiter( chrome::NOTIFICATION_AUTH_NEEDED, @@ -1011,6 +1044,10 @@ IN_PROC_BROWSER_TEST_F(WizardControllerProxyAuthOnSigninTest, auth_needed_waiter.Wait(); } +INSTANTIATE_TEST_CASE_P(WizardControllerProxyAuthOnSigninSuite, + WizardControllerProxyAuthOnSigninTest, + testing::Bool()); + class WizardControllerKioskFlowTest : public WizardControllerFlowTest { protected: WizardControllerKioskFlowTest() {} diff --git a/chrome/browser/chromeos/policy/blocking_login_browsertest.cc b/chrome/browser/chromeos/policy/blocking_login_browsertest.cc index dabc1f7..03b0504 100644 --- a/chrome/browser/chromeos/policy/blocking_login_browsertest.cc +++ b/chrome/browser/chromeos/policy/blocking_login_browsertest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" +#include "chrome/browser/chromeos/login/test/oobe_base_test.h" #include "chrome/browser/chromeos/login/ui/webui_login_display.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" @@ -27,7 +28,6 @@ #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.h" -#include "google_apis/gaia/fake_gaia.h" #include "google_apis/gaia/gaia_switches.h" #include "google_apis/gaia/gaia_urls.h" #include "net/http/http_status_code.h" @@ -81,52 +81,35 @@ struct BlockingLoginTestParam { }; class BlockingLoginTest - : public InProcessBrowserTest, + : public OobeBaseTest, public content::NotificationObserver, public testing::WithParamInterface<BlockingLoginTestParam> { public: BlockingLoginTest() : profile_added_(NULL) {} void SetUpCommandLine(base::CommandLine* command_line) override { - // Initialize the test server early, so that we can use its base url for - // the command line flags. - ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); - - // Use the login manager screens and the gaia auth extension. - command_line->AppendSwitch(switches::kLoginManager); - command_line->AppendSwitch(switches::kForceLoginManagerInTests); - command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); + OobeBaseTest::SetUpCommandLine(command_line); + command_line->AppendSwitchASCII(::switches::kAuthExtensionPath, "gaia_auth"); - - // Redirect requests to gaia and the policy server to the test server. - command_line->AppendSwitchASCII(::switches::kGaiaUrl, - embedded_test_server()->base_url().spec()); - command_line->AppendSwitchASCII(::switches::kLsoUrl, - embedded_test_server()->base_url().spec()); command_line->AppendSwitchASCII( policy::switches::kDeviceManagementUrl, embedded_test_server()->GetURL("/device_management").spec()); } void SetUpOnMainThread() override { - fake_gaia_.Initialize(); - - embedded_test_server()->RegisterRequestHandler( - base::Bind(&BlockingLoginTest::HandleRequest, base::Unretained(this))); - embedded_test_server()->RegisterRequestHandler( - base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); - registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, content::NotificationService::AllSources()); + + OobeBaseTest::SetUpOnMainThread(); } void TearDownOnMainThread() override { RunUntilIdle(); EXPECT_TRUE(responses_.empty()); STLDeleteElements(&responses_); - EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); + OobeBaseTest::TearDownOnMainThread(); } void Observe(int type, @@ -245,10 +228,14 @@ class BlockingLoginTest } protected: + void RegisterAdditionalRequestHandlers() override { + embedded_test_server()->RegisterRequestHandler( + base::Bind(&BlockingLoginTest::HandleRequest, base::Unretained(this))); + } + Profile* profile_added_; private: - FakeGaia fake_gaia_; std::vector<net::test_server::HttpResponse*> responses_; content::NotificationRegistrar registrar_; diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 0657d6f..9d65d26 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1081,6 +1081,10 @@ 'browser/chromeos/login/screenshot_testing/screenshot_tester.h', 'browser/chromeos/login/screenshot_testing/screenshot_testing_mixin.cc', 'browser/chromeos/login/screenshot_testing/screenshot_testing_mixin.h', + 'browser/chromeos/login/test/https_forwarder.cc', + 'browser/chromeos/login/test/https_forwarder.h', + 'browser/chromeos/login/test/oobe_base_test.cc', + 'browser/chromeos/login/test/oobe_base_test.h', 'browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc', 'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.cc', 'browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.h', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 2966dbf..c3678fc 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1919,9 +1919,8 @@ const char kConsumerManagementStage[] = "consumer_management.stage"; const char kNewOobe[] = "NewOobe"; // A boolean pref. If set to true, experimental webview based signin flow -// activated. -const char kWebviewSigninEnabled[] = - "webview_signin_enabled"; +// is deactivated. +const char kWebviewSigninDisabled[] = "webview_signin_disabled"; #endif // defined(OS_CHROMEOS) // Whether there is a Flash version installed that supports clearing LSO data. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index b40b4f0..3badee1 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -677,7 +677,7 @@ extern const char kLogoutStartedLast[]; extern const char kConsumerManagementStage[]; extern const char kNewOobe[]; extern const char kConsumerManagementEnrollmentStage[]; -extern const char kWebviewSigninEnabled[]; +extern const char kWebviewSigninDisabled[]; #endif // defined(OS_CHROMEOS) extern const char kClearPluginLSODataEnabled[]; diff --git a/chrome/interactive_ui_tests.isolate b/chrome/interactive_ui_tests.isolate index 01c2675..9823d0c 100644 --- a/chrome/interactive_ui_tests.isolate +++ b/chrome/interactive_ui_tests.isolate @@ -130,6 +130,7 @@ '<(PRODUCT_DIR)/nacl_helper', '<(PRODUCT_DIR)/nacl_irt_x86_64.nexe', '<(PRODUCT_DIR)/resources/chromeos/', + 'browser/chromeos/login/test/https_forwarder.py', ], }, }], |