Commit 18ca34c6 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

message_center: Remove inline reply on change

Notification inline reply did not support notification update after its
creation properly.

TEST=NotificationViewMD.TestInlineReplyRemovedByUpdate
BUG=894638

Change-Id: Ib03b92ea580fa45d5c4fc58de0bca2a1c7399e50
Reviewed-on: https://chromium-review.googlesource.com/c/1290234
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601840}
parent 3ef69f5c
......@@ -1004,14 +1004,26 @@ void NotificationViewMD::CreateOrUpdateActionButtonViews(
const std::vector<ButtonInfo>& buttons = notification.buttons();
bool new_buttons = action_buttons_.size() != buttons.size();
if (new_buttons || buttons.size() == 0) {
if (new_buttons || buttons.empty()) {
for (auto* item : action_buttons_)
delete item;
action_buttons_.clear();
if (buttons.empty())
actions_row_->SetVisible(false);
}
DCHECK_EQ(this, actions_row_->parent());
// Hide inline reply field if it doesn't exist anymore.
if (inline_reply_->visible()) {
const size_t index =
inline_reply_->textfield()->GetProperty(kTextfieldIndexKey);
if (index >= buttons.size() || !buttons[index].placeholder.has_value()) {
action_buttons_row_->SetVisible(true);
inline_reply_->SetVisible(false);
}
}
for (size_t i = 0; i < buttons.size(); ++i) {
ButtonInfo button_info = buttons[i];
if (new_buttons) {
......@@ -1021,6 +1033,7 @@ void NotificationViewMD::CreateOrUpdateActionButtonViews(
action_buttons_row_->AddChildView(button);
} else {
action_buttons_[i]->SetText(button_info.title);
action_buttons_[i]->set_placeholder(button_info.placeholder);
action_buttons_[i]->SchedulePaint();
action_buttons_[i]->Layout();
}
......
......@@ -99,9 +99,12 @@ class NotificationButtonMD : public views::LabelButton {
const base::Optional<base::string16>& placeholder() const {
return placeholder_;
}
void set_placeholder(const base::Optional<base::string16>& placeholder) {
placeholder_ = placeholder;
}
private:
const base::Optional<base::string16> placeholder_;
base::Optional<base::string16> placeholder_;
DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD);
};
......@@ -213,6 +216,8 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestClickExpanded);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestActionButtonClick);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestInlineReply);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest,
TestInlineReplyRemovedByUpdate);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, ExpandLongMessage);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestAccentColor);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, UseImageAsIcon);
......
......@@ -587,6 +587,55 @@ TEST_F(NotificationViewMDTest, TestInlineReply) {
EXPECT_EQ(base::ASCIIToUTF16("test"), delegate_->submitted_reply_string());
}
TEST_F(NotificationViewMDTest, TestInlineReplyRemovedByUpdate) {
std::unique_ptr<Notification> notification = CreateSimpleNotification();
std::vector<ButtonInfo> buttons = CreateButtons(2);
buttons[1].placeholder = base::string16();
notification->set_buttons(buttons);
UpdateNotificationViews(*notification);
widget()->Show();
ui::test::EventGenerator generator(widget()->GetNativeWindow());
// Action buttons are hidden by collapsed state.
if (!notification_view()->expanded_)
notification_view()->ToggleExpanded();
EXPECT_TRUE(notification_view()->actions_row_->visible());
// Now construct a mouse click event 1 pixel inside the boundary of the action
// button.
gfx::Point cursor_location(1, 1);
views::View::ConvertPointToScreen(notification_view()->action_buttons_[1],
&cursor_location);
generator.MoveMouseTo(cursor_location);
generator.ClickLeftButton();
// Nothing should be submitted at this point.
EXPECT_EQ(-1, delegate_->clicked_button_index());
EXPECT_TRUE(notification_view()->inline_reply_->visible());
EXPECT_FALSE(notification_view()->action_buttons_row_->visible());
buttons[1].placeholder = base::nullopt;
notification->set_buttons(buttons);
UpdateNotificationViews(*notification);
EXPECT_FALSE(notification_view()->inline_reply_->visible());
EXPECT_TRUE(notification_view()->action_buttons_row_->visible());
// Now it emits click event.
delegate_->set_expecting_button_click(true);
generator.ClickLeftButton();
EXPECT_EQ(1, delegate_->clicked_button_index());
buttons.clear();
notification->set_buttons(buttons);
UpdateNotificationViews(*notification);
EXPECT_FALSE(notification_view()->actions_row_->visible());
}
TEST_F(NotificationViewMDTest, SlideOut) {
ui::ScopedAnimationDurationScaleMode zero_duration_scope(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
......
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