Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "ash/common/shelf/wm_shelf.h" | 7 #include "ash/common/shelf/wm_shelf.h" |
| 8 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 9 #include "ash/common/wm_window.h" | 9 #include "ash/common/wm_window.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/chromeos/login/login_manager_test.h" | 18 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 18 #include "chrome/browser/chromeos/login/login_wizard.h" | 19 #include "chrome/browser/chromeos/login/login_wizard.h" |
| 19 #include "chrome/browser/chromeos/login/startup_utils.h" | 20 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 21 #include "chrome/browser/chromeos/login/test/js_checker.h" | |
| 20 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 22 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 21 #include "chrome/browser/chromeos/login/wizard_controller.h" | 23 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 22 #include "chrome/browser/chromeos/settings/cros_settings.h" | 24 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 25 #include "chrome/browser/chromeos/settings/stub_install_attributes.h" | |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/profiles/profiles_state.h" | 27 #include "chrome/browser/profiles/profiles_state.h" |
| 25 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 27 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/grit/generated_resources.h" | |
| 28 #include "chrome/test/base/in_process_browser_test.h" | 32 #include "chrome/test/base/in_process_browser_test.h" |
| 29 #include "chrome/test/base/interactive_test_utils.h" | 33 #include "chrome/test/base/interactive_test_utils.h" |
| 30 #include "chromeos/chromeos_switches.h" | 34 #include "chromeos/chromeos_switches.h" |
| 35 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 36 #include "chromeos/dbus/fake_auth_policy_client.h" | |
| 31 #include "chromeos/settings/cros_settings_names.h" | 37 #include "chromeos/settings/cros_settings_names.h" |
| 32 #include "components/signin/core/account_id/account_id.h" | 38 #include "components/signin/core/account_id/account_id.h" |
| 33 #include "components/user_manager/user_names.h" | 39 #include "components/user_manager/user_names.h" |
| 34 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
| 35 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
| 36 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
| 37 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | |
| 39 #include "ui/gfx/geometry/test/rect_test_util.h" | 46 #include "ui/gfx/geometry/test/rect_test_util.h" |
| 40 | 47 |
| 41 using ::gfx::test::RectContains; | 48 using ::gfx::test::RectContains; |
| 42 using ::testing::_; | 49 using ::testing::_; |
| 43 using ::testing::AnyNumber; | 50 using ::testing::AnyNumber; |
| 44 using ::testing::Return; | 51 using ::testing::Return; |
| 45 | 52 |
| 46 namespace chromeos { | 53 namespace chromeos { |
| 47 namespace { | 54 namespace { |
| 48 | 55 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 | 179 |
| 173 StartGaiaAuthOffline(); | 180 StartGaiaAuthOffline(); |
| 174 | 181 |
| 175 UserContext user_context( | 182 UserContext user_context( |
| 176 AccountId::FromUserEmailGaiaId(kTestUser, kGaiaId)); | 183 AccountId::FromUserEmailGaiaId(kTestUser, kGaiaId)); |
| 177 user_context.SetKey(Key(kPassword)); | 184 user_context.SetKey(Key(kPassword)); |
| 178 SetExpectedCredentials(user_context); | 185 SetExpectedCredentials(user_context); |
| 179 } | 186 } |
| 180 }; | 187 }; |
| 181 | 188 |
| 189 const char kTestRealm[] = "test_realm.com"; | |
| 190 const char kTestActiveDirectoryUser[] = "test-user"; | |
| 191 const char kAdMachineInput[] = "machineNameInput"; | |
| 192 const char kAdUserInput[] = "userInput"; | |
| 193 const char kAdPasswordInput[] = "passwordInput"; | |
| 194 const char kAdButton[] = "button"; | |
| 195 const char kAdWelcomMessage[] = "welcomeMsg"; | |
| 196 const char kAdAutocompleteRealm[] = "userInput /deep/ #domainLabel"; | |
| 197 | |
| 198 class ActiveDirectoryLoginTest : public LoginManagerTest { | |
| 199 public: | |
| 200 ActiveDirectoryLoginTest() | |
| 201 : LoginManagerTest(true), | |
| 202 install_attributes_( | |
| 203 ScopedStubInstallAttributes::CreateActiveDirectoryEnterprise( | |
| 204 kTestRealm)) {} | |
| 205 | |
| 206 ~ActiveDirectoryLoginTest() override = default; | |
| 207 | |
| 208 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 209 command_line->AppendSwitch(switches::kOobeSkipPostLogin); | |
| 210 LoginManagerTest::SetUpCommandLine(command_line); | |
| 211 } | |
| 212 | |
| 213 void SetUpOnMainThread() override { | |
| 214 LoginManagerTest::SetUpOnMainThread(); | |
| 215 fake_auth_policy_client_ = static_cast<FakeAuthPolicyClient*>( | |
| 216 DBusThreadManager::Get()->GetAuthPolicyClient()); | |
| 217 } | |
| 218 | |
| 219 void MarkAsActiveDirectoryEnterprise() { | |
| 220 StartupUtils::MarkOobeCompleted(); | |
| 221 base::RunLoop loop; | |
| 222 fake_auth_policy_client_->RefreshDevicePolicy( | |
| 223 base::Bind(&ActiveDirectoryLoginTest::OnRefreshedPolicy, | |
| 224 base::Unretained(this), loop.QuitClosure())); | |
| 225 loop.Run(); | |
| 226 } | |
| 227 | |
| 228 // Checks if Active Directory login is visible. | |
| 229 void TestLoginVisible() { | |
| 230 // Checks if Gaia signin is hidden. | |
| 231 JSExpect("document.querySelector('#signin-frame').hidden"); | |
| 232 | |
| 233 // Checks if Active Directory signin is visible. | |
| 234 JSExpect("!document.querySelector('#offline-ad-auth').hidden"); | |
| 235 const std::string hidden(".hidden"); | |
|
achuithb
2017/03/09 10:34:06
I don't think there's any value to this temporary.
Roman Sorokin (ftl)
2017/03/22 15:19:25
Done.
| |
| 236 JSExpect(JSElement(kAdMachineInput) + hidden); | |
| 237 JSExpect("!" + JSElement(kAdUserInput) + hidden); | |
| 238 JSExpect("!" + JSElement(kAdPasswordInput) + hidden); | |
| 239 | |
| 240 const std::string innerText(".innerText"); | |
| 241 // Checks if Active Directory welcome message contains realm. | |
| 242 EXPECT_EQ(l10n_util::GetStringFUTF8(IDS_AD_DOMAIN_AUTH_WELCOME_MESSAGE, | |
| 243 base::UTF8ToUTF16(kTestRealm)), | |
| 244 js_checker().GetString(JSElement(kAdWelcomMessage) + innerText)); | |
| 245 | |
| 246 // Checks if realm is set to autocomplete username. | |
| 247 EXPECT_EQ( | |
| 248 "@" + std::string(kTestRealm), | |
| 249 js_checker().GetString(JSElement(kAdAutocompleteRealm) + innerText)); | |
| 250 | |
| 251 // Checks if bottom bar is visible. | |
| 252 JSExpect("!Oobe.getInstance().headerHidden"); | |
| 253 } | |
| 254 | |
| 255 // Checks if user input is marked as invalid. | |
| 256 void TestUserError() { | |
| 257 TestLoginVisible(); | |
| 258 JSExpect(JSElement(kAdUserInput) + ".isInvalid"); | |
| 259 } | |
| 260 | |
| 261 // Checks if password input is marked as invalid. | |
| 262 void TestPasswordError() { | |
| 263 TestLoginVisible(); | |
| 264 JSExpect(JSElement(kAdPasswordInput) + ".isInvalid"); | |
| 265 } | |
| 266 | |
| 267 // Checks if autocomplete domain is visible for the user input. | |
| 268 void TestDomainVisible() { | |
| 269 JSExpect("!" + JSElement(kAdAutocompleteRealm) + ".hidden"); | |
| 270 } | |
| 271 | |
| 272 // Checks if autocomplete domain is hidden for the user input. | |
| 273 void TestDomainHidden() { | |
| 274 JSExpect(JSElement(kAdAutocompleteRealm) + ".hidden"); | |
| 275 } | |
| 276 | |
| 277 // Sets username and password for the Active Directory login and submits it. | |
| 278 void SubmitActiveDirectoryCredentials(const std::string& username, | |
| 279 const std::string& password) { | |
| 280 js_checker().ExecuteAsync(JSElement(kAdUserInput) + ".value='" + username + | |
| 281 "'"); | |
| 282 js_checker().ExecuteAsync(JSElement(kAdPasswordInput) + ".value='" + | |
| 283 password + "'"); | |
| 284 js_checker().Evaluate(JSElement(kAdButton) + ".fire('tap')"); | |
| 285 } | |
| 286 | |
| 287 protected: | |
| 288 std::string JSElement(const std::string& element_id) { | |
|
achuithb
2017/03/09 10:34:06
nit: also add a comment for this.
Roman Sorokin (ftl)
2017/03/22 15:19:25
Done.
| |
| 289 return "document.querySelector('#offline-ad-auth /deep/ #" + element_id + | |
| 290 "')"; | |
| 291 } | |
| 292 FakeAuthPolicyClient* fake_auth_policy_client_ = nullptr; | |
| 293 | |
| 294 private: | |
| 295 // Used for the callback from FakeAuthPolicy::RefreshDevicePolicy. | |
| 296 void OnRefreshedPolicy(const base::Closure& closure, bool status) { | |
| 297 EXPECT_TRUE(status); | |
| 298 closure.Run(); | |
| 299 } | |
| 300 | |
| 301 ScopedStubInstallAttributes install_attributes_; | |
| 302 | |
| 303 DISALLOW_COPY_AND_ASSIGN(ActiveDirectoryLoginTest); | |
| 304 }; | |
| 305 | |
| 182 // Used to make sure that the system tray is visible and within the screen | 306 // Used to make sure that the system tray is visible and within the screen |
| 183 // bounds after login. | 307 // bounds after login. |
| 184 void TestSystemTrayIsVisible() { | 308 void TestSystemTrayIsVisible() { |
| 185 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 309 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); |
| 186 aura::Window* primary_win = ash::Shell::GetPrimaryRootWindow(); | 310 aura::Window* primary_win = ash::Shell::GetPrimaryRootWindow(); |
| 187 ash::WmWindow* wm_primary_win = ash::WmWindow::Get(primary_win); | 311 ash::WmWindow* wm_primary_win = ash::WmWindow::Get(primary_win); |
| 188 ash::WmShelf* wm_shelf = ash::WmShelf::ForWindow(wm_primary_win); | 312 ash::WmShelf* wm_shelf = ash::WmShelf::ForWindow(wm_primary_win); |
| 189 SCOPED_TRACE(testing::Message() | 313 SCOPED_TRACE(testing::Message() |
| 190 << "ShelfVisibilityState=" << wm_shelf->GetVisibilityState() | 314 << "ShelfVisibilityState=" << wm_shelf->GetVisibilityState() |
| 191 << " ShelfAutoHideBehavior=" << wm_shelf->auto_hide_behavior()); | 315 << " ShelfAutoHideBehavior=" << wm_shelf->auto_hide_behavior()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 PrepareOfflineLogin(); | 396 PrepareOfflineLogin(); |
| 273 content::WindowedNotificationObserver session_start_waiter( | 397 content::WindowedNotificationObserver session_start_waiter( |
| 274 chrome::NOTIFICATION_SESSION_STARTED, | 398 chrome::NOTIFICATION_SESSION_STARTED, |
| 275 content::NotificationService::AllSources()); | 399 content::NotificationService::AllSources()); |
| 276 SubmitGaiaAuthOfflineForm(kTestUser, kPassword); | 400 SubmitGaiaAuthOfflineForm(kTestUser, kPassword); |
| 277 session_start_waiter.Wait(); | 401 session_start_waiter.Wait(); |
| 278 | 402 |
| 279 TestSystemTrayIsVisible(); | 403 TestSystemTrayIsVisible(); |
| 280 } | 404 } |
| 281 | 405 |
| 406 // Marks as Active Directory enterprise device and OOBE as completed. | |
| 407 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginSuccess) { | |
| 408 MarkAsActiveDirectoryEnterprise(); | |
| 409 } | |
| 410 | |
| 411 // Test successful Active Directory login. | |
| 412 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginSuccess) { | |
| 413 TestLoginVisible(); | |
| 414 TestDomainVisible(); | |
| 415 | |
| 416 content::WindowedNotificationObserver session_start_waiter( | |
| 417 chrome::NOTIFICATION_SESSION_STARTED, | |
| 418 content::NotificationService::AllSources()); | |
| 419 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword); | |
| 420 session_start_waiter.Wait(); | |
| 421 | |
| 422 // Uncomment once flakiness is fixed, see http://crbug/692364. | |
| 423 // TestSystemTrayIsVisible(); | |
| 424 } | |
| 425 | |
| 426 // Marks as Active Directory enterprise device and OOBE as completed. | |
| 427 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, PRE_LoginErrors) { | |
| 428 MarkAsActiveDirectoryEnterprise(); | |
| 429 } | |
| 430 | |
| 431 // Test different UI errors for Active Directory login. | |
| 432 IN_PROC_BROWSER_TEST_F(ActiveDirectoryLoginTest, LoginErrors) { | |
| 433 TestLoginVisible(); | |
| 434 TestDomainVisible(); | |
| 435 | |
| 436 SubmitActiveDirectoryCredentials("", ""); | |
| 437 TestUserError(); | |
| 438 TestDomainVisible(); | |
| 439 | |
| 440 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, ""); | |
| 441 TestPasswordError(); | |
| 442 TestDomainVisible(); | |
| 443 | |
| 444 fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_USER_NAME); | |
| 445 SubmitActiveDirectoryCredentials(std::string(kTestActiveDirectoryUser) + "@", | |
| 446 kPassword); | |
| 447 TestUserError(); | |
| 448 TestDomainHidden(); | |
| 449 | |
| 450 fake_auth_policy_client_->set_auth_error(authpolicy::ERROR_BAD_PASSWORD); | |
| 451 SubmitActiveDirectoryCredentials(kTestActiveDirectoryUser, kPassword); | |
| 452 TestPasswordError(); | |
| 453 TestDomainVisible(); | |
| 454 } | |
| 455 | |
| 282 } // namespace chromeos | 456 } // namespace chromeos |
| OLD | NEW |