Commit 511edc1c authored by sschmitz@chromium.org's avatar sschmitz@chromium.org

Create unit-test for exiting context menus via mouse button

Added a unit-test to BookmarkBarViewTest. It opens a context
menu. The menu is dismissed by clicking the mouse outside of
it. The underlying view gets the mouse event after the
context menu has exited.

See also: 
https://chromiumcodereview.appspot.com/11761027

BUG=171891
TEST=manual, Run: 
out/Debug/interactive_ui_tests --gtest_filter='BookmarkBarViewTest20.*'

Review URL: https://chromiumcodereview.appspot.com/12217158

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182137 0039d316-1c4b-4281-b951-d872f2087c98
parent 09dc0d4b
......@@ -1584,3 +1584,107 @@ class BookmarkBarViewTest19 : public BookmarkBarViewEventTestBase {
};
VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu)
#if !defined(OS_WIN)
// Verify that when clicking a mouse button outside a context menu,
// the context menu is dismissed *and* the underlying view receives
// the the mouse event (due to event reposting).
class BookmarkBarViewTest20 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest20() : test_view_(new TestViewForMenuExit) {}
protected:
virtual void DoTestOnMessageLoop() OVERRIDE {
// Add |test_view_| next to |bb_view_|.
views::View* parent = bb_view_->parent();
views::View* container_view = new ContainerViewForMenuExit;
container_view->AddChildView(bb_view_.get());
container_view->AddChildView(test_view_);
parent->AddChildView(container_view);
parent->Layout();
ASSERT_EQ(test_view_->press_count(), 0);
// Move the mouse to the Test View and press the left mouse button.
ui_test_utils::MoveMouseToCenterAndPress(
test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest20::Step1));
}
private:
void Step1() {
ASSERT_EQ(test_view_->press_count(), 1);
ASSERT_TRUE(bb_view_->GetMenu() == NULL);
// Move the mouse to the first folder on the bookmark bar and press the
// left mouse button.
views::TextButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(
button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest20::Step2));
}
void Step2() {
ASSERT_EQ(test_view_->press_count(), 1);
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
// Move the mouse to the Test View and press the left mouse button.
// The context menu will consume the event and exit. Thereafter,
// the event is reposted and delivered to the Test View which
// increases its press-count.
ui_test_utils::MoveMouseToCenterAndPress(
test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest20::Step3));
}
void Step3() {
ASSERT_EQ(test_view_->press_count(), 2);
ASSERT_TRUE(bb_view_->GetMenu() == NULL);
Done();
}
class ContainerViewForMenuExit : public views::View {
public:
ContainerViewForMenuExit() {
}
virtual void Layout() OVERRIDE {
DCHECK_EQ(2, child_count());
views::View* bb_view = child_at(0);
views::View* test_view = child_at(1);
const int width = bb_view->width();
const int height = bb_view->height();
bb_view->SetBounds(0,0, width - 22, height);
test_view->SetBounds(width - 20, 0, 20, height);
}
private:
DISALLOW_COPY_AND_ASSIGN(ContainerViewForMenuExit);
};
class TestViewForMenuExit : public views::View {
public:
TestViewForMenuExit() : press_count_(0) {
}
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
++press_count_;
return true;
}
int press_count() const { return press_count_; }
private:
int press_count_;
DISALLOW_COPY_AND_ASSIGN(TestViewForMenuExit);
};
TestViewForMenuExit* test_view_;
};
VIEW_TEST(BookmarkBarViewTest20, ContextMenuExitTest)
#endif // !defined(OS_WIN)
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