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

[iOS] Add InfoBarIOS::infobar_type()

InfobarUIDelegate will not be necessary once we move to the overlay-
based implementation.  The only functionality needed from the UI
delegate necessary with overlays is the InfobarType.  This CL adds
InfoBarIOS::infobar_type() to access this type, as well as a constructor
that does not take an InfobarUIDelegate.

This CL also updates the password infobar to be created with this new
constructor if the overlay feature is enabled.

Bug: 1033228
Change-Id: I3080bc2e5bb9e2e3db23dfe437ada90b70bb1661
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150125
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759741}
parent 21fa04a9
...@@ -61,6 +61,7 @@ source_set("badge") { ...@@ -61,6 +61,7 @@ source_set("badge") {
"//ios/chrome/browser/overlays", "//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/common/infobars", "//ios/chrome/browser/overlays/public/common/infobars",
"//ios/chrome/browser/ui/badges:public", "//ios/chrome/browser/ui/badges:public",
"//ios/chrome/browser/ui/badges:util",
"//ios/chrome/browser/ui/infobars:feature_flags", "//ios/chrome/browser/ui/infobars:feature_flags",
"//ios/chrome/browser/ui/infobars:infobars_ui", "//ios/chrome/browser/ui/infobars:infobars_ui",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ios/chrome/browser/infobars/infobar_badge_model.h" #include "ios/chrome/browser/infobars/infobar_badge_model.h"
#include "ios/chrome/browser/infobars/infobar_badge_tab_helper_delegate.h" #include "ios/chrome/browser/infobars/infobar_badge_tab_helper_delegate.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h" #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#include "ios/chrome/browser/ui/badges/badge_type_util.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/infobar_ui_delegate.h" #import "ios/chrome/browser/ui/infobars/infobar_ui_delegate.h"
...@@ -17,11 +18,12 @@ ...@@ -17,11 +18,12 @@
namespace { namespace {
// Returns |infobar|'s InfobarType. // Returns |infobar|'s InfobarType.
InfobarType GetInfobarType(infobars::InfoBar* infobar) { InfobarType GetInfobarType(infobars::InfoBar* infobar) {
return static_cast<InfoBarIOS*>(infobar)->InfobarUIDelegate().infobarType; return static_cast<InfoBarIOS*>(infobar)->infobar_type();
} }
// Returns whether |infobar| supports badges. // Returns whether |infobar| supports badges.
bool SupportsBadges(infobars::InfoBar* infobar) { bool SupportsBadges(infobars::InfoBar* infobar) {
return static_cast<InfoBarIOS*>(infobar)->InfobarUIDelegate().hasBadge; return BadgeTypeForInfobarType(GetInfobarType(infobar)) !=
BadgeType::kBadgeTypeNone;
} }
} // namespace } // namespace
......
...@@ -53,10 +53,8 @@ class InfobarBadgeTabHelperTest : public PlatformTest { ...@@ -53,10 +53,8 @@ class InfobarBadgeTabHelperTest : public PlatformTest {
// ignored. Returns the added infobar. // ignored. Returns the added infobar.
FakeInfobarIOS* AddInfobar(bool has_badge, bool replace_existing = false) { FakeInfobarIOS* AddInfobar(bool has_badge, bool replace_existing = false) {
std::unique_ptr<FakeInfobarIOS> added_infobar = std::unique_ptr<FakeInfobarIOS> added_infobar =
std::make_unique<FakeInfobarIOS>(); std::make_unique<FakeInfobarIOS>(has_badge ? kInfobarTypeWithBadge
added_infobar->fake_ui_delegate().infobarType = : kInfobarTypeNoBadge);
has_badge ? kInfobarTypeWithBadge : kInfobarTypeNoBadge;
added_infobar->fake_ui_delegate().hasBadge = has_badge;
FakeInfobarIOS* infobar = added_infobar.get(); FakeInfobarIOS* infobar = added_infobar.get();
InfoBarManagerImpl::FromWebState(&web_state_) InfoBarManagerImpl::FromWebState(&web_state_)
->AddInfoBar(std::move(added_infobar), replace_existing); ->AddInfoBar(std::move(added_infobar), replace_existing);
...@@ -79,7 +77,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeState) { ...@@ -79,7 +77,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeState) {
// Add a badge-supporting infobar to the InfobarManager to create the badge // Add a badge-supporting infobar to the InfobarManager to create the badge
// item. // item.
FakeInfobarIOS* infobar = AddInfobar(/*has_badge=*/true); FakeInfobarIOS* infobar = AddInfobar(/*has_badge=*/true);
InfobarType added_type = infobar->fake_ui_delegate().infobarType; InfobarType added_type = infobar->infobar_type();
// Simulate presenting the banner UI and verify that the badge state is sent // Simulate presenting the banner UI and verify that the badge state is sent
// to the delegate. // to the delegate.
tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type); tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type);
...@@ -103,8 +101,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeState) { ...@@ -103,8 +101,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeState) {
TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateDeprecated) { TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateDeprecated) {
// Add a badge-supporting infobar to the InfobarManager to create the badge // Add a badge-supporting infobar to the InfobarManager to create the badge
// item. // item.
InfobarType added_type = InfobarType added_type = AddInfobar(/*has_badge=*/true)->infobar_type();
AddInfobar(/*has_badge=*/true)->fake_ui_delegate().infobarType;
// Simulate presenting the banner UI and verify that the badge state is sent // Simulate presenting the banner UI and verify that the badge state is sent
// to the delegate. // to the delegate.
tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type); tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type);
...@@ -126,8 +123,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateDeprecated) { ...@@ -126,8 +123,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateDeprecated) {
// Tests that adding an infobar that doesn't support badges does not notify the // Tests that adding an infobar that doesn't support badges does not notify the
// delegate of BadgeItem creation. // delegate of BadgeItem creation.
TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateNoBadge) { TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateNoBadge) {
InfobarType added_type = InfobarType added_type = AddInfobar(/*has_badge=*/false)->infobar_type();
AddInfobar(/*has_badge=*/false)->fake_ui_delegate().infobarType;
EXPECT_FALSE( EXPECT_FALSE(
[delegate_ itemForBadgeType:BadgeTypeForInfobarType(added_type)]); [delegate_ itemForBadgeType:BadgeTypeForInfobarType(added_type)]);
} }
...@@ -137,8 +133,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateNoBadge) { ...@@ -137,8 +133,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeStateNoBadge) {
TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerDismissal) { TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerDismissal) {
// Add a badge-supporting infobar to the InfobarManager to create the badge // Add a badge-supporting infobar to the InfobarManager to create the badge
// item, then simulate presentation and dismissal. // item, then simulate presentation and dismissal.
InfobarType added_type = InfobarType added_type = AddInfobar(/*has_badge=*/true)->infobar_type();
AddInfobar(/*has_badge=*/true)->fake_ui_delegate().infobarType;
tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type); tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type);
tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type); tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type);
// Verify that the BadgeItem was not removed and that its state is dismissed. // Verify that the BadgeItem was not removed and that its state is dismissed.
...@@ -154,7 +149,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerAccepted) { ...@@ -154,7 +149,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerAccepted) {
// Add a badge-supporting infobar to the InfobarManager to create the badge // Add a badge-supporting infobar to the InfobarManager to create the badge
// item, then simulate presentation, acceptance, and dismissal. // item, then simulate presentation, acceptance, and dismissal.
FakeInfobarIOS* infobar = AddInfobar(/*has_badge=*/true); FakeInfobarIOS* infobar = AddInfobar(/*has_badge=*/true);
InfobarType added_type = infobar->fake_ui_delegate().infobarType; InfobarType added_type = infobar->infobar_type();
tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type); tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type);
infobar->set_accepted(true); infobar->set_accepted(true);
tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type); tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type);
...@@ -170,8 +165,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerAccepted) { ...@@ -170,8 +165,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerAccepted) {
TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerAcceptedDeprecated) { TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnBannerAcceptedDeprecated) {
// Add a badge-supporting infobar to the InfobarManager to create the badge // Add a badge-supporting infobar to the InfobarManager to create the badge
// item, then simulate presentation, acceptance, and dismissal. // item, then simulate presentation, acceptance, and dismissal.
InfobarType added_type = InfobarType added_type = AddInfobar(/*has_badge=*/true)->infobar_type();
AddInfobar(/*has_badge=*/true)->fake_ui_delegate().infobarType;
tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type); tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type);
tab_helper()->UpdateBadgeForInfobarAccepted(added_type); tab_helper()->UpdateBadgeForInfobarAccepted(added_type);
tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type); tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type);
...@@ -187,7 +181,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnInfobarDestruction) { ...@@ -187,7 +181,7 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeOnInfobarDestruction) {
// Add a badge-supporting infobar to the InfobarManager to create the badge // Add a badge-supporting infobar to the InfobarManager to create the badge
// item, then simulate presentation and dismissal. // item, then simulate presentation and dismissal.
FakeInfobarIOS* added_infobar = AddInfobar(/*has_badge=*/true); FakeInfobarIOS* added_infobar = AddInfobar(/*has_badge=*/true);
InfobarType added_type = added_infobar->fake_ui_delegate().infobarType; InfobarType added_type = added_infobar->infobar_type();
tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type); tab_helper()->UpdateBadgeForInfobarBannerPresented(added_type);
tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type); tab_helper()->UpdateBadgeForInfobarBannerDismissed(added_type);
ASSERT_TRUE([delegate_ itemForBadgeType:BadgeTypeForInfobarType(added_type)]); ASSERT_TRUE([delegate_ itemForBadgeType:BadgeTypeForInfobarType(added_type)]);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/observer_list_types.h" #include "base/observer_list_types.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#import "ios/chrome/browser/infobars/infobar_controller_delegate.h" #import "ios/chrome/browser/infobars/infobar_controller_delegate.h"
#import "ios/chrome/browser/infobars/infobar_type.h"
@protocol InfobarUIDelegate; @protocol InfobarUIDelegate;
namespace infobars { namespace infobars {
...@@ -23,7 +24,12 @@ class InfoBarDelegate; ...@@ -23,7 +24,12 @@ class InfoBarDelegate;
// The iOS version of infobars::InfoBar. // The iOS version of infobars::InfoBar.
class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate { class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate {
public: public:
InfoBarIOS(id<InfobarUIDelegate> controller, InfoBarIOS(InfobarType infobar_type,
std::unique_ptr<infobars::InfoBarDelegate> delegate,
bool skip_banner = false);
// TODO(crbug.com/1030357): InfobarUIDelegate and this constructor can be
// removed once overlay-based infobar UI is fully supported.
InfoBarIOS(id<InfobarUIDelegate> ui_delegate,
std::unique_ptr<infobars::InfoBarDelegate> delegate, std::unique_ptr<infobars::InfoBarDelegate> delegate,
bool skip_banner = false); bool skip_banner = false);
~InfoBarIOS() override; ~InfoBarIOS() override;
...@@ -44,6 +50,9 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate { ...@@ -44,6 +50,9 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate {
void AddObserver(Observer* obs) { observers_.AddObserver(obs); } void AddObserver(Observer* obs) { observers_.AddObserver(obs); }
void RemoveObserver(Observer* obs) { observers_.RemoveObserver(obs); } void RemoveObserver(Observer* obs) { observers_.RemoveObserver(obs); }
// Returns the infobar type.
InfobarType infobar_type() const { return infobar_type_; }
// Whether or not the infobar has been accepted. Set to true when the // Whether or not the infobar has been accepted. Set to true when the
// associated action has been executed (e.g. page translation finished), and // associated action has been executed (e.g. page translation finished), and
// false if the action has not been executed or has been reverted. // false if the action has not been executed or has been reverted.
...@@ -69,7 +78,8 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate { ...@@ -69,7 +78,8 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate {
void RemoveInfoBar() override; void RemoveInfoBar() override;
base::ObserverList<Observer, /*check_empty=*/true> observers_; base::ObserverList<Observer, /*check_empty=*/true> observers_;
id<InfobarUIDelegate> controller_ = nil; id<InfobarUIDelegate> ui_delegate_ = nil;
InfobarType infobar_type_;
bool accepted_ = false; bool accepted_ = false;
bool skip_banner_ = false; bool skip_banner_ = false;
base::WeakPtrFactory<InfoBarIOS> weak_factory_{this}; base::WeakPtrFactory<InfoBarIOS> weak_factory_{this};
......
...@@ -15,20 +15,27 @@ ...@@ -15,20 +15,27 @@
using infobars::InfoBar; using infobars::InfoBar;
using infobars::InfoBarDelegate; using infobars::InfoBarDelegate;
InfoBarIOS::InfoBarIOS(id<InfobarUIDelegate> controller, InfoBarIOS::InfoBarIOS(InfobarType infobar_type,
std::unique_ptr<InfoBarDelegate> delegate, std::unique_ptr<InfoBarDelegate> delegate,
bool skip_banner) bool skip_banner)
: InfoBar(std::move(delegate)), : InfoBar(std::move(delegate)),
controller_(controller), infobar_type_(infobar_type),
skip_banner_(skip_banner) {}
InfoBarIOS::InfoBarIOS(id<InfobarUIDelegate> ui_delegate,
std::unique_ptr<InfoBarDelegate> delegate,
bool skip_banner)
: InfoBar(std::move(delegate)),
ui_delegate_(ui_delegate),
infobar_type_(ui_delegate_.infobarType),
skip_banner_(skip_banner) { skip_banner_(skip_banner) {
DCHECK(controller_); DCHECK(ui_delegate_);
[controller_ setDelegate:this]; [ui_delegate_ setDelegate:this];
} }
InfoBarIOS::~InfoBarIOS() { InfoBarIOS::~InfoBarIOS() {
DCHECK(controller_); [ui_delegate_ detachView];
[controller_ detachView]; ui_delegate_ = nil;
controller_ = nil;
for (auto& observer : observers_) { for (auto& observer : observers_) {
observer.InfobarDestroyed(this); observer.InfobarDestroyed(this);
} }
...@@ -44,13 +51,13 @@ void InfoBarIOS::set_accepted(bool accepted) { ...@@ -44,13 +51,13 @@ void InfoBarIOS::set_accepted(bool accepted) {
} }
id<InfobarUIDelegate> InfoBarIOS::InfobarUIDelegate() { id<InfobarUIDelegate> InfoBarIOS::InfobarUIDelegate() {
DCHECK(controller_); DCHECK(ui_delegate_);
return controller_; return ui_delegate_;
} }
void InfoBarIOS::RemoveView() { void InfoBarIOS::RemoveView() {
DCHECK(controller_); DCHECK(ui_delegate_);
[controller_ removeView]; [ui_delegate_ removeView];
} }
base::WeakPtr<InfoBarIOS> InfoBarIOS::GetWeakPtr() { base::WeakPtr<InfoBarIOS> InfoBarIOS::GetWeakPtr() {
......
...@@ -31,7 +31,6 @@ source_set("overlays") { ...@@ -31,7 +31,6 @@ source_set("overlays") {
"//ios/chrome/browser/overlays/public/infobar_banner", "//ios/chrome/browser/overlays/public/infobar_banner",
"//ios/chrome/browser/overlays/public/infobar_modal", "//ios/chrome/browser/overlays/public/infobar_modal",
"//ios/chrome/browser/passwords:infobar_delegates", "//ios/chrome/browser/passwords:infobar_delegates",
"//ios/chrome/browser/ui/infobars:infobars_ui",
"//ios/web/public", "//ios/web/public",
] ]
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#import "ios/chrome/browser/infobars/infobar_ios.h" #import "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"
#import "ios/chrome/browser/overlays/public/infobar_modal/password_infobar_modal_overlay_request_config.h" #import "ios/chrome/browser/overlays/public/infobar_modal/password_infobar_modal_overlay_request_config.h"
#import "ios/chrome/browser/ui/infobars/infobar_ui_delegate.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -37,8 +36,7 @@ InfobarOverlayRequestFactoryImpl::CreateInfobarRequest( ...@@ -37,8 +36,7 @@ InfobarOverlayRequestFactoryImpl::CreateInfobarRequest(
// non-null after all existing infobars have been converted to using overlays. // non-null after all existing infobars have been converted to using overlays.
// Early return in the interim to prevent crashing while the remaining // Early return in the interim to prevent crashing while the remaining
// infobars are being converted. // infobars are being converted.
FactoryHelper* factory = FactoryHelper* factory = factory_storages_[infobar_ios->infobar_type()][type];
factory_storages_[infobar_ios->InfobarUIDelegate().infobarType][type];
return factory ? factory->CreateInfobarRequest(infobar_ios) : nullptr; return factory ? factory->CreateInfobarRequest(infobar_ios) : nullptr;
} }
......
...@@ -62,8 +62,8 @@ class InfobarOverlayRequestInserterTest : public PlatformTest { ...@@ -62,8 +62,8 @@ class InfobarOverlayRequestInserterTest : public PlatformTest {
// pointer to the added InfoBar. If |message_text| matches an infobar already // pointer to the added InfoBar. If |message_text| matches an infobar already
// added, then it the new one will be ignored. // added, then it the new one will be ignored.
InfoBar* CreateInfobar(base::string16 message_text) { InfoBar* CreateInfobar(base::string16 message_text) {
std::unique_ptr<InfoBar> added_infobar = std::unique_ptr<InfoBar> added_infobar = std::make_unique<FakeInfobarIOS>(
std::make_unique<FakeInfobarIOS>(message_text); InfobarType::kInfobarTypeConfirm, message_text);
InfoBar* infobar = added_infobar.get(); InfoBar* infobar = added_infobar.get();
manager()->AddInfoBar(std::move(added_infobar)); manager()->AddInfoBar(std::move(added_infobar));
return infobar; return infobar;
......
...@@ -12,32 +12,20 @@ ...@@ -12,32 +12,20 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@class FakeInfobarUIDelegate;
class FakeInfobarDelegate; class FakeInfobarDelegate;
// Fake version of InfoBarIOS set up with fake delegates to use in tests. // Fake version of InfoBarIOS set up with fake delegates to use in tests.
class FakeInfobarIOS : public InfoBarIOS { class FakeInfobarIOS : public InfoBarIOS {
public: public:
// Creates a FakeInfobarIOS with |type| that has a delegate that uses
// |message_text| as its message.
FakeInfobarIOS( FakeInfobarIOS(
InfobarType type = InfobarType::kInfobarTypeConfirm,
base::string16 message_text = base::ASCIIToUTF16("FakeInfobar")); base::string16 message_text = base::ASCIIToUTF16("FakeInfobar"));
// Creates a FakeInfobarIOS with |fake_delegate|. Uses
// InfobarType::kInfobarTypeConfirm as a default type value.}
FakeInfobarIOS(std::unique_ptr<FakeInfobarDelegate> fake_delegate); FakeInfobarIOS(std::unique_ptr<FakeInfobarDelegate> fake_delegate);
~FakeInfobarIOS() override; ~FakeInfobarIOS() override;
// Creates a FakeInfobarIOS whose FakeInfobarUIDelegate's infobar type is
// |type|, optionally with badge support.
static std::unique_ptr<FakeInfobarIOS> Create(
InfobarType type,
bool has_badge = false,
base::string16 message_text = base::ASCIIToUTF16("FakeInfobar"));
// The fake UI delegate.
FakeInfobarUIDelegate* fake_ui_delegate() const { return fake_ui_delegate_; }
// The fake InfoBarDelegate.
FakeInfobarDelegate* fake_delegate() const { return fake_delegate_; }
private:
FakeInfobarUIDelegate* fake_ui_delegate_ = nil;
FakeInfobarDelegate* fake_delegate_ = nullptr;
}; };
#endif // IOS_CHROME_BROWSER_INFOBARS_TEST_FAKE_INFOBAR_IOS_H_ #endif // IOS_CHROME_BROWSER_INFOBARS_TEST_FAKE_INFOBAR_IOS_H_
...@@ -6,43 +6,16 @@ ...@@ -6,43 +6,16 @@
#include "base/logging.h" #include "base/logging.h"
#include "ios/chrome/browser/infobars/test/fake_infobar_delegate.h" #include "ios/chrome/browser/infobars/test/fake_infobar_delegate.h"
#import "ios/chrome/browser/ui/infobars/test/fake_infobar_ui_delegate.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
FakeInfobarIOS::FakeInfobarIOS(base::string16 message_text) FakeInfobarIOS::FakeInfobarIOS(InfobarType type, base::string16 message_text)
: InfoBarIOS([[FakeInfobarUIDelegate alloc] init], : InfoBarIOS(type, std::make_unique<FakeInfobarDelegate>(message_text)) {}
std::make_unique<FakeInfobarDelegate>(message_text)),
fake_ui_delegate_(
static_cast<FakeInfobarUIDelegate*>(InfobarUIDelegate())),
fake_delegate_(static_cast<FakeInfobarDelegate*>(delegate())) {
DCHECK([fake_ui_delegate_ isKindOfClass:[FakeInfobarUIDelegate class]]);
DCHECK(fake_delegate_);
}
FakeInfobarIOS::FakeInfobarIOS( FakeInfobarIOS::FakeInfobarIOS(
std::unique_ptr<FakeInfobarDelegate> fake_delegate) std::unique_ptr<FakeInfobarDelegate> fake_delegate)
: InfoBarIOS([[FakeInfobarUIDelegate alloc] init], : InfoBarIOS(InfobarType::kInfobarTypeConfirm, std::move(fake_delegate)) {}
std::move(fake_delegate)),
fake_ui_delegate_(
static_cast<FakeInfobarUIDelegate*>(InfobarUIDelegate())),
fake_delegate_(static_cast<FakeInfobarDelegate*>(delegate())) {
DCHECK([fake_ui_delegate_ isKindOfClass:[FakeInfobarUIDelegate class]]);
DCHECK(fake_delegate_);
}
FakeInfobarIOS::~FakeInfobarIOS() = default; FakeInfobarIOS::~FakeInfobarIOS() = default;
// static
std::unique_ptr<FakeInfobarIOS> FakeInfobarIOS::Create(
InfobarType type,
bool has_badge,
base::string16 message_text) {
std::unique_ptr<FakeInfobarIOS> infobar =
std::make_unique<FakeInfobarIOS>(message_text);
infobar->fake_ui_delegate().infobarType = type;
infobar->fake_ui_delegate().hasBadge = has_badge;
return infobar;
}
...@@ -17,6 +17,7 @@ source_set("infobars") { ...@@ -17,6 +17,7 @@ source_set("infobars") {
"//ios/chrome/browser/infobars:public", "//ios/chrome/browser/infobars:public",
"//ios/chrome/browser/infobars/overlays:overlay_type", "//ios/chrome/browser/infobars/overlays:overlay_type",
"//ios/chrome/browser/overlays", "//ios/chrome/browser/overlays",
"//ios/chrome/browser/ui/badges:util",
"//ios/chrome/browser/ui/infobars:infobars_ui", "//ios/chrome/browser/ui/infobars:infobars_ui",
] ]
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/logging.h" #include "base/logging.h"
#import "ios/chrome/browser/infobars/infobar_ios.h" #import "ios/chrome/browser/infobars/infobar_ios.h"
#import "ios/chrome/browser/ui/infobars/infobar_ui_delegate.h" #include "ios/chrome/browser/ui/badges/badge_type_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -20,8 +20,9 @@ InfobarOverlayRequestConfig::InfobarOverlayRequestConfig( ...@@ -20,8 +20,9 @@ InfobarOverlayRequestConfig::InfobarOverlayRequestConfig(
InfoBarIOS* infobar, InfoBarIOS* infobar,
InfobarOverlayType overlay_type) InfobarOverlayType overlay_type)
: infobar_(infobar->GetWeakPtr()), : infobar_(infobar->GetWeakPtr()),
infobar_type_(infobar->InfobarUIDelegate().infobarType), infobar_type_(infobar->infobar_type()),
has_badge_(infobar->InfobarUIDelegate().hasBadge), has_badge_(BadgeTypeForInfobarType(infobar_type_) !=
BadgeType::kBadgeTypeNone),
overlay_type_(overlay_type) {} overlay_type_(overlay_type) {}
InfobarOverlayRequestConfig::~InfobarOverlayRequestConfig() = default; InfobarOverlayRequestConfig::~InfobarOverlayRequestConfig() = default;
...@@ -764,13 +764,21 @@ NSString* const kSuggestionSuffix = @" ••••••••"; ...@@ -764,13 +764,21 @@ NSString* const kSuggestionSuffix = @" ••••••••";
delegate->set_dispatcher(self.dispatcher); delegate->set_dispatcher(self.dispatcher);
if (IsInfobarUIRebootEnabled()) { if (IsInfobarUIRebootEnabled()) {
InfobarPasswordCoordinator* coordinator = std::unique_ptr<InfoBarIOS> infobar;
[[InfobarPasswordCoordinator alloc]
initWithInfoBarDelegate:delegate.get()
type:InfobarType::kInfobarTypePasswordSave];
// If manual save, skip showing banner. // If manual save, skip showing banner.
std::unique_ptr<InfoBarIOS> infobar = std::make_unique<InfoBarIOS>( bool skip_banner = manual;
coordinator, std::move(delegate), /*skip_banner=*/manual); if (IsInfobarOverlayUIEnabled()) {
infobar = std::make_unique<InfoBarIOS>(
InfobarType::kInfobarTypePasswordSave, std::move(delegate),
skip_banner);
} else {
InfobarPasswordCoordinator* coordinator = [[InfobarPasswordCoordinator
alloc]
initWithInfoBarDelegate:delegate.get()
type:InfobarType::kInfobarTypePasswordSave];
infobar = std::make_unique<InfoBarIOS>(
coordinator, std::move(delegate), skip_banner);
}
infoBarManager->AddInfoBar(std::move(infobar), infoBarManager->AddInfoBar(std::move(infobar),
/*replace_existing=*/true); /*replace_existing=*/true);
} else if (!manual) { } else if (!manual) {
......
...@@ -117,7 +117,7 @@ class BadgeMediatorTest : public testing::TestWithParam<TestParam> { ...@@ -117,7 +117,7 @@ class BadgeMediatorTest : public testing::TestWithParam<TestParam> {
// Pass in different |message_text| to avoid replacing existing infobar. // Pass in different |message_text| to avoid replacing existing infobar.
InfoBarIOS* AddInfobar(InfobarType type, base::string16 message_text) { InfoBarIOS* AddInfobar(InfobarType type, base::string16 message_text) {
std::unique_ptr<InfoBarIOS> added_infobar = std::unique_ptr<InfoBarIOS> added_infobar =
FakeInfobarIOS::Create(type, /*has_badge=*/true, message_text); std::make_unique<FakeInfobarIOS>(type, message_text);
InfoBarIOS* infobar = added_infobar.get(); InfoBarIOS* infobar = added_infobar.get();
infobar_manager()->AddInfoBar(std::move(added_infobar)); infobar_manager()->AddInfoBar(std::move(added_infobar));
return infobar; return infobar;
...@@ -240,8 +240,8 @@ TEST_P(BadgeMediatorTest, ...@@ -240,8 +240,8 @@ TEST_P(BadgeMediatorTest,
EXPECT_EQ(badge_consumer_.displayedBadge.badgeType, EXPECT_EQ(badge_consumer_.displayedBadge.badgeType,
BadgeType::kBadgeTypePasswordSave); BadgeType::kBadgeTypePasswordSave);
InsertActivatedWebState(/*index=*/1); InsertActivatedWebState(/*index=*/1);
std::unique_ptr<InfoBarIOS> added_infobar = FakeInfobarIOS::Create( std::unique_ptr<InfoBarIOS> added_infobar = std::make_unique<FakeInfobarIOS>(
kSecondInfobarType, /*has_badge=*/true, kSecondInfobarMessageText); kSecondInfobarType, kSecondInfobarMessageText);
InfoBarManagerImpl::FromWebState(web_state_list_.GetWebStateAt(0)) InfoBarManagerImpl::FromWebState(web_state_list_.GetWebStateAt(0))
->AddInfoBar(std::move(added_infobar)); ->AddInfoBar(std::move(added_infobar));
EXPECT_FALSE(badge_consumer_.displayedBadge); EXPECT_FALSE(badge_consumer_.displayedBadge);
...@@ -253,8 +253,8 @@ TEST_P(BadgeMediatorTest, BadgeMediatorTestDoNotAddInfobarIfWebStateListGone) { ...@@ -253,8 +253,8 @@ TEST_P(BadgeMediatorTest, BadgeMediatorTestDoNotAddInfobarIfWebStateListGone) {
InsertActivatedWebState(/*index=*/0); InsertActivatedWebState(/*index=*/0);
ASSERT_FALSE(badge_consumer_.displayedBadge); ASSERT_FALSE(badge_consumer_.displayedBadge);
[badge_mediator_ disconnect]; [badge_mediator_ disconnect];
std::unique_ptr<InfoBarIOS> added_infobar = FakeInfobarIOS::Create( std::unique_ptr<InfoBarIOS> added_infobar = std::make_unique<FakeInfobarIOS>(
kSecondInfobarType, /*has_badge=*/true, kSecondInfobarMessageText); kSecondInfobarType, kSecondInfobarMessageText);
InfoBarManagerImpl::FromWebState(web_state_list_.GetActiveWebState()) InfoBarManagerImpl::FromWebState(web_state_list_.GetActiveWebState())
->AddInfoBar(std::move(added_infobar)); ->AddInfoBar(std::move(added_infobar));
EXPECT_FALSE(badge_consumer_.displayedBadge); EXPECT_FALSE(badge_consumer_.displayedBadge);
......
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