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 "ash/shell.h" | |
5 #include "base/bind.h" | 6 #include "base/bind.h" |
6 #include "base/callback.h" | 7 #include "base/callback.h" |
7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
8 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
13 #include "chrome/browser/bookmarks/bookmark_utils.h" | 14 #include "chrome/browser/bookmarks/bookmark_utils.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1577 ASSERT_TRUE(menu != NULL); | 1578 ASSERT_TRUE(menu != NULL); |
1578 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1579 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
1579 | 1580 |
1580 menu->GetMenuController()->CancelAll(); | 1581 menu->GetMenuController()->CancelAll(); |
1581 | 1582 |
1582 Done(); | 1583 Done(); |
1583 } | 1584 } |
1584 }; | 1585 }; |
1585 | 1586 |
1586 VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) | 1587 VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) |
1588 | |
1589 // Verify that when clicking a mouse button outside a context menu, | |
1590 // the context menu is dismissed *and* the underlying view receives | |
1591 // the the mouse event (due to event reposting). | |
1592 class BookmarkBarViewTest20 : public BookmarkBarViewEventTestBase { | |
1593 public: | |
1594 BookmarkBarViewTest20() : test_view_(NULL) {} | |
1595 | |
1596 protected: | |
1597 virtual void DoTestOnMessageLoop() { | |
1598 // Enlarge window | |
1599 const int screen_width = | |
1600 ash::Shell::GetScreen()->GetPrimaryDisplay().bounds().width(); | |
1601 gfx::Rect bounds(window_->GetWindowBoundsInScreen()); | |
1602 const int window_width = screen_width - bounds.x() - 20; | |
1603 bounds.set_width(window_width); | |
1604 window_->SetBoundsConstrained(bounds); | |
1605 window_->Activate(); | |
1606 | |
1607 // Place Test View into bb_view_ at right most edge. | |
1608 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.
| |
1609 for (int ii = 0; ii < bb_view_->child_count(); ++ii) { | |
1610 const int right = bb_view_->child_at(ii)->bounds().right(); | |
1611 if (right > xx) xx = right; | |
sky
2013/01/30 23:01:57
no single ifs.
sschmitz
2013/01/31 01:31:45
Done.
| |
1612 } | |
1613 gfx::Rect bb_view_bounds(bb_view_->bounds()); | |
1614 const int width = bb_view_bounds.width() - xx; | |
1615 const int height = bb_view_bounds.height(); | |
1616 ASSERT_TRUE(width > 1 ); | |
1617 ASSERT_TRUE(height > 1 ); | |
1618 test_view_ = new TestViewForMenuExit; | |
1619 test_view_->SetBounds(xx, 0, width, height); | |
1620 bb_view_->AddChildView(test_view_); | |
1621 | |
1622 ASSERT_EQ(test_view_->press_count(), 0); | |
1623 | |
1624 // Move the mouse to the Test View and press the left mouse button. | |
1625 ui_test_utils::MoveMouseToCenterAndPress( | |
1626 test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
1627 CreateEventTask(this, &BookmarkBarViewTest20::Step1)); | |
1628 } | |
1629 | |
1630 private: | |
1631 void Step1() { | |
1632 ASSERT_EQ(test_view_->press_count(), 1); | |
1633 ASSERT_TRUE(bb_view_->GetMenu() == NULL); | |
1634 | |
1635 // Move the mouse to the first folder on the bookmark bar and press the | |
1636 // left mouse button. | |
1637 views::TextButton* button = GetBookmarkButton(0); | |
1638 ui_test_utils::MoveMouseToCenterAndPress( | |
1639 button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
1640 CreateEventTask(this, &BookmarkBarViewTest20::Step2)); | |
1641 } | |
1642 | |
1643 void Step2() { | |
1644 ASSERT_EQ(test_view_->press_count(), 1); | |
1645 views::MenuItemView* menu = bb_view_->GetMenu(); | |
1646 ASSERT_TRUE(menu != NULL); | |
1647 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | |
1648 | |
1649 // Move the mouse to the Test View and press the left mouse button. | |
1650 // The context menu will consume the event and exit. Thereafter, | |
1651 // the event is reposted and delivered to the Test View which | |
1652 // increases its press-count. | |
1653 ui_test_utils::MoveMouseToCenterAndPress( | |
1654 test_view_, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
1655 CreateEventTask(this, &BookmarkBarViewTest20::Step3)); | |
1656 } | |
1657 | |
1658 void Step3() { | |
1659 ASSERT_EQ(test_view_->press_count(), 2); | |
1660 ASSERT_TRUE(bb_view_->GetMenu() == NULL); | |
1661 Done(); | |
1662 } | |
1663 | |
1664 class TestViewForMenuExit : public views::View { | |
1665 public: | |
1666 TestViewForMenuExit() : press_count_(0) { | |
1667 } | |
1668 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | |
1669 ++press_count_; | |
1670 return true; | |
1671 } | |
1672 int press_count() const { return press_count_; } | |
1673 | |
1674 private: | |
1675 int press_count_; | |
1676 | |
1677 DISALLOW_COPY_AND_ASSIGN(TestViewForMenuExit); | |
1678 }; | |
1679 | |
1680 TestViewForMenuExit* test_view_; | |
1681 }; | |
1682 | |
1683 VIEW_TEST(BookmarkBarViewTest20, ContextMenuExitTest) | |
OLD | NEW |