Commit 7ab0e899 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Fix subclassing bugs in InfobarBannerInteractionHandler

This change leaves BannerVisibilityChanged unimplementated in
InfobarBannerInteractionHandler. This will allow
the PasswordInfobarBannerInteractionHandler implementation to be
executed.

This change also modifies GetInfobarDelegate to return
the generic InfoBarDelegate since BannerDismissedByUser is a general
implementation by all Infobars. Translate is not a
ConfirmInfoBarDelegate.


Change-Id: Id6bfa73a8d1ca274466bb8c14217135438c19e3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2229602Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775180}
parent 849adb4f
......@@ -9,6 +9,7 @@
#import "ios/chrome/browser/infobars/overlays/browser_agent/interaction_handlers/infobar_interaction_handler.h"
class OverlayRequestSupport;
namespace web {
class WebState;
}
......@@ -26,7 +27,7 @@ class InfobarBannerInteractionHandler
~InfobarBannerInteractionHandler() override;
// Updates the model when the visibility of |infobar|'s banner is changed.
virtual void BannerVisibilityChanged(InfoBarIOS* infobar, bool visible);
virtual void BannerVisibilityChanged(InfoBarIOS* infobar, bool visible) {}
// Updates the model when the main button is tapped for |infobar|'s banner.
virtual void MainButtonTapped(InfoBarIOS* infobar) {}
// Shows the modal when the modal button is tapped for |infobar|'s banner.
......
......@@ -6,7 +6,7 @@
#include "base/check.h"
#include "base/logging.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
#include "ios/chrome/browser/infobars/infobar_ios.h"
#import "ios/chrome/browser/infobars/overlays/browser_agent/interaction_handlers/common/infobar_banner_overlay_request_callback_installer.h"
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_inserter.h"
......@@ -17,9 +17,8 @@
#endif
namespace {
ConfirmInfoBarDelegate* GetInfobarDelegate(InfoBarIOS* infobar) {
ConfirmInfoBarDelegate* delegate =
infobar->delegate()->AsConfirmInfoBarDelegate();
infobars::InfoBarDelegate* GetInfobarDelegate(InfoBarIOS* infobar) {
infobars::InfoBarDelegate* delegate = infobar->delegate();
DCHECK(delegate);
return delegate;
}
......@@ -39,13 +38,6 @@ InfobarBannerInteractionHandler::CreateInstaller() {
request_support_, this);
}
void InfobarBannerInteractionHandler::BannerVisibilityChanged(
InfoBarIOS* infobar,
bool visible) {
if (!visible)
GetInfobarDelegate(infobar)->InfoBarDismissed();
}
void InfobarBannerInteractionHandler::ShowModalButtonTapped(
InfoBarIOS* infobar,
web::WebState* web_state) {
......
......@@ -56,13 +56,6 @@ class InfobarBannerInteractionHandlerTest : public PlatformTest {
InfoBarIOS* infobar_;
};
// Tests that BannerVisibilityChanged() calls InfobarPresenting() and
// InfobarDismissed() on the mock delegate.
TEST_F(InfobarBannerInteractionHandlerTest, Presentation) {
EXPECT_CALL(mock_delegate(), InfoBarDismissed());
handler_.BannerVisibilityChanged(infobar_, false);
}
// Tests that pressing the modal button calls adds an OverlayRequest for the
// modal UI to the WebState's queue at OverlayModality::kInfobarModal.
TEST_F(InfobarBannerInteractionHandlerTest, ShowModal) {
......
......@@ -19,6 +19,7 @@ class ConfirmInfobarBannerInteractionHandler
// InfobarBannerInteractionHandler:
void MainButtonTapped(InfoBarIOS* infobar) override;
void BannerVisibilityChanged(InfoBarIOS* infobar, bool visible) override;
private:
// Returns the password delegate from |infobar|.
......
......@@ -29,6 +29,13 @@ void ConfirmInfobarBannerInteractionHandler::MainButtonTapped(
infobar->set_accepted(GetInfobarDelegate(infobar)->Accept());
}
void ConfirmInfobarBannerInteractionHandler::BannerVisibilityChanged(
InfoBarIOS* infobar,
bool visible) {
if (!visible)
GetInfobarDelegate(infobar)->InfoBarDismissed();
}
#pragma mark - Private
ConfirmInfoBarDelegate*
......
......@@ -60,3 +60,9 @@ TEST_F(ConfirmInfobarBannerInteractionHandlerTest, MainButton) {
handler_.MainButtonTapped(infobar_);
EXPECT_TRUE(infobar_->accepted());
}
// Tests that BannerVisibilityChanged() InfobarDismissed() on the mock delegate.
TEST_F(ConfirmInfobarBannerInteractionHandlerTest, Presentation) {
EXPECT_CALL(mock_delegate(), InfoBarDismissed());
handler_.BannerVisibilityChanged(infobar_, false);
}
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