Index: chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc |
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc |
index 5f3281cbf3a9a6aecdb1e58c0189bf4318aa146f..1feee1fbf5c79205dfe9551eee3a11353e428767 100644 |
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc |
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc |
@@ -69,6 +69,22 @@ class TestingPageNavigator : public PageNavigator { |
GURL url_; |
}; |
+class TestForMenuExitView : public views::View { |
+ public: |
+ TestForMenuExitView() : 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_; |
+}; |
sky
2013/01/30 14:53:04
DISALLOW_...
sschmitz
2013/01/30 20:43:58
Done.
|
+ |
} // namespace |
// Base class for event generating bookmark view tests. These test are intended |
@@ -106,6 +122,16 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { |
: ViewEventTestBase(), |
model_(NULL), |
bb_view_(NULL), |
+ test_for_menu_exit_flag_(false), |
+ test_for_menu_exit_view_(NULL), |
+ file_thread_(BrowserThread::FILE, MessageLoop::current()) { |
+ } |
+ explicit BookmarkBarViewEventTestBase(bool test_flag) |
+ : ViewEventTestBase(), |
+ model_(NULL), |
+ bb_view_(NULL), |
+ test_for_menu_exit_flag_(test_flag), |
+ test_for_menu_exit_view_(NULL), |
file_thread_(BrowserThread::FILE, MessageLoop::current()) { |
} |
@@ -143,12 +169,25 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { |
tmp_parent.AddChildView(bb_view_.get()); |
- bb_view_pref_ = bb_view_->GetPreferredSize(); |
- bb_view_pref_.set_width(1000); |
- views::TextButton* button = GetBookmarkButton(4); |
- while (button->visible()) { |
- bb_view_pref_.set_width(bb_view_pref_.width() - 25); |
- bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height()); |
+ if (!test_for_menu_exit_flag_) { |
sky
2013/01/30 14:53:04
Why does this need to be here and not in your test
sschmitz
2013/01/30 20:43:58
Done.
|
+ bb_view_pref_ = bb_view_->GetPreferredSize(); |
+ bb_view_pref_.set_width(1000); |
+ views::TextButton* button = GetBookmarkButton(4); |
+ while (button->visible()) { |
+ bb_view_pref_.set_width(bb_view_pref_.width() - 25); |
+ bb_view_->SetBounds(0, 0, bb_view_pref_.width(), |
+ bb_view_pref_.height()); |
+ bb_view_->Layout(); |
+ } |
+ } else { |
+ int width = 700; |
+ test_for_menu_exit_view_ = new TestForMenuExitView; |
+ test_for_menu_exit_view_->SetBounds(width - 30, 4, 20, 20); |
+ bb_view_->AddChildView(test_for_menu_exit_view_); |
+ bb_view_pref_ = bb_view_->GetPreferredSize(); |
+ bb_view_pref_.set_width(width); |
+ bb_view_->SetBounds(0, 0, bb_view_pref_.width(), |
+ bb_view_pref_.height()); |
bb_view_->Layout(); |
} |
@@ -192,6 +231,8 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { |
BookmarkModel* model_; |
scoped_ptr<BookmarkBarView> bb_view_; |
TestingPageNavigator navigator_; |
+ bool test_for_menu_exit_flag_; |
+ TestForMenuExitView* test_for_menu_exit_view_; |
private: |
void AddTestData(bool big_menu) { |
@@ -1584,3 +1625,65 @@ class BookmarkBarViewTest19 : public BookmarkBarViewEventTestBase { |
}; |
VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) |
+ |
+#if defined(USE_ASH) && defined(USE_X11) |
sky
2013/01/30 14:53:04
Are you sure this is needed?
sschmitz
2013/01/30 20:43:58
I removed it. git try will tell us the answer;)
Do
|
+ |
+// 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() : BookmarkBarViewEventTestBase(true) {} |
+ |
+ protected: |
+ virtual void DoTestOnMessageLoop() { |
+ ASSERT_TRUE(test_for_menu_exit_view_ != NULL); |
+ ASSERT_TRUE(test_for_menu_exit_view_->press_count() == 0); |
+ |
+ // Move the mouse to the Test View and press the left mouse button. |
+ ui_test_utils::MoveMouseToCenterAndPress( |
+ test_for_menu_exit_view_, ui_controls::LEFT, |
+ ui_controls::DOWN | ui_controls::UP, |
+ CreateEventTask(this, &BookmarkBarViewTest20::Step1)); |
+ } |
+ |
+ private: |
+ void Step1() { |
+ ASSERT_TRUE(test_for_menu_exit_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_TRUE(test_for_menu_exit_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_for_menu_exit_view_, ui_controls::LEFT, |
+ ui_controls::DOWN | ui_controls::UP, |
+ CreateEventTask(this, &BookmarkBarViewTest20::Step3)); |
+ } |
+ |
+ void Step3() { |
+ ASSERT_TRUE(test_for_menu_exit_view_->press_count() == 2); |
+ ASSERT_TRUE(bb_view_->GetMenu() == NULL); |
+ Done(); |
+ } |
+ |
+}; |
+ |
+VIEW_TEST(BookmarkBarViewTest20, ContextMenuExitTest) |
+ |
+#endif |