Commit 0ac3472c authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Add title field to ConfirmInfobarDelegate.

Adds title field attribute to that will allow InfoBar overlay in iOS
code to set both a title and subtitle in its message. This is required
in some instances where the required notification provides a title
as will be the case for sign-in account notifications.

Approved UX Design:
https://docs.google.com/presentation/d/1tgAFQVKEUd-NcxyJhs6ZNqEu9j4QvX3-S_1wH9sU55k/edit#slide=id.ga6d0dd7c46_0_709

Bug: 1145592
Change-Id: Ic10bc8ed01f93f471e39c558dc09295d4257308c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521619
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825383}
parent 9dc47d86
......@@ -26,6 +26,10 @@ ConfirmInfoBarDelegate::GetInfoBarAutomationType() const {
return CONFIRM_INFOBAR;
}
base::string16 ConfirmInfoBarDelegate::GetTitleText() const {
return base::string16();
}
gfx::ElideBehavior ConfirmInfoBarDelegate::GetMessageElideBehavior() const {
return gfx::ELIDE_TAIL;
}
......
......@@ -35,6 +35,10 @@ class ConfirmInfoBarDelegate : public infobars::InfoBarDelegate {
// Returns the InfoBar type to be displayed for the InfoBar.
InfoBarAutomationType GetInfoBarAutomationType() const override;
// Returns the title string to be displayed for the InfoBar.
// Defaults to having not title. Currently only used on iOS.
virtual base::string16 GetTitleText() const;
// Returns the message string to be displayed for the InfoBar.
virtual base::string16 GetMessageText() const = 0;
......
......@@ -7,17 +7,37 @@
#include "base/strings/utf_string_conversions.h"
FakeInfobarDelegate::FakeInfobarDelegate()
: identifier_(infobars::InfoBarDelegate::InfoBarIdentifier::TEST_INFOBAR),
message_text_(base::ASCIIToUTF16("FakeInfobarDelegate")) {}
: FakeInfobarDelegate(
infobars::InfoBarDelegate::InfoBarIdentifier::TEST_INFOBAR,
/*title_text=*/base::string16(),
base::ASCIIToUTF16("FakeInfobarDelegate")) {}
FakeInfobarDelegate::FakeInfobarDelegate(
infobars::InfoBarDelegate::InfoBarIdentifier identifier)
: identifier_(identifier),
message_text_(base::ASCIIToUTF16("FakeInfobarDelegate")) {}
: FakeInfobarDelegate(identifier,
/*title_text=*/base::string16(),
base::ASCIIToUTF16("FakeInfobarDelegate")) {}
FakeInfobarDelegate::FakeInfobarDelegate(base::string16 message_text)
: identifier_(infobars::InfoBarDelegate::InfoBarIdentifier::TEST_INFOBAR),
message_text_(message_text) {}
: FakeInfobarDelegate(
infobars::InfoBarDelegate::InfoBarIdentifier::TEST_INFOBAR,
/*title_text=*/base::string16(),
std::move(message_text)) {}
FakeInfobarDelegate::FakeInfobarDelegate(base::string16 title_text,
base::string16 message_text)
: FakeInfobarDelegate(
infobars::InfoBarDelegate::InfoBarIdentifier::TEST_INFOBAR,
std::move(title_text),
std::move(message_text)) {}
FakeInfobarDelegate::FakeInfobarDelegate(
infobars::InfoBarDelegate::InfoBarIdentifier identifier,
base::string16 title_text,
base::string16 message_text)
: identifier_(identifier),
title_text_(std::move(title_text)),
message_text_(std::move(message_text)) {}
FakeInfobarDelegate::~FakeInfobarDelegate() = default;
......@@ -26,6 +46,11 @@ FakeInfobarDelegate::GetIdentifier() const {
return identifier_;
}
// Returns the title string to be displayed for the Infobar.
base::string16 FakeInfobarDelegate::GetTitleText() const {
return title_text_;
}
// Returns the message string to be displayed for the Infobar.
base::string16 FakeInfobarDelegate::GetMessageText() const {
return message_text_;
......
......@@ -14,17 +14,25 @@ class FakeInfobarDelegate : public ConfirmInfoBarDelegate {
public:
FakeInfobarDelegate();
FakeInfobarDelegate(base::string16 message_text);
FakeInfobarDelegate(base::string16 title_text, base::string16 message_text);
FakeInfobarDelegate(infobars::InfoBarDelegate::InfoBarIdentifier identifier);
~FakeInfobarDelegate() override;
// Returns |identifier_|, set during construction.
InfoBarIdentifier GetIdentifier() const override;
// Returns the message string to be displayed for the Infobar.
base::string16 GetTitleText() const override;
// Returns the message string to be displayed for the Infobar.
base::string16 GetMessageText() const override;
private:
FakeInfobarDelegate(infobars::InfoBarDelegate::InfoBarIdentifier identifier,
base::string16 title_text,
base::string16 message_text);
infobars::InfoBarDelegate::InfoBarIdentifier identifier_;
base::string16 title_text_;
base::string16 message_text_;
};
......
......@@ -23,6 +23,9 @@ class ConfirmBannerRequestConfig
public:
~ConfirmBannerRequestConfig() override;
// The title text.
base::string16 title_text() const { return title_text_; }
// The message text.
base::string16 message_text() const { return message_text_; }
......@@ -45,6 +48,7 @@ class ConfirmBannerRequestConfig
// The InfoBar causing this banner.
infobars::InfoBar* infobar_ = nullptr;
// Configuration data extracted from |infobar_|'s confirm delegate.
base::string16 title_text_;
base::string16 message_text_;
base::string16 button_label_text_;
gfx::Image icon_image_;
......
......@@ -24,6 +24,7 @@ ConfirmBannerRequestConfig::ConfirmBannerRequestConfig(
DCHECK(infobar_);
ConfirmInfoBarDelegate* delegate =
static_cast<ConfirmInfoBarDelegate*>(infobar_->delegate());
title_text_ = delegate->GetTitleText();
message_text_ = delegate->GetMessageText();
button_label_text_ =
delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK);
......
......@@ -58,7 +58,14 @@ using confirm_infobar_overlays::ConfirmBannerRequestConfig;
if (!config->icon_image().IsEmpty())
[self.consumer setIconImage:config->icon_image().ToUIImage()];
[self.consumer setPresentsModal:NO];
[self.consumer setTitleText:base::SysUTF16ToNSString(config->message_text())];
if (config->title_text().empty()) {
[self.consumer
setTitleText:base::SysUTF16ToNSString(config->message_text())];
} else {
[self.consumer setTitleText:base::SysUTF16ToNSString(config->title_text())];
[self.consumer
setSubtitleText:base::SysUTF16ToNSString(config->message_text())];
}
}
@end
......@@ -38,8 +38,41 @@ class ConfirmInfobarBannerOverlayMediatorTest : public PlatformTest {
};
// Tests that a ConfirmInfobarBannerOverlayMediator correctly sets up its
// consumer.
TEST_F(ConfirmInfobarBannerOverlayMediatorTest, SetUpConsumer) {
// consumer with a title and display message.
TEST_F(ConfirmInfobarBannerOverlayMediatorTest,
SetUpConsumerWithTitleAndMessage) {
// Create an InfoBarIOS with a ConfirmInfoBarDelegate.
std::unique_ptr<FakeInfobarDelegate> passed_delegate =
std::make_unique<FakeInfobarDelegate>(base::ASCIIToUTF16("title"),
base::ASCIIToUTF16("message"));
FakeInfobarDelegate* delegate = passed_delegate.get();
InfoBarIOS infobar(InfobarType::kInfobarTypeConfirm,
std::move(passed_delegate));
// Package the infobar into an OverlayRequest, then create a mediator that
// uses this request in order to set up a fake consumer.
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<ConfirmBannerRequestConfig>(&infobar);
ConfirmInfobarBannerOverlayMediator* mediator =
[[ConfirmInfobarBannerOverlayMediator alloc]
initWithRequest:request.get()];
FakeInfobarBannerConsumer* consumer =
[[FakeInfobarBannerConsumer alloc] init];
mediator.consumer = consumer;
// Verify that the infobar was set up properly.
NSString* title = base::SysUTF16ToNSString(delegate->GetTitleText());
NSString* subtitle = base::SysUTF16ToNSString(delegate->GetMessageText());
EXPECT_NSEQ(title, consumer.titleText);
EXPECT_NSEQ(subtitle, consumer.subtitleText);
EXPECT_NSEQ(base::SysUTF16ToNSString(
delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)),
consumer.buttonText);
EXPECT_FALSE(consumer.presentsModal);
}
// Tests that a ConfirmInfobarBannerOverlayMediator correctly sets up its
// consumer with a display message.
TEST_F(ConfirmInfobarBannerOverlayMediatorTest, SetUpConsumerWithMessage) {
// Create an InfoBarIOS with a ConfirmInfoBarDelegate.
std::unique_ptr<FakeInfobarDelegate> passed_delegate =
std::make_unique<FakeInfobarDelegate>();
......
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