Commit 01c4b1c4 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions Click-to-Script] Update refresh-required bubble

New mocks use a bubble with title only (as opposed to title and body),
different strings, and no cancel button. Update the bubble accordingly,
and allow ToolbarActionsBarBubble* to accept a null body.

Bug: 834494

Change-Id: Iea23483d894e001e23b14e4e7450120c21d6c87a
Reviewed-on: https://chromium-review.googlesource.com/1033320Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555470}
parent ea4e757d
...@@ -3323,16 +3323,10 @@ are declared in build/common.gypi. ...@@ -3323,16 +3323,10 @@ are declared in build/common.gypi.
<if expr="enable_extensions"> <if expr="enable_extensions">
<!-- Extension blocked action bubble --> <!-- Extension blocked action bubble -->
<message name="IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_HEADING" desc="Heading of the bubble to tell users that in order to run an extension, they'll need to refresh the page."> <message name="IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_HEADING" desc="Heading of the bubble to tell users that in order to run an extension, they'll need to refresh the page.">
Refresh required Reload page to use this extension
</message>
<message name="IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_CONTENT" desc="The content of the bubble to tell users that in order to run an extension, they'll need to refresh the page.">
In order to run this extension, you need to refresh the page. You can run this extension automatically on this site by right-clicking on the extension icon.
</message> </message>
<message name="IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_OK_BUTTON" desc="The text of the button to proceed with the page refresh for running an extension."> <message name="IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_OK_BUTTON" desc="The text of the button to proceed with the page refresh for running an extension.">
OK, refresh Reload
</message>
<message name="IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_CANCEL_BUTTON" desc="The text of the button to close the bubble and not refresh the page or run the extension.">
Never mind
</message> </message>
</if> </if>
......
...@@ -27,6 +27,10 @@ class ToolbarActionsBarBubbleDelegate; ...@@ -27,6 +27,10 @@ class ToolbarActionsBarBubbleDelegate;
// Required. // Required.
NSButton* actionButton_; NSButton* actionButton_;
// The text to display in the body of the bubble, excluding the item list.
// Optional.
NSTextField* bodyText_;
// The list of items to display. Optional. // The list of items to display. Optional.
NSTextField* itemList_; NSTextField* itemList_;
...@@ -57,6 +61,7 @@ class ToolbarActionsBarBubbleDelegate; ...@@ -57,6 +61,7 @@ class ToolbarActionsBarBubbleDelegate;
+ (void)setAnimationEnabledForTesting:(BOOL)enabled; + (void)setAnimationEnabledForTesting:(BOOL)enabled;
@property(readonly, nonatomic) NSButton* actionButton; @property(readonly, nonatomic) NSButton* actionButton;
@property(readonly, nonatomic) NSTextField* bodyText;
@property(readonly, nonatomic) NSTextField* itemList; @property(readonly, nonatomic) NSTextField* itemList;
@property(readonly, nonatomic) NSButton* dismissButton; @property(readonly, nonatomic) NSButton* dismissButton;
@property(readonly, nonatomic) NSButton* link; @property(readonly, nonatomic) NSButton* link;
......
...@@ -61,6 +61,7 @@ CGFloat kMinWidth = 320.0; ...@@ -61,6 +61,7 @@ CGFloat kMinWidth = 320.0;
@implementation ToolbarActionsBarBubbleMac @implementation ToolbarActionsBarBubbleMac
@synthesize actionButton = actionButton_; @synthesize actionButton = actionButton_;
@synthesize bodyText = bodyText_;
@synthesize itemList = itemList_; @synthesize itemList = itemList_;
@synthesize dismissButton = dismissButton_; @synthesize dismissButton = dismissButton_;
@synthesize link = link_; @synthesize link = link_;
...@@ -258,6 +259,9 @@ CGFloat kMinWidth = 320.0; ...@@ -258,6 +259,9 @@ CGFloat kMinWidth = 320.0;
} }
DCHECK(actionButton_ || dismissButton_); DCHECK(actionButton_ || dismissButton_);
// TODO(devlin): This doesn't currently take into account
// delegate_->GetDefaultDialogButton().
CGFloat buttonStripHeight = CGFloat buttonStripHeight =
std::max(actionButtonSize.height, dismissButtonSize.height); std::max(actionButtonSize.height, dismissButtonSize.height);
...@@ -276,16 +280,19 @@ CGFloat kMinWidth = 320.0; ...@@ -276,16 +280,19 @@ CGFloat kMinWidth = 320.0;
CGFloat windowWidth = CGFloat windowWidth =
std::max(std::max(kMinWidth, buttonStripWidth), headingWidth); std::max(std::max(kMinWidth, buttonStripWidth), headingWidth);
NSTextField* content = base::string16 bodyTextString = delegate_->GetBodyText(anchoredToAction_);
[self addTextFieldWithString:delegate_->GetBodyText(anchoredToAction_) NSSize bodyTextSize;
fontSize:12.0 if (!bodyTextString.empty()) {
alignment:NSLeftTextAlignment]; bodyText_ = [self addTextFieldWithString:bodyTextString
[content setFrame:NSMakeRect(0, 0, windowWidth, 0)]; fontSize:12.0
// The content should have the same (max) width as the heading, which means alignment:NSLeftTextAlignment];
// the text will most likely wrap. [bodyText_ setFrame:NSMakeRect(0, 0, windowWidth, 0)];
NSSize contentSize = NSMakeSize(windowWidth, // The content should have the same (max) width as the heading, which means
[GTMUILocalizerAndLayoutTweaker // the text will most likely wrap.
sizeToFitFixedWidthTextField:content]); bodyTextSize =
NSMakeSize(windowWidth, [GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:bodyText_]);
}
const CGFloat kItemListIndentation = 10.0; const CGFloat kItemListIndentation = 10.0;
base::string16 itemListStr = delegate_->GetItemListText(); base::string16 itemListStr = delegate_->GetItemListText();
...@@ -360,11 +367,12 @@ CGFloat kMinWidth = 320.0; ...@@ -360,11 +367,12 @@ CGFloat kMinWidth = 320.0;
currentHeight += itemListSize.height + kVerticalPadding; currentHeight += itemListSize.height + kVerticalPadding;
} }
[content setFrame:NSMakeRect(kHorizontalPadding, if (bodyText_) {
currentHeight, [bodyText_ setFrame:NSMakeRect(kHorizontalPadding, currentHeight,
contentSize.width, bodyTextSize.width, bodyTextSize.height)];
contentSize.height)]; currentHeight += bodyTextSize.height + kVerticalPadding;
currentHeight += contentSize.height + kVerticalPadding; }
[heading setFrame:NSMakeRect(kHorizontalPadding, [heading setFrame:NSMakeRect(kHorizontalPadding,
currentHeight, currentHeight,
headingSize.width, headingSize.width,
......
...@@ -191,6 +191,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { ...@@ -191,6 +191,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
EXPECT_FALSE([bubble label]); EXPECT_FALSE([bubble label]);
EXPECT_FALSE([bubble link]); EXPECT_FALSE([bubble link]);
EXPECT_FALSE([bubble dismissButton]); EXPECT_FALSE([bubble dismissButton]);
EXPECT_TRUE([bubble bodyText]);
EXPECT_FALSE([bubble itemList]); EXPECT_FALSE([bubble itemList]);
[bubble close]; [bubble close];
...@@ -216,6 +217,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { ...@@ -216,6 +217,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
EXPECT_FALSE([bubble label]); EXPECT_FALSE([bubble label]);
EXPECT_TRUE([bubble link]); EXPECT_TRUE([bubble link]);
EXPECT_TRUE([bubble dismissButton]); EXPECT_TRUE([bubble dismissButton]);
EXPECT_TRUE([bubble bodyText]);
EXPECT_FALSE([bubble itemList]); EXPECT_FALSE([bubble itemList]);
[bubble close]; [bubble close];
...@@ -233,6 +235,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { ...@@ -233,6 +235,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
EXPECT_FALSE([bubble label]); EXPECT_FALSE([bubble label]);
EXPECT_FALSE([bubble link]); EXPECT_FALSE([bubble link]);
EXPECT_TRUE([bubble dismissButton]); EXPECT_TRUE([bubble dismissButton]);
EXPECT_TRUE([bubble bodyText]);
EXPECT_FALSE([bubble itemList]); EXPECT_FALSE([bubble itemList]);
[bubble close]; [bubble close];
...@@ -250,12 +253,30 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { ...@@ -250,12 +253,30 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
EXPECT_FALSE([bubble label]); EXPECT_FALSE([bubble label]);
EXPECT_FALSE([bubble link]); EXPECT_FALSE([bubble link]);
EXPECT_FALSE([bubble dismissButton]); EXPECT_FALSE([bubble dismissButton]);
EXPECT_TRUE([bubble bodyText]);
EXPECT_TRUE([bubble itemList]); EXPECT_TRUE([bubble itemList]);
[bubble close]; [bubble close];
chrome::testing::NSRunLoopRunAllPending(); chrome::testing::NSRunLoopRunAllPending();
} }
// Test with no body text.
{
TestToolbarActionsBarBubbleDelegate delegate(
HeadingString(), base::string16(), ActionString());
ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
EXPECT_TRUE([bubble actionButton]);
EXPECT_FALSE([bubble iconView]);
EXPECT_FALSE([bubble label]);
EXPECT_FALSE([bubble link]);
EXPECT_FALSE([bubble dismissButton]);
EXPECT_FALSE([bubble bodyText]);
EXPECT_FALSE([bubble itemList]);
[bubble close];
chrome::testing::NSRunLoopRunAllPending();
}
// Test with a null extra view. // Test with a null extra view.
{ {
TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(), TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
...@@ -266,6 +287,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { ...@@ -266,6 +287,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
EXPECT_FALSE([bubble label]); EXPECT_FALSE([bubble label]);
EXPECT_FALSE([bubble link]); EXPECT_FALSE([bubble link]);
EXPECT_FALSE([bubble dismissButton]); EXPECT_FALSE([bubble dismissButton]);
EXPECT_TRUE([bubble bodyText]);
EXPECT_FALSE([bubble itemList]); EXPECT_FALSE([bubble itemList]);
[bubble close]; [bubble close];
...@@ -292,6 +314,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { ...@@ -292,6 +314,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
EXPECT_TRUE([bubble label]); EXPECT_TRUE([bubble label]);
EXPECT_FALSE([bubble link]); EXPECT_FALSE([bubble link]);
EXPECT_FALSE([bubble dismissButton]); EXPECT_FALSE([bubble dismissButton]);
EXPECT_TRUE([bubble bodyText]);
EXPECT_FALSE([bubble itemList]); EXPECT_FALSE([bubble itemList]);
[bubble close]; [bubble close];
...@@ -318,6 +341,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { ...@@ -318,6 +341,7 @@ TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
EXPECT_FALSE([bubble label]); EXPECT_FALSE([bubble label]);
EXPECT_TRUE([bubble link]); EXPECT_TRUE([bubble link]);
EXPECT_TRUE([bubble dismissButton]); EXPECT_TRUE([bubble dismissButton]);
EXPECT_TRUE([bubble bodyText]);
EXPECT_TRUE([bubble itemList]); EXPECT_TRUE([bubble itemList]);
[bubble close]; [bubble close];
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_types.h"
BlockedActionBubbleDelegate::BlockedActionBubbleDelegate( BlockedActionBubbleDelegate::BlockedActionBubbleDelegate(
const base::Callback<void(CloseAction)>& callback, const base::Callback<void(CloseAction)>& callback,
...@@ -32,7 +33,7 @@ base::string16 BlockedActionBubbleDelegate::GetHeadingText() { ...@@ -32,7 +33,7 @@ base::string16 BlockedActionBubbleDelegate::GetHeadingText() {
base::string16 BlockedActionBubbleDelegate::GetBodyText( base::string16 BlockedActionBubbleDelegate::GetBodyText(
bool anchored_to_action) { bool anchored_to_action) {
return l10n_util::GetStringUTF16(IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_CONTENT); return base::string16();
} }
base::string16 BlockedActionBubbleDelegate::GetItemListText() { base::string16 BlockedActionBubbleDelegate::GetItemListText() {
...@@ -45,8 +46,11 @@ base::string16 BlockedActionBubbleDelegate::GetActionButtonText() { ...@@ -45,8 +46,11 @@ base::string16 BlockedActionBubbleDelegate::GetActionButtonText() {
} }
base::string16 BlockedActionBubbleDelegate::GetDismissButtonText() { base::string16 BlockedActionBubbleDelegate::GetDismissButtonText() {
return l10n_util::GetStringUTF16( return base::string16();
IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_CANCEL_BUTTON); }
ui::DialogButton BlockedActionBubbleDelegate::GetDefaultDialogButton() {
return ui::DIALOG_BUTTON_OK;
} }
std::string BlockedActionBubbleDelegate::GetAnchorActionId() { std::string BlockedActionBubbleDelegate::GetAnchorActionId() {
......
...@@ -26,6 +26,7 @@ class BlockedActionBubbleDelegate : public ToolbarActionsBarBubbleDelegate { ...@@ -26,6 +26,7 @@ class BlockedActionBubbleDelegate : public ToolbarActionsBarBubbleDelegate {
base::string16 GetItemListText() override; base::string16 GetItemListText() override;
base::string16 GetActionButtonText() override; base::string16 GetActionButtonText() override;
base::string16 GetDismissButtonText() override; base::string16 GetDismissButtonText() override;
ui::DialogButton GetDefaultDialogButton() override;
std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo> std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo>
GetExtraViewInfo() override; GetExtraViewInfo() override;
std::string GetAnchorActionId() override; std::string GetAnchorActionId() override;
......
...@@ -70,6 +70,12 @@ base::string16 ExtensionMessageBubbleBridge::GetDismissButtonText() { ...@@ -70,6 +70,12 @@ base::string16 ExtensionMessageBubbleBridge::GetDismissButtonText() {
return controller_->delegate()->GetDismissButtonLabel(); return controller_->delegate()->GetDismissButtonLabel();
} }
ui::DialogButton ExtensionMessageBubbleBridge::GetDefaultDialogButton() {
// TODO(estade): we should set a default where appropriate. See
// http://crbug.com/751279
return ui::DIALOG_BUTTON_NONE;
}
std::string ExtensionMessageBubbleBridge::GetAnchorActionId() { std::string ExtensionMessageBubbleBridge::GetAnchorActionId() {
return controller_->GetExtensionIdList().size() == 1u return controller_->GetExtensionIdList().size() == 1u
? controller_->GetExtensionIdList()[0] ? controller_->GetExtensionIdList()[0]
......
...@@ -33,6 +33,7 @@ class ExtensionMessageBubbleBridge : public ToolbarActionsBarBubbleDelegate { ...@@ -33,6 +33,7 @@ class ExtensionMessageBubbleBridge : public ToolbarActionsBarBubbleDelegate {
base::string16 GetItemListText() override; base::string16 GetItemListText() override;
base::string16 GetActionButtonText() override; base::string16 GetActionButtonText() override;
base::string16 GetDismissButtonText() override; base::string16 GetDismissButtonText() override;
ui::DialogButton GetDefaultDialogButton() override;
std::unique_ptr<ExtraViewInfo> GetExtraViewInfo() override; std::unique_ptr<ExtraViewInfo> GetExtraViewInfo() override;
std::string GetAnchorActionId() override; std::string GetAnchorActionId() override;
void OnBubbleShown(const base::Closure& close_bubble_callback) override; void OnBubbleShown(const base::Closure& close_bubble_callback) override;
......
...@@ -26,6 +26,9 @@ class TestToolbarActionsBarBubbleDelegate::DelegateImpl ...@@ -26,6 +26,9 @@ class TestToolbarActionsBarBubbleDelegate::DelegateImpl
base::string16 GetItemListText() override { return parent_->item_list_; } base::string16 GetItemListText() override { return parent_->item_list_; }
base::string16 GetActionButtonText() override { return parent_->action_; } base::string16 GetActionButtonText() override { return parent_->action_; }
base::string16 GetDismissButtonText() override { return parent_->dismiss_; } base::string16 GetDismissButtonText() override { return parent_->dismiss_; }
ui::DialogButton GetDefaultDialogButton() override {
return parent_->default_button_;
}
std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo> std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo>
GetExtraViewInfo() override { GetExtraViewInfo() override {
if (parent_->info_) if (parent_->info_)
...@@ -56,6 +59,7 @@ TestToolbarActionsBarBubbleDelegate::TestToolbarActionsBarBubbleDelegate( ...@@ -56,6 +59,7 @@ TestToolbarActionsBarBubbleDelegate::TestToolbarActionsBarBubbleDelegate(
heading_(heading), heading_(heading),
body_(body), body_(body),
action_(action), action_(action),
default_button_(ui::DIALOG_BUTTON_NONE),
close_on_deactivate_(true) {} close_on_deactivate_(true) {}
TestToolbarActionsBarBubbleDelegate::~TestToolbarActionsBarBubbleDelegate() { TestToolbarActionsBarBubbleDelegate::~TestToolbarActionsBarBubbleDelegate() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h"
#include "ui/base/ui_base_types.h"
// A test delegate for a bubble to hang off the toolbar actions bar. // A test delegate for a bubble to hang off the toolbar actions bar.
class TestToolbarActionsBarBubbleDelegate { class TestToolbarActionsBarBubbleDelegate {
...@@ -40,6 +41,9 @@ class TestToolbarActionsBarBubbleDelegate { ...@@ -40,6 +41,9 @@ class TestToolbarActionsBarBubbleDelegate {
info_->text = learn_more; info_->text = learn_more;
info_->is_learn_more = true; info_->is_learn_more = true;
} }
void set_default_dialog_button(ui::DialogButton default_button) {
default_button_ = default_button;
}
void set_item_list_text(const base::string16& item_list) { void set_item_list_text(const base::string16& item_list) {
item_list_ = item_list; item_list_ = item_list;
} }
...@@ -72,6 +76,9 @@ class TestToolbarActionsBarBubbleDelegate { ...@@ -72,6 +76,9 @@ class TestToolbarActionsBarBubbleDelegate {
base::string16 learn_more_; base::string16 learn_more_;
base::string16 item_list_; base::string16 item_list_;
// The default button for the bubble.
ui::DialogButton default_button_;
// Whether to close the bubble on deactivation. // Whether to close the bubble on deactivation.
bool close_on_deactivate_; bool close_on_deactivate_;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/base/ui_base_types.h"
namespace gfx { namespace gfx {
struct VectorIcon; struct VectorIcon;
...@@ -73,6 +74,9 @@ class ToolbarActionsBarBubbleDelegate { ...@@ -73,6 +74,9 @@ class ToolbarActionsBarBubbleDelegate {
// button will be added. // button will be added.
virtual base::string16 GetDismissButtonText() = 0; virtual base::string16 GetDismissButtonText() = 0;
// Returns the button that should be set to the default.
virtual ui::DialogButton GetDefaultDialogButton() = 0;
// Returns the id of the action to point to, or the empty string if the // Returns the id of the action to point to, or the empty string if the
// bubble should point to the center of the actions container. // bubble should point to the center of the actions container.
virtual std::string GetAnchorActionId() = 0; virtual std::string GetAnchorActionId() = 0;
......
...@@ -132,23 +132,27 @@ bool ToolbarActionsBarBubbleViews::Close() { ...@@ -132,23 +132,27 @@ bool ToolbarActionsBarBubbleViews::Close() {
} }
void ToolbarActionsBarBubbleViews::Init() { void ToolbarActionsBarBubbleViews::Init() {
base::string16 body_text_string = delegate_->GetBodyText(anchored_to_action_);
base::string16 item_list = delegate_->GetItemListText();
if (body_text_string.empty() && item_list.empty())
return;
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kVertical, gfx::Insets(), views::BoxLayout::kVertical, gfx::Insets(),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL))); provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
// Add the content string.
views::Label* content_label =
new views::Label(delegate_->GetBodyText(anchored_to_action_));
content_label->SetMultiLine(true);
int width = provider->GetDistanceMetric( int width = provider->GetDistanceMetric(
ChromeDistanceMetric::DISTANCE_BUBBLE_PREFERRED_WIDTH) - ChromeDistanceMetric::DISTANCE_BUBBLE_PREFERRED_WIDTH) -
margins().width(); margins().width();
content_label->SizeToFit(width);
content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(content_label);
base::string16 item_list = delegate_->GetItemListText(); if (!body_text_string.empty()) {
body_text_ = new views::Label(body_text_string);
body_text_->SetMultiLine(true);
body_text_->SizeToFit(width);
body_text_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(body_text_);
}
if (!item_list.empty()) { if (!item_list.empty()) {
item_list_ = new views::Label(item_list); item_list_ = new views::Label(item_list);
...@@ -173,9 +177,7 @@ int ToolbarActionsBarBubbleViews::GetDialogButtons() const { ...@@ -173,9 +177,7 @@ int ToolbarActionsBarBubbleViews::GetDialogButtons() const {
} }
int ToolbarActionsBarBubbleViews::GetDefaultDialogButton() const { int ToolbarActionsBarBubbleViews::GetDefaultDialogButton() const {
// TODO(estade): we should set a default where appropriate. See return delegate_->GetDefaultDialogButton();
// http://crbug.com/751279
return ui::DIALOG_BUTTON_NONE;
} }
base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel(
......
...@@ -33,6 +33,7 @@ class ToolbarActionsBarBubbleViews : public views::BubbleDialogDelegateView, ...@@ -33,6 +33,7 @@ class ToolbarActionsBarBubbleViews : public views::BubbleDialogDelegateView,
void Show(); void Show();
const views::Label* body_text() const { return body_text_; }
const views::Label* item_list() const { return item_list_; } const views::Label* item_list() const { return item_list_; }
views::ImageButton* learn_more_button() const { return image_button_; } views::ImageButton* learn_more_button() const { return image_button_; }
...@@ -56,6 +57,7 @@ class ToolbarActionsBarBubbleViews : public views::BubbleDialogDelegateView, ...@@ -56,6 +57,7 @@ class ToolbarActionsBarBubbleViews : public views::BubbleDialogDelegateView,
std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate_; std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate_;
bool delegate_notified_of_close_ = false; bool delegate_notified_of_close_ = false;
views::Label* body_text_ = nullptr;
views::Label* item_list_ = nullptr; views::Label* item_list_ = nullptr;
views::ImageButton* image_button_ = nullptr; views::ImageButton* image_button_ = nullptr;
const bool anchored_to_action_; const bool anchored_to_action_;
......
...@@ -209,6 +209,38 @@ TEST_F(ToolbarActionsBarBubbleViewsTest, TestBubbleLayoutListView) { ...@@ -209,6 +209,38 @@ TEST_F(ToolbarActionsBarBubbleViewsTest, TestBubbleLayoutListView) {
CloseBubble(); CloseBubble();
} }
TEST_F(ToolbarActionsBarBubbleViewsTest, TestBubbleLayoutNoBodyText) {
TestToolbarActionsBarBubbleDelegate delegate(
HeadingString(), base::string16(), ActionString());
ShowBubble(&delegate);
EXPECT_TRUE(bubble()->GetDialogClientView()->ok_button());
EXPECT_EQ(ActionString(),
bubble()->GetDialogClientView()->ok_button()->GetText());
EXPECT_FALSE(bubble()->GetDialogClientView()->cancel_button());
EXPECT_FALSE(bubble()->learn_more_button());
EXPECT_FALSE(bubble()->body_text());
EXPECT_FALSE(bubble()->item_list());
CloseBubble();
}
TEST_F(ToolbarActionsBarBubbleViewsTest, TestBubbleDefaultDialogButtons) {
TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
ActionString());
delegate.set_dismiss_button_text(DismissString());
delegate.set_default_dialog_button(ui::DIALOG_BUTTON_OK);
ShowBubble(&delegate);
ASSERT_TRUE(bubble()->GetDialogClientView()->ok_button());
EXPECT_TRUE(bubble()->GetDialogClientView()->ok_button()->is_default());
ASSERT_TRUE(bubble()->GetDialogClientView()->cancel_button());
EXPECT_FALSE(bubble()->GetDialogClientView()->cancel_button()->is_default());
CloseBubble();
}
TEST_F(ToolbarActionsBarBubbleViewsTest, TestShowAndCloseBubble) { TEST_F(ToolbarActionsBarBubbleViewsTest, TestShowAndCloseBubble) {
std::unique_ptr<views::Widget> anchor_widget = CreateAnchorWidget(); std::unique_ptr<views::Widget> anchor_widget = CreateAnchorWidget();
TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(), TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
......
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