Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm

Issue 8141003: [Mac] Restore the old bookmark menus now that the experiment is over. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_nsobject.h" 9 #include "base/memory/scoped_nsobject.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/bookmarks/bookmark_model.h" 14 #include "chrome/browser/bookmarks/bookmark_model.h"
15 #include "chrome/browser/bookmarks/bookmark_utils.h" 15 #include "chrome/browser/bookmarks/bookmark_utils.h"
16 #import "chrome/browser/ui/cocoa/animation_utils.h" 16 #import "chrome/browser/ui/cocoa/animation_utils.h"
17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h"
20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h"
21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h" 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h"
22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
23 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" 23 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
24 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu.h" 24 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu.h"
25 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h"
26 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 25 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
27 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" 26 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
28 #include "chrome/test/base/model_test_utils.h" 27 #include "chrome/test/base/model_test_utils.h"
29 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
30 #import "testing/gtest_mac.h" 29 #import "testing/gtest_mac.h"
31 #include "testing/platform_test.h" 30 #include "testing/platform_test.h"
32 #include "third_party/ocmock/gtest_support.h" 31 #include "third_party/ocmock/gtest_support.h"
33 #import "third_party/ocmock/OCMock/OCMock.h" 32 #import "third_party/ocmock/OCMock/OCMock.h"
34 #include "ui/base/test/cocoa_test_event_utils.h" 33 #include "ui/base/test/cocoa_test_event_utils.h"
35 #include "ui/base/theme_provider.h" 34 #include "ui/base/theme_provider.h"
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); 569 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]);
571 } 570 }
572 571
573 const BookmarkNode* parent = model->bookmark_bar_node(); 572 const BookmarkNode* parent = model->bookmark_bar_node();
574 for (int i = 0; i < 20; i++) { 573 for (int i = 0; i < 20; i++) {
575 model->AddURL(parent, parent->child_count(), 574 model->AddURL(parent, parent->child_count(),
576 ASCIIToUTF16("super duper wide title"), 575 ASCIIToUTF16("super duper wide title"),
577 GURL("http://superfriends.hall-of-justice.edu")); 576 GURL("http://superfriends.hall-of-justice.edu"));
578 } 577 }
579 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); 578 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]);
579
580 // Open the "off the side" and start deleting nodes. Make sure
581 // deletion of the last node in "off the side" causes the folder to
582 // close.
583 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]);
584 NSButton* offTheSideButton = [bar_ offTheSideButton];
585 // Open "off the side" menu.
586 [bar_ openOffTheSideFolderFromButton:offTheSideButton];
587 BookmarkBarFolderController* bbfc = [bar_ folderController];
588 EXPECT_TRUE(bbfc);
589 [bbfc setIgnoreAnimations:YES];
590 while (!parent->empty()) {
591 // We've completed the job so we're done.
592 if ([bar_ offTheSideButtonIsHidden])
593 break;
594 // Delete the last button.
595 model->Remove(parent, parent->child_count() - 1);
596 // If last one make sure the menu is closed and the button is hidden.
597 // Else make sure menu stays open.
598 if ([bar_ offTheSideButtonIsHidden]) {
599 EXPECT_FALSE([bar_ folderController]);
600 } else {
601 EXPECT_TRUE([bar_ folderController]);
602 }
603 }
604 }
605
606 // http://crbug.com/46175 is a crash when deleting bookmarks from the
607 // off-the-side menu while it is open. This test tries to bang hard
608 // in this area to reproduce the crash.
609 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) {
610 BookmarkModel* model = profile()->GetBookmarkModel();
611 [bar_ setIgnoreAnimations:YES];
612 [bar_ loaded:model];
613
614 // Add a lot of bookmarks (per the bug).
615 const BookmarkNode* parent = model->bookmark_bar_node();
616 for (int i = 0; i < 100; i++) {
617 std::ostringstream title;
618 title << "super duper wide title " << i;
619 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()),
620 GURL("http://superfriends.hall-of-justice.edu"));
621 }
622 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]);
623
624 // Open "off the side" menu.
625 NSButton* offTheSideButton = [bar_ offTheSideButton];
626 [bar_ openOffTheSideFolderFromButton:offTheSideButton];
627 BookmarkBarFolderController* bbfc = [bar_ folderController];
628 EXPECT_TRUE(bbfc);
629 [bbfc setIgnoreAnimations:YES];
630
631 // Start deleting items; try and delete randomish ones in case it
632 // makes a difference.
633 int indices[] = { 2, 4, 5, 1, 7, 9, 2, 0, 10, 9 };
634 while (!parent->empty()) {
635 for (unsigned int i = 0; i < arraysize(indices); i++) {
636 if (indices[i] < parent->child_count()) {
637 // First we mouse-enter the button to make things harder.
638 NSArray* buttons = [bbfc buttons];
639 for (BookmarkButton* button in buttons) {
640 if ([button bookmarkNode] == parent->GetChild(indices[i])) {
641 [bbfc mouseEnteredButton:button event:nil];
642 break;
643 }
644 }
645 // Then we remove the node. This triggers the button to get
646 // deleted.
647 model->Remove(parent, indices[i]);
648 // Force visual update which is otherwise delayed.
649 [[bbfc window] displayIfNeeded];
650 }
651 }
652 }
580 } 653 }
581 654
582 // Test whether |-dragShouldLockBarVisibility| returns NO iff the bar is 655 // Test whether |-dragShouldLockBarVisibility| returns NO iff the bar is
583 // detached. 656 // detached.
584 TEST_F(BookmarkBarControllerTest, TestDragShouldLockBarVisibility) { 657 TEST_F(BookmarkBarControllerTest, TestDragShouldLockBarVisibility) {
585 [bar_ updateAndShowNormalBar:NO 658 [bar_ updateAndShowNormalBar:NO
586 showDetachedBar:NO 659 showDetachedBar:NO
587 withAnimation:NO]; 660 withAnimation:NO];
588 EXPECT_TRUE([bar_ dragShouldLockBarVisibility]); 661 EXPECT_TRUE([bar_ dragShouldLockBarVisibility]);
589 662
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 bar_.reset(); 1280 bar_.reset();
1208 1281
1209 // Make sure that everything is cleared. 1282 // Make sure that everything is cleared.
1210 for (BookmarkButton* button in buttons.get()) { 1283 for (BookmarkButton* button in buttons.get()) {
1211 EXPECT_FALSE([button delegate]); 1284 EXPECT_FALSE([button delegate]);
1212 EXPECT_FALSE([button target]); 1285 EXPECT_FALSE([button target]);
1213 EXPECT_FALSE([button action]); 1286 EXPECT_FALSE([button action]);
1214 } 1287 }
1215 } 1288 }
1216 1289
1290 TEST_F(BookmarkBarControllerTest, TestFolders) {
1291 BookmarkModel* model = profile()->GetBookmarkModel();
1292
1293 // Create some folder buttons.
1294 const BookmarkNode* parent = model->bookmark_bar_node();
1295 const BookmarkNode* folder = model->AddFolder(parent,
1296 parent->child_count(),
1297 ASCIIToUTF16("folder"));
1298 model->AddURL(folder, folder->child_count(),
1299 ASCIIToUTF16("f1"), GURL("http://framma-lamma.com"));
1300 folder = model->AddFolder(parent, parent->child_count(),
1301 ASCIIToUTF16("empty"));
1302
1303 EXPECT_EQ([[bar_ buttons] count], 2U);
1304
1305 // First confirm mouseEntered does nothing if "menus" aren't active.
1306 NSEvent* event = cocoa_test_event_utils::MakeMouseEvent(NSOtherMouseUp, 0);
1307 [bar_ mouseEnteredButton:[[bar_ buttons] objectAtIndex:0] event:event];
1308 EXPECT_FALSE([bar_ folderController]);
1309
1310 // Make one active. Entering it is now a no-op.
1311 [bar_ openBookmarkFolderFromButton:[[bar_ buttons] objectAtIndex:0]];
1312 BookmarkBarFolderController* bbfc = [bar_ folderController];
1313 EXPECT_TRUE(bbfc);
1314 [bar_ mouseEnteredButton:[[bar_ buttons] objectAtIndex:0] event:event];
1315 EXPECT_EQ(bbfc, [bar_ folderController]);
1316
1317 // Enter a different one; a new folderController is active.
1318 [bar_ mouseEnteredButton:[[bar_ buttons] objectAtIndex:1] event:event];
1319 EXPECT_NE(bbfc, [bar_ folderController]);
1320
1321 // Confirm exited is a no-op.
1322 [bar_ mouseExitedButton:[[bar_ buttons] objectAtIndex:1] event:event];
1323 EXPECT_NE(bbfc, [bar_ folderController]);
1324
1325 // Clean up.
1326 [bar_ closeBookmarkFolder:nil];
1327 }
1328
1329 // Verify that the folder menu presentation properly tracks mouse movements
1330 // over the bar. Until there is a click no folder menus should show. After a
1331 // click on a folder folder menus should show until another click on a folder
1332 // button, and a click outside the bar and its folder menus.
1333 TEST_F(BookmarkBarControllerTest, TestFolderButtons) {
1334 BookmarkModel& model(*profile()->GetBookmarkModel());
1335 const BookmarkNode* root = model.bookmark_bar_node();
1336 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b 4f:[ 4f1b 4f2b ] ");
1337 model_test_utils::AddNodesFromModelString(model, root, model_string);
1338
1339 // Validate initial model and that we do not have a folder controller.
1340 std::string actualModelString = model_test_utils::ModelStringFromNode(root);
1341 EXPECT_EQ(model_string, actualModelString);
1342 EXPECT_FALSE([bar_ folderController]);
1343
1344 // Add a real bookmark so we can click on it.
1345 const BookmarkNode* folder = root->GetChild(3);
1346 model.AddURL(folder, folder->child_count(), ASCIIToUTF16("CLICK ME"),
1347 GURL("http://www.google.com/"));
1348
1349 // Click on a folder button.
1350 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"4f"];
1351 EXPECT_TRUE(button);
1352 [bar_ openBookmarkFolderFromButton:button];
1353 BookmarkBarFolderController* bbfc = [bar_ folderController];
1354 EXPECT_TRUE(bbfc);
1355
1356 // Make sure a 2nd click on the same button closes things.
1357 [bar_ openBookmarkFolderFromButton:button];
1358 EXPECT_FALSE([bar_ folderController]);
1359
1360 // Next open is a different button.
1361 button = [bar_ buttonWithTitleEqualTo:@"2f"];
1362 EXPECT_TRUE(button);
1363 [bar_ openBookmarkFolderFromButton:button];
1364 EXPECT_TRUE([bar_ folderController]);
1365
1366 // Mouse over a non-folder button and confirm controller has gone away.
1367 button = [bar_ buttonWithTitleEqualTo:@"1b"];
1368 EXPECT_TRUE(button);
1369 NSEvent* event = cocoa_test_event_utils::MouseEventAtPoint([button center],
1370 NSMouseMoved, 0);
1371 [bar_ mouseEnteredButton:button event:event];
1372 EXPECT_FALSE([bar_ folderController]);
1373
1374 // Mouse over the original folder and confirm a new controller.
1375 button = [bar_ buttonWithTitleEqualTo:@"2f"];
1376 EXPECT_TRUE(button);
1377 [bar_ mouseEnteredButton:button event:event];
1378 BookmarkBarFolderController* oldBBFC = [bar_ folderController];
1379 EXPECT_TRUE(oldBBFC);
1380
1381 // 'Jump' over to a different folder and confirm a new controller.
1382 button = [bar_ buttonWithTitleEqualTo:@"4f"];
1383 EXPECT_TRUE(button);
1384 [bar_ mouseEnteredButton:button event:event];
1385 BookmarkBarFolderController* newBBFC = [bar_ folderController];
1386 EXPECT_TRUE(newBBFC);
1387 EXPECT_NE(oldBBFC, newBBFC);
1388 }
1389
1217 // Make sure the "off the side" folder looks like a bookmark folder 1390 // Make sure the "off the side" folder looks like a bookmark folder
1218 // but only contains "off the side" items. 1391 // but only contains "off the side" items.
1219 // TODO(rsesek): Fix the off the side folder. 1392 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) {
1220 TEST_F(BookmarkBarControllerTest, DISABLED_OffTheSideFolder) {
1221 1393
1222 // It starts hidden. 1394 // It starts hidden.
1223 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); 1395 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]);
1224 1396
1225 // Create some buttons. 1397 // Create some buttons.
1226 BookmarkModel* model = profile()->GetBookmarkModel(); 1398 BookmarkModel* model = profile()->GetBookmarkModel();
1227 const BookmarkNode* parent = model->bookmark_bar_node(); 1399 const BookmarkNode* parent = model->bookmark_bar_node();
1228 for (int x = 0; x < 30; x++) { 1400 for (int x = 0; x < 30; x++) {
1229 model->AddURL(parent, parent->child_count(), 1401 model->AddURL(parent, parent->child_count(),
1230 ASCIIToUTF16("medium-size-title"), 1402 ASCIIToUTF16("medium-size-title"),
(...skipping 12 matching lines...) Expand all
1243 // Open it; make sure we have a folder controller. 1415 // Open it; make sure we have a folder controller.
1244 EXPECT_FALSE([bar_ folderController]); 1416 EXPECT_FALSE([bar_ folderController]);
1245 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]]; 1417 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]];
1246 BookmarkBarFolderController* bbfc = [bar_ folderController]; 1418 BookmarkBarFolderController* bbfc = [bar_ folderController];
1247 EXPECT_TRUE(bbfc); 1419 EXPECT_TRUE(bbfc);
1248 1420
1249 // Confirm the contents are only buttons which fell off the side by 1421 // Confirm the contents are only buttons which fell off the side by
1250 // making sure that none of the nodes in the off-the-side folder are 1422 // making sure that none of the nodes in the off-the-side folder are
1251 // found in bar buttons. Be careful since not all the bar buttons 1423 // found in bar buttons. Be careful since not all the bar buttons
1252 // may be currently displayed. 1424 // may be currently displayed.
1253 NSArray* folderItems = [[[bbfc menuBridge]->controller() menu] itemArray]; 1425 NSArray* folderButtons = [bbfc buttons];
1254 NSArray* barButtons = [bar_ buttons]; 1426 NSArray* barButtons = [bar_ buttons];
1255 for (NSMenuItem* folderItem in folderItems) { 1427 for (BookmarkButton* folderButton in folderButtons) {
1256 for (BookmarkButton* barButton in barButtons) { 1428 for (BookmarkButton* barButton in barButtons) {
1257 if ([barButton superview]) { 1429 if ([barButton superview]) {
1258 EXPECT_NE([folderItem tag], [barButton bookmarkNode]->id()); 1430 EXPECT_NE([folderButton bookmarkNode], [barButton bookmarkNode]);
1259 } 1431 }
1260 } 1432 }
1261 } 1433 }
1434
1435 // Delete a bookmark in the off-the-side and verify it's gone.
1436 BookmarkButton* button = [bbfc buttonWithTitleEqualTo:@"DELETE_ME"];
1437 EXPECT_TRUE(button);
1438 model->Remove(parent, parent->child_count() - 2);
1439 button = [bbfc buttonWithTitleEqualTo:@"DELETE_ME"];
1440 EXPECT_FALSE(button);
1441 }
1442
1443 TEST_F(BookmarkBarControllerTest, EventToExitCheck) {
1444 NSEvent* event = cocoa_test_event_utils::MakeMouseEvent(NSMouseMoved, 0);
1445 EXPECT_FALSE([bar_ isEventAnExitEvent:event]);
1446
1447 BookmarkBarFolderWindow* folderWindow = [[[BookmarkBarFolderWindow alloc]
1448 init] autorelease];
1449 [[[bar_ view] window] addChildWindow:folderWindow
1450 ordered:NSWindowAbove];
1451 event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow(NSMakePoint(1,1),
1452 folderWindow);
1453 EXPECT_FALSE([bar_ isEventAnExitEvent:event]);
1454
1455 event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow(
1456 NSMakePoint(100,100), test_window());
1457 EXPECT_TRUE([bar_ isEventAnExitEvent:event]);
1458
1459 // Many components are arbitrary (e.g. location, keycode).
1460 event = [NSEvent keyEventWithType:NSKeyDown
1461 location:NSMakePoint(1,1)
1462 modifierFlags:0
1463 timestamp:0
1464 windowNumber:0
1465 context:nil
1466 characters:@"x"
1467 charactersIgnoringModifiers:@"x"
1468 isARepeat:NO
1469 keyCode:87];
1470 EXPECT_FALSE([bar_ isEventAnExitEvent:event]);
1471
1472 [[[bar_ view] window] removeChildWindow:folderWindow];
1262 } 1473 }
1263 1474
1264 TEST_F(BookmarkBarControllerTest, DropDestination) { 1475 TEST_F(BookmarkBarControllerTest, DropDestination) {
1265 // Make some buttons. 1476 // Make some buttons.
1266 BookmarkModel* model = profile()->GetBookmarkModel(); 1477 BookmarkModel* model = profile()->GetBookmarkModel();
1267 const BookmarkNode* parent = model->bookmark_bar_node(); 1478 const BookmarkNode* parent = model->bookmark_bar_node();
1268 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 1")); 1479 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 1"));
1269 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 2")); 1480 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 2"));
1270 EXPECT_EQ([[bar_ buttons] count], 2U); 1481 EXPECT_EQ([[bar_ buttons] count], 2U);
1271 1482
(...skipping 21 matching lines...) Expand all
1293 // On the very edges: NOT a match 1504 // On the very edges: NOT a match
1294 x = NSMinX([button frame]) + viewFrameXOffset; 1505 x = NSMinX([button frame]) + viewFrameXOffset;
1295 EXPECT_NE(button, 1506 EXPECT_NE(button,
1296 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 9)]); 1507 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 9)]);
1297 x = NSMaxX([button frame]) + viewFrameXOffset; 1508 x = NSMaxX([button frame]) + viewFrameXOffset;
1298 EXPECT_NE(button, 1509 EXPECT_NE(button,
1299 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 11)]); 1510 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 11)]);
1300 } 1511 }
1301 } 1512 }
1302 1513
1514 TEST_F(BookmarkBarControllerTest, NodeDeletedWhileMenuIsOpen) {
1515 BookmarkModel* model = profile()->GetBookmarkModel();
1516 [bar_ loaded:model];
1517
1518 const BookmarkNode* parent = model->bookmark_bar_node();
1519 const BookmarkNode* initialNode = model->AddURL(
1520 parent, parent->child_count(),
1521 ASCIIToUTF16("initial"),
1522 GURL("http://www.google.com"));
1523
1524 NSMenuItem* item = ItemForBookmarkBarMenu(initialNode);
1525 EXPECT_EQ(0U, noOpenBar()->urls_.size());
1526
1527 // Basic check of the menu item and an IBOutlet it can call.
1528 EXPECT_EQ(initialNode, [bar_ nodeFromMenuItem:item]);
1529 [bar_ openBookmarkInNewWindow:item];
1530 EXPECT_EQ(1U, noOpenBar()->urls_.size());
1531 [bar_ clear];
1532
1533 // Now delete the node and make sure things are happy (no crash,
1534 // NULL node caught).
1535 model->Remove(parent, parent->GetIndexOf(initialNode));
1536 EXPECT_EQ(nil, [bar_ nodeFromMenuItem:item]);
1537 // Should not crash by referencing a deleted node.
1538 [bar_ openBookmarkInNewWindow:item];
1539 // Confirm the above did nothing in case it somehow didn't crash.
1540 EXPECT_EQ(0U, noOpenBar()->urls_.size());
1541
1542 // Confirm some more non-crashes.
1543 [bar_ openBookmarkInNewForegroundTab:item];
1544 [bar_ openBookmarkInIncognitoWindow:item];
1545 [bar_ editBookmark:item];
1546 [bar_ copyBookmark:item];
1547 [bar_ deleteBookmark:item];
1548 [bar_ openAllBookmarks:item];
1549 [bar_ openAllBookmarksNewWindow:item];
1550 [bar_ openAllBookmarksIncognitoWindow:item];
1551 }
1552
1303 TEST_F(BookmarkBarControllerTest, NodeDeletedWhileContextMenuIsOpen) { 1553 TEST_F(BookmarkBarControllerTest, NodeDeletedWhileContextMenuIsOpen) {
1304 BookmarkModel* model = profile()->GetBookmarkModel(); 1554 BookmarkModel* model = profile()->GetBookmarkModel();
1305 [bar_ loaded:model]; 1555 [bar_ loaded:model];
1306 1556
1307 const BookmarkNode* parent = model->bookmark_bar_node(); 1557 const BookmarkNode* parent = model->bookmark_bar_node();
1308 const BookmarkNode* folder = model->AddFolder(parent, 1558 const BookmarkNode* folder = model->AddFolder(parent,
1309 parent->child_count(), 1559 parent->child_count(),
1310 ASCIIToUTF16("folder")); 1560 ASCIIToUTF16("folder"));
1311 const BookmarkNode* framma = model->AddURL(folder, folder->child_count(), 1561 const BookmarkNode* framma = model->AddURL(folder, folder->child_count(),
1312 ASCIIToUTF16("f1"), 1562 ASCIIToUTF16("f1"),
1313 GURL("http://framma-lamma.com")); 1563 GURL("http://framma-lamma.com"));
1314 1564
1315 // Mock in a menu 1565 // Mock in a menu
1316 id origMenu = [bar_ buttonContextMenu]; 1566 id origMenu = [bar_ buttonContextMenu];
1317 id fakeMenu = [OCMockObject partialMockForObject:origMenu]; 1567 id fakeMenu = [OCMockObject partialMockForObject:origMenu];
1318 [[fakeMenu expect] cancelTracking]; 1568 [[fakeMenu expect] cancelTracking];
1319 [bar_ setButtonContextMenu:fakeMenu]; 1569 [bar_ setButtonContextMenu:fakeMenu];
1320 1570
1321 // Force a delete which should cancelTracking on the menu. 1571 // Force a delete which should cancelTracking on the menu.
1322 model->Remove(framma->parent(), framma->parent()->GetIndexOf(framma)); 1572 model->Remove(framma->parent(), framma->parent()->GetIndexOf(framma));
1323 1573
1324 // Restore, then confirm cancelTracking was called. 1574 // Restore, then confirm cancelTracking was called.
1325 [bar_ setButtonContextMenu:origMenu]; 1575 [bar_ setButtonContextMenu:origMenu];
1326 EXPECT_OCMOCK_VERIFY(fakeMenu); 1576 EXPECT_OCMOCK_VERIFY(fakeMenu);
1327 } 1577 }
1328 1578
1579 TEST_F(BookmarkBarControllerTest, CloseFolderOnAnimate) {
1580 BookmarkModel* model = profile()->GetBookmarkModel();
1581 const BookmarkNode* parent = model->bookmark_bar_node();
1582 const BookmarkNode* folder = model->AddFolder(parent,
1583 parent->child_count(),
1584 ASCIIToUTF16("folder"));
1585 model->AddFolder(parent, parent->child_count(),
1586 ASCIIToUTF16("sibbling folder"));
1587 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("title a"),
1588 GURL("http://www.google.com/a"));
1589 model->AddURL(folder, folder->child_count(),
1590 ASCIIToUTF16("title super duper long long whoa momma title you betcha"),
1591 GURL("http://www.google.com/b"));
1592 BookmarkButton* button = [[bar_ buttons] objectAtIndex:0];
1593 EXPECT_FALSE([bar_ folderController]);
1594 [bar_ openBookmarkFolderFromButton:button];
1595 BookmarkBarFolderController* bbfc = [bar_ folderController];
1596 // The following tells us that the folder menu is showing. We want to make
1597 // sure the folder menu goes away if the bookmark bar is hidden.
1598 EXPECT_TRUE(bbfc);
1599 EXPECT_TRUE([bar_ isVisible]);
1600
1601 // Hide the bookmark bar.
1602 [bar_ updateAndShowNormalBar:NO
1603 showDetachedBar:YES
1604 withAnimation:YES];
1605 EXPECT_TRUE([bar_ isAnimationRunning]);
1606
1607 // Now that we've closed the bookmark bar (with animation) the folder menu
1608 // should have been closed thus releasing the folderController.
1609 EXPECT_FALSE([bar_ folderController]);
1610 }
1611
1329 TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) { 1612 TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) {
1330 BookmarkModel& model(*profile()->GetBookmarkModel()); 1613 BookmarkModel& model(*profile()->GetBookmarkModel());
1331 const BookmarkNode* root = model.bookmark_bar_node(); 1614 const BookmarkNode* root = model.bookmark_bar_node();
1332 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); 1615 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b ");
1333 model_test_utils::AddNodesFromModelString(model, root, model_string); 1616 model_test_utils::AddNodesFromModelString(model, root, model_string);
1334 1617
1335 // Validate initial model. 1618 // Validate initial model.
1336 std::string actualModelString = model_test_utils::ModelStringFromNode(root); 1619 std::string actualModelString = model_test_utils::ModelStringFromNode(root);
1337 EXPECT_EQ(model_string, actualModelString); 1620 EXPECT_EQ(model_string, actualModelString);
1338 1621
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 bar_.reset( 1863 bar_.reset(
1581 [[BookmarkBarControllerDragData alloc] 1864 [[BookmarkBarControllerDragData alloc]
1582 initWithBrowser:browser() 1865 initWithBrowser:browser()
1583 initialWidth:NSWidth([parent_view_ frame]) 1866 initialWidth:NSWidth([parent_view_ frame])
1584 delegate:nil 1867 delegate:nil
1585 resizeDelegate:resizeDelegate_.get()]); 1868 resizeDelegate:resizeDelegate_.get()]);
1586 InstallAndToggleBar(bar_.get()); 1869 InstallAndToggleBar(bar_.get());
1587 } 1870 }
1588 }; 1871 };
1589 1872
1590 // TODO(rsesek): Fix off the side menu for new-style menus. 1873 TEST_F(BookmarkBarControllerDragDropTest, DragMoveBarBookmarkToOffTheSide) {
1591 TEST_F(BookmarkBarControllerDragDropTest,
1592 DISABLED_DragMoveBarBookmarkToOffTheSide) {
1593 BookmarkModel& model(*profile()->GetBookmarkModel()); 1874 BookmarkModel& model(*profile()->GetBookmarkModel());
1594 const BookmarkNode* root = model.bookmark_bar_node(); 1875 const BookmarkNode* root = model.bookmark_bar_node();
1595 const std::string model_string("1bWithLongName 2fWithLongName:[ " 1876 const std::string model_string("1bWithLongName 2fWithLongName:[ "
1596 "2f1bWithLongName 2f2fWithLongName:[ 2f2f1bWithLongName " 1877 "2f1bWithLongName 2f2fWithLongName:[ 2f2f1bWithLongName "
1597 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " 1878 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] "
1598 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " 1879 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName "
1599 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " 1880 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName "
1600 "11bWithLongName 12bWithLongName 13b "); 1881 "11bWithLongName 12bWithLongName 13b ");
1601 model_test_utils::AddNodesFromModelString(model, root, model_string); 1882 model_test_utils::AddNodesFromModelString(model, root, model_string);
1602 1883
1603 // Validate initial model. 1884 // Validate initial model.
1604 std::string actualModelString = model_test_utils::ModelStringFromNode(root); 1885 std::string actualModelString = model_test_utils::ModelStringFromNode(root);
1605 EXPECT_EQ(model_string, actualModelString); 1886 EXPECT_EQ(model_string, actualModelString);
1606 1887
1607 // Insure that the off-the-side is not showing. 1888 // Insure that the off-the-side is not showing.
1608 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); 1889 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]);
1609 1890
1610 // Remember how many buttons are showing and are available. 1891 // Remember how many buttons are showing and are available.
1611 int oldDisplayedButtons = [bar_ displayedButtonCount]; 1892 int oldDisplayedButtons = [bar_ displayedButtonCount];
1612 int oldChildCount = root->child_count(); 1893 int oldChildCount = root->child_count();
1613 1894
1614 // Pop up the off-the-side menu. 1895 // Pop up the off-the-side menu.
1615 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; 1896 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton];
1616 ASSERT_TRUE(otsButton); 1897 ASSERT_TRUE(otsButton);
1617 1898 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:)
1899 withObject:otsButton];
1618 BookmarkBarFolderController* otsController = [bar_ folderController]; 1900 BookmarkBarFolderController* otsController = [bar_ folderController];
1619 EXPECT_TRUE(otsController); 1901 EXPECT_TRUE(otsController);
1620 1902 NSWindow* toWindow = [otsController window];
1903 EXPECT_TRUE(toWindow);
1621 BookmarkButton* draggedButton = 1904 BookmarkButton* draggedButton =
1622 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"]; 1905 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"];
1623 ASSERT_TRUE(draggedButton); 1906 ASSERT_TRUE(draggedButton);
1624 1907 int oldOTSCount = (int)[[otsController buttons] count];
1625 int oldOTSCount = NumberOfMenuItems(otsController);
1626 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons); 1908 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons);
1627 1909 BookmarkButton* targetButton = [[otsController buttons] objectAtIndex:0];
1628 NSRect frame = [otsButton frame]; 1910 ASSERT_TRUE(targetButton);
1629 [bar_ dragButton:draggedButton 1911 [otsController dragButton:draggedButton
1630 to:NSMakePoint(NSMidX(frame), NSMidY(frame)) 1912 to:[targetButton center]
1631 copy:YES]; 1913 copy:YES];
1632
1633 // There should still be the same number of buttons in the bar 1914 // There should still be the same number of buttons in the bar
1634 // and off-the-side should have one more. 1915 // and off-the-side should have one more.
1635 int newDisplayedButtons = [bar_ displayedButtonCount]; 1916 int newDisplayedButtons = [bar_ displayedButtonCount];
1636 int newChildCount = root->child_count(); 1917 int newChildCount = root->child_count();
1637 int newOTSCount = NumberOfMenuItems(otsController); 1918 int newOTSCount = (int)[[otsController buttons] count];
1638 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); 1919 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons);
1639 EXPECT_EQ(oldChildCount + 1, newChildCount); 1920 EXPECT_EQ(oldChildCount + 1, newChildCount);
1640 EXPECT_EQ(oldOTSCount + 1, newOTSCount); 1921 EXPECT_EQ(oldOTSCount + 1, newOTSCount);
1641 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); 1922 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons);
1642 } 1923 }
1643 1924
1925 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) {
1926 BookmarkModel& model(*profile()->GetBookmarkModel());
1927 const BookmarkNode* root = model.bookmark_bar_node();
1928 const std::string model_string("1bWithLongName 2bWithLongName "
1929 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName "
1930 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName "
1931 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName "
1932 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName "
1933 "19bWithLongName 20bWithLongName ");
1934 model_test_utils::AddNodesFromModelString(model, root, model_string);
1935
1936 const BookmarkNode* other = model.other_node();
1937 const std::string other_string("1other 2other 3other ");
1938 model_test_utils::AddNodesFromModelString(model, other, other_string);
1939
1940 // Validate initial model.
1941 std::string actualModelString = model_test_utils::ModelStringFromNode(root);
1942 EXPECT_EQ(model_string, actualModelString);
1943 std::string actualOtherString = model_test_utils::ModelStringFromNode(other);
1944 EXPECT_EQ(other_string, actualOtherString);
1945
1946 // Insure that the off-the-side is showing.
1947 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]);
1948
1949 // Remember how many buttons are showing and are available.
1950 int oldDisplayedButtons = [bar_ displayedButtonCount];
1951 int oldRootCount = root->child_count();
1952 int oldOtherCount = other->child_count();
1953
1954 // Pop up the off-the-side menu.
1955 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton];
1956 ASSERT_TRUE(otsButton);
1957 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:)
1958 withObject:otsButton];
1959 BookmarkBarFolderController* otsController = [bar_ folderController];
1960 EXPECT_TRUE(otsController);
1961 int oldOTSCount = (int)[[otsController buttons] count];
1962 EXPECT_EQ(oldOTSCount, oldRootCount - oldDisplayedButtons);
1963
1964 // Pick an off-the-side button and drag it to the other bookmarks.
1965 BookmarkButton* draggedButton =
1966 [otsController buttonWithTitleEqualTo:@"20bWithLongName"];
1967 ASSERT_TRUE(draggedButton);
1968 BookmarkButton* targetButton = [bar_ otherBookmarksButton];
1969 ASSERT_TRUE(targetButton);
1970 [bar_ dragButton:draggedButton to:[targetButton center] copy:NO];
1971
1972 // There should one less button in the bar, one less in off-the-side,
1973 // and one more in other bookmarks.
1974 int newRootCount = root->child_count();
1975 int newOTSCount = (int)[[otsController buttons] count];
1976 int newOtherCount = other->child_count();
1977 EXPECT_EQ(oldRootCount - 1, newRootCount);
1978 EXPECT_EQ(oldOTSCount - 1, newOTSCount);
1979 EXPECT_EQ(oldOtherCount + 1, newOtherCount);
1980 }
1981
1644 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkData) { 1982 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkData) {
1645 BookmarkModel& model(*profile()->GetBookmarkModel()); 1983 BookmarkModel& model(*profile()->GetBookmarkModel());
1646 const BookmarkNode* root = model.bookmark_bar_node(); 1984 const BookmarkNode* root = model.bookmark_bar_node();
1647 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " 1985 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] "
1648 "2f3b ] 3b 4b "); 1986 "2f3b ] 3b 4b ");
1649 model_test_utils::AddNodesFromModelString(model, root, model_string); 1987 model_test_utils::AddNodesFromModelString(model, root, model_string);
1650 const BookmarkNode* other = model.other_node(); 1988 const BookmarkNode* other = model.other_node();
1651 const std::string other_string("O1b O2b O3f:[ O3f1b O3f2f ] " 1989 const std::string other_string("O1b O2b O3f:[ O3f1b O3f2f ] "
1652 "O4f:[ O4f1b O4f2f ] 05b "); 1990 "O4f:[ O4f1b O4f2f ] 05b ");
1653 model_test_utils::AddNodesFromModelString(model, other, other_string); 1991 model_test_utils::AddNodesFromModelString(model, other, other_string);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 "2f3b ] 4b "); 2181 "2f3b ] 4b ");
1844 actual = model_test_utils::ModelStringFromNode(root); 2182 actual = model_test_utils::ModelStringFromNode(root);
1845 EXPECT_EQ(expected, actual); 2183 EXPECT_EQ(expected, actual);
1846 2184
1847 // Verify that the other bookmark folder can't be deleted. 2185 // Verify that the other bookmark folder can't be deleted.
1848 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; 2186 BookmarkButton *otherButton = [bar_ otherBookmarksButton];
1849 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); 2187 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]);
1850 } 2188 }
1851 2189
1852 } // namespace 2190 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698