OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #import "chrome/browser/cocoa/bookmark_bar_constants.h" | 10 #import "chrome/browser/cocoa/bookmark_bar_constants.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 EXPECT_EQ(0, [[bar_ view] frame].size.height); | 211 EXPECT_EQ(0, [[bar_ view] frame].size.height); |
212 } | 212 } |
213 | 213 |
214 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { | 214 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { |
215 helper_.profile()->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false); | 215 helper_.profile()->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false); |
216 | 216 |
217 scoped_nsobject<BookmarkBarControllerTogglePong> bar; | 217 scoped_nsobject<BookmarkBarControllerTogglePong> bar; |
218 bar.reset( | 218 bar.reset( |
219 [[AlwaysNewTabPageBookmarkBarController alloc] | 219 [[AlwaysNewTabPageBookmarkBarController alloc] |
220 initWithBrowser:helper_.browser() | 220 initWithBrowser:helper_.browser() |
221 initialWidth:100 // arbitrary | 221 initialWidth:800 // arbitrary |
222 compressDelegate:compressDelegate_.get() | 222 compressDelegate:compressDelegate_.get() |
223 resizeDelegate:resizeDelegate_.get() | 223 resizeDelegate:resizeDelegate_.get() |
224 urlDelegate:nil]); | 224 urlDelegate:nil]); |
225 InstallAndToggleBar(bar.get()); | 225 InstallAndToggleBar(bar.get()); |
226 | 226 |
227 [bar setBookmarkBarEnabled:NO]; | 227 [bar setBookmarkBarEnabled:NO]; |
228 [bar updateVisibility]; | 228 [bar updateVisibility]; |
229 | 229 |
230 EXPECT_TRUE([bar isVisible]); | 230 EXPECT_TRUE([bar isVisible]); |
231 EXPECT_FALSE([[bar view] isHidden]); | 231 EXPECT_FALSE([[bar view] isHidden]); |
232 EXPECT_GT([resizeDelegate_ height], 0); | 232 EXPECT_GT([resizeDelegate_ height], 0); |
233 EXPECT_GT([[bar view] frame].size.height, 0); | 233 EXPECT_GT([[bar view] frame].size.height, 0); |
| 234 |
| 235 // Make sure no buttons fall off the bar, either now or when resized |
| 236 // bigger or smaller. |
| 237 CGFloat sizes[] = { 300.0, -100.0, 200.0, -420.0 }; |
| 238 CGFloat previousX = 0.0; |
| 239 for (unsigned x = 0; x < arraysize(sizes); x++) { |
| 240 // Confirm the buttons moved from the last check (which may be |
| 241 // init but that's fine). |
| 242 CGFloat newX = [[bar offTheSideButton] frame].origin.x; |
| 243 EXPECT_NE(previousX, newX); |
| 244 previousX = newX; |
| 245 |
| 246 // Confirm the buttons have a reasonable bounds. |
| 247 EXPECT_TRUE(NSContainsRect([[bar buttonView] frame], |
| 248 [[bar offTheSideButton] frame])); |
| 249 EXPECT_TRUE(NSContainsRect([[bar buttonView] frame], |
| 250 [[bar otherBookmarksButton] frame])); |
| 251 |
| 252 // Now move them implicitly. |
| 253 // We confirm FrameChangeNotification works in the next unit test; |
| 254 // we simply assume it works here to resize or reposition the |
| 255 // buttons above. |
| 256 NSRect frame = [[bar view] frame]; |
| 257 frame.size.width += sizes[x]; |
| 258 [[bar view] setFrame:frame]; |
| 259 } |
234 } | 260 } |
235 | 261 |
236 // Make sure we're watching for frame change notifications. | 262 // Make sure we're watching for frame change notifications. |
237 TEST_F(BookmarkBarControllerTest, FrameChangeNotification) { | 263 TEST_F(BookmarkBarControllerTest, FrameChangeNotification) { |
238 scoped_nsobject<BookmarkBarControllerTogglePong> bar; | 264 scoped_nsobject<BookmarkBarControllerTogglePong> bar; |
239 bar.reset( | 265 bar.reset( |
240 [[BookmarkBarControllerTogglePong alloc] | 266 [[BookmarkBarControllerTogglePong alloc] |
241 initWithBrowser:helper_.browser() | 267 initWithBrowser:helper_.browser() |
242 initialWidth:100 // arbitrary | 268 initialWidth:100 // arbitrary |
243 compressDelegate:compressDelegate_.get() | 269 compressDelegate:compressDelegate_.get() |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 EXPECT_TRUE(i == end); | 571 EXPECT_TRUE(i == end); |
546 | 572 |
547 EXPECT_EQ(pong.get()->dispositions_[3], NEW_BACKGROUND_TAB); | 573 EXPECT_EQ(pong.get()->dispositions_[3], NEW_BACKGROUND_TAB); |
548 | 574 |
549 [bar_ setUrlDelegate:nil]; | 575 [bar_ setUrlDelegate:nil]; |
550 } | 576 } |
551 | 577 |
552 // TODO(jrg): write a test to confirm that nodeFavIconLoaded calls | 578 // TODO(jrg): write a test to confirm that nodeFavIconLoaded calls |
553 // checkForBookmarkButtonGrowth:. | 579 // checkForBookmarkButtonGrowth:. |
554 | 580 |
555 // TODO(jrg): Make sure showing the bookmark bar calls loaded: (to | 581 TEST_F(BookmarkBarControllerTest, Cell) { |
556 // process bookmarks) | 582 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
557 TEST_F(BookmarkBarControllerTest, ShowAndLoad) { | 583 [bar_ loaded:model]; |
558 } | |
559 | 584 |
560 // TODO(jrg): Test cellForBookmarkNode: | 585 const BookmarkNode* parent = model->GetBookmarkBarNode(); |
561 TEST_F(BookmarkBarControllerTest, Cell) { | 586 model->AddURL(parent, parent->GetChildCount(), |
562 } | 587 L"supertitle", |
| 588 GURL("http://superfriends.hall-of-justice.edu")); |
| 589 const BookmarkNode* node = parent->GetChild(0); |
563 | 590 |
564 TEST_F(BookmarkBarControllerTest, Contents) { | 591 NSCell* cell = [bar_ cellForBookmarkNode:node]; |
565 // TODO(jrg): addNodesToBar has a LOT of TODOs; when flushed out, write | 592 EXPECT_TRUE(cell); |
566 // appropriate tests. | 593 EXPECT_TRUE([[cell title] isEqual:@"supertitle"]); |
| 594 EXPECT_EQ(node, [[cell representedObject] pointerValue]); |
| 595 |
| 596 // cell is autoreleased; no need to release here |
567 } | 597 } |
568 | 598 |
569 // Test drawing, mostly to ensure nothing leaks or crashes. | 599 // Test drawing, mostly to ensure nothing leaks or crashes. |
570 TEST_F(BookmarkBarControllerTest, Display) { | 600 TEST_F(BookmarkBarControllerTest, Display) { |
571 [[bar_ view] display]; | 601 [[bar_ view] display]; |
572 } | 602 } |
573 | 603 |
574 // Test that middle clicking on a bookmark button results in an open action. | 604 // Test that middle clicking on a bookmark button results in an open action. |
575 TEST_F(BookmarkBarControllerTest, MiddleClick) { | 605 TEST_F(BookmarkBarControllerTest, MiddleClick) { |
576 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 606 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 723 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
694 const BookmarkNode* parent = model->GetBookmarkBarNode(); | 724 const BookmarkNode* parent = model->GetBookmarkBarNode(); |
695 [bar_ addURLs:nsurls withTitles:nstitles at:NSZeroPoint]; | 725 [bar_ addURLs:nsurls withTitles:nstitles at:NSZeroPoint]; |
696 EXPECT_EQ(3, parent->GetChildCount()); | 726 EXPECT_EQ(3, parent->GetChildCount()); |
697 for (int i = 0; i < parent->GetChildCount(); ++i) { | 727 for (int i = 0; i < parent->GetChildCount(); ++i) { |
698 EXPECT_EQ(parent->GetChild(i)->GetURL(), GURL(urls[i])); | 728 EXPECT_EQ(parent->GetChild(i)->GetURL(), GURL(urls[i])); |
699 EXPECT_EQ(parent->GetChild(i)->GetTitle(), titles[i]); | 729 EXPECT_EQ(parent->GetChild(i)->GetTitle(), titles[i]); |
700 } | 730 } |
701 } | 731 } |
702 | 732 |
703 | |
704 // Cannot test these methods since they simply call a single static | |
705 // method, BookmarkEditor::Show(), which is impossible to mock. | |
706 // editBookmark:, addPage: | |
707 | |
708 | |
709 } // namespace | 733 } // namespace |
OLD | NEW |