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..6a5380f161af85acc611d25e54467a9f8898f6b4 100644 |
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc |
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "ash/shell.h" |
#include "base/bind.h" |
#include "base/callback.h" |
#include "base/compiler_specific.h" |
@@ -1584,3 +1585,99 @@ class BookmarkBarViewTest19 : public BookmarkBarViewEventTestBase { |
}; |
VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) |
+ |
+// 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_(NULL) {} |
+ |
+ protected: |
+ virtual void DoTestOnMessageLoop() { |
+ // Enlarge window |
+ const int screen_width = |
+ ash::Shell::GetScreen()->GetPrimaryDisplay().bounds().width(); |
+ gfx::Rect bounds(window_->GetWindowBoundsInScreen()); |
+ const int window_width = screen_width - bounds.x() - 20; |
+ bounds.set_width(window_width); |
+ window_->SetBoundsConstrained(bounds); |
+ window_->Activate(); |
+ |
+ // Place Test View into bb_view_ at right most edge. |
+ int xx = 0; |
sky
2013/01/30 23:01:57
Why are you adding directly to the bookmark bar vi
sschmitz
2013/01/31 01:31:45
Done.
|
+ for (int ii = 0; ii < bb_view_->child_count(); ++ii) { |
+ const int right = bb_view_->child_at(ii)->bounds().right(); |
+ if (right > xx) xx = right; |
sky
2013/01/30 23:01:57
no single ifs.
sschmitz
2013/01/31 01:31:45
Done.
|
+ } |
+ gfx::Rect bb_view_bounds(bb_view_->bounds()); |
+ const int width = bb_view_bounds.width() - xx; |
+ const int height = bb_view_bounds.height(); |
+ ASSERT_TRUE(width > 1 ); |
+ ASSERT_TRUE(height > 1 ); |
+ test_view_ = new TestViewForMenuExit; |
+ test_view_->SetBounds(xx, 0, width, height); |
+ bb_view_->AddChildView(test_view_); |
+ |
+ 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 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) |