| 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 #import "chrome/browser/cocoa/bookmark_bar_constants.h" // namespace bookmarks | 9 #import "chrome/browser/cocoa/bookmark_bar_constants.h" // namespace bookmarks |
| 10 #import "chrome/browser/cocoa/bookmark_bar_controller.h" | 10 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 // We don't have a real BookmarkBarController as our parent root so | 76 // We don't have a real BookmarkBarController as our parent root so |
| 77 // we fake this one out. | 77 // we fake this one out. |
| 78 - (void)closeAllBookmarkFolders { | 78 - (void)closeAllBookmarkFolders { |
| 79 [self closeBookmarkFolder:self]; | 79 [self closeBookmarkFolder:self]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 @end | 82 @end |
| 83 | 83 |
| 84 namespace { |
| 85 const int kLotsOfNodesCount = 150; |
| 86 }; |
| 87 |
| 84 class BookmarkBarFolderControllerTest : public CocoaTest { | 88 class BookmarkBarFolderControllerTest : public CocoaTest { |
| 85 public: | 89 public: |
| 86 BrowserTestHelper helper_; | 90 BrowserTestHelper helper_; |
| 87 scoped_nsobject<BookmarkBarController> parentBarController_; | 91 scoped_nsobject<BookmarkBarController> parentBarController_; |
| 88 const BookmarkNode* folderA_; // owned by model | 92 const BookmarkNode* folderA_; // owned by model |
| 89 const BookmarkNode* longTitleNode_; // owned by model | 93 const BookmarkNode* longTitleNode_; // owned by model |
| 90 | 94 |
| 91 BookmarkBarFolderControllerTest() { | 95 BookmarkBarFolderControllerTest() { |
| 92 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 96 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
| 93 const BookmarkNode* parent = model->GetBookmarkBarNode(); | 97 const BookmarkNode* parent = model->GetBookmarkBarNode(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 123 } | 127 } |
| 124 | 128 |
| 125 // Remove the bookmark with the long title. | 129 // Remove the bookmark with the long title. |
| 126 void RemoveLongTitleNode() { | 130 void RemoveLongTitleNode() { |
| 127 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 131 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
| 128 model->Remove(longTitleNode_->GetParent(), | 132 model->Remove(longTitleNode_->GetParent(), |
| 129 longTitleNode_->GetParent()->IndexOfChild(longTitleNode_)); | 133 longTitleNode_->GetParent()->IndexOfChild(longTitleNode_)); |
| 130 } | 134 } |
| 131 | 135 |
| 132 // Add LOTS of nodes to our model if needed (e.g. scrolling). | 136 // Add LOTS of nodes to our model if needed (e.g. scrolling). |
| 133 void AddLotsOfNodes() { | 137 // Returns the number of nodes added. |
| 138 int AddLotsOfNodes() { |
| 134 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 139 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
| 135 for (int i = 0; i < 150; i++) { | 140 for (int i = 0; i < kLotsOfNodesCount; i++) { |
| 136 model->AddURL(folderA_, folderA_->GetChildCount(), L"repeated title", | 141 model->AddURL(folderA_, folderA_->GetChildCount(), L"repeated title", |
| 137 GURL("http://www.google.com/repeated/url")); | 142 GURL("http://www.google.com/repeated/url")); |
| 138 } | 143 } |
| 144 return kLotsOfNodesCount; |
| 139 } | 145 } |
| 140 | 146 |
| 141 | 147 |
| 142 // Return a simple BookmarkBarFolderController. | 148 // Return a simple BookmarkBarFolderController. |
| 143 BookmarkBarFolderController* SimpleBookmarkBarFolderController() { | 149 BookmarkBarFolderController* SimpleBookmarkBarFolderController() { |
| 144 BookmarkButton* parentButton = [[parentBarController_ buttons] | 150 BookmarkButton* parentButton = [[parentBarController_ buttons] |
| 145 objectAtIndex:0]; | 151 objectAtIndex:0]; |
| 146 BookmarkBarFolderController* c = | 152 BookmarkBarFolderController* c = |
| 147 [[BookmarkBarFolderControllerPong alloc] | 153 [[BookmarkBarFolderControllerPong alloc] |
| 148 initWithParentButton:parentButton | 154 initWithParentButton:parentButton |
| 149 parentController:nil | 155 parentController:nil |
| 150 barController:parentBarController_]; | 156 barController:parentBarController_]; |
| 151 [c window]; // Force nib load. | 157 [c window]; // Force nib load. |
| 152 return c; | 158 return c; |
| 153 } | 159 } |
| 154 | |
| 155 }; | 160 }; |
| 156 | 161 |
| 157 TEST_F(BookmarkBarFolderControllerTest, InitCreateAndDelete) { | 162 TEST_F(BookmarkBarFolderControllerTest, InitCreateAndDelete) { |
| 158 scoped_nsobject<BookmarkBarFolderController> bbfc; | 163 scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 159 bbfc.reset(SimpleBookmarkBarFolderController()); | 164 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 160 | 165 |
| 161 // Make sure none of the buttons overlap, that all are inside | 166 // Make sure none of the buttons overlap, that all are inside |
| 162 // the content frame, and their cells are of the proper class. | 167 // the content frame, and their cells are of the proper class. |
| 163 NSArray* buttons = [bbfc buttons]; | 168 NSArray* buttons = [bbfc buttons]; |
| 164 EXPECT_TRUE([buttons count]); | 169 EXPECT_TRUE([buttons count]); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 CGFloat thinWidth = NSWidth([[bbfc window] frame]); | 326 CGFloat thinWidth = NSWidth([[bbfc window] frame]); |
| 322 | 327 |
| 323 // Make sure window size changed as expected. | 328 // Make sure window size changed as expected. |
| 324 EXPECT_GT(wideWidth, thinWidth); | 329 EXPECT_GT(wideWidth, thinWidth); |
| 325 } | 330 } |
| 326 | 331 |
| 327 // Simple scrolling tests. | 332 // Simple scrolling tests. |
| 328 TEST_F(BookmarkBarFolderControllerTest, SimpleScroll) { | 333 TEST_F(BookmarkBarFolderControllerTest, SimpleScroll) { |
| 329 scoped_nsobject<BookmarkBarFolderController> bbfc; | 334 scoped_nsobject<BookmarkBarFolderController> bbfc; |
| 330 | 335 |
| 331 AddLotsOfNodes(); | 336 int nodecount = AddLotsOfNodes(); |
| 332 bbfc.reset(SimpleBookmarkBarFolderController()); | 337 bbfc.reset(SimpleBookmarkBarFolderController()); |
| 333 EXPECT_TRUE(bbfc.get()); | 338 EXPECT_TRUE(bbfc.get()); |
| 334 [bbfc showWindow:bbfc.get()]; | 339 [bbfc showWindow:bbfc.get()]; |
| 335 | 340 |
| 336 // Make sure the window fits on the screen. | 341 // Make sure the window fits on the screen. |
| 337 EXPECT_LT(NSHeight([[bbfc window] frame]), | 342 EXPECT_LT(NSHeight([[bbfc window] frame]), |
| 338 NSHeight([[NSScreen mainScreen] frame])); | 343 NSHeight([[NSScreen mainScreen] frame])); |
| 339 | 344 |
| 345 // Verify the logic used by the scroll arrow code. |
| 346 EXPECT_TRUE([bbfc canScrollUp]); |
| 347 EXPECT_FALSE([bbfc canScrollDown]); |
| 348 |
| 340 // Scroll it up. Make sure the window has gotten bigger each time. | 349 // Scroll it up. Make sure the window has gotten bigger each time. |
| 341 // Also, for each scroll, make sure our hit test finds a new button | 350 // Also, for each scroll, make sure our hit test finds a new button |
| 342 // (to confirm the content area changed). | 351 // (to confirm the content area changed). |
| 343 NSView* savedHit = nil; | 352 NSView* savedHit = nil; |
| 344 for (int i=0; i<3; i++) { | 353 for (int i=0; i<3; i++) { |
| 345 CGFloat height = NSHeight([[bbfc window] frame]); | 354 CGFloat height = NSHeight([[bbfc window] frame]); |
| 346 [bbfc performOneScroll:60]; | 355 [bbfc performOneScroll:60]; |
| 347 EXPECT_GT(NSHeight([[bbfc window] frame]), height); | 356 EXPECT_GT(NSHeight([[bbfc window] frame]), height); |
| 348 NSView* hit = [[[bbfc window] contentView] hitTest:NSMakePoint(10, 10)]; | 357 NSView* hit = [[[bbfc window] contentView] hitTest:NSMakePoint(22, 22)]; |
| 349 EXPECT_NE(hit, savedHit); | 358 EXPECT_NE(hit, savedHit); |
| 350 savedHit = hit; | 359 savedHit = hit; |
| 351 } | 360 } |
| 352 | 361 |
| 353 // Keep scrolling up; make sure we never get bigger than the screen. | 362 // Keep scrolling up; make sure we never get bigger than the screen. |
| 354 // Also confirm we never scroll the window off the screen. | 363 // Also confirm we never scroll the window off the screen. |
| 364 bool bothAtOnce = false; |
| 355 NSRect screenFrame = [[NSScreen mainScreen] frame]; | 365 NSRect screenFrame = [[NSScreen mainScreen] frame]; |
| 356 for (int i=0; i<100; i++) { | 366 for (int i = 0; i < nodecount; i++) { |
| 357 [bbfc performOneScroll:60]; | 367 [bbfc performOneScroll:60]; |
| 358 EXPECT_TRUE(NSContainsRect(screenFrame, | 368 EXPECT_TRUE(NSContainsRect(screenFrame, |
| 359 [[bbfc window] frame])); | 369 [[bbfc window] frame])); |
| 370 // Make sure, sometime during our scroll, we have the ability to |
| 371 // scroll in either direction. |
| 372 if ([bbfc canScrollUp] && |
| 373 [bbfc canScrollDown]) |
| 374 bothAtOnce = true; |
| 360 } | 375 } |
| 376 EXPECT_TRUE(bothAtOnce); |
| 377 |
| 378 // Once we've scrolled to the end, our only option should be to scroll back. |
| 379 EXPECT_FALSE([bbfc canScrollUp]); |
| 380 EXPECT_TRUE([bbfc canScrollDown]); |
| 361 | 381 |
| 362 // Now scroll down and make sure the window size does not change. | 382 // Now scroll down and make sure the window size does not change. |
| 363 // Also confirm we never scroll the window off the screen the other | 383 // Also confirm we never scroll the window off the screen the other |
| 364 // way. | 384 // way. |
| 365 for (int i=0; i<200; i++) { | 385 for (int i=0; i<nodecount+50; i++) { |
| 366 CGFloat height = NSHeight([[bbfc window] frame]); | 386 CGFloat height = NSHeight([[bbfc window] frame]); |
| 367 [bbfc performOneScroll:-60]; | 387 [bbfc performOneScroll:-60]; |
| 368 EXPECT_EQ(height, NSHeight([[bbfc window] frame])); | 388 EXPECT_EQ(height, NSHeight([[bbfc window] frame])); |
| 369 EXPECT_TRUE(NSContainsRect(screenFrame, | 389 EXPECT_TRUE(NSContainsRect(screenFrame, |
| 370 [[bbfc window] frame])); | 390 [[bbfc window] frame])); |
| 371 } | 391 } |
| 372 } | 392 } |
| 373 | 393 |
| 374 class BookmarkBarFolderControllerDragDropTest : public CocoaTest { | 394 class BookmarkBarFolderControllerDragDropTest : public CocoaTest { |
| 375 public: | 395 public: |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 [folder deleteBookmark:folder]; | 957 [folder deleteBookmark:folder]; |
| 938 EXPECT_FALSE([folder folderController]); | 958 EXPECT_FALSE([folder folderController]); |
| 939 } | 959 } |
| 940 | 960 |
| 941 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so | 961 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so |
| 942 // they are hard to test. Factor out "fire timers" into routines | 962 // they are hard to test. Factor out "fire timers" into routines |
| 943 // which can be overridden to fire immediately to make behavior | 963 // which can be overridden to fire immediately to make behavior |
| 944 // confirmable. | 964 // confirmable. |
| 945 // There is a similar problem with mouseEnteredButton: and | 965 // There is a similar problem with mouseEnteredButton: and |
| 946 // mouseExitedButton:. | 966 // mouseExitedButton:. |
| OLD | NEW |