| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 6 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 9 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "chrome/browser/ui/views/passwords/account_chooser_dialog_view.h" | 12 #include "chrome/browser/ui/views/passwords/account_chooser_dialog_view.h" |
| 12 #include "chrome/browser/ui/views/passwords/auto_signin_first_run_dialog_view.h" | 13 #include "chrome/browser/ui/views/passwords/auto_signin_first_run_dialog_view.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 16 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 16 #include "components/password_manager/core/common/password_manager_pref_names.h" | 17 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 17 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 18 #include "net/url_request/test_url_fetcher_factory.h" | 19 #include "net/url_request/test_url_fetcher_factory.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 194 |
| 194 SetupChooseCredentials(std::move(local_credentials), | 195 SetupChooseCredentials(std::move(local_credentials), |
| 195 ScopedVector<autofill::PasswordForm>(), origin); | 196 ScopedVector<autofill::PasswordForm>(), origin); |
| 196 ASSERT_TRUE(controller()->current_account_chooser()); | 197 ASSERT_TRUE(controller()->current_account_chooser()); |
| 197 AccountChooserDialogView* dialog = controller()->current_account_chooser(); | 198 AccountChooserDialogView* dialog = controller()->current_account_chooser(); |
| 198 EXPECT_CALL(*this, | 199 EXPECT_CALL(*this, |
| 199 OnChooseCredential(Field( | 200 OnChooseCredential(Field( |
| 200 &password_manager::CredentialInfo::type, | 201 &password_manager::CredentialInfo::type, |
| 201 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY))); | 202 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY))); |
| 202 EXPECT_CALL(*controller(), OnDialogClosed()); | 203 EXPECT_CALL(*controller(), OnDialogClosed()); |
| 203 EXPECT_TRUE(dialog->Close()); | 204 dialog->GetWidget()->Close(); |
| 204 | 205 |
| 205 EXPECT_FALSE(controller()->current_autosignin_prompt()); | 206 EXPECT_FALSE(controller()->current_autosignin_prompt()); |
| 206 } | 207 } |
| 207 | 208 |
| 208 IN_PROC_BROWSER_TEST_F( | 209 IN_PROC_BROWSER_TEST_F( |
| 209 PasswordDialogViewTest, | 210 PasswordDialogViewTest, |
| 210 PopupAccountChooserWithMultipleCredentialsReturnNonEmpty) { | 211 PopupAccountChooserWithMultipleCredentialsReturnNonEmpty) { |
| 211 GURL origin("https://example.com"); | 212 GURL origin("https://example.com"); |
| 212 ScopedVector<autofill::PasswordForm> local_credentials; | 213 ScopedVector<autofill::PasswordForm> local_credentials; |
| 213 autofill::PasswordForm form; | 214 autofill::PasswordForm form; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 SetupChooseCredentials(std::move(local_credentials), | 255 SetupChooseCredentials(std::move(local_credentials), |
| 255 ScopedVector<autofill::PasswordForm>(), origin); | 256 ScopedVector<autofill::PasswordForm>(), origin); |
| 256 | 257 |
| 257 EXPECT_TRUE(controller()->current_account_chooser()); | 258 EXPECT_TRUE(controller()->current_account_chooser()); |
| 258 AccountChooserDialogView* dialog = controller()->current_account_chooser(); | 259 AccountChooserDialogView* dialog = controller()->current_account_chooser(); |
| 259 EXPECT_CALL(*this, | 260 EXPECT_CALL(*this, |
| 260 OnChooseCredential(Field( | 261 OnChooseCredential(Field( |
| 261 &password_manager::CredentialInfo::type, | 262 &password_manager::CredentialInfo::type, |
| 262 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY))); | 263 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY))); |
| 263 EXPECT_CALL(*controller(), OnDialogClosed()); | 264 EXPECT_CALL(*controller(), OnDialogClosed()); |
| 264 EXPECT_TRUE(dialog->Close()); | 265 dialog->GetWidget()->Close(); |
| 265 EXPECT_FALSE(controller()->current_autosignin_prompt()); | 266 EXPECT_FALSE(controller()->current_autosignin_prompt()); |
| 266 } | 267 } |
| 267 | 268 |
| 268 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, | 269 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, |
| 269 PopupAccountChooserWithSingleCredentialReturnNonEmpty) { | 270 PopupAccountChooserWithSingleCredentialReturnNonEmpty) { |
| 270 GURL origin("https://example.com"); | 271 GURL origin("https://example.com"); |
| 271 ScopedVector<autofill::PasswordForm> local_credentials; | 272 ScopedVector<autofill::PasswordForm> local_credentials; |
| 272 autofill::PasswordForm form; | 273 autofill::PasswordForm form; |
| 273 form.origin = origin; | 274 form.origin = origin; |
| 274 form.display_name = base::ASCIIToUTF16("Peter"); | 275 form.display_name = base::ASCIIToUTF16("Peter"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 285 EXPECT_CALL(*this, | 286 EXPECT_CALL(*this, |
| 286 OnChooseCredential(Field( | 287 OnChooseCredential(Field( |
| 287 &password_manager::CredentialInfo::type, | 288 &password_manager::CredentialInfo::type, |
| 288 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD))); | 289 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD))); |
| 289 EXPECT_TRUE( | 290 EXPECT_TRUE( |
| 290 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 291 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
| 291 browser()->profile()->GetPrefs())); | 292 browser()->profile()->GetPrefs())); |
| 292 controller()->ChooseCredential( | 293 controller()->ChooseCredential( |
| 293 form, password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | 294 form, password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 294 | 295 |
| 295 EXPECT_CALL(*controller(), OnDialogClosed()); | |
| 296 EXPECT_TRUE(controller()->current_autosignin_prompt()); | 296 EXPECT_TRUE(controller()->current_autosignin_prompt()); |
| 297 } | 297 } |
| 298 | 298 |
| 299 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, | 299 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, |
| 300 PopupAccountChooserWithDisabledAutoSignin) { | 300 PopupAccountChooserWithDisabledAutoSignin) { |
| 301 EXPECT_TRUE( | 301 EXPECT_TRUE( |
| 302 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 302 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
| 303 browser()->profile()->GetPrefs())); | 303 browser()->profile()->GetPrefs())); |
| 304 GURL origin("https://example.com"); | 304 GURL origin("https://example.com"); |
| 305 ScopedVector<autofill::PasswordForm> local_credentials; | 305 ScopedVector<autofill::PasswordForm> local_credentials; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 370 |
| 371 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, PopupAutoSigninPrompt) { | 371 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, PopupAutoSigninPrompt) { |
| 372 EXPECT_TRUE( | 372 EXPECT_TRUE( |
| 373 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 373 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
| 374 browser()->profile()->GetPrefs())); | 374 browser()->profile()->GetPrefs())); |
| 375 controller()->OnPromptEnableAutoSignin(); | 375 controller()->OnPromptEnableAutoSignin(); |
| 376 ASSERT_TRUE(controller()->current_autosignin_prompt()); | 376 ASSERT_TRUE(controller()->current_autosignin_prompt()); |
| 377 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); | 377 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); |
| 378 AutoSigninFirstRunDialogView* dialog = | 378 AutoSigninFirstRunDialogView* dialog = |
| 379 controller()->current_autosignin_prompt(); | 379 controller()->current_autosignin_prompt(); |
| 380 // This is the way how ESC is processed. It's important to reproduce it | |
| 381 // because of double AutoSigninFirstRunDialogView::OnClosed call due to a bug | |
| 382 // http://crbug.com/583330. | |
| 383 ui::Accelerator esc(ui::VKEY_ESCAPE, 0); | 380 ui::Accelerator esc(ui::VKEY_ESCAPE, 0); |
| 384 EXPECT_CALL(*controller(), OnDialogClosed()); | 381 EXPECT_CALL(*controller(), OnDialogClosed()); |
| 385 EXPECT_TRUE(dialog->GetWidget()->client_view()->AcceleratorPressed(esc)); | 382 EXPECT_TRUE(dialog->GetWidget()->client_view()->AcceleratorPressed(esc)); |
| 383 content::RunAllPendingInMessageLoop(); |
| 386 testing::Mock::VerifyAndClearExpectations(controller()); | 384 testing::Mock::VerifyAndClearExpectations(controller()); |
| 387 EXPECT_TRUE( | 385 EXPECT_TRUE( |
| 388 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 386 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
| 389 browser()->profile()->GetPrefs())); | 387 browser()->profile()->GetPrefs())); |
| 390 } | 388 } |
| 391 | 389 |
| 392 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, | 390 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, |
| 393 PopupAutoSigninPromptAfterBlockedZeroclick) { | 391 PopupAutoSigninPromptAfterBlockedZeroclick) { |
| 394 EXPECT_TRUE( | 392 EXPECT_TRUE( |
| 395 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( | 393 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 426 client()->NotifyUserAutoSigninBlockedOnFirstRun(std::move(blocked_form)); | 424 client()->NotifyUserAutoSigninBlockedOnFirstRun(std::move(blocked_form)); |
| 427 client()->NotifySuccessfulLoginWithExistingPassword(form); | 425 client()->NotifySuccessfulLoginWithExistingPassword(form); |
| 428 ASSERT_FALSE(controller()->current_autosignin_prompt()); | 426 ASSERT_FALSE(controller()->current_autosignin_prompt()); |
| 429 browser()->profile()->GetPrefs()->SetBoolean( | 427 browser()->profile()->GetPrefs()->SetBoolean( |
| 430 password_manager::prefs::kCredentialsEnableAutosignin, true); | 428 password_manager::prefs::kCredentialsEnableAutosignin, true); |
| 431 | 429 |
| 432 // Successful login with the same form after block will prompt: | 430 // Successful login with the same form after block will prompt: |
| 433 blocked_form.reset(new autofill::PasswordForm(form)); | 431 blocked_form.reset(new autofill::PasswordForm(form)); |
| 434 client()->NotifyUserAutoSigninBlockedOnFirstRun(std::move(blocked_form)); | 432 client()->NotifyUserAutoSigninBlockedOnFirstRun(std::move(blocked_form)); |
| 435 client()->NotifySuccessfulLoginWithExistingPassword(form); | 433 client()->NotifySuccessfulLoginWithExistingPassword(form); |
| 436 EXPECT_CALL(*controller(), OnDialogClosed()); | |
| 437 ASSERT_TRUE(controller()->current_autosignin_prompt()); | 434 ASSERT_TRUE(controller()->current_autosignin_prompt()); |
| 438 } | 435 } |
| 439 | 436 |
| 440 } // namespace | 437 } // namespace |
| OLD | NEW |