Chromium Code Reviews| 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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 class TestingPageNavigator : public PageNavigator { | 62 class TestingPageNavigator : public PageNavigator { |
| 63 public: | 63 public: |
| 64 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE { | 64 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE { |
| 65 url_ = params.url; | 65 url_ = params.url; |
| 66 return NULL; | 66 return NULL; |
| 67 } | 67 } |
| 68 | 68 |
| 69 GURL url_; | 69 GURL url_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 class TestForMenuExitView : public views::View { | |
| 73 public: | |
| 74 TestForMenuExitView() : press_count_(0) { | |
| 75 } | |
| 76 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | |
| 77 ++press_count_; | |
| 78 return true; | |
| 79 } | |
| 80 int press_count() const { | |
| 81 return press_count_; | |
| 82 } | |
| 83 | |
| 84 private: | |
| 85 int press_count_; | |
| 86 }; | |
|
sky
2013/01/30 14:53:04
DISALLOW_...
sschmitz
2013/01/30 20:43:58
Done.
| |
| 87 | |
| 72 } // namespace | 88 } // namespace |
| 73 | 89 |
| 74 // Base class for event generating bookmark view tests. These test are intended | 90 // Base class for event generating bookmark view tests. These test are intended |
| 75 // to exercise View's menus, but that's easier done with BookmarkBarView rather | 91 // to exercise View's menus, but that's easier done with BookmarkBarView rather |
| 76 // than View's menu itself. | 92 // than View's menu itself. |
| 77 // | 93 // |
| 78 // SetUp creates a bookmark model with the following structure. | 94 // SetUp creates a bookmark model with the following structure. |
| 79 // All folders are in upper case, all URLs in lower case. | 95 // All folders are in upper case, all URLs in lower case. |
| 80 // F1 | 96 // F1 |
| 81 // f1a | 97 // f1a |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 99 // the names f1-f100. | 115 // the names f1-f100. |
| 100 // | 116 // |
| 101 // Subclasses should be sure and invoke super's implementation of SetUp and | 117 // Subclasses should be sure and invoke super's implementation of SetUp and |
| 102 // TearDown. | 118 // TearDown. |
| 103 class BookmarkBarViewEventTestBase : public ViewEventTestBase { | 119 class BookmarkBarViewEventTestBase : public ViewEventTestBase { |
| 104 public: | 120 public: |
| 105 BookmarkBarViewEventTestBase() | 121 BookmarkBarViewEventTestBase() |
| 106 : ViewEventTestBase(), | 122 : ViewEventTestBase(), |
| 107 model_(NULL), | 123 model_(NULL), |
| 108 bb_view_(NULL), | 124 bb_view_(NULL), |
| 125 test_for_menu_exit_flag_(false), | |
| 126 test_for_menu_exit_view_(NULL), | |
| 127 file_thread_(BrowserThread::FILE, MessageLoop::current()) { | |
| 128 } | |
| 129 explicit BookmarkBarViewEventTestBase(bool test_flag) | |
| 130 : ViewEventTestBase(), | |
| 131 model_(NULL), | |
| 132 bb_view_(NULL), | |
| 133 test_for_menu_exit_flag_(test_flag), | |
| 134 test_for_menu_exit_view_(NULL), | |
| 109 file_thread_(BrowserThread::FILE, MessageLoop::current()) { | 135 file_thread_(BrowserThread::FILE, MessageLoop::current()) { |
| 110 } | 136 } |
| 111 | 137 |
| 112 virtual void SetUp() { | 138 virtual void SetUp() { |
| 113 bookmark_utils::DisableBookmarkBarViewAnimationsForTesting(true); | 139 bookmark_utils::DisableBookmarkBarViewAnimationsForTesting(true); |
| 114 | 140 |
| 115 profile_.reset(new TestingProfile()); | 141 profile_.reset(new TestingProfile()); |
| 116 profile_->CreateBookmarkModel(true); | 142 profile_->CreateBookmarkModel(true); |
| 117 profile_->BlockUntilBookmarkModelLoaded(); | 143 profile_->BlockUntilBookmarkModelLoaded(); |
| 118 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); | 144 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 136 // GetPreferredSize hard codes a width of 1. For that reason we add the | 162 // GetPreferredSize hard codes a width of 1. For that reason we add the |
| 137 // BookmarkBarView to a dumby view as the parent. | 163 // BookmarkBarView to a dumby view as the parent. |
| 138 // | 164 // |
| 139 // This code looks a bit hacky, but I've written it so that it shouldn't | 165 // This code looks a bit hacky, but I've written it so that it shouldn't |
| 140 // be dependant upon any of the layout code in BookmarkBarView. Instead | 166 // be dependant upon any of the layout code in BookmarkBarView. Instead |
| 141 // we brute force search for a size that triggers the overflow button. | 167 // we brute force search for a size that triggers the overflow button. |
| 142 views::View tmp_parent; | 168 views::View tmp_parent; |
| 143 | 169 |
| 144 tmp_parent.AddChildView(bb_view_.get()); | 170 tmp_parent.AddChildView(bb_view_.get()); |
| 145 | 171 |
| 146 bb_view_pref_ = bb_view_->GetPreferredSize(); | 172 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.
| |
| 147 bb_view_pref_.set_width(1000); | 173 bb_view_pref_ = bb_view_->GetPreferredSize(); |
| 148 views::TextButton* button = GetBookmarkButton(4); | 174 bb_view_pref_.set_width(1000); |
| 149 while (button->visible()) { | 175 views::TextButton* button = GetBookmarkButton(4); |
| 150 bb_view_pref_.set_width(bb_view_pref_.width() - 25); | 176 while (button->visible()) { |
| 151 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height()); | 177 bb_view_pref_.set_width(bb_view_pref_.width() - 25); |
| 178 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), | |
| 179 bb_view_pref_.height()); | |
| 180 bb_view_->Layout(); | |
| 181 } | |
| 182 } else { | |
| 183 int width = 700; | |
| 184 test_for_menu_exit_view_ = new TestForMenuExitView; | |
| 185 test_for_menu_exit_view_->SetBounds(width - 30, 4, 20, 20); | |
| 186 bb_view_->AddChildView(test_for_menu_exit_view_); | |
| 187 bb_view_pref_ = bb_view_->GetPreferredSize(); | |
| 188 bb_view_pref_.set_width(width); | |
| 189 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), | |
| 190 bb_view_pref_.height()); | |
| 152 bb_view_->Layout(); | 191 bb_view_->Layout(); |
| 153 } | 192 } |
| 154 | 193 |
| 155 tmp_parent.RemoveChildView(bb_view_.get()); | 194 tmp_parent.RemoveChildView(bb_view_.get()); |
| 156 | 195 |
| 157 views::ViewsDelegate::views_delegate = &views_delegate_; | 196 views::ViewsDelegate::views_delegate = &views_delegate_; |
| 158 ViewEventTestBase::SetUp(); | 197 ViewEventTestBase::SetUp(); |
| 159 } | 198 } |
| 160 | 199 |
| 161 virtual void TearDown() { | 200 virtual void TearDown() { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 185 views::TextButton* GetBookmarkButton(int view_index) { | 224 views::TextButton* GetBookmarkButton(int view_index) { |
| 186 return bb_view_->GetBookmarkButton(view_index); | 225 return bb_view_->GetBookmarkButton(view_index); |
| 187 } | 226 } |
| 188 | 227 |
| 189 // See comment above class description for what this does. | 228 // See comment above class description for what this does. |
| 190 virtual bool CreateBigMenu() { return false; } | 229 virtual bool CreateBigMenu() { return false; } |
| 191 | 230 |
| 192 BookmarkModel* model_; | 231 BookmarkModel* model_; |
| 193 scoped_ptr<BookmarkBarView> bb_view_; | 232 scoped_ptr<BookmarkBarView> bb_view_; |
| 194 TestingPageNavigator navigator_; | 233 TestingPageNavigator navigator_; |
| 234 bool test_for_menu_exit_flag_; | |
| 235 TestForMenuExitView* test_for_menu_exit_view_; | |
| 195 | 236 |
| 196 private: | 237 private: |
| 197 void AddTestData(bool big_menu) { | 238 void AddTestData(bool big_menu) { |
| 198 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 239 const BookmarkNode* bb_node = model_->bookmark_bar_node(); |
| 199 std::string test_base = "file:///c:/tmp/"; | 240 std::string test_base = "file:///c:/tmp/"; |
| 200 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1")); | 241 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1")); |
| 201 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); | 242 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); |
| 202 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); | 243 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); |
| 203 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); | 244 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); |
| 204 if (big_menu) { | 245 if (big_menu) { |
| (...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1577 ASSERT_TRUE(menu != NULL); | 1618 ASSERT_TRUE(menu != NULL); |
| 1578 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1619 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1579 | 1620 |
| 1580 menu->GetMenuController()->CancelAll(); | 1621 menu->GetMenuController()->CancelAll(); |
| 1581 | 1622 |
| 1582 Done(); | 1623 Done(); |
| 1583 } | 1624 } |
| 1584 }; | 1625 }; |
| 1585 | 1626 |
| 1586 VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) | 1627 VIEW_TEST(BookmarkBarViewTest19, BookmarkBarViewTest19_SiblingMenu) |
| 1628 | |
| 1629 #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
| |
| 1630 | |
| 1631 // Verify that when clicking a mouse button outside a context menu, | |
| 1632 // the context menu is dismissed *and* the underlying view receives | |
| 1633 // the the mouse event (due to event reposting). | |
| 1634 class BookmarkBarViewTest20 : public BookmarkBarViewEventTestBase { | |
| 1635 public: | |
| 1636 BookmarkBarViewTest20() : BookmarkBarViewEventTestBase(true) {} | |
| 1637 | |
| 1638 protected: | |
| 1639 virtual void DoTestOnMessageLoop() { | |
| 1640 ASSERT_TRUE(test_for_menu_exit_view_ != NULL); | |
| 1641 ASSERT_TRUE(test_for_menu_exit_view_->press_count() == 0); | |
| 1642 | |
| 1643 // Move the mouse to the Test View and press the left mouse button. | |
| 1644 ui_test_utils::MoveMouseToCenterAndPress( | |
| 1645 test_for_menu_exit_view_, ui_controls::LEFT, | |
| 1646 ui_controls::DOWN | ui_controls::UP, | |
| 1647 CreateEventTask(this, &BookmarkBarViewTest20::Step1)); | |
| 1648 } | |
| 1649 | |
| 1650 private: | |
| 1651 void Step1() { | |
| 1652 ASSERT_TRUE(test_for_menu_exit_view_->press_count() == 1); | |
| 1653 ASSERT_TRUE(bb_view_->GetMenu() == NULL); | |
| 1654 | |
| 1655 // Move the mouse to the first folder on the bookmark bar and press the | |
| 1656 // left mouse button. | |
| 1657 views::TextButton* button = GetBookmarkButton(0); | |
| 1658 ui_test_utils::MoveMouseToCenterAndPress( | |
| 1659 button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
| 1660 CreateEventTask(this, &BookmarkBarViewTest20::Step2)); | |
| 1661 } | |
| 1662 | |
| 1663 void Step2() { | |
| 1664 ASSERT_TRUE(test_for_menu_exit_view_->press_count() == 1); | |
| 1665 views::MenuItemView* menu = bb_view_->GetMenu(); | |
| 1666 ASSERT_TRUE(menu != NULL); | |
| 1667 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | |
| 1668 | |
| 1669 // Move the mouse to the Test View and press the left mouse button. | |
| 1670 // The context menu will consume the event and exit. Thereafter, | |
| 1671 // the event is reposted and delivered to the Test View which | |
| 1672 // increases its press-count. | |
| 1673 ui_test_utils::MoveMouseToCenterAndPress( | |
| 1674 test_for_menu_exit_view_, ui_controls::LEFT, | |
| 1675 ui_controls::DOWN | ui_controls::UP, | |
| 1676 CreateEventTask(this, &BookmarkBarViewTest20::Step3)); | |
| 1677 } | |
| 1678 | |
| 1679 void Step3() { | |
| 1680 ASSERT_TRUE(test_for_menu_exit_view_->press_count() == 2); | |
| 1681 ASSERT_TRUE(bb_view_->GetMenu() == NULL); | |
| 1682 Done(); | |
| 1683 } | |
| 1684 | |
| 1685 }; | |
| 1686 | |
| 1687 VIEW_TEST(BookmarkBarViewTest20, ContextMenuExitTest) | |
| 1688 | |
| 1689 #endif | |
| OLD | NEW |