| Index: chrome/browser/chromeos/login/login_browsertest.cc
|
| diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc
|
| index b074a04962ce64ec101833d9f8c7180b3cffdd09..c98ee6b2903d0d329d7fca5daa70e020ca077cb7 100644
|
| --- a/chrome/browser/chromeos/login/login_browsertest.cc
|
| +++ b/chrome/browser/chromeos/login/login_browsertest.cc
|
| @@ -12,22 +12,28 @@
|
| #include "base/location.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/strings/string_util.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #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/startup_utils.h"
|
| +#include "chrome/browser/chromeos/login/test/js_checker.h"
|
| #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
|
| #include "chrome/browser/chromeos/login/wizard_controller.h"
|
| #include "chrome/browser/chromeos/settings/cros_settings.h"
|
| +#include "chrome/browser/chromeos/settings/stub_install_attributes.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/profiles/profiles_state.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/common/chrome_constants.h"
|
| #include "chrome/common/chrome_switches.h"
|
| +#include "chrome/grit/generated_resources.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| #include "chrome/test/base/interactive_test_utils.h"
|
| #include "chromeos/chromeos_switches.h"
|
| +#include "chromeos/dbus/dbus_thread_manager.h"
|
| +#include "chromeos/dbus/fake_auth_policy_client.h"
|
| #include "chromeos/settings/cros_settings_names.h"
|
| #include "components/signin/core/account_id/account_id.h"
|
| #include "components/user_manager/user_names.h"
|
| @@ -36,6 +42,7 @@
|
| #include "extensions/browser/extension_system.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| #include "ui/gfx/geometry/test/rect_test_util.h"
|
|
|
| using ::gfx::test::RectContains;
|
| @@ -179,6 +186,126 @@ class LoginTest : public LoginManagerTest {
|
| }
|
| };
|
|
|
| +const char kDeviceId[] = "device_id";
|
| +const char kTestRealm[] = "test_realm.com";
|
| +const char kTestActiveDirectoryUser[] = "test-user";
|
| +const char kAdMachineInput[] = "machineNameInput";
|
| +const char kAdUserInput[] = "userInput";
|
| +const char kAdPasswordInput[] = "passwordInput";
|
| +const char kAdButton[] = "button";
|
| +const char kAdWelcomMessage[] = "welcomeMsg";
|
| +const char kAdAutocompleteRealm[] = "userInput /deep/ #domainLabel";
|
| +
|
| +class ActiveDirectoryLoginTest : public LoginManagerTest {
|
| + public:
|
| + ActiveDirectoryLoginTest()
|
| + : LoginManagerTest(true),
|
| + install_attributes_(
|
| + ScopedStubInstallAttributes::CreateActiveDirectoryManaged(
|
| + kTestRealm,
|
| + kDeviceId)) {}
|
| +
|
| + ~ActiveDirectoryLoginTest() override = default;
|
| +
|
| + void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + command_line->AppendSwitch(switches::kOobeSkipPostLogin);
|
| + LoginManagerTest::SetUpCommandLine(command_line);
|
| + }
|
| +
|
| + void SetUpOnMainThread() override {
|
| + LoginManagerTest::SetUpOnMainThread();
|
| + fake_auth_policy_client_ = static_cast<FakeAuthPolicyClient*>(
|
| + DBusThreadManager::Get()->GetAuthPolicyClient());
|
| + }
|
| +
|
| + void MarkAsActiveDirectoryEnterprise() {
|
| + StartupUtils::MarkOobeCompleted();
|
| + base::RunLoop loop;
|
| + fake_auth_policy_client_->RefreshDevicePolicy(
|
| + base::Bind(&ActiveDirectoryLoginTest::OnRefreshedPolicy,
|
| + base::Unretained(this), loop.QuitClosure()));
|
| + loop.Run();
|
| + }
|
| +
|
| + // Checks if Active Directory login is visible.
|
| + void TestLoginVisible() {
|
| + // Checks if Gaia signin is hidden.
|
| + JSExpect("document.querySelector('#signin-frame').hidden");
|
| +
|
| + // Checks if Active Directory signin is visible.
|
| + JSExpect("!document.querySelector('#offline-ad-auth').hidden");
|
| + JSExpect(JSElement(kAdMachineInput) + ".hidden");
|
| + JSExpect("!" + JSElement(kAdUserInput) + ".hidden");
|
| + JSExpect("!" + JSElement(kAdPasswordInput) + ".hidden");
|
| +
|
| + const std::string innerText(".innerText");
|
| + // Checks if Active Directory welcome message contains realm.
|
| + EXPECT_EQ(l10n_util::GetStringFUTF8(IDS_AD_DOMAIN_AUTH_WELCOME_MESSAGE,
|
| + base::UTF8ToUTF16(kTestRealm)),
|
| + js_checker().GetString(JSElement(kAdWelcomMessage) + innerText));
|
| +
|
| + // Checks if realm is set to autocomplete username.
|
| + EXPECT_EQ(
|
| + "@" + std::string(kTestRealm),
|
| + js_checker().GetString(JSElement(kAdAutocompleteRealm) + innerText));
|
| +
|
| + // Checks if bottom bar is visible.
|
| + JSExpect("!Oobe.getInstance().headerHidden");
|
| + }
|
| +
|
| + // Checks if user input is marked as invalid.
|
| + void TestUserError() {
|
| + TestLoginVisible();
|
| + JSExpect(JSElement(kAdUserInput) + ".isInvalid");
|
| + }
|
| +
|
| + // Checks if password input is marked as invalid.
|
| + void TestPasswordError() {
|
| + TestLoginVisible();
|
| + JSExpect(JSElement(kAdPasswordInput) + ".isInvalid");
|
| + }
|
| +
|
| + // Checks if autocomplete domain is visible for the user input.
|
| + void TestDomainVisible() {
|
| + JSExpect("!" + JSElement(kAdAutocompleteRealm) + ".hidden");
|
| + }
|
| +
|
| + // Checks if autocomplete domain is hidden for the user input.
|
| + void TestDomainHidden() {
|
| + JSExpect(JSElement(kAdAutocompleteRealm) + ".hidden");
|
| + }
|
| +
|
| + // Sets username and password for the Active Directory login and submits it.
|
| + void SubmitActiveDirectoryCredentials(const std::string& username,
|
| + const std::string& password) {
|
| + js_checker().ExecuteAsync(JSElement(kAdUserInput) + ".value='" + username +
|
| + "'");
|
| + js_checker().ExecuteAsync(JSElement(kAdPasswordInput) + ".value='" +
|
| + password + "'");
|
| + js_checker().Evaluate(JSElement(kAdButton) + ".fire('tap')");
|
| + }
|
| +
|
| + protected:
|
| + // Returns string representing element with id=|element_id| inside Active
|
| + // Directory login element.
|
| + std::string JSElement(const std::string& element_id) {
|
| + return "document.querySelector('#offline-ad-auth /deep/ #" + element_id +
|
| + "')";
|
| + }
|
| + FakeAuthPolicyClient* fake_auth_policy_client_ = nullptr;
|
| +
|
| + private:
|
| + // Used for the callback from FakeAuthPolicy::RefreshDevicePolicy.
|
| + void OnRefreshedPolicy(const base::Closure& closure, bool status) {
|
| + EXPECT_TRUE(status);
|
| + closure.Run();
|
| + }
|
| +
|
| + ScopedStubInstallAttributes install_attributes_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ActiveDirectoryLoginTest);
|
| +};
|
| +
|
| // Used to make sure that the system tray is visible and within the screen
|
| // bounds after login.
|
| void TestSystemTrayIsVisible(bool otr) {
|
| @@ -280,4 +407,54 @@ IN_PROC_BROWSER_TEST_F(LoginTest, DISABLED_GaiaAuthOffline) {
|
| TestSystemTrayIsVisible(false);
|
| }
|
|
|
| +// Marks as Active Directory enterprise device and OOBE as completed.
|
| +IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginSuccess) {
|
| + MarkAsActiveDirectoryEnterprise();
|
| +}
|
| +
|
| +// Test successful Active Directory login.
|
| +IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginSuccess) {
|
| + TestLoginVisible();
|
| + TestDomainVisible();
|
| +
|
| + content::WindowedNotificationObserver session_start_waiter(
|
| + chrome::NOTIFICATION_SESSION_STARTED,
|
| + content::NotificationService::AllSources());
|
| + SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword);
|
| + session_start_waiter.Wait();
|
| +
|
| + // Uncomment once flakiness is fixed, see http://crbug/692364.
|
| + // TestSystemTrayIsVisible();
|
| +}
|
| +
|
| +// Marks as Active Directory enterprise device and OOBE as completed.
|
| +IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginErrors) {
|
| + MarkAsActiveDirectoryEnterprise();
|
| +}
|
| +
|
| +// Test different UI errors for Active Directory login.
|
| +IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginErrors) {
|
| + TestLoginVisible();
|
| + TestDomainVisible();
|
| +
|
| + SubmitActiveDirectoryCredentials("", "");
|
| + TestUserError();
|
| + TestDomainVisible();
|
| +
|
| + SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, "");
|
| + TestPasswordError();
|
| + TestDomainVisible();
|
| +
|
| + fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_USER_NAME);
|
| + SubmitActiveDirectoryCredentials(std::string(kTestActiveDirectoryUser) + "@",
|
| + kPassword);
|
| + TestUserError();
|
| + TestDomainHidden();
|
| +
|
| + fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_PASSWORD);
|
| + SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword);
|
| + TestPasswordError();
|
| + TestDomainVisible();
|
| +}
|
| +
|
| } // namespace chromeos
|
|
|