Chromium Code Reviews| 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 8444d612fc975c6329ddecaab3ebf10e7fe68b4b..2f450cd6bd4c2db6894ec6a2d4f46514e4965de9 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,115 @@ class LoginTest : public LoginManagerTest { |
| } |
| }; |
| +namespace { |
| + |
| +const char kTestRealm[] = "test_realm.com"; |
| +const char kTestActiveDirectoryUser[] = "test-user"; |
| +#define JS_AD_PREFIX "document.querySelector('#offline-ad-auth /deep/ " |
|
achuithb
2017/03/07 15:07:03
Hmm, pretty sure new macros are banned.
Roman Sorokin (ftl)
2017/03/07 16:32:05
Done.
|
| +const char kAdMachineInput[] = JS_AD_PREFIX "#machineNameInput')"; |
| +const char kAdUserInput[] = JS_AD_PREFIX "#userInput')"; |
| +const char kAdPasswordInput[] = JS_AD_PREFIX "#passwordInput')"; |
| +const char kAdWelcomMessage[] = JS_AD_PREFIX "#welcomeMsg')"; |
| +const char kAdAutocompleteRealm[] = |
| + JS_AD_PREFIX "#userInput /deep/ #domainLabel')"; |
| +#undef JS_AD_PREFIX |
| + |
| +} // namespace |
| + |
| +class ActiveDirectoryLoginTest : public LoginManagerTest { |
|
achuithb
2017/03/07 15:07:03
This should also be in the anonymous namespace - w
Roman Sorokin (ftl)
2017/03/07 16:32:05
Done. My bad - I put anonymous namespace inside an
|
| + public: |
| + ActiveDirectoryLoginTest() |
|
achuithb
2017/03/07 15:07:03
Newlines between methods please. This is very dens
Roman Sorokin (ftl)
2017/03/07 16:32:05
Done.
|
| + : LoginManagerTest(true), |
| + install_attributes_( |
| + ScopedStubInstallAttributes::CreateActiveDirectoryEnterprise( |
| + kTestRealm)) {} |
| + ~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. |
| + js_checker().ExpectTrue("document.querySelector('#signin-frame').hidden"); |
|
achuithb
2017/03/07 15:07:03
You can replace these with JSExpect() (switch the
Roman Sorokin (ftl)
2017/03/07 16:32:05
Done.
|
| + |
| + // Checks if Active Directory signin is visible. |
| + js_checker().ExpectFalse( |
| + "document.querySelector('#offline-ad-auth').hidden"); |
| + const std::string hidden(".hidden"); |
| + js_checker().ExpectTrue(kAdMachineInput + hidden); |
| + js_checker().ExpectFalse(kAdUserInput + hidden); |
| + js_checker().ExpectFalse(kAdPasswordInput + hidden); |
|
achuithb
2017/03/07 15:07:03
I think a method like JSElement(const std::string&
Roman Sorokin (ftl)
2017/03/07 16:32:05
Done.
|
| + |
| + 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(kAdWelcomMessage + innerText)); |
| + |
| + // Checks if realm is set to autocomplete username. |
| + EXPECT_EQ("@" + std::string(kTestRealm), |
| + js_checker().GetString(kAdAutocompleteRealm + innerText)); |
| + |
| + // Checks if bottom bar is visible. |
| + js_checker().ExpectFalse("Oobe.getInstance().headerHidden"); |
| + } |
| + // Checks if user input is marked as invalid. |
| + void TestUserError() { |
| + TestLoginVisible(); |
| + js_checker().ExpectTrue(kAdUserInput + std::string(".isInvalid")); |
| + } |
| + // Checks if password input is marked as invalid. |
| + void TestPasswordError() { |
| + TestLoginVisible(); |
| + js_checker().ExpectTrue(kAdPasswordInput + std::string(".isInvalid")); |
| + } |
| + // Checks if autocomplete domain is visible for the user input. |
| + void TestDomainVisible() { |
| + js_checker().ExpectFalse(kAdAutocompleteRealm + std::string(".hidden")); |
| + } |
| + // Checks if autocomplete domain is hidden for the user input. |
| + void TestDomainHidden() { |
| + js_checker().ExpectTrue(kAdAutocompleteRealm + std::string(".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(kAdUserInput + std::string(".value='") + |
| + username + "'"); |
| + js_checker().ExecuteAsync(kAdPasswordInput + std::string(".value='") + |
| + password + "'"); |
| + js_checker().Evaluate( |
| + "document.querySelector('#offline-ad-auth /deep/ " |
| + "#button').fire('tap')"); |
| + } |
| + |
| + protected: |
| + 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_; |
| +}; |
|
achuithb
2017/03/07 15:07:03
DISALLOW_COPY_AND_ASSIGN
Roman Sorokin (ftl)
2017/03/07 16:32:05
Done.
|
| + |
| // Used to make sure that the system tray is visible and within the screen |
| // bounds after login. |
| void TestSystemTrayIsVisible() { |
| @@ -279,4 +395,50 @@ IN_PROC_BROWSER_TEST_F(LoginTest, DISABLED_GaiaAuthOffline) { |
| TestSystemTrayIsVisible(); |
| } |
| +IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginSuccess) { |
|
achuithb
2017/03/07 15:07:03
Test comments for all functions please
Roman Sorokin (ftl)
2017/03/07 16:32:05
Done.
|
| + MarkAsActiveDirectoryEnterprise(); |
| +} |
| + |
| +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(); |
|
achuithb
2017/03/07 15:07:03
Sad
Roman Sorokin (ftl)
2017/03/07 16:32:05
Acknowledged.
|
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginErrors) { |
| + MarkAsActiveDirectoryEnterprise(); |
| +} |
| + |
| +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 |