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 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 // Delay before allowing menu selection. When context menu is shown on mouse | |
73 // press, we enforce a delay before a selection can be made. So for tests that | |
74 // perform selection on context menu, we add this delay before going to the next | |
75 // step. See comment on |kContextMenuSelectionHoldTimeMs| in menu_controller.cc | |
76 // for more info. The delay here should be greater than | |
77 // |kContextMenuSelectionHoldTimeMs|. | |
78 #define STEP_3_WITH_SELECTION_DELAY(test_class)\ | |
79 void Step3() {\ | |
80 views::MenuItemView* menu = bb_view_->GetContextMenu();\ | |
81 ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing());\ | |
82 if (views::View::ShouldShowContextMenuOnMousePress()) {\ | |
83 MessageLoop::current()->PostDelayedTask(FROM_HERE,\ | |
84 CreateEventTask(this, &test_class::Step3_1),\ | |
85 base::TimeDelta::FromMilliseconds(250));\ | |
86 } else {\ | |
87 Step3_1();\ | |
88 }\ | |
89 }\ | |
90 void Step3_1() { | |
91 | |
92 } // namespace | 72 } // namespace |
93 | 73 |
94 // Base class for event generating bookmark view tests. These test are intended | 74 // Base class for event generating bookmark view tests. These test are intended |
95 // to exercise View's menus, but that's easier done with BookmarkBarView rather | 75 // to exercise View's menus, but that's easier done with BookmarkBarView rather |
96 // than View's menu itself. | 76 // than View's menu itself. |
97 // | 77 // |
98 // SetUp creates a bookmark model with the following structure. | 78 // SetUp creates a bookmark model with the following structure. |
99 // All folders are in upper case, all URLs in lower case. | 79 // All folders are in upper case, all URLs in lower case. |
100 // F1 | 80 // F1 |
101 // f1a | 81 // f1a |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 views::MenuItemView* child_menu = | 475 views::MenuItemView* child_menu = |
496 menu->GetSubmenu()->GetMenuItemAt(0); | 476 menu->GetSubmenu()->GetMenuItemAt(0); |
497 ASSERT_TRUE(child_menu != NULL); | 477 ASSERT_TRUE(child_menu != NULL); |
498 | 478 |
499 // Right click on the first child to get its context menu. | 479 // Right click on the first child to get its context menu. |
500 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 480 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
501 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 481 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
502 // Step3 will be invoked by ContextMenuNotificationObserver. | 482 // Step3 will be invoked by ContextMenuNotificationObserver. |
503 } | 483 } |
504 | 484 |
505 STEP_3_WITH_SELECTION_DELAY(BookmarkBarViewTest4) | 485 void Step3() { |
506 // Make sure the context menu is showing. | 486 // Make sure the context menu is showing. |
507 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 487 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
508 ASSERT_TRUE(menu != NULL); | 488 ASSERT_TRUE(menu != NULL); |
509 ASSERT_TRUE(menu->GetSubmenu()); | 489 ASSERT_TRUE(menu->GetSubmenu()); |
510 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 490 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
511 | 491 |
512 // Select the first menu item (open). | 492 // Select the first menu item (open). |
513 ui_test_utils::MoveMouseToCenterAndPress( | 493 ui_test_utils::MoveMouseToCenterAndPress( |
514 menu->GetSubmenu()->GetMenuItemAt(0), | 494 menu->GetSubmenu()->GetMenuItemAt(0), |
515 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 495 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 views::MenuItemView* child_menu = | 1102 views::MenuItemView* child_menu = |
1123 menu->GetSubmenu()->GetMenuItemAt(1); | 1103 menu->GetSubmenu()->GetMenuItemAt(1); |
1124 ASSERT_TRUE(child_menu != NULL); | 1104 ASSERT_TRUE(child_menu != NULL); |
1125 | 1105 |
1126 // Right click on the second child (a folder) to get its context menu. | 1106 // Right click on the second child (a folder) to get its context menu. |
1127 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 1107 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
1128 ui_controls::DOWN | ui_controls::UP, | 1108 ui_controls::DOWN | ui_controls::UP, |
1129 CreateEventTask(this, &BookmarkBarViewTest12::Step3)); | 1109 CreateEventTask(this, &BookmarkBarViewTest12::Step3)); |
1130 } | 1110 } |
1131 | 1111 |
1132 STEP_3_WITH_SELECTION_DELAY(BookmarkBarViewTest12) | 1112 void Step3() { |
1133 // Make sure the context menu is showing. | 1113 // Make sure the context menu is showing. |
1134 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1114 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
1135 ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing()); | 1115 ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing()); |
1136 | 1116 |
1137 // Select the first item in the context menu (open all). | 1117 // Select the first item in the context menu (open all). |
1138 views::MenuItemView* child_menu = | 1118 views::MenuItemView* child_menu = |
1139 menu->GetSubmenu()->GetMenuItemAt(0); | 1119 menu->GetSubmenu()->GetMenuItemAt(0); |
1140 ASSERT_TRUE(child_menu != NULL); | 1120 ASSERT_TRUE(child_menu != NULL); |
1141 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT, | 1121 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT, |
1142 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1122 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 views::MenuItemView* child_menu = | 1188 views::MenuItemView* child_menu = |
1209 menu->GetSubmenu()->GetMenuItemAt(0); | 1189 menu->GetSubmenu()->GetMenuItemAt(0); |
1210 ASSERT_TRUE(child_menu != NULL); | 1190 ASSERT_TRUE(child_menu != NULL); |
1211 | 1191 |
1212 // Right click on the first child to get its context menu. | 1192 // Right click on the first child to get its context menu. |
1213 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 1193 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
1214 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1194 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
1215 // Step3 will be invoked by ContextMenuNotificationObserver. | 1195 // Step3 will be invoked by ContextMenuNotificationObserver. |
1216 } | 1196 } |
1217 | 1197 |
1218 STEP_3_WITH_SELECTION_DELAY(BookmarkBarViewTest13) | 1198 void Step3() { |
1219 // Make sure the context menu is showing. | 1199 // Make sure the context menu is showing. |
1220 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1200 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
1221 ASSERT_TRUE(menu != NULL); | 1201 ASSERT_TRUE(menu != NULL); |
1222 ASSERT_TRUE(menu->GetSubmenu()); | 1202 ASSERT_TRUE(menu->GetSubmenu()); |
1223 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1203 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
1224 | 1204 |
1225 // Find the first separator. | 1205 // Find the first separator. |
1226 views::SubmenuView* submenu = menu->GetSubmenu(); | 1206 views::SubmenuView* submenu = menu->GetSubmenu(); |
1227 views::View* separator_view = NULL; | 1207 views::View* separator_view = NULL; |
1228 for (int i = 0; i < submenu->child_count(); ++i) { | 1208 for (int i = 0; i < submenu->child_count(); ++i) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 ASSERT_TRUE(child_menu != NULL); | 1315 ASSERT_TRUE(child_menu != NULL); |
1336 | 1316 |
1337 deleted_menu_id_ = child_menu->GetCommand(); | 1317 deleted_menu_id_ = child_menu->GetCommand(); |
1338 | 1318 |
1339 // Right click on the second child to get its context menu. | 1319 // Right click on the second child to get its context menu. |
1340 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 1320 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
1341 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1321 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
1342 // Step3 will be invoked by ContextMenuNotificationObserver. | 1322 // Step3 will be invoked by ContextMenuNotificationObserver. |
1343 } | 1323 } |
1344 | 1324 |
1345 STEP_3_WITH_SELECTION_DELAY(BookmarkBarViewTest15) | 1325 void Step3() { |
1346 // Make sure the context menu is showing. | 1326 // Make sure the context menu is showing. |
1347 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1327 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
1348 ASSERT_TRUE(menu != NULL); | 1328 ASSERT_TRUE(menu != NULL); |
1349 ASSERT_TRUE(menu->GetSubmenu()); | 1329 ASSERT_TRUE(menu->GetSubmenu()); |
1350 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1330 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
1351 | 1331 |
1352 views::MenuItemView* delete_menu = | 1332 views::MenuItemView* delete_menu = |
1353 menu->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE); | 1333 menu->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE); |
1354 ASSERT_TRUE(delete_menu); | 1334 ASSERT_TRUE(delete_menu); |
1355 | 1335 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 ASSERT_TRUE(view != NULL); | 1742 ASSERT_TRUE(view != NULL); |
1763 EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id()); | 1743 EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id()); |
1764 | 1744 |
1765 // Right click on the first child to get its context menu. | 1745 // Right click on the first child to get its context menu. |
1766 ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::RIGHT, | 1746 ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::RIGHT, |
1767 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1747 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
1768 // Step3 will be invoked by ContextMenuNotificationObserver. | 1748 // Step3 will be invoked by ContextMenuNotificationObserver. |
1769 } | 1749 } |
1770 | 1750 |
1771 // Confirm that context menu shows and click REMOVE menu. | 1751 // Confirm that context menu shows and click REMOVE menu. |
1772 STEP_3_WITH_SELECTION_DELAY(BookmarkBarViewTest21) | 1752 void Step3() { |
1773 // Make sure the context menu is showing. | 1753 // Make sure the context menu is showing. |
1774 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1754 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
1775 ASSERT_TRUE(menu != NULL); | 1755 ASSERT_TRUE(menu != NULL); |
1776 ASSERT_TRUE(menu->GetSubmenu()); | 1756 ASSERT_TRUE(menu->GetSubmenu()); |
1777 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1757 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
1778 | 1758 |
1779 views::MenuItemView* delete_menu = | 1759 views::MenuItemView* delete_menu = |
1780 menu->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE); | 1760 menu->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE); |
1781 ASSERT_TRUE(delete_menu); | 1761 ASSERT_TRUE(delete_menu); |
1782 | 1762 |
(...skipping 11 matching lines...) Expand all Loading... |
1794 EXPECT_TRUE(bb_view_->GetContextMenu() == NULL); | 1774 EXPECT_TRUE(bb_view_->GetContextMenu() == NULL); |
1795 EXPECT_TRUE(bb_view_->GetMenu() == NULL); | 1775 EXPECT_TRUE(bb_view_->GetMenu() == NULL); |
1796 | 1776 |
1797 Done(); | 1777 Done(); |
1798 } | 1778 } |
1799 | 1779 |
1800 ContextMenuNotificationObserver observer_; | 1780 ContextMenuNotificationObserver observer_; |
1801 }; | 1781 }; |
1802 | 1782 |
1803 VIEW_TEST(BookmarkBarViewTest21, ContextMenusForEmptyFolder) | 1783 VIEW_TEST(BookmarkBarViewTest21, ContextMenusForEmptyFolder) |
OLD | NEW |