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/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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 | 425 |
| 426 Done(); | 426 Done(); |
| 427 } | 427 } |
| 428 }; | 428 }; |
| 429 | 429 |
| 430 VIEW_TEST(BookmarkBarViewTest3, Submenus) | 430 VIEW_TEST(BookmarkBarViewTest3, Submenus) |
| 431 | 431 |
| 432 // Observer that posts task upon the context menu creation. | 432 // Observer that posts task upon the context menu creation. |
| 433 // This is necessary for Linux as the context menu has to check | 433 // This is necessary for Linux as the context menu has to check |
| 434 // the clipboard, which invokes the event loop. | 434 // the clipboard, which invokes the event loop. |
| 435 class ContextMenuNotificationObserver : public content::NotificationObserver { | 435 class BookmarkContextMenuNotificationObserver |
|
lazyboy
2014/01/28 21:02:30
This rename is to make it not conflict with Contex
| |
| 436 : public content::NotificationObserver { | |
| 436 public: | 437 public: |
| 437 explicit ContextMenuNotificationObserver(const base::Closure& task) | 438 explicit BookmarkContextMenuNotificationObserver(const base::Closure& task) |
| 438 : task_(task) { | 439 : task_(task) { |
| 439 registrar_.Add(this, | 440 registrar_.Add(this, |
| 440 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, | 441 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, |
| 441 content::NotificationService::AllSources()); | 442 content::NotificationService::AllSources()); |
| 442 } | 443 } |
| 443 | 444 |
| 444 virtual void Observe(int type, | 445 virtual void Observe(int type, |
| 445 const content::NotificationSource& source, | 446 const content::NotificationSource& source, |
| 446 const content::NotificationDetails& details) OVERRIDE { | 447 const content::NotificationDetails& details) OVERRIDE { |
| 447 base::MessageLoop::current()->PostTask(FROM_HERE, task_); | 448 base::MessageLoop::current()->PostTask(FROM_HERE, task_); |
| 448 } | 449 } |
| 449 | 450 |
| 450 // Sets the task that is posted when the context menu is shown. | 451 // Sets the task that is posted when the context menu is shown. |
| 451 void set_task(const base::Closure& task) { task_ = task; } | 452 void set_task(const base::Closure& task) { task_ = task; } |
| 452 | 453 |
| 453 private: | 454 private: |
| 454 content::NotificationRegistrar registrar_; | 455 content::NotificationRegistrar registrar_; |
| 455 base::Closure task_; | 456 base::Closure task_; |
| 456 | 457 |
| 457 DISALLOW_COPY_AND_ASSIGN(ContextMenuNotificationObserver); | 458 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuNotificationObserver); |
| 458 }; | 459 }; |
| 459 | 460 |
| 460 // Tests context menus by way of opening a context menu for a bookmark, | 461 // Tests context menus by way of opening a context menu for a bookmark, |
| 461 // then right clicking to get context menu and selecting the first menu item | 462 // then right clicking to get context menu and selecting the first menu item |
| 462 // (open). | 463 // (open). |
| 463 class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase { | 464 class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase { |
| 464 public: | 465 public: |
| 465 BookmarkBarViewTest4() | 466 BookmarkBarViewTest4() |
| 466 : observer_(CreateEventTask(this, &BookmarkBarViewTest4::Step3)) { | 467 : observer_(CreateEventTask(this, &BookmarkBarViewTest4::Step3)) { |
| 467 } | 468 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 483 ASSERT_TRUE(menu != NULL); | 484 ASSERT_TRUE(menu != NULL); |
| 484 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 485 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 485 | 486 |
| 486 views::MenuItemView* child_menu = | 487 views::MenuItemView* child_menu = |
| 487 menu->GetSubmenu()->GetMenuItemAt(0); | 488 menu->GetSubmenu()->GetMenuItemAt(0); |
| 488 ASSERT_TRUE(child_menu != NULL); | 489 ASSERT_TRUE(child_menu != NULL); |
| 489 | 490 |
| 490 // Right click on the first child to get its context menu. | 491 // Right click on the first child to get its context menu. |
| 491 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 492 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
| 492 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 493 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 493 // Step3 will be invoked by ContextMenuNotificationObserver. | 494 // Step3 will be invoked by BookmarkContextMenuNotificationObserver. |
| 494 } | 495 } |
| 495 | 496 |
| 496 void Step3() { | 497 void Step3() { |
| 497 // Make sure the context menu is showing. | 498 // Make sure the context menu is showing. |
| 498 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 499 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
| 499 ASSERT_TRUE(menu != NULL); | 500 ASSERT_TRUE(menu != NULL); |
| 500 ASSERT_TRUE(menu->GetSubmenu()); | 501 ASSERT_TRUE(menu->GetSubmenu()); |
| 501 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 502 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 502 | 503 |
| 503 // Select the first menu item (open). | 504 // Select the first menu item (open). |
| 504 ui_test_utils::MoveMouseToCenterAndPress( | 505 ui_test_utils::MoveMouseToCenterAndPress( |
| 505 menu->GetSubmenu()->GetMenuItemAt(0), | 506 menu->GetSubmenu()->GetMenuItemAt(0), |
| 506 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 507 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
| 507 CreateEventTask(this, &BookmarkBarViewTest4::Step4)); | 508 CreateEventTask(this, &BookmarkBarViewTest4::Step4)); |
| 508 } | 509 } |
| 509 | 510 |
| 510 void Step4() { | 511 void Step4() { |
| 511 EXPECT_EQ(navigator_.url_, model_->other_node()->GetChild(0)->url()); | 512 EXPECT_EQ(navigator_.url_, model_->other_node()->GetChild(0)->url()); |
| 512 Done(); | 513 Done(); |
| 513 } | 514 } |
| 514 | 515 |
| 515 ContextMenuNotificationObserver observer_; | 516 BookmarkContextMenuNotificationObserver observer_; |
| 516 }; | 517 }; |
| 517 | 518 |
| 518 VIEW_TEST(BookmarkBarViewTest4, ContextMenus) | 519 VIEW_TEST(BookmarkBarViewTest4, ContextMenus) |
| 519 | 520 |
| 520 // Tests drag and drop within the same menu. | 521 // Tests drag and drop within the same menu. |
| 521 class BookmarkBarViewTest5 : public BookmarkBarViewEventTestBase { | 522 class BookmarkBarViewTest5 : public BookmarkBarViewEventTestBase { |
| 522 protected: | 523 protected: |
| 523 virtual void DoTestOnMessageLoop() OVERRIDE { | 524 virtual void DoTestOnMessageLoop() OVERRIDE { |
| 524 url_dragging_ = | 525 url_dragging_ = |
| 525 model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url(); | 526 model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url(); |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 ASSERT_TRUE(menu != NULL); | 1038 ASSERT_TRUE(menu != NULL); |
| 1038 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1039 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1039 | 1040 |
| 1040 views::MenuItemView* child_menu = | 1041 views::MenuItemView* child_menu = |
| 1041 menu->GetSubmenu()->GetMenuItemAt(0); | 1042 menu->GetSubmenu()->GetMenuItemAt(0); |
| 1042 ASSERT_TRUE(child_menu != NULL); | 1043 ASSERT_TRUE(child_menu != NULL); |
| 1043 | 1044 |
| 1044 // Right click on the first child to get its context menu. | 1045 // Right click on the first child to get its context menu. |
| 1045 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 1046 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
| 1046 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1047 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 1047 // Step3 will be invoked by ContextMenuNotificationObserver. | 1048 // Step3 will be invoked by BookmarkContextMenuNotificationObserver. |
| 1048 } | 1049 } |
| 1049 | 1050 |
| 1050 void Step3() { | 1051 void Step3() { |
| 1051 // Send escape so that the context menu hides. | 1052 // Send escape so that the context menu hides. |
| 1052 ui_controls::SendKeyPressNotifyWhenDone( | 1053 ui_controls::SendKeyPressNotifyWhenDone( |
| 1053 window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false, | 1054 window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false, |
| 1054 CreateEventTask(this, &BookmarkBarViewTest11::Step4)); | 1055 CreateEventTask(this, &BookmarkBarViewTest11::Step4)); |
| 1055 } | 1056 } |
| 1056 | 1057 |
| 1057 void Step4() { | 1058 void Step4() { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1074 } | 1075 } |
| 1075 | 1076 |
| 1076 void Step5() { | 1077 void Step5() { |
| 1077 // Make sure the menu is not showing. | 1078 // Make sure the menu is not showing. |
| 1078 views::MenuItemView* menu = bb_view_->GetMenu(); | 1079 views::MenuItemView* menu = bb_view_->GetMenu(); |
| 1079 ASSERT_TRUE(!menu || !menu->GetSubmenu() || | 1080 ASSERT_TRUE(!menu || !menu->GetSubmenu() || |
| 1080 !menu->GetSubmenu()->IsShowing()); | 1081 !menu->GetSubmenu()->IsShowing()); |
| 1081 Done(); | 1082 Done(); |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 ContextMenuNotificationObserver observer_; | 1085 BookmarkContextMenuNotificationObserver observer_; |
| 1085 }; | 1086 }; |
| 1086 | 1087 |
| 1087 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) | 1088 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) |
| 1088 // TODO(erg): linux_aura bringup: http://crbug.com/163931 | 1089 // TODO(erg): linux_aura bringup: http://crbug.com/163931 |
| 1089 #define MAYBE_CloseMenuAfterClosingContextMenu \ | 1090 #define MAYBE_CloseMenuAfterClosingContextMenu \ |
| 1090 DISABLED_CloseMenuAfterClosingContextMenu | 1091 DISABLED_CloseMenuAfterClosingContextMenu |
| 1091 #else | 1092 #else |
| 1092 #define MAYBE_CloseMenuAfterClosingContextMenu CloseMenuAfterClosingContextMenu | 1093 #define MAYBE_CloseMenuAfterClosingContextMenu CloseMenuAfterClosingContextMenu |
| 1093 #endif | 1094 #endif |
| 1094 | 1095 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1211 ASSERT_TRUE(menu != NULL); | 1212 ASSERT_TRUE(menu != NULL); |
| 1212 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1213 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1213 | 1214 |
| 1214 views::MenuItemView* child_menu = | 1215 views::MenuItemView* child_menu = |
| 1215 menu->GetSubmenu()->GetMenuItemAt(0); | 1216 menu->GetSubmenu()->GetMenuItemAt(0); |
| 1216 ASSERT_TRUE(child_menu != NULL); | 1217 ASSERT_TRUE(child_menu != NULL); |
| 1217 | 1218 |
| 1218 // Right click on the first child to get its context menu. | 1219 // Right click on the first child to get its context menu. |
| 1219 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 1220 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
| 1220 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1221 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 1221 // Step3 will be invoked by ContextMenuNotificationObserver. | 1222 // Step3 will be invoked by BookmarkContextMenuNotificationObserver. |
| 1222 } | 1223 } |
| 1223 | 1224 |
| 1224 void Step3() { | 1225 void Step3() { |
| 1225 // Make sure the context menu is showing. | 1226 // Make sure the context menu is showing. |
| 1226 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1227 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
| 1227 ASSERT_TRUE(menu != NULL); | 1228 ASSERT_TRUE(menu != NULL); |
| 1228 ASSERT_TRUE(menu->GetSubmenu()); | 1229 ASSERT_TRUE(menu->GetSubmenu()); |
| 1229 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1230 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1230 | 1231 |
| 1231 // Find the first separator. | 1232 // Find the first separator. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1258 menu->GetSubmenu()->GetMenuItemAt(0), | 1259 menu->GetSubmenu()->GetMenuItemAt(0), |
| 1259 ui_controls::LEFT, | 1260 ui_controls::LEFT, |
| 1260 ui_controls::DOWN | ui_controls::UP, | 1261 ui_controls::DOWN | ui_controls::UP, |
| 1261 CreateEventTask(this, &BookmarkBarViewTest13::Step5)); | 1262 CreateEventTask(this, &BookmarkBarViewTest13::Step5)); |
| 1262 } | 1263 } |
| 1263 | 1264 |
| 1264 void Step5() { | 1265 void Step5() { |
| 1265 Done(); | 1266 Done(); |
| 1266 } | 1267 } |
| 1267 | 1268 |
| 1268 ContextMenuNotificationObserver observer_; | 1269 BookmarkContextMenuNotificationObserver observer_; |
| 1269 }; | 1270 }; |
| 1270 | 1271 |
| 1271 VIEW_TEST(BookmarkBarViewTest13, ClickOnContextMenuSeparator) | 1272 VIEW_TEST(BookmarkBarViewTest13, ClickOnContextMenuSeparator) |
| 1272 | 1273 |
| 1273 // Makes sure right clicking on a folder on the bookmark bar doesn't result in | 1274 // Makes sure right clicking on a folder on the bookmark bar doesn't result in |
| 1274 // both a context menu and showing the menu. | 1275 // both a context menu and showing the menu. |
| 1275 class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase { | 1276 class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase { |
| 1276 public: | 1277 public: |
| 1277 BookmarkBarViewTest14() | 1278 BookmarkBarViewTest14() |
| 1278 : observer_(CreateEventTask(this, &BookmarkBarViewTest14::Step2)) { | 1279 : observer_(CreateEventTask(this, &BookmarkBarViewTest14::Step2)) { |
| 1279 } | 1280 } |
| 1280 | 1281 |
| 1281 protected: | 1282 protected: |
| 1282 virtual void DoTestOnMessageLoop() OVERRIDE { | 1283 virtual void DoTestOnMessageLoop() OVERRIDE { |
| 1283 // Move the mouse to the first folder on the bookmark bar and press the | 1284 // Move the mouse to the first folder on the bookmark bar and press the |
| 1284 // right mouse button. | 1285 // right mouse button. |
| 1285 views::TextButton* button = GetBookmarkButton(0); | 1286 views::TextButton* button = GetBookmarkButton(0); |
| 1286 ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::RIGHT, | 1287 ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::RIGHT, |
| 1287 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1288 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 1288 // Step2 will be invoked by ContextMenuNotificationObserver. | 1289 // Step2 will be invoked by BookmarkContextMenuNotificationObserver. |
| 1289 } | 1290 } |
| 1290 | 1291 |
| 1291 private: | 1292 private: |
| 1292 | 1293 |
| 1293 void Step2() { | 1294 void Step2() { |
| 1294 // Menu should NOT be showing. | 1295 // Menu should NOT be showing. |
| 1295 views::MenuItemView* menu = bb_view_->GetMenu(); | 1296 views::MenuItemView* menu = bb_view_->GetMenu(); |
| 1296 ASSERT_TRUE(menu == NULL); | 1297 ASSERT_TRUE(menu == NULL); |
| 1297 | 1298 |
| 1298 // Send escape so that the context menu hides. | 1299 // Send escape so that the context menu hides. |
| 1299 ui_controls::SendKeyPressNotifyWhenDone( | 1300 ui_controls::SendKeyPressNotifyWhenDone( |
| 1300 window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false, | 1301 window_->GetNativeWindow(), ui::VKEY_ESCAPE, false, false, false, false, |
| 1301 CreateEventTask(this, &BookmarkBarViewTest14::Step3)); | 1302 CreateEventTask(this, &BookmarkBarViewTest14::Step3)); |
| 1302 } | 1303 } |
| 1303 | 1304 |
| 1304 void Step3() { | 1305 void Step3() { |
| 1305 Done(); | 1306 Done(); |
| 1306 } | 1307 } |
| 1307 | 1308 |
| 1308 ContextMenuNotificationObserver observer_; | 1309 BookmarkContextMenuNotificationObserver observer_; |
| 1309 }; | 1310 }; |
| 1310 | 1311 |
| 1311 VIEW_TEST(BookmarkBarViewTest14, ContextMenus2) | 1312 VIEW_TEST(BookmarkBarViewTest14, ContextMenus2) |
| 1312 | 1313 |
| 1313 // Makes sure deleting from the context menu keeps the bookmark menu showing. | 1314 // Makes sure deleting from the context menu keeps the bookmark menu showing. |
| 1314 class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase { | 1315 class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase { |
| 1315 public: | 1316 public: |
| 1316 BookmarkBarViewTest15() | 1317 BookmarkBarViewTest15() |
| 1317 : deleted_menu_id_(0), | 1318 : deleted_menu_id_(0), |
| 1318 observer_(CreateEventTask(this, &BookmarkBarViewTest15::Step3)) { | 1319 observer_(CreateEventTask(this, &BookmarkBarViewTest15::Step3)) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1336 | 1337 |
| 1337 views::MenuItemView* child_menu = | 1338 views::MenuItemView* child_menu = |
| 1338 menu->GetSubmenu()->GetMenuItemAt(1); | 1339 menu->GetSubmenu()->GetMenuItemAt(1); |
| 1339 ASSERT_TRUE(child_menu != NULL); | 1340 ASSERT_TRUE(child_menu != NULL); |
| 1340 | 1341 |
| 1341 deleted_menu_id_ = child_menu->GetCommand(); | 1342 deleted_menu_id_ = child_menu->GetCommand(); |
| 1342 | 1343 |
| 1343 // Right click on the second child to get its context menu. | 1344 // Right click on the second child to get its context menu. |
| 1344 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 1345 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
| 1345 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1346 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 1346 // Step3 will be invoked by ContextMenuNotificationObserver. | 1347 // Step3 will be invoked by BookmarkContextMenuNotificationObserver. |
| 1347 } | 1348 } |
| 1348 | 1349 |
| 1349 void Step3() { | 1350 void Step3() { |
| 1350 // Make sure the context menu is showing. | 1351 // Make sure the context menu is showing. |
| 1351 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1352 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
| 1352 ASSERT_TRUE(menu != NULL); | 1353 ASSERT_TRUE(menu != NULL); |
| 1353 ASSERT_TRUE(menu->GetSubmenu()); | 1354 ASSERT_TRUE(menu->GetSubmenu()); |
| 1354 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1355 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1355 | 1356 |
| 1356 views::MenuItemView* delete_menu = | 1357 views::MenuItemView* delete_menu = |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1375 | 1376 |
| 1376 // And the deleted_menu_id_ should have been removed. | 1377 // And the deleted_menu_id_ should have been removed. |
| 1377 ASSERT_TRUE(menu->GetMenuItemByID(deleted_menu_id_) == NULL); | 1378 ASSERT_TRUE(menu->GetMenuItemByID(deleted_menu_id_) == NULL); |
| 1378 | 1379 |
| 1379 bb_view_->GetMenu()->GetMenuController()->CancelAll(); | 1380 bb_view_->GetMenu()->GetMenuController()->CancelAll(); |
| 1380 | 1381 |
| 1381 Done(); | 1382 Done(); |
| 1382 } | 1383 } |
| 1383 | 1384 |
| 1384 int deleted_menu_id_; | 1385 int deleted_menu_id_; |
| 1385 ContextMenuNotificationObserver observer_; | 1386 BookmarkContextMenuNotificationObserver observer_; |
| 1386 }; | 1387 }; |
| 1387 | 1388 |
| 1388 VIEW_TEST(BookmarkBarViewTest15, MenuStaysVisibleAfterDelete) | 1389 VIEW_TEST(BookmarkBarViewTest15, MenuStaysVisibleAfterDelete) |
| 1389 | 1390 |
| 1390 // Tests that we don't crash or get stuck if the parent of a menu is closed. | 1391 // Tests that we don't crash or get stuck if the parent of a menu is closed. |
| 1391 class BookmarkBarViewTest16 : public BookmarkBarViewEventTestBase { | 1392 class BookmarkBarViewTest16 : public BookmarkBarViewEventTestBase { |
| 1392 protected: | 1393 protected: |
| 1393 virtual void DoTestOnMessageLoop() OVERRIDE { | 1394 virtual void DoTestOnMessageLoop() OVERRIDE { |
| 1394 // Move the mouse to the first folder on the bookmark bar and press the | 1395 // Move the mouse to the first folder on the bookmark bar and press the |
| 1395 // mouse. | 1396 // mouse. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1451 // Menu should be showing. | 1452 // Menu should be showing. |
| 1452 views::MenuItemView* menu = bb_view_->GetMenu(); | 1453 views::MenuItemView* menu = bb_view_->GetMenu(); |
| 1453 ASSERT_TRUE(menu != NULL); | 1454 ASSERT_TRUE(menu != NULL); |
| 1454 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1455 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1455 | 1456 |
| 1456 // Right click on the second item to show its context menu. | 1457 // Right click on the second item to show its context menu. |
| 1457 views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(2); | 1458 views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(2); |
| 1458 ASSERT_TRUE(child_menu != NULL); | 1459 ASSERT_TRUE(child_menu != NULL); |
| 1459 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, | 1460 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, |
| 1460 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1461 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 1461 // Step3 will be invoked by ContextMenuNotificationObserver. | 1462 // Step3 will be invoked by BookmarkContextMenuNotificationObserver. |
| 1462 } | 1463 } |
| 1463 | 1464 |
| 1464 void Step3() { | 1465 void Step3() { |
| 1465 // Make sure the context menu is showing. | 1466 // Make sure the context menu is showing. |
| 1466 views::MenuItemView* context_menu = bb_view_->GetContextMenu(); | 1467 views::MenuItemView* context_menu = bb_view_->GetContextMenu(); |
| 1467 ASSERT_TRUE(context_menu != NULL); | 1468 ASSERT_TRUE(context_menu != NULL); |
| 1468 ASSERT_TRUE(context_menu->GetSubmenu()); | 1469 ASSERT_TRUE(context_menu->GetSubmenu()); |
| 1469 ASSERT_TRUE(context_menu->GetSubmenu()->IsShowing()); | 1470 ASSERT_TRUE(context_menu->GetSubmenu()->IsShowing()); |
| 1470 | 1471 |
| 1471 // Right click on the first menu item to trigger its context menu. | 1472 // Right click on the first menu item to trigger its context menu. |
| 1472 views::MenuItemView* menu = bb_view_->GetMenu(); | 1473 views::MenuItemView* menu = bb_view_->GetMenu(); |
| 1473 ASSERT_TRUE(menu != NULL); | 1474 ASSERT_TRUE(menu != NULL); |
| 1474 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1475 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1475 views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(1); | 1476 views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(1); |
| 1476 ASSERT_TRUE(child_menu != NULL); | 1477 ASSERT_TRUE(child_menu != NULL); |
| 1477 | 1478 |
| 1478 // The context menu and child_menu can be overlapped, calculate the | 1479 // The context menu and child_menu can be overlapped, calculate the |
| 1479 // non-intersected Rect of the child menu and click on its center to make | 1480 // non-intersected Rect of the child menu and click on its center to make |
| 1480 // sure the click is always on the child menu. | 1481 // sure the click is always on the child menu. |
| 1481 gfx::Rect context_rect = context_menu->GetSubmenu()->GetBoundsInScreen(); | 1482 gfx::Rect context_rect = context_menu->GetSubmenu()->GetBoundsInScreen(); |
| 1482 gfx::Rect child_menu_rect = child_menu->GetBoundsInScreen(); | 1483 gfx::Rect child_menu_rect = child_menu->GetBoundsInScreen(); |
| 1483 gfx::Rect clickable_rect = | 1484 gfx::Rect clickable_rect = |
| 1484 gfx::SubtractRects(child_menu_rect, context_rect); | 1485 gfx::SubtractRects(child_menu_rect, context_rect); |
| 1485 ASSERT_FALSE(clickable_rect.IsEmpty()); | 1486 ASSERT_FALSE(clickable_rect.IsEmpty()); |
| 1486 observer_.set_task(CreateEventTask(this, &BookmarkBarViewTest17::Step4)); | 1487 observer_.set_task(CreateEventTask(this, &BookmarkBarViewTest17::Step4)); |
| 1487 MoveMouseAndPress(clickable_rect.CenterPoint(), ui_controls::RIGHT, | 1488 MoveMouseAndPress(clickable_rect.CenterPoint(), ui_controls::RIGHT, |
| 1488 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1489 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 1489 // Step4 will be invoked by ContextMenuNotificationObserver. | 1490 // Step4 will be invoked by BookmarkContextMenuNotificationObserver. |
| 1490 } | 1491 } |
| 1491 | 1492 |
| 1492 void Step4() { | 1493 void Step4() { |
| 1493 // The context menu should still be showing. | 1494 // The context menu should still be showing. |
| 1494 views::MenuItemView* context_menu = bb_view_->GetContextMenu(); | 1495 views::MenuItemView* context_menu = bb_view_->GetContextMenu(); |
| 1495 ASSERT_TRUE(context_menu != NULL); | 1496 ASSERT_TRUE(context_menu != NULL); |
| 1496 | 1497 |
| 1497 // And the menu should be showing. | 1498 // And the menu should be showing. |
| 1498 views::MenuItemView* menu = bb_view_->GetMenu(); | 1499 views::MenuItemView* menu = bb_view_->GetMenu(); |
| 1499 ASSERT_TRUE(menu != NULL); | 1500 ASSERT_TRUE(menu != NULL); |
| 1500 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1501 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1501 | 1502 |
| 1502 bb_view_->GetMenu()->GetMenuController()->CancelAll(); | 1503 bb_view_->GetMenu()->GetMenuController()->CancelAll(); |
| 1503 | 1504 |
| 1504 Done(); | 1505 Done(); |
| 1505 } | 1506 } |
| 1506 | 1507 |
| 1507 ContextMenuNotificationObserver observer_; | 1508 BookmarkContextMenuNotificationObserver observer_; |
| 1508 }; | 1509 }; |
| 1509 | 1510 |
| 1510 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) | 1511 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) |
| 1511 // TODO(erg): linux_aura bringup: http://crbug.com/163931 | 1512 // TODO(erg): linux_aura bringup: http://crbug.com/163931 |
| 1512 #define MAYBE_ContextMenus3 DISABLED_ContextMenus3 | 1513 #define MAYBE_ContextMenus3 DISABLED_ContextMenus3 |
| 1513 #else | 1514 #else |
| 1514 #define MAYBE_ContextMenus3 ContextMenus3 | 1515 #define MAYBE_ContextMenus3 ContextMenus3 |
| 1515 #endif | 1516 #endif |
| 1516 | 1517 |
| 1517 VIEW_TEST(BookmarkBarViewTest17, MAYBE_ContextMenus3) | 1518 VIEW_TEST(BookmarkBarViewTest17, MAYBE_ContextMenus3) |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1784 ASSERT_TRUE(submenu->IsShowing()); | 1785 ASSERT_TRUE(submenu->IsShowing()); |
| 1785 ASSERT_EQ(1, submenu->child_count()); | 1786 ASSERT_EQ(1, submenu->child_count()); |
| 1786 | 1787 |
| 1787 views::View* view = submenu->child_at(0); | 1788 views::View* view = submenu->child_at(0); |
| 1788 ASSERT_TRUE(view != NULL); | 1789 ASSERT_TRUE(view != NULL); |
| 1789 EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id()); | 1790 EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id()); |
| 1790 | 1791 |
| 1791 // Right click on the first child to get its context menu. | 1792 // Right click on the first child to get its context menu. |
| 1792 ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::RIGHT, | 1793 ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::RIGHT, |
| 1793 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1794 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
| 1794 // Step3 will be invoked by ContextMenuNotificationObserver. | 1795 // Step3 will be invoked by BookmarkContextMenuNotificationObserver. |
| 1795 } | 1796 } |
| 1796 | 1797 |
| 1797 // Confirm that context menu shows and click REMOVE menu. | 1798 // Confirm that context menu shows and click REMOVE menu. |
| 1798 void Step3() { | 1799 void Step3() { |
| 1799 // Make sure the context menu is showing. | 1800 // Make sure the context menu is showing. |
| 1800 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1801 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
| 1801 ASSERT_TRUE(menu != NULL); | 1802 ASSERT_TRUE(menu != NULL); |
| 1802 ASSERT_TRUE(menu->GetSubmenu()); | 1803 ASSERT_TRUE(menu->GetSubmenu()); |
| 1803 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1804 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
| 1804 | 1805 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1816 void Step4() { | 1817 void Step4() { |
| 1817 views::TextButton* button = GetBookmarkButton(5); | 1818 views::TextButton* button = GetBookmarkButton(5); |
| 1818 ASSERT_TRUE(button); | 1819 ASSERT_TRUE(button); |
| 1819 EXPECT_EQ(ASCIIToUTF16("d"), button->text()); | 1820 EXPECT_EQ(ASCIIToUTF16("d"), button->text()); |
| 1820 EXPECT_TRUE(bb_view_->GetContextMenu() == NULL); | 1821 EXPECT_TRUE(bb_view_->GetContextMenu() == NULL); |
| 1821 EXPECT_TRUE(bb_view_->GetMenu() == NULL); | 1822 EXPECT_TRUE(bb_view_->GetMenu() == NULL); |
| 1822 | 1823 |
| 1823 Done(); | 1824 Done(); |
| 1824 } | 1825 } |
| 1825 | 1826 |
| 1826 ContextMenuNotificationObserver observer_; | 1827 BookmarkContextMenuNotificationObserver observer_; |
| 1827 }; | 1828 }; |
| 1828 | 1829 |
| 1829 VIEW_TEST(BookmarkBarViewTest21, ContextMenusForEmptyFolder) | 1830 VIEW_TEST(BookmarkBarViewTest21, ContextMenusForEmptyFolder) |
| OLD | NEW |