| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_nsobject.h" | 6 #include "base/mac/scoped_nsobject.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
| 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" |
| 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" | 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" | 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" |
| 15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 16 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 16 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 122 |
| 123 - (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child { | 123 - (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child { |
| 124 [childFolderDelegate_ childFolderWillClose:child]; | 124 [childFolderDelegate_ childFolderWillClose:child]; |
| 125 } | 125 } |
| 126 | 126 |
| 127 @end | 127 @end |
| 128 | 128 |
| 129 | 129 |
| 130 class BookmarkBarFolderControllerTest : public CocoaProfileTest { | 130 class BookmarkBarFolderControllerTest : public CocoaProfileTest { |
| 131 public: | 131 public: |
| 132 scoped_nsobject<BookmarkBarControllerChildFolderRedirect> bar_; | 132 base::scoped_nsobject<BookmarkBarControllerChildFolderRedirect> bar_; |
| 133 const BookmarkNode* folderA_; // Owned by model. | 133 const BookmarkNode* folderA_; // Owned by model. |
| 134 const BookmarkNode* longTitleNode_; // Owned by model. | 134 const BookmarkNode* longTitleNode_; // Owned by model. |
| 135 | 135 |
| 136 virtual void SetUp() { | 136 virtual void SetUp() { |
| 137 CocoaProfileTest::SetUp(); | 137 CocoaProfileTest::SetUp(); |
| 138 ASSERT_TRUE(profile()); | 138 ASSERT_TRUE(profile()); |
| 139 | 139 |
| 140 CreateModel(); | 140 CreateModel(); |
| 141 } | 141 } |
| 142 | 142 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 initWithParentButton:parentButton | 210 initWithParentButton:parentButton |
| 211 parentController:nil | 211 parentController:nil |
| 212 barController:bar_ | 212 barController:bar_ |
| 213 profile:profile()]; | 213 profile:profile()]; |
| 214 [c window]; // Force nib load. | 214 [c window]; // Force nib load. |
| 215 return c; | 215 return c; |
| 216 } | 216 } |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 TEST_F(BookmarkBarFolderControllerTest, InitCreateAndDelete) { | 219 TEST_F(BookmarkBarFolderControllerTest, InitCreateAndDelete) { |
| 220 scoped_nsobject<BookmarkBarFolderController> bbfc; | 220 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 221 bbfc.reset(SimpleBookmarkBarFolderController()); | 221 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 222 | 222 |
| 223 // Make sure none of the buttons overlap, that all are inside | 223 // Make sure none of the buttons overlap, that all are inside |
| 224 // the content frame, and their cells are of the proper class. | 224 // the content frame, and their cells are of the proper class. |
| 225 NSArray* buttons = [bbfc buttons]; | 225 NSArray* buttons = [bbfc buttons]; |
| 226 EXPECT_TRUE([buttons count]); | 226 EXPECT_TRUE([buttons count]); |
| 227 for (unsigned int i = 0; i < ([buttons count]-1); i++) { | 227 for (unsigned int i = 0; i < ([buttons count]-1); i++) { |
| 228 EXPECT_FALSE(NSContainsRect([[buttons objectAtIndex:i] frame], | 228 EXPECT_FALSE(NSContainsRect([[buttons objectAtIndex:i] frame], |
| 229 [[buttons objectAtIndex:i+1] frame])); | 229 [[buttons objectAtIndex:i+1] frame])); |
| 230 } | 230 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 244 if ([button isFolder]) | 244 if ([button isFolder]) |
| 245 EXPECT_FALSE([button toolTip]); | 245 EXPECT_FALSE([button toolTip]); |
| 246 else | 246 else |
| 247 EXPECT_TRUE([button toolTip]); | 247 EXPECT_TRUE([button toolTip]); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 // Make sure closing of the window releases the controller. | 251 // Make sure closing of the window releases the controller. |
| 252 // (e.g. valgrind shouldn't complain if we do this). | 252 // (e.g. valgrind shouldn't complain if we do this). |
| 253 TEST_F(BookmarkBarFolderControllerTest, ReleaseOnClose) { | 253 TEST_F(BookmarkBarFolderControllerTest, ReleaseOnClose) { |
| 254 scoped_nsobject<BookmarkBarFolderController> bbfc; | 254 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 255 bbfc.reset(SimpleBookmarkBarFolderController()); | 255 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 256 EXPECT_TRUE(bbfc.get()); | 256 EXPECT_TRUE(bbfc.get()); |
| 257 | 257 |
| 258 [bbfc retain]; // stop the scoped_nsobject from doing anything | 258 [bbfc retain]; // stop the scoped_nsobject from doing anything |
| 259 [[bbfc window] close]; // trigger an autorelease of bbfc.get() | 259 [[bbfc window] close]; // trigger an autorelease of bbfc.get() |
| 260 } | 260 } |
| 261 | 261 |
| 262 TEST_F(BookmarkBarFolderControllerTest, BasicPosition) { | 262 TEST_F(BookmarkBarFolderControllerTest, BasicPosition) { |
| 263 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; | 263 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; |
| 264 EXPECT_TRUE(parentButton); | 264 EXPECT_TRUE(parentButton); |
| 265 | 265 |
| 266 // If parent is a BookmarkBarController, grow down. | 266 // If parent is a BookmarkBarController, grow down. |
| 267 scoped_nsobject<BookmarkBarFolderController> bbfc; | 267 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 268 bbfc.reset([[BookmarkBarFolderController alloc] | 268 bbfc.reset([[BookmarkBarFolderController alloc] |
| 269 initWithParentButton:parentButton | 269 initWithParentButton:parentButton |
| 270 parentController:nil | 270 parentController:nil |
| 271 barController:bar_ | 271 barController:bar_ |
| 272 profile:profile()]); | 272 profile:profile()]); |
| 273 [bbfc window]; | 273 [bbfc window]; |
| 274 NSPoint pt = [bbfc windowTopLeftForWidth:0 height:100]; // screen coords | 274 NSPoint pt = [bbfc windowTopLeftForWidth:0 height:100]; // screen coords |
| 275 NSPoint buttonOriginInWindow = | 275 NSPoint buttonOriginInWindow = |
| 276 [parentButton convertRect:[parentButton bounds] | 276 [parentButton convertRect:[parentButton bounds] |
| 277 toView:nil].origin; | 277 toView:nil].origin; |
| 278 NSPoint buttonOriginInScreen = | 278 NSPoint buttonOriginInScreen = |
| 279 [[parentButton window] convertBaseToScreen:buttonOriginInWindow]; | 279 [[parentButton window] convertBaseToScreen:buttonOriginInWindow]; |
| 280 // Within margin | 280 // Within margin |
| 281 EXPECT_LE(abs(pt.x - buttonOriginInScreen.x), | 281 EXPECT_LE(abs(pt.x - buttonOriginInScreen.x), |
| 282 bookmarks::kBookmarkMenuOverlap + 1); | 282 bookmarks::kBookmarkMenuOverlap + 1); |
| 283 EXPECT_LE(abs(pt.y - buttonOriginInScreen.y), | 283 EXPECT_LE(abs(pt.y - buttonOriginInScreen.y), |
| 284 bookmarks::kBookmarkMenuOverlap + 1); | 284 bookmarks::kBookmarkMenuOverlap + 1); |
| 285 | 285 |
| 286 // Make sure we see the window shift left if it spills off the screen | 286 // Make sure we see the window shift left if it spills off the screen |
| 287 pt = [bbfc windowTopLeftForWidth:0 height:100]; | 287 pt = [bbfc windowTopLeftForWidth:0 height:100]; |
| 288 NSPoint shifted = [bbfc windowTopLeftForWidth:9999999 height:100]; | 288 NSPoint shifted = [bbfc windowTopLeftForWidth:9999999 height:100]; |
| 289 EXPECT_LT(shifted.x, pt.x); | 289 EXPECT_LT(shifted.x, pt.x); |
| 290 | 290 |
| 291 // If parent is a BookmarkBarFolderController, grow right. | 291 // If parent is a BookmarkBarFolderController, grow right. |
| 292 scoped_nsobject<BookmarkBarFolderController> bbfc2; | 292 base::scoped_nsobject<BookmarkBarFolderController> bbfc2; |
| 293 bbfc2.reset([[BookmarkBarFolderController alloc] | 293 bbfc2.reset([[BookmarkBarFolderController alloc] |
| 294 initWithParentButton:[[bbfc buttons] objectAtIndex:0] | 294 initWithParentButton:[[bbfc buttons] objectAtIndex:0] |
| 295 parentController:bbfc.get() | 295 parentController:bbfc.get() |
| 296 barController:bar_ | 296 barController:bar_ |
| 297 profile:profile()]); | 297 profile:profile()]); |
| 298 [bbfc2 window]; | 298 [bbfc2 window]; |
| 299 pt = [bbfc2 windowTopLeftForWidth:0 height:100]; | 299 pt = [bbfc2 windowTopLeftForWidth:0 height:100]; |
| 300 // We're now overlapping the window a bit. | 300 // We're now overlapping the window a bit. |
| 301 EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) - | 301 EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) - |
| 302 bookmarks::kBookmarkMenuOverlap); | 302 bookmarks::kBookmarkMenuOverlap); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 316 folder = model->AddFolder(folder, 0, ASCIIToUTF16("nested folder")); | 316 folder = model->AddFolder(folder, 0, ASCIIToUTF16("nested folder")); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Setup initial state for opening all folders. | 319 // Setup initial state for opening all folders. |
| 320 folder = parent; | 320 folder = parent; |
| 321 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; | 321 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; |
| 322 BookmarkBarFolderController* parentController = nil; | 322 BookmarkBarFolderController* parentController = nil; |
| 323 EXPECT_TRUE(parentButton); | 323 EXPECT_TRUE(parentButton); |
| 324 | 324 |
| 325 // Open them all. | 325 // Open them all. |
| 326 scoped_nsobject<NSMutableArray> folder_controller_array; | 326 base::scoped_nsobject<NSMutableArray> folder_controller_array; |
| 327 folder_controller_array.reset([[NSMutableArray array] retain]); | 327 folder_controller_array.reset([[NSMutableArray array] retain]); |
| 328 for (i=0; i<count; i++) { | 328 for (i=0; i<count; i++) { |
| 329 BookmarkBarFolderControllerNoLevel* bbfcl = | 329 BookmarkBarFolderControllerNoLevel* bbfcl = |
| 330 [[BookmarkBarFolderControllerNoLevel alloc] | 330 [[BookmarkBarFolderControllerNoLevel alloc] |
| 331 initWithParentButton:parentButton | 331 initWithParentButton:parentButton |
| 332 parentController:parentController | 332 parentController:parentController |
| 333 barController:bar_ | 333 barController:bar_ |
| 334 profile:profile()]; | 334 profile:profile()]; |
| 335 [folder_controller_array addObject:bbfcl]; | 335 [folder_controller_array addObject:bbfcl]; |
| 336 [bbfcl autorelease]; | 336 [bbfcl autorelease]; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 361 i = j; | 361 i = j; |
| 362 | 362 |
| 363 // Finally, confirm we see a "grow right" once more. | 363 // Finally, confirm we see a "grow right" once more. |
| 364 while (leftPositions[i] < leftPositions[i-1]) | 364 while (leftPositions[i] < leftPositions[i-1]) |
| 365 i++; | 365 i++; |
| 366 // (No need to EXPECT a final "grow right"; if we didn't find one | 366 // (No need to EXPECT a final "grow right"; if we didn't find one |
| 367 // we'd get a C++ array bounds exception). | 367 // we'd get a C++ array bounds exception). |
| 368 } | 368 } |
| 369 | 369 |
| 370 TEST_F(BookmarkBarFolderControllerTest, DropDestination) { | 370 TEST_F(BookmarkBarFolderControllerTest, DropDestination) { |
| 371 scoped_nsobject<BookmarkBarFolderController> bbfc; | 371 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 372 bbfc.reset(SimpleBookmarkBarFolderController()); | 372 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 373 EXPECT_TRUE(bbfc.get()); | 373 EXPECT_TRUE(bbfc.get()); |
| 374 | 374 |
| 375 // Confirm "off the top" and "off the bottom" match no buttons. | 375 // Confirm "off the top" and "off the bottom" match no buttons. |
| 376 NSPoint p = NSMakePoint(NSMidX([[bbfc folderView] frame]), 10000); | 376 NSPoint p = NSMakePoint(NSMidX([[bbfc folderView] frame]), 10000); |
| 377 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); | 377 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); |
| 378 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); | 378 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); |
| 379 p = NSMakePoint(NSMidX([[bbfc folderView] frame]), -1); | 379 p = NSMakePoint(NSMidX([[bbfc folderView] frame]), -1); |
| 380 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); | 380 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]); |
| 381 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); | 381 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 397 } else { | 397 } else { |
| 398 // If not a folder we don't drop into it. | 398 // If not a folder we don't drop into it. |
| 399 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:NSMakePoint(x-1, y+1)]); | 399 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:NSMakePoint(x-1, y+1)]); |
| 400 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:NSMakePoint(x+1, y-1)]); | 400 EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:NSMakePoint(x+1, y-1)]); |
| 401 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:NSMakePoint(x, y)]);; | 401 EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:NSMakePoint(x, y)]);; |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 TEST_F(BookmarkBarFolderControllerTest, OpenFolder) { | 406 TEST_F(BookmarkBarFolderControllerTest, OpenFolder) { |
| 407 scoped_nsobject<BookmarkBarFolderController> bbfc; | 407 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 408 bbfc.reset(SimpleBookmarkBarFolderController()); | 408 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 409 EXPECT_TRUE(bbfc.get()); | 409 EXPECT_TRUE(bbfc.get()); |
| 410 | 410 |
| 411 EXPECT_FALSE([bbfc folderController]); | 411 EXPECT_FALSE([bbfc folderController]); |
| 412 BookmarkButton* button = [[bbfc buttons] objectAtIndex:0]; | 412 BookmarkButton* button = [[bbfc buttons] objectAtIndex:0]; |
| 413 [bbfc openBookmarkFolderFromButton:button]; | 413 [bbfc openBookmarkFolderFromButton:button]; |
| 414 id controller = [bbfc folderController]; | 414 id controller = [bbfc folderController]; |
| 415 EXPECT_TRUE(controller); | 415 EXPECT_TRUE(controller); |
| 416 EXPECT_EQ([controller parentButton], button); | 416 EXPECT_EQ([controller parentButton], button); |
| 417 | 417 |
| 418 // Click the same one --> it gets closed. | 418 // Click the same one --> it gets closed. |
| 419 [bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:0]]; | 419 [bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:0]]; |
| 420 EXPECT_FALSE([bbfc folderController]); | 420 EXPECT_FALSE([bbfc folderController]); |
| 421 | 421 |
| 422 // Open a new one --> change. | 422 // Open a new one --> change. |
| 423 [bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:1]]; | 423 [bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:1]]; |
| 424 EXPECT_NE(controller, [bbfc folderController]); | 424 EXPECT_NE(controller, [bbfc folderController]); |
| 425 EXPECT_NE([[bbfc folderController] parentButton], button); | 425 EXPECT_NE([[bbfc folderController] parentButton], button); |
| 426 | 426 |
| 427 // Close it --> all gone! | 427 // Close it --> all gone! |
| 428 [bbfc closeBookmarkFolder:nil]; | 428 [bbfc closeBookmarkFolder:nil]; |
| 429 EXPECT_FALSE([bbfc folderController]); | 429 EXPECT_FALSE([bbfc folderController]); |
| 430 } | 430 } |
| 431 | 431 |
| 432 TEST_F(BookmarkBarFolderControllerTest, DeleteOpenFolder) { | 432 TEST_F(BookmarkBarFolderControllerTest, DeleteOpenFolder) { |
| 433 scoped_nsobject<BookmarkBarFolderController> parent_controller( | 433 base::scoped_nsobject<BookmarkBarFolderController> parent_controller( |
| 434 SimpleBookmarkBarFolderController()); | 434 SimpleBookmarkBarFolderController()); |
| 435 | 435 |
| 436 // Open a folder. | 436 // Open a folder. |
| 437 EXPECT_FALSE([parent_controller folderController]); | 437 EXPECT_FALSE([parent_controller folderController]); |
| 438 BookmarkButton* button = [[parent_controller buttons] objectAtIndex:0]; | 438 BookmarkButton* button = [[parent_controller buttons] objectAtIndex:0]; |
| 439 [parent_controller openBookmarkFolderFromButton:button]; | 439 [parent_controller openBookmarkFolderFromButton:button]; |
| 440 EXPECT_EQ([[parent_controller folderController] parentButton], button); | 440 EXPECT_EQ([[parent_controller folderController] parentButton], button); |
| 441 | 441 |
| 442 // Delete the folder's button - the folder should close. | 442 // Delete the folder's button - the folder should close. |
| 443 [parent_controller removeButton:0 animate:NO]; | 443 [parent_controller removeButton:0 animate:NO]; |
| 444 EXPECT_FALSE([parent_controller folderController]); | 444 EXPECT_FALSE([parent_controller folderController]); |
| 445 } | 445 } |
| 446 | 446 |
| 447 TEST_F(BookmarkBarFolderControllerTest, ChildFolderCallbacks) { | 447 TEST_F(BookmarkBarFolderControllerTest, ChildFolderCallbacks) { |
| 448 scoped_nsobject<BookmarkBarFolderControllerPong> bbfc; | 448 base::scoped_nsobject<BookmarkBarFolderControllerPong> bbfc; |
| 449 bbfc.reset(SimpleBookmarkBarFolderController()); | 449 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 450 EXPECT_TRUE(bbfc.get()); | 450 EXPECT_TRUE(bbfc.get()); |
| 451 [bar_ setChildFolderDelegate:bbfc.get()]; | 451 [bar_ setChildFolderDelegate:bbfc.get()]; |
| 452 | 452 |
| 453 EXPECT_FALSE([bbfc childFolderWillShow]); | 453 EXPECT_FALSE([bbfc childFolderWillShow]); |
| 454 [bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:0]]; | 454 [bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:0]]; |
| 455 EXPECT_TRUE([bbfc childFolderWillShow]); | 455 EXPECT_TRUE([bbfc childFolderWillShow]); |
| 456 | 456 |
| 457 EXPECT_FALSE([bbfc childFolderWillClose]); | 457 EXPECT_FALSE([bbfc childFolderWillClose]); |
| 458 [bbfc closeBookmarkFolder:nil]; | 458 [bbfc closeBookmarkFolder:nil]; |
| 459 EXPECT_TRUE([bbfc childFolderWillClose]); | 459 EXPECT_TRUE([bbfc childFolderWillClose]); |
| 460 | 460 |
| 461 [bar_ setChildFolderDelegate:nil]; | 461 [bar_ setChildFolderDelegate:nil]; |
| 462 } | 462 } |
| 463 | 463 |
| 464 // Make sure bookmark folders have variable widths. | 464 // Make sure bookmark folders have variable widths. |
| 465 TEST_F(BookmarkBarFolderControllerTest, ChildFolderWidth) { | 465 TEST_F(BookmarkBarFolderControllerTest, ChildFolderWidth) { |
| 466 scoped_nsobject<BookmarkBarFolderController> bbfc; | 466 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 467 | 467 |
| 468 bbfc.reset(SimpleBookmarkBarFolderController()); | 468 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 469 EXPECT_TRUE(bbfc.get()); | 469 EXPECT_TRUE(bbfc.get()); |
| 470 [bbfc showWindow:bbfc.get()]; | 470 [bbfc showWindow:bbfc.get()]; |
| 471 CGFloat wideWidth = NSWidth([[bbfc window] frame]); | 471 CGFloat wideWidth = NSWidth([[bbfc window] frame]); |
| 472 | 472 |
| 473 RemoveLongTitleNode(); | 473 RemoveLongTitleNode(); |
| 474 bbfc.reset(SimpleBookmarkBarFolderController()); | 474 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 475 EXPECT_TRUE(bbfc.get()); | 475 EXPECT_TRUE(bbfc.get()); |
| 476 CGFloat thinWidth = NSWidth([[bbfc window] frame]); | 476 CGFloat thinWidth = NSWidth([[bbfc window] frame]); |
| 477 | 477 |
| 478 // Make sure window size changed as expected. | 478 // Make sure window size changed as expected. |
| 479 EXPECT_GT(wideWidth, thinWidth); | 479 EXPECT_GT(wideWidth, thinWidth); |
| 480 } | 480 } |
| 481 | 481 |
| 482 // Simple scrolling tests. | 482 // Simple scrolling tests. |
| 483 // Currently flaky due to a changed definition of the correct menu boundaries. | 483 // Currently flaky due to a changed definition of the correct menu boundaries. |
| 484 TEST_F(BookmarkBarFolderControllerTest, DISABLED_SimpleScroll) { | 484 TEST_F(BookmarkBarFolderControllerTest, DISABLED_SimpleScroll) { |
| 485 scoped_nsobject<BookmarkBarFolderController> bbfc; | 485 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 486 NSRect screenFrame = [[NSScreen mainScreen] visibleFrame]; | 486 NSRect screenFrame = [[NSScreen mainScreen] visibleFrame]; |
| 487 CGFloat screenHeight = NSHeight(screenFrame); | 487 CGFloat screenHeight = NSHeight(screenFrame); |
| 488 int nodecount = AddLotsOfNodes(); | 488 int nodecount = AddLotsOfNodes(); |
| 489 bbfc.reset(SimpleBookmarkBarFolderController()); | 489 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 490 EXPECT_TRUE(bbfc.get()); | 490 EXPECT_TRUE(bbfc.get()); |
| 491 [bbfc showWindow:bbfc.get()]; | 491 [bbfc showWindow:bbfc.get()]; |
| 492 NSWindow* window = [bbfc window]; | 492 NSWindow* window = [bbfc window]; |
| 493 | 493 |
| 494 // The window should be shorter than the screen but reach exactly to the | 494 // The window should be shorter than the screen but reach exactly to the |
| 495 // bottom of the screen since it's scrollable. | 495 // bottom of the screen since it's scrollable. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 EXPECT_TRUE(NSContainsRect(wholeScreenRect, [window frame])); | 565 EXPECT_TRUE(NSContainsRect(wholeScreenRect, [window frame])); |
| 566 } | 566 } |
| 567 | 567 |
| 568 EXPECT_GT(NSHeight(wholeScreenRect), NSHeight([window frame])); | 568 EXPECT_GT(NSHeight(wholeScreenRect), NSHeight([window frame])); |
| 569 EXPECT_TRUE(NSContainsRect(wholeScreenRect, [window frame])); | 569 EXPECT_TRUE(NSContainsRect(wholeScreenRect, [window frame])); |
| 570 } | 570 } |
| 571 | 571 |
| 572 // Folder menu sizing and placement while deleting bookmarks | 572 // Folder menu sizing and placement while deleting bookmarks |
| 573 // and scrolling tests. | 573 // and scrolling tests. |
| 574 TEST_F(BookmarkBarFolderControllerTest, MenuPlacementWhileScrollingDeleting) { | 574 TEST_F(BookmarkBarFolderControllerTest, MenuPlacementWhileScrollingDeleting) { |
| 575 scoped_nsobject<BookmarkBarFolderController> bbfc; | 575 base::scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 576 AddLotsOfNodes(); | 576 AddLotsOfNodes(); |
| 577 bbfc.reset(SimpleBookmarkBarFolderController()); | 577 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 578 [bbfc showWindow:bbfc.get()]; | 578 [bbfc showWindow:bbfc.get()]; |
| 579 NSWindow* menuWindow = [bbfc window]; | 579 NSWindow* menuWindow = [bbfc window]; |
| 580 BookmarkBarFolderController* folder = [bar_ folderController]; | 580 BookmarkBarFolderController* folder = [bar_ folderController]; |
| 581 NSArray* buttons = [folder buttons]; | 581 NSArray* buttons = [folder buttons]; |
| 582 | 582 |
| 583 // Before scrolling any, delete a bookmark and make sure the window top has | 583 // Before scrolling any, delete a bookmark and make sure the window top has |
| 584 // not moved. Pick a button which is near the top and visible. | 584 // not moved. Pick a button which is near the top and visible. |
| 585 CGFloat oldTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 585 CGFloat oldTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 --buttonCounter; | 618 --buttonCounter; |
| 619 } | 619 } |
| 620 button = [buttons objectAtIndex:buttonCounter + 3]; | 620 button = [buttons objectAtIndex:buttonCounter + 3]; |
| 621 DeleteBookmark(button, profile()); | 621 DeleteBookmark(button, profile()); |
| 622 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 622 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
| 623 EXPECT_CGFLOAT_EQ(oldTop - bookmarks::kScrollWindowVerticalMargin, newTop); | 623 EXPECT_CGFLOAT_EQ(oldTop - bookmarks::kScrollWindowVerticalMargin, newTop); |
| 624 } | 624 } |
| 625 | 625 |
| 626 // Make sure that we return the correct browser window. | 626 // Make sure that we return the correct browser window. |
| 627 TEST_F(BookmarkBarFolderControllerTest, BrowserWindow) { | 627 TEST_F(BookmarkBarFolderControllerTest, BrowserWindow) { |
| 628 scoped_nsobject<BookmarkBarFolderController> controller( | 628 base::scoped_nsobject<BookmarkBarFolderController> controller( |
| 629 SimpleBookmarkBarFolderController()); | 629 SimpleBookmarkBarFolderController()); |
| 630 EXPECT_EQ([bar_ browserWindow], [controller browserWindow]); | 630 EXPECT_EQ([bar_ browserWindow], [controller browserWindow]); |
| 631 } | 631 } |
| 632 | 632 |
| 633 @interface FakedDragInfo : NSObject { | 633 @interface FakedDragInfo : NSObject { |
| 634 @public | 634 @public |
| 635 NSPoint dropLocation_; | 635 NSPoint dropLocation_; |
| 636 NSDragOperation sourceMask_; | 636 NSDragOperation sourceMask_; |
| 637 } | 637 } |
| 638 @property (nonatomic, assign) NSPoint dropLocation; | 638 @property (nonatomic, assign) NSPoint dropLocation; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 673 |
| 674 - (void)setDraggingSourceOperationMask:(NSDragOperation)mask { | 674 - (void)setDraggingSourceOperationMask:(NSDragOperation)mask { |
| 675 sourceMask_ = mask; | 675 sourceMask_ = mask; |
| 676 } | 676 } |
| 677 | 677 |
| 678 @end | 678 @end |
| 679 | 679 |
| 680 | 680 |
| 681 class BookmarkBarFolderControllerMenuTest : public CocoaProfileTest { | 681 class BookmarkBarFolderControllerMenuTest : public CocoaProfileTest { |
| 682 public: | 682 public: |
| 683 scoped_nsobject<NSView> parent_view_; | 683 base::scoped_nsobject<NSView> parent_view_; |
| 684 scoped_nsobject<ViewResizerPong> resizeDelegate_; | 684 base::scoped_nsobject<ViewResizerPong> resizeDelegate_; |
| 685 scoped_nsobject<BookmarkBarController> bar_; | 685 base::scoped_nsobject<BookmarkBarController> bar_; |
| 686 | 686 |
| 687 virtual void SetUp() { | 687 virtual void SetUp() { |
| 688 CocoaProfileTest::SetUp(); | 688 CocoaProfileTest::SetUp(); |
| 689 ASSERT_TRUE(browser()); | 689 ASSERT_TRUE(browser()); |
| 690 | 690 |
| 691 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 691 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
| 692 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 692 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
| 693 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); | 693 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); |
| 694 [parent_view_ setHidden:YES]; | 694 [parent_view_ setHidden:YES]; |
| 695 bar_.reset([[BookmarkBarController alloc] | 695 bar_.reset([[BookmarkBarController alloc] |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 model_test_utils::AddNodesFromModelString(model, other, other_string); | 1372 model_test_utils::AddNodesFromModelString(model, other, other_string); |
| 1373 | 1373 |
| 1374 // Validate initial model. | 1374 // Validate initial model. |
| 1375 std::string actual = model_test_utils::ModelStringFromNode(root); | 1375 std::string actual = model_test_utils::ModelStringFromNode(root); |
| 1376 EXPECT_EQ(model_string, actual); | 1376 EXPECT_EQ(model_string, actual); |
| 1377 actual = model_test_utils::ModelStringFromNode(other); | 1377 actual = model_test_utils::ModelStringFromNode(other); |
| 1378 EXPECT_EQ(other_string, actual); | 1378 EXPECT_EQ(other_string, actual); |
| 1379 | 1379 |
| 1380 // Pop open a folder. | 1380 // Pop open a folder. |
| 1381 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; | 1381 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; |
| 1382 scoped_nsobject<BookmarkBarFolderControllerDragData> folderController; | 1382 base::scoped_nsobject<BookmarkBarFolderControllerDragData> folderController; |
| 1383 folderController.reset([[BookmarkBarFolderControllerDragData alloc] | 1383 folderController.reset([[BookmarkBarFolderControllerDragData alloc] |
| 1384 initWithParentButton:button | 1384 initWithParentButton:button |
| 1385 parentController:nil | 1385 parentController:nil |
| 1386 barController:bar_ | 1386 barController:bar_ |
| 1387 profile:profile()]); | 1387 profile:profile()]); |
| 1388 BookmarkButton* targetButton = | 1388 BookmarkButton* targetButton = |
| 1389 [folderController buttonWithTitleEqualTo:@"2f1b"]; | 1389 [folderController buttonWithTitleEqualTo:@"2f1b"]; |
| 1390 ASSERT_TRUE(targetButton); | 1390 ASSERT_TRUE(targetButton); |
| 1391 | 1391 |
| 1392 // Gen up some dragging data. | 1392 // Gen up some dragging data. |
| 1393 const BookmarkNode* newNode = other->GetChild(2); | 1393 const BookmarkNode* newNode = other->GetChild(2); |
| 1394 [folderController setDragDataNode:newNode]; | 1394 [folderController setDragDataNode:newNode]; |
| 1395 scoped_nsobject<FakedDragInfo> dragInfo([[FakedDragInfo alloc] init]); | 1395 base::scoped_nsobject<FakedDragInfo> dragInfo([[FakedDragInfo alloc] init]); |
| 1396 [dragInfo setDropLocation:[targetButton top]]; | 1396 [dragInfo setDropLocation:[targetButton top]]; |
| 1397 [folderController dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; | 1397 [folderController dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; |
| 1398 | 1398 |
| 1399 // Verify the model. | 1399 // Verify the model. |
| 1400 const std::string expected("1b 2f:[ O3f:[ O3f1b O3f2f ] 2f1b 2f2f:[ 2f2f1b " | 1400 const std::string expected("1b 2f:[ O3f:[ O3f1b O3f2f ] 2f1b 2f2f:[ 2f2f1b " |
| 1401 "2f2f2b 2f2f3b ] 2f3b ] 3b 4b "); | 1401 "2f2f2b 2f2f3b ] 2f3b ] 3b 4b "); |
| 1402 actual = model_test_utils::ModelStringFromNode(root); | 1402 actual = model_test_utils::ModelStringFromNode(root); |
| 1403 EXPECT_EQ(expected, actual); | 1403 EXPECT_EQ(expected, actual); |
| 1404 | 1404 |
| 1405 // Now drag over a folder button. | 1405 // Now drag over a folder button. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1431 | 1431 |
| 1432 // Validate initial model. | 1432 // Validate initial model. |
| 1433 std::string actual = model_test_utils::ModelStringFromNode(root); | 1433 std::string actual = model_test_utils::ModelStringFromNode(root); |
| 1434 EXPECT_EQ(model_string, actual); | 1434 EXPECT_EQ(model_string, actual); |
| 1435 | 1435 |
| 1436 const BookmarkNode* folderNode = root->GetChild(1); | 1436 const BookmarkNode* folderNode = root->GetChild(1); |
| 1437 int oldFolderChildCount = folderNode->child_count(); | 1437 int oldFolderChildCount = folderNode->child_count(); |
| 1438 | 1438 |
| 1439 // Pop open a folder. | 1439 // Pop open a folder. |
| 1440 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; | 1440 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; |
| 1441 scoped_nsobject<BookmarkBarFolderControllerDragData> folderController; | 1441 base::scoped_nsobject<BookmarkBarFolderControllerDragData> folderController; |
| 1442 folderController.reset([[BookmarkBarFolderControllerDragData alloc] | 1442 folderController.reset([[BookmarkBarFolderControllerDragData alloc] |
| 1443 initWithParentButton:button | 1443 initWithParentButton:button |
| 1444 parentController:nil | 1444 parentController:nil |
| 1445 barController:bar_ | 1445 barController:bar_ |
| 1446 profile:profile()]); | 1446 profile:profile()]); |
| 1447 | 1447 |
| 1448 // Drag a button to the trash. | 1448 // Drag a button to the trash. |
| 1449 BookmarkButton* buttonToDelete = | 1449 BookmarkButton* buttonToDelete = |
| 1450 [folderController buttonWithTitleEqualTo:@"2f1b"]; | 1450 [folderController buttonWithTitleEqualTo:@"2f1b"]; |
| 1451 ASSERT_TRUE(buttonToDelete); | 1451 ASSERT_TRUE(buttonToDelete); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 DeleteBookmark([folder parentButton], profile()); | 1599 DeleteBookmark([folder parentButton], profile()); |
| 1600 EXPECT_FALSE([folder folderController]); | 1600 EXPECT_FALSE([folder folderController]); |
| 1601 } | 1601 } |
| 1602 | 1602 |
| 1603 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so | 1603 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so |
| 1604 // they are hard to test. Factor out "fire timers" into routines | 1604 // they are hard to test. Factor out "fire timers" into routines |
| 1605 // which can be overridden to fire immediately to make behavior | 1605 // which can be overridden to fire immediately to make behavior |
| 1606 // confirmable. | 1606 // confirmable. |
| 1607 // There is a similar problem with mouseEnteredButton: and | 1607 // There is a similar problem with mouseEnteredButton: and |
| 1608 // mouseExitedButton:. | 1608 // mouseExitedButton:. |
| OLD | NEW |