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