| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_nsobject.h" | 8 #include "base/scoped_nsobject.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // For testing. | 57 // For testing. |
| 58 @interface BookmarkBarFolderControllerNoLevel : BookmarkBarFolderController | 58 @interface BookmarkBarFolderControllerNoLevel : BookmarkBarFolderController |
| 59 @end | 59 @end |
| 60 | 60 |
| 61 @implementation BookmarkBarFolderControllerNoLevel | 61 @implementation BookmarkBarFolderControllerNoLevel |
| 62 - (void)configureWindowLevel { | 62 - (void)configureWindowLevel { |
| 63 // Intentionally empty. | 63 // Intentionally empty. |
| 64 } | 64 } |
| 65 @end | 65 @end |
| 66 | 66 |
| 67 // No window level and the ability to fake the "top left" point of the window. | 67 @interface BookmarkBarFolderControllerPong : BookmarkBarFolderController { |
| 68 // For testing. | |
| 69 @interface BookmarkBarFolderControllerLow : BookmarkBarFolderControllerNoLevel { | |
| 70 BOOL realTopLeft_; // Use the real windowTopLeft call? | |
| 71 } | |
| 72 @property (nonatomic) BOOL realTopLeft; | |
| 73 @end | |
| 74 | |
| 75 | |
| 76 @implementation BookmarkBarFolderControllerLow | |
| 77 | |
| 78 @synthesize realTopLeft = realTopLeft_; | |
| 79 | |
| 80 - (NSPoint)windowTopLeftForWidth:(int)width { | |
| 81 return realTopLeft_ ? [super windowTopLeftForWidth:width] : | |
| 82 NSMakePoint(200,200); | |
| 83 } | |
| 84 | |
| 85 @end | |
| 86 | |
| 87 | |
| 88 @interface BookmarkBarFolderControllerPong : BookmarkBarFolderControllerLow { | |
| 89 BOOL childFolderWillShow_; | 68 BOOL childFolderWillShow_; |
| 90 BOOL childFolderWillClose_; | 69 BOOL childFolderWillClose_; |
| 91 } | 70 } |
| 92 @property (nonatomic, readonly) BOOL childFolderWillShow; | 71 @property (nonatomic, readonly) BOOL childFolderWillShow; |
| 93 @property (nonatomic, readonly) BOOL childFolderWillClose; | 72 @property (nonatomic, readonly) BOOL childFolderWillClose; |
| 94 @end | 73 @end |
| 95 | 74 |
| 96 @implementation BookmarkBarFolderControllerPong | 75 @implementation BookmarkBarFolderControllerPong |
| 97 @synthesize childFolderWillShow = childFolderWillShow_; | 76 @synthesize childFolderWillShow = childFolderWillShow_; |
| 98 @synthesize childFolderWillClose = childFolderWillClose_; | 77 @synthesize childFolderWillClose = childFolderWillClose_; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 153 |
| 175 bar_.reset( | 154 bar_.reset( |
| 176 [[BookmarkBarControllerChildFolderRedirect alloc] | 155 [[BookmarkBarControllerChildFolderRedirect alloc] |
| 177 initWithBrowser:helper_.browser() | 156 initWithBrowser:helper_.browser() |
| 178 initialWidth:300 | 157 initialWidth:300 |
| 179 delegate:nil | 158 delegate:nil |
| 180 resizeDelegate:nil]); | 159 resizeDelegate:nil]); |
| 181 [bar_ loaded:model]; | 160 [bar_ loaded:model]; |
| 182 // Make parent frame for bookmark bar then open it. | 161 // Make parent frame for bookmark bar then open it. |
| 183 NSRect frame = [[test_window() contentView] frame]; | 162 NSRect frame = [[test_window() contentView] frame]; |
| 184 frame = NSInsetRect(frame, 100, 200); | 163 frame = NSMakeRect(frame.origin.x, |
| 164 frame.size.height - bookmarks::kNTPBookmarkBarHeight, |
| 165 frame.size.width, bookmarks::kNTPBookmarkBarHeight); |
| 185 NSView* fakeToolbarView = [[[NSView alloc] initWithFrame:frame] | 166 NSView* fakeToolbarView = [[[NSView alloc] initWithFrame:frame] |
| 186 autorelease]; | 167 autorelease]; |
| 187 [[test_window() contentView] addSubview:fakeToolbarView]; | 168 [[test_window() contentView] addSubview:fakeToolbarView]; |
| 188 [fakeToolbarView addSubview:[bar_ view]]; | 169 [fakeToolbarView addSubview:[bar_ view]]; |
| 189 [bar_ setBookmarkBarEnabled:YES]; | 170 [bar_ setBookmarkBarEnabled:YES]; |
| 190 } | 171 } |
| 191 | 172 |
| 192 // Remove the bookmark with the long title. | 173 // Remove the bookmark with the long title. |
| 193 void RemoveLongTitleNode() { | 174 void RemoveLongTitleNode() { |
| 194 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 175 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // Make sure none of the buttons overlap, that all are inside | 209 // Make sure none of the buttons overlap, that all are inside |
| 229 // the content frame, and their cells are of the proper class. | 210 // the content frame, and their cells are of the proper class. |
| 230 NSArray* buttons = [bbfc buttons]; | 211 NSArray* buttons = [bbfc buttons]; |
| 231 EXPECT_TRUE([buttons count]); | 212 EXPECT_TRUE([buttons count]); |
| 232 for (unsigned int i = 0; i < ([buttons count]-1); i++) { | 213 for (unsigned int i = 0; i < ([buttons count]-1); i++) { |
| 233 EXPECT_FALSE(NSContainsRect([[buttons objectAtIndex:i] frame], | 214 EXPECT_FALSE(NSContainsRect([[buttons objectAtIndex:i] frame], |
| 234 [[buttons objectAtIndex:i+1] frame])); | 215 [[buttons objectAtIndex:i+1] frame])); |
| 235 } | 216 } |
| 236 Class cellClass = [BookmarkBarFolderButtonCell class]; | 217 Class cellClass = [BookmarkBarFolderButtonCell class]; |
| 237 for (BookmarkButton* button in buttons) { | 218 for (BookmarkButton* button in buttons) { |
| 238 NSRect r = [[bbfc mainView] convertRect:[button frame] fromView:button]; | 219 NSRect r = [[bbfc folderView] convertRect:[button frame] fromView:button]; |
| 239 // TODO(jrg): remove this adjustment. | 220 // TODO(jrg): remove this adjustment. |
| 240 NSRect bigger = NSInsetRect([[bbfc mainView] frame], -2, 0); | 221 NSRect bigger = NSInsetRect([[bbfc folderView] frame], -2, 0); |
| 241 EXPECT_TRUE(NSContainsRect(bigger, r)); | 222 EXPECT_TRUE(NSContainsRect(bigger, r)); |
| 242 EXPECT_TRUE([[button cell] isKindOfClass:cellClass]); | 223 EXPECT_TRUE([[button cell] isKindOfClass:cellClass]); |
| 243 } | 224 } |
| 244 | 225 |
| 245 // Confirm folder buttons have no tooltip. The important thing | 226 // Confirm folder buttons have no tooltip. The important thing |
| 246 // really is that we insure folders and non-folders are treated | 227 // really is that we insure folders and non-folders are treated |
| 247 // differently; not sure of any other generic way to do this. | 228 // differently; not sure of any other generic way to do this. |
| 248 for (BookmarkButton* button in buttons) { | 229 for (BookmarkButton* button in buttons) { |
| 249 if ([button isFolder]) | 230 if ([button isFolder]) |
| 250 EXPECT_FALSE([button toolTip]); | 231 EXPECT_FALSE([button toolTip]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 262 | 243 |
| 263 [bbfc retain]; // stop the scoped_nsobject from doing anything | 244 [bbfc retain]; // stop the scoped_nsobject from doing anything |
| 264 [[bbfc window] close]; // trigger an autorelease of bbfc.get() | 245 [[bbfc window] close]; // trigger an autorelease of bbfc.get() |
| 265 } | 246 } |
| 266 | 247 |
| 267 TEST_F(BookmarkBarFolderControllerTest, BasicPosition) { | 248 TEST_F(BookmarkBarFolderControllerTest, BasicPosition) { |
| 268 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; | 249 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; |
| 269 EXPECT_TRUE(parentButton); | 250 EXPECT_TRUE(parentButton); |
| 270 | 251 |
| 271 // If parent is a BookmarkBarController, grow down. | 252 // If parent is a BookmarkBarController, grow down. |
| 272 scoped_nsobject<BookmarkBarFolderControllerLow> bbfc; | 253 scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 273 bbfc.reset([[BookmarkBarFolderControllerLow alloc] | 254 bbfc.reset([[BookmarkBarFolderController alloc] |
| 274 initWithParentButton:parentButton | 255 initWithParentButton:parentButton |
| 275 parentController:nil | 256 parentController:nil |
| 276 barController:bar_]); | 257 barController:bar_]); |
| 277 [bbfc window]; | 258 [bbfc window]; |
| 278 [bbfc setRealTopLeft:YES]; | |
| 279 NSPoint pt = [bbfc windowTopLeftForWidth:0]; // screen coords | 259 NSPoint pt = [bbfc windowTopLeftForWidth:0]; // screen coords |
| 280 NSPoint buttonOriginInScreen = | 260 NSPoint buttonOriginInScreen = |
| 281 [[parentButton window] | 261 [[parentButton window] |
| 282 convertBaseToScreen:[parentButton | 262 convertBaseToScreen:[parentButton |
| 283 convertRectToBase:[parentButton frame]].origin]; | 263 convertRectToBase:[parentButton frame]].origin]; |
| 284 // Within margin | 264 // Within margin |
| 285 EXPECT_LE(abs(pt.x - buttonOriginInScreen.x), | 265 EXPECT_LE(abs(pt.x - buttonOriginInScreen.x), |
| 286 bookmarks::kBookmarkMenuOverlap+1); | 266 bookmarks::kBookmarkMenuOverlap+1); |
| 287 EXPECT_LE(abs(pt.y - buttonOriginInScreen.y), | 267 EXPECT_LE(abs(pt.y - buttonOriginInScreen.y), |
| 288 bookmarks::kBookmarkMenuOverlap+1); | 268 bookmarks::kBookmarkMenuOverlap+1); |
| 289 | 269 |
| 290 // Make sure we see the window shift left if it spills off the screen | 270 // Make sure we see the window shift left if it spills off the screen |
| 291 pt = [bbfc windowTopLeftForWidth:0]; | 271 pt = [bbfc windowTopLeftForWidth:0]; |
| 292 NSPoint shifted = [bbfc windowTopLeftForWidth:9999999]; | 272 NSPoint shifted = [bbfc windowTopLeftForWidth:9999999]; |
| 293 EXPECT_LT(shifted.x, pt.x); | 273 EXPECT_LT(shifted.x, pt.x); |
| 294 | 274 |
| 295 // If parent is a BookmarkBarFolderController, grow right. | 275 // If parent is a BookmarkBarFolderController, grow right. |
| 296 scoped_nsobject<BookmarkBarFolderControllerLow> bbfc2; | 276 scoped_nsobject<BookmarkBarFolderController> bbfc2; |
| 297 bbfc2.reset([[BookmarkBarFolderControllerLow alloc] | 277 bbfc2.reset([[BookmarkBarFolderController alloc] |
| 298 initWithParentButton:[[bbfc buttons] objectAtIndex:0] | 278 initWithParentButton:[[bbfc buttons] objectAtIndex:0] |
| 299 parentController:bbfc.get() | 279 parentController:bbfc.get() |
| 300 barController:bar_]); | 280 barController:bar_]); |
| 301 [bbfc2 window]; | 281 [bbfc2 window]; |
| 302 [bbfc2 setRealTopLeft:YES]; | |
| 303 pt = [bbfc2 windowTopLeftForWidth:0]; | 282 pt = [bbfc2 windowTopLeftForWidth:0]; |
| 304 // We're now overlapping the window a bit. | 283 // We're now overlapping the window a bit. |
| 305 EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) - | 284 EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) - |
| 306 bookmarks::kBookmarkMenuOverlap); | 285 bookmarks::kBookmarkMenuOverlap); |
| 307 } | 286 } |
| 308 | 287 |
| 309 // Confirm we grow right until end of screen, then start growing left | 288 // Confirm we grow right until end of screen, then start growing left |
| 310 // until end of screen again, then right. | 289 // until end of screen again, then right. |
| 311 TEST_F(BookmarkBarFolderControllerTest, PositionRightLeftRight) { | 290 TEST_F(BookmarkBarFolderControllerTest, PositionRightLeftRight) { |
| 312 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 291 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // (No need to EXPECT a final "grow right"; if we didn't find one | 348 // (No need to EXPECT a final "grow right"; if we didn't find one |
| 370 // we'd get a C++ array bounds exception). | 349 // we'd get a C++ array bounds exception). |
| 371 } | 350 } |
| 372 | 351 |
| 373 TEST_F(BookmarkBarFolderControllerTest, DropDestination) { | 352 TEST_F(BookmarkBarFolderControllerTest, DropDestination) { |
| 374 scoped_nsobject<BookmarkBarFolderController> bbfc; | 353 scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 375 bbfc.reset(SimpleBookmarkBarFolderController()); | 354 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 376 EXPECT_TRUE(bbfc.get()); | 355 EXPECT_TRUE(bbfc.get()); |
| 377 | 356 |
| 378 // Confirm "off the top" and "off the bottom" match no buttons. | 357 // Confirm "off the top" and "off the bottom" match no buttons. |
| 379 NSPoint p = NSMakePoint(NSMidX([[bbfc mainView] frame]), 10000); | 358 NSPoint p = NSMakePoint(NSMidX([[bbfc folderView] frame]), 10000); |
| 380 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); | 359 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); |
| 381 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); | 360 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); |
| 382 p = NSMakePoint(NSMidX([[bbfc mainView] frame]), -1); | 361 p = NSMakePoint(NSMidX([[bbfc folderView] frame]), -1); |
| 383 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); | 362 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); |
| 384 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); | 363 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); |
| 385 | 364 |
| 386 // Confirm "right in the center" (give or take a pixel) is a match, | 365 // Confirm "right in the center" (give or take a pixel) is a match, |
| 387 // and confirm "just barely in the button" is not. Anything more | 366 // and confirm "just barely in the button" is not. Anything more |
| 388 // specific seems likely to be tweaked. We don't loop over all | 367 // specific seems likely to be tweaked. We don't loop over all |
| 389 // buttons because the scroll view makes them not visible. | 368 // buttons because the scroll view makes them not visible. |
| 390 for (BookmarkButton* button in [bbfc buttons]) { | 369 for (BookmarkButton* button in [bbfc buttons]) { |
| 391 CGFloat x = NSMidX([button frame]); | 370 CGFloat x = NSMidX([button frame]); |
| 392 CGFloat y = NSMidY([button frame]); | 371 CGFloat y = NSMidY([button frame]); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 EXPECT_TRUE(bbfc.get()); | 442 EXPECT_TRUE(bbfc.get()); |
| 464 CGFloat thinWidth = NSWidth([[bbfc window] frame]); | 443 CGFloat thinWidth = NSWidth([[bbfc window] frame]); |
| 465 | 444 |
| 466 // Make sure window size changed as expected. | 445 // Make sure window size changed as expected. |
| 467 EXPECT_GT(wideWidth, thinWidth); | 446 EXPECT_GT(wideWidth, thinWidth); |
| 468 } | 447 } |
| 469 | 448 |
| 470 // Simple scrolling tests. | 449 // Simple scrolling tests. |
| 471 TEST_F(BookmarkBarFolderControllerTest, SimpleScroll) { | 450 TEST_F(BookmarkBarFolderControllerTest, SimpleScroll) { |
| 472 scoped_nsobject<BookmarkBarFolderController> bbfc; | 451 scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 473 | 452 NSRect screenFrame = [[NSScreen mainScreen] frame]; |
| 453 CGFloat screenHeight = NSHeight(screenFrame); |
| 474 int nodecount = AddLotsOfNodes(); | 454 int nodecount = AddLotsOfNodes(); |
| 475 bbfc.reset(SimpleBookmarkBarFolderController()); | 455 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 476 EXPECT_TRUE(bbfc.get()); | 456 EXPECT_TRUE(bbfc.get()); |
| 477 [bbfc showWindow:bbfc.get()]; | 457 [bbfc showWindow:bbfc.get()]; |
| 458 NSWindow* window = [bbfc window]; |
| 478 | 459 |
| 479 // Make sure the window fits on the screen. | 460 // The window should be shorter than the screen but reach exactly to the |
| 480 EXPECT_LT(NSHeight([[bbfc window] frame]), | 461 // bottom of the screen since it's scrollable. |
| 481 NSHeight([[NSScreen mainScreen] frame])); | 462 EXPECT_LT(NSHeight([window frame]), screenHeight); |
| 463 EXPECT_CGFLOAT_EQ(0.0, [window frame].origin.y); |
| 482 | 464 |
| 483 // Verify the logic used by the scroll arrow code. | 465 // Initially, should show scroll-up but not scroll-down. |
| 484 EXPECT_TRUE([bbfc canScrollUp]); | 466 EXPECT_TRUE([bbfc canScrollUp]); |
| 485 EXPECT_FALSE([bbfc canScrollDown]); | 467 EXPECT_FALSE([bbfc canScrollDown]); |
| 486 | 468 |
| 487 // Scroll it up. Make sure the window has gotten bigger each time. | 469 // Scroll up a bit. Make sure the window has gotten bigger each time. |
| 488 // Also, for each scroll, make sure our hit test finds a new button | 470 // Also, for each scroll, make sure our hit test finds a new button |
| 489 // (to confirm the content area changed). | 471 // (to confirm the content area changed). |
| 490 NSView* savedHit = nil; | 472 NSView* savedHit = nil; |
| 491 for (int i=0; i<3; i++) { | 473 NSView* scrollView = [bbfc scrollView]; |
| 492 CGFloat height = NSHeight([[bbfc window] frame]); | 474 |
| 475 // Find the next-to-last button showing at the bottom of the window and |
| 476 // us its center for hit testing. |
| 477 BookmarkButton* targetButton = nil; |
| 478 NSPoint scrollPoint = [[bbfc scrollView] documentVisibleRect].origin; |
| 479 for (BookmarkButton* button in [bbfc buttons]) { |
| 480 NSRect buttonFrame = [button frame]; |
| 481 buttonFrame.origin.y -= scrollPoint.y; |
| 482 if (buttonFrame.origin.y < 0.0) |
| 483 break; |
| 484 targetButton = button; |
| 485 } |
| 486 NSPoint hitPoint = [targetButton frame].origin; |
| 487 hitPoint.x += 50.0; |
| 488 hitPoint.y += (bookmarks::kBookmarkButtonHeight / 2.0) - scrollPoint.y; |
| 489 |
| 490 for (int i = 0; i < 3; i++) { |
| 491 CGFloat height = NSHeight([window frame]); |
| 493 [bbfc performOneScroll:60]; | 492 [bbfc performOneScroll:60]; |
| 494 EXPECT_GT(NSHeight([[bbfc window] frame]), height); | 493 EXPECT_GT(NSHeight([window frame]), height); |
| 495 NSView* hit = [[[bbfc window] contentView] hitTest:NSMakePoint(22, 22)]; | 494 NSView* hit = [scrollView hitTest:hitPoint]; |
| 495 // We should hit a bookmark button. |
| 496 EXPECT_TRUE([[hit className] isEqualToString:@"BookmarkButton"]); |
| 496 EXPECT_NE(hit, savedHit); | 497 EXPECT_NE(hit, savedHit); |
| 497 savedHit = hit; | 498 savedHit = hit; |
| 498 } | 499 } |
| 499 | 500 |
| 500 // Keep scrolling up; make sure we never get bigger than the screen. | 501 // Keep scrolling up; make sure we never get bigger than the screen. |
| 501 // Also confirm we never scroll the window off the screen. | 502 // Also confirm we never scroll the window off the screen. |
| 502 bool bothAtOnce = false; | 503 bool bothAtOnce = false; |
| 503 NSRect screenFrame = [[NSScreen mainScreen] frame]; | 504 while ([bbfc canScrollUp]) { |
| 504 for (int i = 0; i < nodecount; i++) { | |
| 505 [bbfc performOneScroll:60]; | 505 [bbfc performOneScroll:60]; |
| 506 EXPECT_TRUE(NSContainsRect(screenFrame, | 506 EXPECT_TRUE(NSContainsRect(screenFrame, [window frame])); |
| 507 [[bbfc window] frame])); | |
| 508 // Make sure, sometime during our scroll, we have the ability to | 507 // Make sure, sometime during our scroll, we have the ability to |
| 509 // scroll in either direction. | 508 // scroll in either direction. |
| 510 if ([bbfc canScrollUp] && | 509 if ([bbfc canScrollUp] && |
| 511 [bbfc canScrollDown]) | 510 [bbfc canScrollDown]) |
| 512 bothAtOnce = true; | 511 bothAtOnce = true; |
| 513 } | 512 } |
| 514 EXPECT_TRUE(bothAtOnce); | 513 EXPECT_TRUE(bothAtOnce); |
| 515 | 514 |
| 516 // Once we've scrolled to the end, our only option should be to scroll back. | 515 // Once we've scrolled to the end, our only option should be to scroll back. |
| 517 EXPECT_FALSE([bbfc canScrollUp]); | 516 EXPECT_FALSE([bbfc canScrollUp]); |
| 518 EXPECT_TRUE([bbfc canScrollDown]); | 517 EXPECT_TRUE([bbfc canScrollDown]); |
| 519 | 518 |
| 520 // Now scroll down and make sure the window size does not change. | 519 // Now scroll down and make sure the window size does not change. |
| 521 // Also confirm we never scroll the window off the screen the other | 520 // Also confirm we never scroll the window off the screen the other |
| 522 // way. | 521 // way. |
| 523 for (int i=0; i<nodecount+50; i++) { | 522 for (int i = 0; i < nodecount+50; ++i) { |
| 524 CGFloat height = NSHeight([[bbfc window] frame]); | |
| 525 [bbfc performOneScroll:-60]; | 523 [bbfc performOneScroll:-60]; |
| 526 EXPECT_EQ(height, NSHeight([[bbfc window] frame])); | 524 // Once we can no longer scroll down the window height changes. |
| 527 EXPECT_TRUE(NSContainsRect(screenFrame, | 525 if (![bbfc canScrollDown]) |
| 528 [[bbfc window] frame])); | 526 break; |
| 527 EXPECT_EQ(screenHeight, NSHeight([window frame])); |
| 528 EXPECT_TRUE(NSContainsRect(screenFrame, [window frame])); |
| 529 } | 529 } |
| 530 // The final height should be offset from the top of the screen and still |
| 531 // within the screen. |
| 532 CGFloat height = screenHeight - bookmarks::kScrollWindowVerticalMargin; |
| 533 EXPECT_CGFLOAT_EQ(height, NSHeight([window frame])); |
| 534 EXPECT_TRUE(NSContainsRect(screenFrame, [window frame])); |
| 530 } | 535 } |
| 531 | 536 |
| 532 // Folder menu sizing and placementwhile deleting bookmarks and scrolling tests. | 537 // Folder menu sizing and placement while deleting bookmarks |
| 538 // and scrolling tests. |
| 533 TEST_F(BookmarkBarFolderControllerTest, MenuPlacementWhileScrollingDeleting) { | 539 TEST_F(BookmarkBarFolderControllerTest, MenuPlacementWhileScrollingDeleting) { |
| 534 scoped_nsobject<BookmarkBarFolderController> bbfc; | 540 scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 535 AddLotsOfNodes(); | 541 AddLotsOfNodes(); |
| 536 bbfc.reset(SimpleBookmarkBarFolderController()); | 542 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 537 [bbfc showWindow:bbfc.get()]; | 543 [bbfc showWindow:bbfc.get()]; |
| 538 NSWindow* menuWindow = [bbfc window]; | 544 NSWindow* menuWindow = [bbfc window]; |
| 539 BookmarkBarFolderController* folder = [bar_ folderController]; | 545 BookmarkBarFolderController* folder = [bar_ folderController]; |
| 540 NSArray* buttons = [folder buttons]; | 546 NSArray* buttons = [folder buttons]; |
| 541 | 547 |
| 542 // Before scrolling any, delete a bookmark and make sure the window top has | 548 // Before scrolling any, delete a bookmark and make sure the window top has |
| (...skipping 29 matching lines...) Expand all Loading... |
| 572 // Scroll so that the top scroll arrow is no longer showing, make sure | 578 // Scroll so that the top scroll arrow is no longer showing, make sure |
| 573 // the top of the window has not moved, then delete a visible button and | 579 // the top of the window has not moved, then delete a visible button and |
| 574 // make sure the top has not moved. | 580 // make sure the top has not moved. |
| 575 while ([bbfc canScrollDown]) { | 581 while ([bbfc canScrollDown]) { |
| 576 [bbfc performOneScroll:-scrollOneBookmark]; | 582 [bbfc performOneScroll:-scrollOneBookmark]; |
| 577 --buttonCounter; | 583 --buttonCounter; |
| 578 } | 584 } |
| 579 button = [buttons objectAtIndex:buttonCounter + 3]; | 585 button = [buttons objectAtIndex:buttonCounter + 3]; |
| 580 [folder deleteBookmark:button]; | 586 [folder deleteBookmark:button]; |
| 581 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 587 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
| 582 EXPECT_CGFLOAT_EQ(oldTop, newTop); | 588 EXPECT_CGFLOAT_EQ(oldTop - bookmarks::kScrollWindowVerticalMargin, newTop); |
| 583 } | 589 } |
| 584 | 590 |
| 585 @interface FakedDragInfo : NSObject { | 591 @interface FakedDragInfo : NSObject { |
| 586 @public | 592 @public |
| 587 NSPoint dropLocation_; | 593 NSPoint dropLocation_; |
| 588 NSDragOperation sourceMask_; | 594 NSDragOperation sourceMask_; |
| 589 } | 595 } |
| 590 @property (nonatomic, assign) NSPoint dropLocation; | 596 @property (nonatomic, assign) NSPoint dropLocation; |
| 591 - (void)setDraggingSourceOperationMask:(NSDragOperation)mask; | 597 - (void)setDraggingSourceOperationMask:(NSDragOperation)mask; |
| 592 @end | 598 @end |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 resizeDelegate:resizeDelegate_.get()]); | 655 resizeDelegate:resizeDelegate_.get()]); |
| 650 InstallAndToggleBar(bar_.get()); | 656 InstallAndToggleBar(bar_.get()); |
| 651 } | 657 } |
| 652 | 658 |
| 653 void InstallAndToggleBar(BookmarkBarController* bar) { | 659 void InstallAndToggleBar(BookmarkBarController* bar) { |
| 654 // Force loading of the nib. | 660 // Force loading of the nib. |
| 655 [bar view]; | 661 [bar view]; |
| 656 // Awkwardness to look like we've been installed. | 662 // Awkwardness to look like we've been installed. |
| 657 [parent_view_ addSubview:[bar view]]; | 663 [parent_view_ addSubview:[bar view]]; |
| 658 NSRect frame = [[[bar view] superview] frame]; | 664 NSRect frame = [[[bar view] superview] frame]; |
| 659 frame.origin.y = 100; | 665 frame.origin.y = 400; |
| 660 [[[bar view] superview] setFrame:frame]; | 666 [[[bar view] superview] setFrame:frame]; |
| 661 | 667 |
| 662 // Make sure it's on in a window so viewDidMoveToWindow is called | 668 // Make sure it's on in a window so viewDidMoveToWindow is called |
| 663 [[test_window() contentView] addSubview:parent_view_]; | 669 [[test_window() contentView] addSubview:parent_view_]; |
| 664 | 670 |
| 665 // Make sure it's open so certain things aren't no-ops. | 671 // Make sure it's open so certain things aren't no-ops. |
| 666 [bar updateAndShowNormalBar:YES | 672 [bar updateAndShowNormalBar:YES |
| 667 showDetachedBar:NO | 673 showDetachedBar:NO |
| 668 withAnimation:NO]; | 674 withAnimation:NO]; |
| 669 } | 675 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 [folderController validateMenuSpacing]; | 869 [folderController validateMenuSpacing]; |
| 864 [subfolderController validateMenuSpacing]; | 870 [subfolderController validateMenuSpacing]; |
| 865 | 871 |
| 866 // Check the window layouts. The folder window should not have changed, | 872 // Check the window layouts. The folder window should not have changed, |
| 867 // but the subfolder window should have shifted vertically and grown. | 873 // but the subfolder window should have shifted vertically and grown. |
| 868 NSRect newToWindowFrame = [toWindow frame]; | 874 NSRect newToWindowFrame = [toWindow frame]; |
| 869 EXPECT_NSRECT_EQ(oldToWindowFrame, newToWindowFrame); | 875 EXPECT_NSRECT_EQ(oldToWindowFrame, newToWindowFrame); |
| 870 NSRect newToSubwindowFrame = [toSubwindow frame]; | 876 NSRect newToSubwindowFrame = [toSubwindow frame]; |
| 871 NSRect expectedToSubwindowFrame = oldToSubwindowFrame; | 877 NSRect expectedToSubwindowFrame = oldToSubwindowFrame; |
| 872 expectedToSubwindowFrame.origin.y -= | 878 expectedToSubwindowFrame.origin.y -= |
| 873 bookmarks::kBookmarkBarHeight + bookmarks::kVisualHeightOffset; | 879 (bookmarks::kBookmarkButtonHeight + bookmarks::kVisualHeightOffset); |
| 874 expectedToSubwindowFrame.size.height += | 880 expectedToSubwindowFrame.size.height += |
| 875 bookmarks::kBookmarkBarHeight + bookmarks::kVisualHeightOffset; | 881 (bookmarks::kBookmarkButtonHeight + bookmarks::kVisualHeightOffset); |
| 876 EXPECT_NSRECT_EQ(expectedToSubwindowFrame, newToSubwindowFrame); | 882 EXPECT_NSRECT_EQ(expectedToSubwindowFrame, newToSubwindowFrame); |
| 877 } | 883 } |
| 878 | 884 |
| 879 TEST_F(BookmarkBarFolderControllerMenuTest, DragMoveWithinFolder) { | 885 TEST_F(BookmarkBarFolderControllerMenuTest, DragMoveWithinFolder) { |
| 880 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); | 886 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); |
| 881 const BookmarkNode* root = model.GetBookmarkBarNode(); | 887 const BookmarkNode* root = model.GetBookmarkBarNode(); |
| 882 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b " | 888 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b " |
| 883 "2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b " | 889 "2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b " |
| 884 "4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); | 890 "4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); |
| 885 model_test_utils::AddNodesFromModelString(model, root, model_string); | 891 model_test_utils::AddNodesFromModelString(model, root, model_string); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 const BookmarkNode* folder = model.AddGroup(parent, | 1172 const BookmarkNode* folder = model.AddGroup(parent, |
| 1167 parent->GetChildCount(), | 1173 parent->GetChildCount(), |
| 1168 ASCIIToUTF16("BIG")); | 1174 ASCIIToUTF16("BIG")); |
| 1169 | 1175 |
| 1170 // Pop open the new folder window and verify it has one (empty) item. | 1176 // Pop open the new folder window and verify it has one (empty) item. |
| 1171 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"BIG"]; | 1177 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"BIG"]; |
| 1172 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) | 1178 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) |
| 1173 withObject:button]; | 1179 withObject:button]; |
| 1174 BookmarkBarFolderController* folderController = [bar_ folderController]; | 1180 BookmarkBarFolderController* folderController = [bar_ folderController]; |
| 1175 EXPECT_TRUE(folderController); | 1181 EXPECT_TRUE(folderController); |
| 1176 NSWindow* folderMenu = [folderController window]; | 1182 NSWindow* folderWindow = [folderController window]; |
| 1177 EXPECT_TRUE(folderMenu); | 1183 EXPECT_TRUE(folderWindow); |
| 1178 CGFloat expectedHeight = (CGFloat)bookmarks::kBookmarkButtonHeight + | 1184 CGFloat expectedHeight = (CGFloat)bookmarks::kBookmarkButtonHeight + |
| 1179 (2*bookmarks::kBookmarkVerticalPadding); | 1185 (2*bookmarks::kBookmarkVerticalPadding); |
| 1180 NSRect menuFrame = [folderMenu frame]; | 1186 NSRect windowFrame = [folderWindow frame]; |
| 1181 CGFloat menuHeight = NSHeight(menuFrame); | 1187 CGFloat windowHeight = NSHeight(windowFrame); |
| 1182 EXPECT_CGFLOAT_EQ(expectedHeight, menuHeight); | 1188 EXPECT_CGFLOAT_EQ(expectedHeight, windowHeight); |
| 1183 EXPECT_FALSE([folderController scrollable]); | 1189 EXPECT_FALSE([folderController canScrollUp]); |
| 1190 EXPECT_FALSE([folderController canScrollDown]); |
| 1184 | 1191 |
| 1185 // Now add a real bookmark and reopen. | 1192 // Now add a real bookmark and reopen. |
| 1186 model.AddURL(folder, folder->GetChildCount(), ASCIIToUTF16("a"), | 1193 model.AddURL(folder, folder->GetChildCount(), ASCIIToUTF16("a"), |
| 1187 GURL("http://a.com/")); | 1194 GURL("http://a.com/")); |
| 1188 folderController = [bar_ folderController]; | 1195 folderController = [bar_ folderController]; |
| 1189 EXPECT_TRUE(folderController); | 1196 EXPECT_TRUE(folderController); |
| 1190 folderMenu = [folderController window]; | 1197 NSView* folderView = [folderController folderView]; |
| 1191 EXPECT_TRUE(folderMenu); | 1198 EXPECT_TRUE(folderView); |
| 1192 menuFrame = [folderMenu frame]; | 1199 NSRect menuFrame = [folderView frame]; |
| 1193 menuHeight = NSHeight(menuFrame); | 1200 NSView* visibleView = [folderController visibleView]; |
| 1201 NSRect visibleFrame = [visibleView frame]; |
| 1202 NSView* scrollView = [folderController scrollView]; |
| 1203 NSRect scrollFrame = [scrollView frame]; |
| 1204 |
| 1205 // Determine the margins between the scroll frame and the visible frame. |
| 1206 CGFloat widthDelta = NSWidth(visibleFrame) - NSWidth(scrollFrame); |
| 1207 |
| 1208 CGFloat menuHeight = NSHeight(menuFrame); |
| 1194 EXPECT_CGFLOAT_EQ(expectedHeight, menuHeight); | 1209 EXPECT_CGFLOAT_EQ(expectedHeight, menuHeight); |
| 1195 CGFloat menuWidth = NSWidth(menuFrame); | 1210 CGFloat scrollerWidth = NSWidth(scrollFrame); |
| 1196 button = [folderController buttonWithTitleEqualTo:@"a"]; | 1211 button = [folderController buttonWithTitleEqualTo:@"a"]; |
| 1197 CGFloat buttonWidth = NSWidth([button frame]); | 1212 CGFloat buttonWidth = NSWidth([button frame]); |
| 1198 CGFloat expectedWidth = | 1213 EXPECT_CGFLOAT_EQ(scrollerWidth, buttonWidth); |
| 1199 buttonWidth + (2 * bookmarks::kBookmarkSubMenuHorizontalPadding); | 1214 CGFloat visibleWidth = NSWidth(visibleFrame); |
| 1200 EXPECT_CGFLOAT_EQ(expectedWidth, menuWidth); | 1215 EXPECT_CGFLOAT_EQ(visibleWidth - widthDelta, buttonWidth); |
| 1216 EXPECT_LT(scrollerWidth, NSWidth([folderView frame])); |
| 1201 | 1217 |
| 1202 // Add a wider bookmark and make sure the button widths match. | 1218 // Add a wider bookmark and make sure the button widths match. |
| 1203 model.AddURL(folder, folder->GetChildCount(), | 1219 int reallyWideButtonNumber = folder->GetChildCount(); |
| 1204 ASCIIToUTF16("A really, really long name"), | 1220 model.AddURL(folder, reallyWideButtonNumber, |
| 1221 ASCIIToUTF16("A really, really, really, really, really, " |
| 1222 "really long name"), |
| 1205 GURL("http://www.google.com/a")); | 1223 GURL("http://www.google.com/a")); |
| 1206 EXPECT_LT(menuWidth, NSWidth([folderMenu frame])); | 1224 BookmarkButton* bigButton = |
| 1207 EXPECT_LT(buttonWidth, NSWidth([button frame])); | 1225 [folderController buttonWithTitleEqualTo: |
| 1208 buttonWidth = NSWidth([button frame]); | 1226 @"A really, really, really, really, really, really long name"]; |
| 1209 BookmarkButton* buttonB = | 1227 EXPECT_TRUE(bigButton); |
| 1210 [folderController buttonWithTitleEqualTo:@"A really, really long name"]; | 1228 CGFloat buttonWidthB = NSWidth([bigButton frame]); |
| 1211 EXPECT_TRUE(buttonB); | 1229 EXPECT_LT(buttonWidth, buttonWidthB); |
| 1212 CGFloat buttonWidthB = NSWidth([buttonB frame]); | 1230 // Add a bunch of bookmarks until the window becomes scrollable, then check |
| 1213 EXPECT_CGFLOAT_EQ(buttonWidth, buttonWidthB); | 1231 // for a scroll up arrow. |
| 1214 // Add a bunch of bookmarks until the window grows no more, then check for | |
| 1215 // a scroll down arrow. | |
| 1216 CGFloat oldMenuHeight = 0.0; // It just has to be different for first run. | |
| 1217 menuHeight = NSHeight([folderMenu frame]); | |
| 1218 NSUInteger tripWire = 0; // Prevent a runaway. | 1232 NSUInteger tripWire = 0; // Prevent a runaway. |
| 1219 while (![folderController scrollable] && ++tripWire < 100) { | 1233 while (![folderController canScrollUp] && ++tripWire < 1000) { |
| 1220 model.AddURL(folder, folder->GetChildCount(), ASCIIToUTF16("B"), | 1234 model.AddURL(folder, folder->GetChildCount(), ASCIIToUTF16("B"), |
| 1221 GURL("http://b.com/")); | 1235 GURL("http://b.com/")); |
| 1222 oldMenuHeight = menuHeight; | |
| 1223 menuHeight = NSHeight([folderMenu frame]); | |
| 1224 } | 1236 } |
| 1225 EXPECT_TRUE([folderController scrollable]); | |
| 1226 EXPECT_TRUE([folderController canScrollUp]); | 1237 EXPECT_TRUE([folderController canScrollUp]); |
| 1227 | 1238 |
| 1228 // Remove one bookmark and make sure the scroll down arrow has been removed. | 1239 // Remove one bookmark and make sure the scroll down arrow has been removed. |
| 1229 // We'll remove the really long node so we can see if the buttons get resized. | 1240 // We'll remove the really long node so we can see if the buttons get resized. |
| 1230 menuWidth = NSWidth([folderMenu frame]); | 1241 scrollerWidth = NSWidth([folderView frame]); |
| 1231 buttonWidth = NSWidth([button frame]); | 1242 buttonWidth = NSWidth([button frame]); |
| 1232 model.Remove(folder, 1); | 1243 model.Remove(folder, reallyWideButtonNumber); |
| 1233 EXPECT_FALSE([folderController scrollable]); | |
| 1234 EXPECT_FALSE([folderController canScrollUp]); | 1244 EXPECT_FALSE([folderController canScrollUp]); |
| 1235 EXPECT_FALSE([folderController canScrollDown]); | 1245 EXPECT_FALSE([folderController canScrollDown]); |
| 1236 | 1246 |
| 1237 // Check the size. It should have reduced. | 1247 // Check the size. It should have reduced. |
| 1238 EXPECT_GT(menuWidth, NSWidth([folderMenu frame])); | 1248 EXPECT_GT(scrollerWidth, NSWidth([folderView frame])); |
| 1239 EXPECT_GT(buttonWidth, NSWidth([button frame])); | 1249 EXPECT_GT(buttonWidth, NSWidth([button frame])); |
| 1240 | 1250 |
| 1241 // Check button spacing. | 1251 // Check button spacing. |
| 1242 [folderController validateMenuSpacing]; | 1252 [folderController validateMenuSpacing]; |
| 1243 } | 1253 } |
| 1244 | 1254 |
| 1245 // See http://crbug.com/46101 | 1255 // See http://crbug.com/46101 |
| 1246 TEST_F(BookmarkBarFolderControllerMenuTest, HoverThenDeleteBookmark) { | 1256 TEST_F(BookmarkBarFolderControllerMenuTest, HoverThenDeleteBookmark) { |
| 1247 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); | 1257 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); |
| 1248 const BookmarkNode* root = model.GetBookmarkBarNode(); | 1258 const BookmarkNode* root = model.GetBookmarkBarNode(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 ASSERT_TRUE(targetButton); | 1365 ASSERT_TRUE(targetButton); |
| 1356 newNode = other->GetChild(2); // Should be O4f. | 1366 newNode = other->GetChild(2); // Should be O4f. |
| 1357 EXPECT_EQ(newNode->GetTitle(), ASCIIToUTF16("O4f")); | 1367 EXPECT_EQ(newNode->GetTitle(), ASCIIToUTF16("O4f")); |
| 1358 [folderController setDragDataNode:newNode]; | 1368 [folderController setDragDataNode:newNode]; |
| 1359 [dragInfo setDropLocation:[targetButton center]]; | 1369 [dragInfo setDropLocation:[targetButton center]]; |
| 1360 [folderController dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; | 1370 [folderController dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; |
| 1361 | 1371 |
| 1362 // Verify the model. | 1372 // Verify the model. |
| 1363 const std::string expectedA("1b 2f:[ O3f:[ O3f1b O3f2f ] 2f1b 2f2f:[ " | 1373 const std::string expectedA("1b 2f:[ O3f:[ O3f1b O3f2f ] 2f1b 2f2f:[ " |
| 1364 "2f2f1b 2f2f2b 2f2f3b O4f:[ O4f1b O4f2f ] ] " | 1374 "2f2f1b 2f2f2b 2f2f3b O4f:[ O4f1b O4f2f ] ] " |
| 1365 "2f3b ] 3b 4b "); | 1375 "2f3b ] 3b 4b "); |
| 1366 actual = model_test_utils::ModelStringFromNode(root); | 1376 actual = model_test_utils::ModelStringFromNode(root); |
| 1367 EXPECT_EQ(expectedA, actual); | 1377 EXPECT_EQ(expectedA, actual); |
| 1368 | 1378 |
| 1369 // Check button spacing. | 1379 // Check button spacing. |
| 1370 [folderController validateMenuSpacing]; | 1380 [folderController validateMenuSpacing]; |
| 1371 } | 1381 } |
| 1372 | 1382 |
| 1373 TEST_F(BookmarkBarFolderControllerMenuTest, DragBookmarkDataToTrash) { | 1383 TEST_F(BookmarkBarFolderControllerMenuTest, DragBookmarkDataToTrash) { |
| 1374 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); | 1384 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); |
| 1375 const BookmarkNode* root = model.GetBookmarkBarNode(); | 1385 const BookmarkNode* root = model.GetBookmarkBarNode(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 [folder deleteBookmark:folder]; | 1553 [folder deleteBookmark:folder]; |
| 1544 EXPECT_FALSE([folder folderController]); | 1554 EXPECT_FALSE([folder folderController]); |
| 1545 } | 1555 } |
| 1546 | 1556 |
| 1547 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so | 1557 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so |
| 1548 // they are hard to test. Factor out "fire timers" into routines | 1558 // they are hard to test. Factor out "fire timers" into routines |
| 1549 // which can be overridden to fire immediately to make behavior | 1559 // which can be overridden to fire immediately to make behavior |
| 1550 // confirmable. | 1560 // confirmable. |
| 1551 // There is a similar problem with mouseEnteredButton: and | 1561 // There is a similar problem with mouseEnteredButton: and |
| 1552 // mouseExitedButton:. | 1562 // mouseExitedButton:. |
| OLD | NEW |