| 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 "chrome/browser/ui/passwords/password_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/passwords/password_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
| 14 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" | |
| 15 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" | 14 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" |
| 15 #include "chrome/browser/ui/passwords/passwords_model_delegate_mock.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
| 18 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 18 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 19 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 19 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
| 20 #include "components/password_manager/core/common/password_manager_pref_names.h" | 20 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 21 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "content/public/test/web_contents_tester.h" | |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 using testing::ElementsAre; | 28 using testing::ElementsAre; |
| 30 using testing::Pointee; | 29 using testing::Pointee; |
| 31 using testing::StrictMock; | 30 using testing::StrictMock; |
| 32 | 31 |
| 33 const char kUsername[] = "user1"; | 32 const char kUsername[] = "user1"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 autofill::PasswordForm GetFederationProviderForm() { | 55 autofill::PasswordForm GetFederationProviderForm() { |
| 57 autofill::PasswordForm form; | 56 autofill::PasswordForm form; |
| 58 form.username_value = base::ASCIIToUTF16(kUsername); | 57 form.username_value = base::ASCIIToUTF16(kUsername); |
| 59 form.origin = GURL("http://idp.com"); | 58 form.origin = GURL("http://idp.com"); |
| 60 return form; | 59 return form; |
| 61 } | 60 } |
| 62 | 61 |
| 63 class PasswordDialogControllerTest : public testing::Test { | 62 class PasswordDialogControllerTest : public testing::Test { |
| 64 public: | 63 public: |
| 65 PasswordDialogControllerTest() | 64 PasswordDialogControllerTest() |
| 66 : test_web_contents_(content::WebContentsTester::CreateTestWebContents( | 65 : controller_(&profile_, &ui_controller_mock_) { |
| 67 &profile_, nullptr)), | |
| 68 ui_controller_mock_(new StrictMock<ManagePasswordsUIControllerMock>( | |
| 69 test_web_contents_.get())), | |
| 70 controller_(&profile_, ui_controller_mock_) { | |
| 71 } | 66 } |
| 72 | 67 |
| 73 ManagePasswordsUIControllerMock& ui_controller_mock() { | 68 PasswordsModelDelegateMock& ui_controller_mock() { |
| 74 return *ui_controller_mock_; | 69 return ui_controller_mock_; |
| 75 } | 70 } |
| 76 | 71 |
| 77 PasswordDialogControllerImpl& controller() { return controller_; } | 72 PasswordDialogControllerImpl& controller() { return controller_; } |
| 78 | 73 |
| 79 PrefService* prefs() { return profile_.GetPrefs(); } | 74 PrefService* prefs() { return profile_.GetPrefs(); } |
| 80 | 75 |
| 81 private: | 76 private: |
| 82 content::TestBrowserThreadBundle thread_bundle_; | 77 content::TestBrowserThreadBundle thread_bundle_; |
| 83 TestingProfile profile_; | 78 TestingProfile profile_; |
| 84 std::unique_ptr<content::WebContents> test_web_contents_; | 79 StrictMock<PasswordsModelDelegateMock> ui_controller_mock_; |
| 85 // Owned by |test_web_contents_|. | |
| 86 ManagePasswordsUIControllerMock* ui_controller_mock_; | |
| 87 PasswordDialogControllerImpl controller_; | 80 PasswordDialogControllerImpl controller_; |
| 88 }; | 81 }; |
| 89 | 82 |
| 90 TEST_F(PasswordDialogControllerTest, ShowAccountChooser) { | 83 TEST_F(PasswordDialogControllerTest, ShowAccountChooser) { |
| 91 base::HistogramTester histogram_tester; | 84 base::HistogramTester histogram_tester; |
| 92 StrictMock<MockPasswordPrompt> prompt; | 85 StrictMock<MockPasswordPrompt> prompt; |
| 93 autofill::PasswordForm local_form = GetLocalForm(); | 86 autofill::PasswordForm local_form = GetLocalForm(); |
| 94 autofill::PasswordForm local_form2 = local_form; | 87 autofill::PasswordForm local_form2 = local_form; |
| 95 local_form2.username_value = base::ASCIIToUTF16(kUsername2); | 88 local_form2.username_value = base::ASCIIToUTF16(kUsername2); |
| 96 autofill::PasswordForm idp_form = GetFederationProviderForm(); | 89 autofill::PasswordForm idp_form = GetFederationProviderForm(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 "PasswordManager.AutoSigninFirstRunDialog", | 237 "PasswordManager.AutoSigninFirstRunDialog", |
| 245 password_manager::metrics_util::AUTO_SIGNIN_TURN_OFF, 1); | 238 password_manager::metrics_util::AUTO_SIGNIN_TURN_OFF, 1); |
| 246 } | 239 } |
| 247 | 240 |
| 248 TEST_F(PasswordDialogControllerTest, OnBrandLinkClicked) { | 241 TEST_F(PasswordDialogControllerTest, OnBrandLinkClicked) { |
| 249 EXPECT_CALL(ui_controller_mock(), NavigateToSmartLockHelpPage()); | 242 EXPECT_CALL(ui_controller_mock(), NavigateToSmartLockHelpPage()); |
| 250 controller().OnSmartLockLinkClicked(); | 243 controller().OnSmartLockLinkClicked(); |
| 251 } | 244 } |
| 252 | 245 |
| 253 } // namespace | 246 } // namespace |
| OLD | NEW |