Commit c85b2ddb authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Update mock save infobar delegate to specify username/password.

This CL updates the Create() factory method to allow specifying the
username and password for a mock infobar delegate.  It also converts
the password banner test to use the mock delegate.

Bug: none
Change-Id: Ied9dcec354e49c5bd523b9c417fa94a0d2cc5014
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1995632
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Auto-Submit: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731677}
parent ca621a8d
...@@ -21,8 +21,10 @@ ...@@ -21,8 +21,10 @@
class PasswordInfobarBannerInteractionHandlerTest : public PlatformTest { class PasswordInfobarBannerInteractionHandlerTest : public PlatformTest {
public: public:
PasswordInfobarBannerInteractionHandlerTest() PasswordInfobarBannerInteractionHandlerTest()
: infobar_([[FakeInfobarUIDelegate alloc] init], : infobar_(
MockIOSChromeSavePasswordInfoBarDelegate::Create()) { [[FakeInfobarUIDelegate alloc] init],
MockIOSChromeSavePasswordInfoBarDelegate::Create(@"username",
@"password")) {
scoped_feature_list_.InitWithFeatures({kInfobarUIReboot}, {}); scoped_feature_list_.InitWithFeatures({kInfobarUIReboot}, {});
} }
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#ifndef IOS_CHROME_BROWSER_PASSWORDS_TEST_MOCK_IOS_CHROME_SAVE_PASSWORDS_INFOBAR_DELEGATE_H_ #ifndef IOS_CHROME_BROWSER_PASSWORDS_TEST_MOCK_IOS_CHROME_SAVE_PASSWORDS_INFOBAR_DELEGATE_H_
#define IOS_CHROME_BROWSER_PASSWORDS_TEST_MOCK_IOS_CHROME_SAVE_PASSWORDS_INFOBAR_DELEGATE_H_ #define IOS_CHROME_BROWSER_PASSWORDS_TEST_MOCK_IOS_CHROME_SAVE_PASSWORDS_INFOBAR_DELEGATE_H_
#import <Foundation/Foundation.h>
#include <memory> #include <memory>
#include "components/autofill/core/common/password_form.h"
#import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.h" #import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -20,14 +22,22 @@ class MockIOSChromeSavePasswordInfoBarDelegate ...@@ -20,14 +22,22 @@ class MockIOSChromeSavePasswordInfoBarDelegate
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save); std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save);
~MockIOSChromeSavePasswordInfoBarDelegate() override; ~MockIOSChromeSavePasswordInfoBarDelegate() override;
// Factory method that creates a MockIOSChromeSavePasswordInfoBarDelegate // Factory method that creates a mock save password delegate for pending
// using a mock form. // with credentials |username| and |password|.
static std::unique_ptr<MockIOSChromeSavePasswordInfoBarDelegate> Create(); static std::unique_ptr<MockIOSChromeSavePasswordInfoBarDelegate> Create(
NSString* username,
NSString* password);
MOCK_METHOD0(InfoBarDismissed, void()); MOCK_METHOD0(InfoBarDismissed, void());
MOCK_METHOD0(Accept, bool()); MOCK_METHOD0(Accept, bool());
MOCK_METHOD1(InfobarPresenting, void(bool automatic)); MOCK_METHOD1(InfobarPresenting, void(bool automatic));
MOCK_METHOD0(InfobarDismissed, void()); MOCK_METHOD0(InfobarDismissed, void());
private:
explicit MockIOSChromeSavePasswordInfoBarDelegate(
std::unique_ptr<autofill::PasswordForm> form);
std::unique_ptr<autofill::PasswordForm> form_;
}; };
#endif // IOS_CHROME_BROWSER_PASSWORDS_TEST_MOCK_IOS_CHROME_SAVE_PASSWORDS_INFOBAR_DELEGATE_H_ #endif // IOS_CHROME_BROWSER_PASSWORDS_TEST_MOCK_IOS_CHROME_SAVE_PASSWORDS_INFOBAR_DELEGATE_H_
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#import "ios/chrome/browser/passwords/test/mock_ios_chrome_save_passwords_infobar_delegate.h" #import "ios/chrome/browser/passwords/test/mock_ios_chrome_save_passwords_infobar_delegate.h"
#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
#include "components/password_manager/core/browser/mock_password_form_manager_for_ui.h" #include "components/password_manager/core/browser/mock_password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h" #include "components/password_manager/core/browser/password_manager_metrics_util.h"
...@@ -11,30 +13,43 @@ ...@@ -11,30 +13,43 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
// static namespace {
std::unique_ptr<MockIOSChromeSavePasswordInfoBarDelegate> std::unique_ptr<password_manager::PasswordFormManagerForUI> CreateFormManager(
MockIOSChromeSavePasswordInfoBarDelegate::Create() { autofill::PasswordForm* form) {
std::unique_ptr<password_manager::MockPasswordFormManagerForUI> form = DCHECK(form);
std::unique_ptr<password_manager::MockPasswordFormManagerForUI> form_manager =
std::make_unique<password_manager::MockPasswordFormManagerForUI>(); std::make_unique<password_manager::MockPasswordFormManagerForUI>();
EXPECT_CALL(*form, GetMetricsRecorder()) EXPECT_CALL(*form_manager, GetPendingCredentials())
.WillRepeatedly(testing::ReturnRef(*form));
EXPECT_CALL(*form_manager, GetMetricsRecorder())
.WillRepeatedly(testing::Return(nullptr)); .WillRepeatedly(testing::Return(nullptr));
EXPECT_CALL(*form, GetCredentialSource()) EXPECT_CALL(*form_manager, GetCredentialSource())
.WillRepeatedly(testing::Return( .WillRepeatedly(testing::Return(
password_manager::metrics_util::CredentialSourceType::kUnknown)); password_manager::metrics_util::CredentialSourceType::kUnknown));
return std::make_unique<MockIOSChromeSavePasswordInfoBarDelegate>( return form_manager;
/*is_sync_user=*/false, }
/*password_update=*/false, std::move(form)); } // namespace
// static
std::unique_ptr<MockIOSChromeSavePasswordInfoBarDelegate>
MockIOSChromeSavePasswordInfoBarDelegate::Create(NSString* username,
NSString* password) {
std::unique_ptr<autofill::PasswordForm> form =
std::make_unique<autofill::PasswordForm>();
form->username_value = base::SysNSStringToUTF16(username);
form->password_value = base::SysNSStringToUTF16(password);
return base::WrapUnique(
new MockIOSChromeSavePasswordInfoBarDelegate(std::move(form)));
} }
MockIOSChromeSavePasswordInfoBarDelegate:: MockIOSChromeSavePasswordInfoBarDelegate::
MockIOSChromeSavePasswordInfoBarDelegate( MockIOSChromeSavePasswordInfoBarDelegate(
bool is_sync_user, std::unique_ptr<autofill::PasswordForm> form)
bool password_update, : IOSChromeSavePasswordInfoBarDelegate(
std::unique_ptr<password_manager::PasswordFormManagerForUI> /*is_sync_user=*/false,
form_to_save) /*password_update=*/false,
: IOSChromeSavePasswordInfoBarDelegate(is_sync_user, CreateFormManager(form.get())),
password_update, form_(std::move(form)) {}
std::move(form_to_save)) {}
MockIOSChromeSavePasswordInfoBarDelegate:: MockIOSChromeSavePasswordInfoBarDelegate::
~MockIOSChromeSavePasswordInfoBarDelegate() = default; ~MockIOSChromeSavePasswordInfoBarDelegate() = default;
...@@ -41,6 +41,7 @@ source_set("unit_tests") { ...@@ -41,6 +41,7 @@ source_set("unit_tests") {
"//ios/chrome/browser/overlays/public/infobar_banner", "//ios/chrome/browser/overlays/public/infobar_banner",
"//ios/chrome/browser/overlays/test", "//ios/chrome/browser/overlays/test",
"//ios/chrome/browser/passwords:infobar_delegates", "//ios/chrome/browser/passwords:infobar_delegates",
"//ios/chrome/browser/passwords/test",
"//ios/chrome/browser/ui/infobars:feature_flags", "//ios/chrome/browser/ui/infobars:feature_flags",
"//ios/chrome/browser/ui/infobars/banners/test", "//ios/chrome/browser/ui/infobars/banners/test",
"//ios/chrome/browser/ui/infobars/test", "//ios/chrome/browser/ui/infobars/test",
......
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "components/password_manager/core/browser/mock_password_form_manager_for_ui.h"
#include "ios/chrome/browser/infobars/infobar_ios.h" #include "ios/chrome/browser/infobars/infobar_ios.h"
#import "ios/chrome/browser/overlays/public/infobar_banner/save_password_infobar_banner_overlay.h" #import "ios/chrome/browser/overlays/public/infobar_banner/save_password_infobar_banner_overlay.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h" #include "ios/chrome/browser/overlays/public/overlay_request.h"
#include "ios/chrome/browser/overlays/public/overlay_response.h" #include "ios/chrome/browser/overlays/public/overlay_response.h"
#import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.h" #import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.h"
#import "ios/chrome/browser/passwords/test/mock_ios_chrome_save_passwords_infobar_delegate.h"
#import "ios/chrome/browser/ui/infobars/banners/test/fake_infobar_banner_consumer.h" #import "ios/chrome/browser/ui/infobars/banners/test/fake_infobar_banner_consumer.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h" #import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/ui/infobars/test/fake_infobar_ui_delegate.h" #import "ios/chrome/browser/ui/infobars/test/fake_infobar_ui_delegate.h"
...@@ -51,17 +51,8 @@ class SavePasswordInfobarBannerOverlayMediatorTest : public PlatformTest { ...@@ -51,17 +51,8 @@ class SavePasswordInfobarBannerOverlayMediatorTest : public PlatformTest {
TEST_F(SavePasswordInfobarBannerOverlayMediatorTest, SetUpConsumer) { TEST_F(SavePasswordInfobarBannerOverlayMediatorTest, SetUpConsumer) {
// Create an InfoBarIOS with a IOSChromeSavePasswordInfoBarDelegate. // Create an InfoBarIOS with a IOSChromeSavePasswordInfoBarDelegate.
FakeInfobarUIDelegate* ui_delegate = [[FakeInfobarUIDelegate alloc] init]; FakeInfobarUIDelegate* ui_delegate = [[FakeInfobarUIDelegate alloc] init];
ui_delegate.infobarType = InfobarType::kInfobarTypePasswordSave;
std::unique_ptr<password_manager::MockPasswordFormManagerForUI> form_manager =
std::make_unique<password_manager::MockPasswordFormManagerForUI>();
autofill::PasswordForm form;
form.username_value = base::SysNSStringToUTF16(kUsername);
form.password_value = base::SysNSStringToUTF16(kPassword);
EXPECT_CALL(*form_manager, GetPendingCredentials())
.WillRepeatedly(testing::ReturnRef(form));
std::unique_ptr<IOSChromeSavePasswordInfoBarDelegate> passed_delegate = std::unique_ptr<IOSChromeSavePasswordInfoBarDelegate> passed_delegate =
std::make_unique<IOSChromeSavePasswordInfoBarDelegate>( MockIOSChromeSavePasswordInfoBarDelegate::Create(kUsername, kPassword);
false, false, std::move(form_manager));
IOSChromeSavePasswordInfoBarDelegate* delegate = passed_delegate.get(); IOSChromeSavePasswordInfoBarDelegate* delegate = passed_delegate.get();
InfoBarIOS infobar(ui_delegate, std::move(passed_delegate)); InfoBarIOS infobar(ui_delegate, std::move(passed_delegate));
// Package the infobar into an OverlayRequest, then create a mediator that // Package the infobar into an OverlayRequest, then create a mediator that
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment