Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h" | 6 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h" |
| 7 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper. h" | 7 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper. h" |
| 8 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ impl.h" | 8 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ impl.h" |
| 9 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ mock.h" | 9 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ mock.h" |
| 10 #include "chrome/browser/chromeos/login/login_manager_test.h" | 10 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 11 #include "chrome/browser/chromeos/login/startup_utils.h" | 11 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 12 #include "chrome/browser/chromeos/login/test/js_checker.h" | 12 #include "chrome/browser/chromeos/login/test/js_checker.h" |
| 13 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 13 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
| 14 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 14 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 15 #include "chrome/browser/chromeos/login/wizard_controller.h" | 15 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 16 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 16 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 17 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
| 18 #include "chromeos/dbus/upstart_client.h" | 18 #include "chromeos/dbus/upstart_client.h" |
| 19 #include "content/public/test/browser_test_utils.h" | |
| 19 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
| 20 | 21 |
| 21 using testing::_; | 22 using testing::_; |
| 22 using testing::Invoke; | 23 using testing::Invoke; |
| 23 using testing::InvokeWithoutArgs; | 24 using testing::InvokeWithoutArgs; |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 EnterpriseEnrollmentHelperMock* enrollment_helper) { | 149 EnterpriseEnrollmentHelperMock* enrollment_helper) { |
| 149 // Causes the attribute-prompt flow to activate. | 150 // Causes the attribute-prompt flow to activate. |
| 150 EXPECT_CALL(*enrollment_helper, EnrollUsingAuthCode("test_auth_code", _)) | 151 EXPECT_CALL(*enrollment_helper, EnrollUsingAuthCode("test_auth_code", _)) |
| 151 .WillOnce(InvokeWithoutArgs([this]() { | 152 .WillOnce(InvokeWithoutArgs([this]() { |
| 152 this->enrollment_screen()->JoinDomain(base::BindOnce([]( | 153 this->enrollment_screen()->JoinDomain(base::BindOnce([]( |
| 153 const std::string& realm) { EXPECT_EQ(kAdTestRealm, realm); })); | 154 const std::string& realm) { EXPECT_EQ(kAdTestRealm, realm); })); |
| 154 })); | 155 })); |
| 155 }); | 156 }); |
| 156 } | 157 } |
| 157 | 158 |
| 159 void SetupActiveDirectoryJSNotifications() { | |
| 160 js_checker().Evaluate( | |
| 161 "var testShowStep = login.OAuthEnrollmentScreen.showStep;" | |
| 162 "login.OAuthEnrollmentScreen.showStep = function(step) {" | |
| 163 " testShowStep(step);" | |
| 164 " if (step == 'working') {" | |
| 165 " window.domAutomationController.setAutomationId(0);" | |
| 166 " window.domAutomationController.send('ShowSpinnerScreen');" | |
| 167 " }" | |
| 168 "}"); | |
| 169 js_checker().Evaluate( | |
| 170 "var testInvalidateAd = login.OAuthEnrollmentScreen.invalidateAd;" | |
| 171 "login.OAuthEnrollmentScreen.invalidateAd = function(machineName, " | |
| 172 "user, errorState) {" | |
| 173 " testInvalidateAd(machineName, user, errorState);" | |
| 174 " window.domAutomationController.setAutomationId(0);" | |
| 175 " window.domAutomationController.send('ShowJoinDomainError');" | |
| 176 "}"); | |
| 177 } | |
| 178 | |
| 179 void WaitForMessage(const std::string& expected_message) { | |
| 180 content::DOMMessageQueue message_queue; | |
|
xiyuan
2017/04/07 15:04:24
This impl pattern would cause test flakes. This ha
Roman Sorokin (ftl)
2017/04/10 16:09:00
Done.
| |
| 181 std::string message; | |
| 182 do { | |
| 183 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 184 } while (message != expected_message); | |
| 185 } | |
| 186 | |
| 158 // Fills out the UI with device attribute information and submits it. | 187 // Fills out the UI with device attribute information and submits it. |
| 159 void SubmitAttributePromptUpdate() { | 188 void SubmitAttributePromptUpdate() { |
| 160 // Fill out the attribute prompt info and submit it. | 189 // Fill out the attribute prompt info and submit it. |
| 161 js_checker().ExecuteAsync("$('oauth-enroll-asset-id').value = 'asset_id'"); | 190 js_checker().ExecuteAsync("$('oauth-enroll-asset-id').value = 'asset_id'"); |
| 162 js_checker().ExecuteAsync("$('oauth-enroll-location').value = 'location'"); | 191 js_checker().ExecuteAsync("$('oauth-enroll-location').value = 'location'"); |
| 163 js_checker().Evaluate( | 192 js_checker().Evaluate( |
| 164 "$('oauth-enroll-attribute-prompt-card').fire('submit')"); | 193 "$('oauth-enroll-attribute-prompt-card').fire('submit')"); |
| 165 } | 194 } |
| 166 | 195 |
| 167 // Completes the enrollment process. | 196 // Completes the enrollment process. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 TestActiveDirectoryEnrollment_Success) { | 319 TestActiveDirectoryEnrollment_Success) { |
| 291 ShowEnrollmentScreen(); | 320 ShowEnrollmentScreen(); |
| 292 DisableAttributePromptUpdate(); | 321 DisableAttributePromptUpdate(); |
| 293 SetupActiveDirectoryJoin(); | 322 SetupActiveDirectoryJoin(); |
| 294 SubmitEnrollmentCredentials(); | 323 SubmitEnrollmentCredentials(); |
| 295 | 324 |
| 296 chromeos::DBusThreadManager::Get() | 325 chromeos::DBusThreadManager::Get() |
| 297 ->GetUpstartClient() | 326 ->GetUpstartClient() |
| 298 ->StartAuthPolicyService(); | 327 ->StartAuthPolicyService(); |
| 299 | 328 |
| 329 SetupActiveDirectoryJSNotifications(); | |
| 300 SubmitActiveDirectoryCredentials("machine_name", kAdTestUser, "password"); | 330 SubmitActiveDirectoryCredentials("machine_name", kAdTestUser, "password"); |
| 331 WaitForMessage("\"ShowSpinnerScreen\""); | |
| 301 EXPECT_FALSE(IsStepDisplayed("ad-join")); | 332 EXPECT_FALSE(IsStepDisplayed("ad-join")); |
| 302 | 333 |
| 303 CompleteEnrollment(); | 334 CompleteEnrollment(); |
| 304 // Verify that the success page is displayed. | 335 // Verify that the success page is displayed. |
| 305 EXPECT_TRUE(IsStepDisplayed("success")); | 336 EXPECT_TRUE(IsStepDisplayed("success")); |
| 306 EXPECT_FALSE(IsStepDisplayed("error")); | 337 EXPECT_FALSE(IsStepDisplayed("error")); |
| 307 | 338 |
| 308 // We have to remove the enrollment_helper before the dtor gets called. | 339 // We have to remove the enrollment_helper before the dtor gets called. |
| 309 enrollment_screen()->enrollment_helper_.reset(); | 340 enrollment_screen()->enrollment_helper_.reset(); |
| 310 } | 341 } |
| 311 | 342 |
| 312 // Shows the enrollment screen and mocks the enrollment helper to show Active | 343 // Shows the enrollment screen and mocks the enrollment helper to show Active |
| 313 // Directory domain join screen. Verifies the domain join screen is displayed. | 344 // Directory domain join screen. Verifies the domain join screen is displayed. |
| 314 // Submits Active Directory different incorrect credentials. Verifies that the | 345 // Submits Active Directory different incorrect credentials. Verifies that the |
| 315 // correct error is displayed. | 346 // correct error is displayed. |
| 316 IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentTest, | 347 IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentTest, |
| 317 TestActiveDirectoryEnrollment_UIErrors) { | 348 TestActiveDirectoryEnrollment_UIErrors) { |
| 318 ShowEnrollmentScreen(); | 349 ShowEnrollmentScreen(); |
| 319 SetupActiveDirectoryJoin(); | 350 SetupActiveDirectoryJoin(); |
| 320 SubmitEnrollmentCredentials(); | 351 SubmitEnrollmentCredentials(); |
| 321 | 352 |
| 322 chromeos::DBusThreadManager::Get() | 353 chromeos::DBusThreadManager::Get() |
| 323 ->GetUpstartClient() | 354 ->GetUpstartClient() |
| 324 ->StartAuthPolicyService(); | 355 ->StartAuthPolicyService(); |
| 325 | 356 |
| 326 // Checking error in case of empty password. Whether password is not empty | 357 // Checking error in case of empty password. Whether password is not empty |
| 327 // being checked in the UI. Machine name length is checked after that in the | 358 // being checked in the UI. Machine name length is checked after that in the |
| 328 // authpolicyd. | 359 // authpolicyd. |
| 360 SetupActiveDirectoryJSNotifications(); | |
| 329 SubmitActiveDirectoryCredentials("too_long_machine_name", kAdTestUser, ""); | 361 SubmitActiveDirectoryCredentials("too_long_machine_name", kAdTestUser, ""); |
| 330 EXPECT_TRUE(IsStepDisplayed("ad-join")); | 362 EXPECT_TRUE(IsStepDisplayed("ad-join")); |
| 331 js_checker().ExpectFalse(std::string(kAdMachineNameInput) + ".isInvalid"); | 363 js_checker().ExpectFalse(std::string(kAdMachineNameInput) + ".isInvalid"); |
| 332 js_checker().ExpectFalse(std::string(kAdUsernameInput) + ".isInvalid"); | 364 js_checker().ExpectFalse(std::string(kAdUsernameInput) + ".isInvalid"); |
| 333 js_checker().ExpectTrue(std::string(kAdPasswordInput) + ".isInvalid"); | 365 js_checker().ExpectTrue(std::string(kAdPasswordInput) + ".isInvalid"); |
| 334 | 366 |
| 335 // Checking error in case of too long machine name. | 367 // Checking error in case of too long machine name. |
| 336 SubmitActiveDirectoryCredentials("too_long_machine_name", kAdTestUser, | 368 SubmitActiveDirectoryCredentials("too_long_machine_name", kAdTestUser, |
| 337 "password"); | 369 "password"); |
| 370 WaitForMessage("\"ShowJoinDomainError\""); | |
| 338 EXPECT_TRUE(IsStepDisplayed("ad-join")); | 371 EXPECT_TRUE(IsStepDisplayed("ad-join")); |
| 339 js_checker().ExpectTrue(std::string(kAdMachineNameInput) + ".isInvalid"); | 372 js_checker().ExpectTrue(std::string(kAdMachineNameInput) + ".isInvalid"); |
| 340 js_checker().ExpectFalse(std::string(kAdUsernameInput) + ".isInvalid"); | 373 js_checker().ExpectFalse(std::string(kAdUsernameInput) + ".isInvalid"); |
| 341 js_checker().ExpectFalse(std::string(kAdPasswordInput) + ".isInvalid"); | 374 js_checker().ExpectFalse(std::string(kAdPasswordInput) + ".isInvalid"); |
| 342 | 375 |
| 343 // Checking error in case of bad username (without realm). | 376 // Checking error in case of bad username (without realm). |
| 344 SubmitActiveDirectoryCredentials("machine_name", "test_user", "password"); | 377 SubmitActiveDirectoryCredentials("machine_name", "test_user", "password"); |
| 378 WaitForMessage("\"ShowJoinDomainError\""); | |
| 345 EXPECT_TRUE(IsStepDisplayed("ad-join")); | 379 EXPECT_TRUE(IsStepDisplayed("ad-join")); |
| 346 js_checker().ExpectFalse(std::string(kAdMachineNameInput) + ".isInvalid"); | 380 js_checker().ExpectFalse(std::string(kAdMachineNameInput) + ".isInvalid"); |
| 347 js_checker().ExpectTrue(std::string(kAdUsernameInput) + ".isInvalid"); | 381 js_checker().ExpectTrue(std::string(kAdUsernameInput) + ".isInvalid"); |
| 348 js_checker().ExpectFalse(std::string(kAdPasswordInput) + ".isInvalid"); | 382 js_checker().ExpectFalse(std::string(kAdPasswordInput) + ".isInvalid"); |
| 349 | 383 |
| 350 // We have to remove the enrollment_helper before the dtor gets called. | 384 // We have to remove the enrollment_helper before the dtor gets called. |
| 351 enrollment_screen()->enrollment_helper_.reset(); | 385 enrollment_screen()->enrollment_helper_.reset(); |
| 352 } | 386 } |
| 353 | 387 |
| 354 } // namespace chromeos | 388 } // namespace chromeos |
| OLD | NEW |