Commit 852ab97c authored by Denis Kuznetsov's avatar Denis Kuznetsov Committed by Commit Bot

Login: Add tests for offline GAIA with domain autocompletion

Also updated OfflineGaiaTestMixin to use new JSChecker features.

Bug: 1110790
Change-Id: If30fde066b4768affc1ace615d2a745d791bbc1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418407
Commit-Queue: Denis Kuznetsov [CET] <antrim@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808905}
parent 774c24d4
......@@ -15,6 +15,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/login/test/device_state_mixin.h"
#include "chrome/browser/chromeos/login/test/embedded_test_server_mixin.h"
#include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h"
#include "chrome/browser/chromeos/login/test/guest_session_mixin.h"
......@@ -32,9 +33,11 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/policy/proto/chrome_device_policy.pb.h"
#include "components/user_manager/user_names.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/geometry/test/rect_test_util.h"
......@@ -85,6 +88,43 @@ class LoginOfflineTest : public LoginManagerTest {
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
};
class LoginOfflineManagedTest : public LoginManagerTest {
public:
LoginOfflineManagedTest() {
login_manager_.AppendManagedUsers(1);
managed_user_id_ = login_manager_.users()[0].account_id;
}
~LoginOfflineManagedTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
LoginManagerTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(
chromeos::switches::kAllowFailedPolicyFetchForTest);
}
void ConfigurePolicy(const std::string& autocomplete_domain) {
std::unique_ptr<ScopedDevicePolicyUpdate> device_policy_update =
device_state_.RequestDevicePolicyUpdate();
device_policy_update->policy_payload()
->mutable_login_screen_domain_auto_complete()
->set_login_screen_domain_auto_complete(autocomplete_domain);
device_policy_update->policy_payload()
->mutable_show_user_names()
->set_show_user_names(false);
}
protected:
AccountId managed_user_id_;
DeviceStateMixin device_state_{
&mixin_host_, DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED};
LoginManagerMixin login_manager_{&mixin_host_};
OfflineGaiaTestMixin offline_gaia_test_mixin_{&mixin_host_};
// We need Fake gaia to avoid network errors that can be caused by
// attempts to load real GAIA.
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
};
// Used to make sure that the system tray is visible and within the screen
// bounds after login.
void TestSystemTrayIsVisible(bool otr) {
......@@ -179,4 +219,39 @@ IN_PROC_BROWSER_TEST_F(LoginOfflineTest, GaiaAuthOffline) {
TestSystemTrayIsVisible(false);
}
IN_PROC_BROWSER_TEST_F(LoginOfflineManagedTest, CorrectDomainCompletion) {
std::string domain = gaia::ExtractDomainName(managed_user_id_.GetUserEmail());
ConfigurePolicy(domain);
std::string email = managed_user_id_.GetUserEmail();
size_t separator_pos = email.find('@');
ASSERT_TRUE(separator_pos != email.npos &&
separator_pos < email.length() - 1);
std::string prefix = email.substr(0, separator_pos);
offline_gaia_test_mixin_.GoOffline();
offline_gaia_test_mixin_.InitOfflineLogin(managed_user_id_,
LoginManagerTest::kPassword);
offline_gaia_test_mixin_.CheckManagedStatus(true);
offline_gaia_test_mixin_.SubmitGaiaAuthOfflineForm(
prefix, LoginManagerTest::kPassword, true /* wait for sign-in */);
TestSystemTrayIsVisible(false);
}
IN_PROC_BROWSER_TEST_F(LoginOfflineManagedTest, FullEmailDontMatchProvided) {
ConfigurePolicy("another.domain");
offline_gaia_test_mixin_.GoOffline();
offline_gaia_test_mixin_.InitOfflineLogin(managed_user_id_,
LoginManagerTest::kPassword);
offline_gaia_test_mixin_.SubmitGaiaAuthOfflineForm(
managed_user_id_.GetUserEmail(), LoginManagerTest::kPassword,
true /* wait for sign-in */);
TestSystemTrayIsVisible(false);
}
} // namespace chromeos
......@@ -24,6 +24,22 @@ namespace chromeos {
namespace {
const test::UIPath kOfflineLoginLink = {"error-offline-login-link"};
const test::UIPath kOfflineGaiaDialog = {"gaia-signin", "offline-gaia"};
const test::UIPath kOnlineGaiaDialog = {"gaia-signin", "signin-frame-dialog"};
const test::UIPath kEmailPage = {"gaia-signin", "offline-gaia",
"email-section"};
const test::UIPath kPasswordPage = {"gaia-signin", "offline-gaia",
"password-section"};
const test::UIPath kEmailInput = {"gaia-signin", "offline-gaia", "emailInput"};
const test::UIPath kPasswordInput = {"gaia-signin", "offline-gaia",
"passwordInput"};
const test::UIPath kNextButton = {"gaia-signin", "offline-gaia", "next-button"};
const test::UIPath kManagementDisclosure = {"gaia-signin", "offline-gaia",
"managedBy"};
void SetExpectedCredentials(const AccountId& test_account_id,
const std::string& password) {
UserContext user_context(user_manager::UserType::USER_TYPE_REGULAR,
......@@ -70,11 +86,9 @@ void OfflineGaiaTestMixin::GoOnline() {
void OfflineGaiaTestMixin::CheckManagedStatus(bool expected_is_managed) {
if (expected_is_managed) {
test::OobeJS().ExpectVisiblePath(
{"gaia-signin", "offline-gaia", "managedBy"});
test::OobeJS().ExpectVisiblePath(kManagementDisclosure);
} else {
test::OobeJS().ExpectHiddenPath(
{"gaia-signin", "offline-gaia", "managedBy"});
test::OobeJS().ExpectHiddenPath(kManagementDisclosure);
}
}
......@@ -94,42 +108,31 @@ void OfflineGaiaTestMixin::StartGaiaAuthOffline() {
test::OobeJS()
.CreateWaiter("window.$ && $('error-offline-login-link')")
->Wait();
test::ExecuteOobeJS("$('error-offline-login-link').onclick();");
test::OobeJS()
.CreateVisibilityWaiter(true, {"gaia-signin", "offline-gaia"})
->Wait();
test::OobeJS().TapLinkOnPath(kOfflineLoginLink);
test::OobeJS().CreateVisibilityWaiter(true, kOfflineGaiaDialog)->Wait();
}
void OfflineGaiaTestMixin::SubmitGaiaAuthOfflineForm(
const std::string& user_email,
const std::string& password,
bool wait_for_signin) {
test::OobeJS().ExpectVisiblePath({"gaia-signin", "offline-gaia"});
test::OobeJS().ExpectHiddenPath({"gaia-signin", "signin-frame-dialog"});
test::OobeJS()
.CreateDisplayedWaiter(true,
{"gaia-signin", "offline-gaia", "email-section"})
->Wait();
test::OobeJS()
.CreateDisplayedWaiter(
false, {"gaia-signin", "offline-gaia", "password-section"})
->Wait();
test::OobeJS().TypeIntoPath(user_email,
{"gaia-signin", "offline-gaia", "emailInput"});
test::OobeJS().ClickOnPath(
{"gaia-signin", "offline-gaia", "next-button"});
test::OobeJS()
.CreateDisplayedWaiter(false,
{"gaia-signin", "offline-gaia", "email-section"})
->Wait();
test::OobeJS()
.CreateDisplayedWaiter(
true, {"gaia-signin", "offline-gaia", "password-section"})
->Wait();
test::OobeJS().TypeIntoPath(password,
{"gaia-signin", "offline-gaia", "passwordInput"});
test::OobeJS().ClickOnPath(
{"gaia-signin", "offline-gaia", "next-button"});
test::OobeJS().ExpectVisiblePath(kOfflineGaiaDialog);
test::OobeJS().ExpectHiddenPath(kOnlineGaiaDialog);
test::OobeJS().CreateDisplayedWaiter(true, kEmailPage)->Wait();
test::OobeJS().CreateDisplayedWaiter(false, kPasswordPage)->Wait();
test::OobeJS().TypeIntoPath(user_email, kEmailInput);
test::OobeJS().ClickOnPath(kNextButton);
test::OobeJS().CreateDisplayedWaiter(false, kEmailPage)->Wait();
test::OobeJS().CreateDisplayedWaiter(true, kPasswordPage)->Wait();
test::OobeJS().TypeIntoPath(password, kPasswordInput);
test::OobeJS().ClickOnPath(kNextButton);
if (wait_for_signin) {
SessionStateWaiter(session_manager::SessionState::LOGGED_IN_NOT_ACTIVE)
.Wait();
......
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