OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1577 ASSERT_TRUE(menu != NULL); | 1577 ASSERT_TRUE(menu != NULL); |
1578 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1578 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
1579 | 1579 |
1580 menu->GetMenuController()->CancelAll(); | 1580 menu->GetMenuController()->CancelAll(); |
1581 | 1581 |
1582 Done(); | 1582 Done(); |
1583 } | 1583 } |
1584 }; | 1584 }; |
1585 | 1585 |
1586 VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) | 1586 VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) |
1587 | |
1588 #if !defined(OS_WIN) | |
tfarina
2013/02/13 00:44:26
where is this test supposed to run? ChromeOS? if y
| |
1589 | |
1590 // Verify that when clicking a mouse button outside a context menu, | |
1591 // the context menu is dismissed *and* the underlying view receives | |
1592 // the the mouse event (due to event reposting). | |
1593 class BookmarkBarViewTest20 : public BookmarkBarViewEventTestBase { | |
1594 public: | |
1595 BookmarkBarViewTest20() : test_view_(new TestViewForMenuExit) {} | |
1596 | |
1597 protected: | |
1598 virtual void DoTestOnMessageLoop() OVERRIDE { | |
1599 // Add |test_view_| next to |bb_view_|. | |
1600 views::View* parent = bb_view_->parent(); | |
1601 views::View* container_view = new ContainerViewForMenuExit; | |
1602 container_view->AddChildView(bb_view_.get()); | |
1603 container_view->AddChildView(test_view_); | |
1604 parent->AddChildView(container_view); | |
1605 parent->Layout(); | |
1606 | |
1607 ASSERT_EQ(test_view_->press_count(), 0); | |
1608 | |
1609 // Move the mouse to the Test View and press the left mouse button. | |
1610 ui_test_utils::MoveMouseToCenterAndPress( | |
1611 test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
1612 CreateEventTask(this, &BookmarkBarViewTest20::Step1)); | |
1613 } | |
1614 | |
1615 private: | |
1616 void Step1() { | |
1617 ASSERT_EQ(test_view_->press_count(), 1); | |
1618 ASSERT_TRUE(bb_view_->GetMenu() == NULL); | |
1619 | |
1620 // Move the mouse to the first folder on the bookmark bar and press the | |
1621 // left mouse button. | |
1622 views::TextButton* button = GetBookmarkButton(0); | |
1623 ui_test_utils::MoveMouseToCenterAndPress( | |
1624 button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
1625 CreateEventTask(this, &BookmarkBarViewTest20::Step2)); | |
1626 } | |
1627 | |
1628 void Step2() { | |
1629 ASSERT_EQ(test_view_->press_count(), 1); | |
1630 views::MenuItemView* menu = bb_view_->GetMenu(); | |
1631 ASSERT_TRUE(menu != NULL); | |
1632 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | |
1633 | |
1634 // Move the mouse to the Test View and press the left mouse button. | |
1635 // The context menu will consume the event and exit. Thereafter, | |
1636 // the event is reposted and delivered to the Test View which | |
1637 // increases its press-count. | |
1638 ui_test_utils::MoveMouseToCenterAndPress( | |
1639 test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
1640 CreateEventTask(this, &BookmarkBarViewTest20::Step3)); | |
1641 } | |
1642 | |
1643 void Step3() { | |
1644 ASSERT_EQ(test_view_->press_count(), 2); | |
1645 ASSERT_TRUE(bb_view_->GetMenu() == NULL); | |
1646 Done(); | |
1647 } | |
1648 | |
1649 class ContainerViewForMenuExit : public views::View { | |
1650 public: | |
1651 ContainerViewForMenuExit() { | |
1652 } | |
1653 | |
1654 virtual void Layout() OVERRIDE { | |
1655 DCHECK_EQ(2, child_count()); | |
1656 views::View* bb_view = child_at(0); | |
1657 views::View* test_view = child_at(1); | |
1658 const int width = bb_view->width(); | |
1659 const int height = bb_view->height(); | |
1660 bb_view->SetBounds(0,0, width - 22, height); | |
1661 test_view->SetBounds(width - 20, 0, 20, height); | |
1662 } | |
1663 | |
1664 private: | |
1665 | |
1666 DISALLOW_COPY_AND_ASSIGN(ContainerViewForMenuExit); | |
1667 }; | |
1668 | |
1669 class TestViewForMenuExit : public views::View { | |
1670 public: | |
1671 TestViewForMenuExit() : press_count_(0) { | |
1672 } | |
1673 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | |
1674 ++press_count_; | |
1675 return true; | |
1676 } | |
1677 int press_count() const { return press_count_; } | |
1678 | |
1679 private: | |
1680 int press_count_; | |
1681 | |
1682 DISALLOW_COPY_AND_ASSIGN(TestViewForMenuExit); | |
1683 }; | |
1684 | |
1685 TestViewForMenuExit* test_view_; | |
1686 }; | |
1687 | |
1688 VIEW_TEST(BookmarkBarViewTest20, ContextMenuExitTest) | |
1689 | |
1690 #endif // !defined(OS_WIN) | |
OLD | NEW |