Commit 848163c8 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add unit tests for action button click and inline reply.

User interaction with NotificationViewMD should fire the appropriate
callback methods defined in MessageViewDelegate.

Especially, with the interaction in the actions row, we should fire
- ClickOnNotificationButon
- ClickOnNotificationButtonWithReply

This CL adds the following unit tests to test these callbacks.
- TestActionButtonClick
- TestInlineReply

TEST=message_center_unittests
BUG=789057

Change-Id: Iba71e1f928830071fe73a7e49feb44efe493c8dd
Reviewed-on: https://chromium-review.googlesource.com/799592
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520837}
parent 7936295b
......@@ -210,6 +210,8 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestIconSizing);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, UpdateButtonsStateTest);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, UpdateButtonCountTest);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestActionButtonClick);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestInlineReply);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, ExpandLongMessage);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestAccentColor);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, UseImageAsIcon);
......
......@@ -81,6 +81,11 @@ class NotificationViewMDTest : public views::ViewsTestBase,
void ScrollBy(int dx);
views::View* GetCloseButton();
bool expecting_button_click_ = false;
bool expecting_reply_submission_ = false;
int clicked_button_index_ = -1;
base::string16 submitted_reply_string_;
private:
std::set<std::string> removed_ids_;
......@@ -123,6 +128,13 @@ void NotificationViewMDTest::SetUp() {
widget_->SetContentsView(notification_view_.get());
widget_->SetSize(notification_view_->GetPreferredSize());
widget_->Show();
widget_->widget_delegate()->set_can_activate(true);
widget_->Activate();
expecting_button_click_ = false;
expecting_reply_submission_ = false;
clicked_button_index_ = -1;
submitted_reply_string_.clear();
}
void NotificationViewMDTest::TearDown() {
......@@ -146,16 +158,22 @@ void NotificationViewMDTest::RemoveNotification(
void NotificationViewMDTest::ClickOnNotificationButton(
const std::string& notification_id,
int button_index) {
// For this test, this method should not be invoked.
NOTREACHED();
if (!expecting_button_click_) {
ADD_FAILURE() << "ClickOnNotificationButton should not be invoked.";
}
clicked_button_index_ = button_index;
}
void NotificationViewMDTest::ClickOnNotificationButtonWithReply(
const std::string& notification_id,
int button_index,
const base::string16& reply) {
// For this test, this method should not be invoked.
NOTREACHED();
if (!expecting_reply_submission_) {
ADD_FAILURE()
<< "ClickOnNotificationButtonWithReply should not be invoked.";
}
clicked_button_index_ = button_index;
submitted_reply_string_ = reply;
}
void NotificationViewMDTest::ClickOnSettingsButton(
......@@ -420,6 +438,83 @@ TEST_F(NotificationViewMDTest, UpdateButtonCountTest) {
notification_view()->action_buttons_[0]->state());
}
TEST_F(NotificationViewMDTest, TestActionButtonClick) {
expecting_button_click_ = true;
notification()->set_buttons(CreateButtons(2));
notification_view()->UpdateWithNotification(*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();
EXPECT_EQ(1, clicked_button_index_);
}
TEST_F(NotificationViewMDTest, TestInlineReply) {
expecting_reply_submission_ = true;
std::vector<ButtonInfo> buttons = CreateButtons(2);
buttons[1].type = ButtonType::TEXT;
notification()->set_buttons(buttons);
notification_view()->UpdateWithNotification(*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, clicked_button_index_);
// Toggling should hide the inline textfield.
EXPECT_TRUE(notification_view()->inline_reply_->visible());
notification_view()->ToggleExpanded();
notification_view()->ToggleExpanded();
EXPECT_FALSE(notification_view()->inline_reply_->visible());
// Click the button again and focus on the inline textfield.
generator.ClickLeftButton();
generator.ClickLeftButton();
EXPECT_TRUE(notification_view()->inline_reply_->visible());
EXPECT_TRUE(notification_view()->inline_reply_->HasFocus());
// Type the text and submit.
ui::KeyboardCode keycodes[] = {ui::VKEY_T, ui::VKEY_E, ui::VKEY_S, ui::VKEY_T,
ui::VKEY_RETURN};
for (ui::KeyboardCode keycode : keycodes) {
generator.PressKey(keycode, ui::EF_NONE);
generator.ReleaseKey(keycode, ui::EF_NONE);
}
EXPECT_EQ(1, clicked_button_index_);
EXPECT_EQ(base::ASCIIToUTF16("test"), submitted_reply_string_);
}
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