| 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 #import "chrome/browser/cocoa/bookmark_bar_controller.h" | 9 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
| 10 #include "chrome/browser/cocoa/browser_test_helper.h" | 10 #include "chrome/browser/cocoa/browser_test_helper.h" |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 EXPECT_TRUE(first); | 517 EXPECT_TRUE(first); |
| 518 | 518 |
| 519 scoped_nsobject<BookmarkURLOpenerPong> pong([[BookmarkURLOpenerPong alloc] | 519 scoped_nsobject<BookmarkURLOpenerPong> pong([[BookmarkURLOpenerPong alloc] |
| 520 init]); | 520 init]); |
| 521 [bar_ setUrlDelegate:pong.get()]; | 521 [bar_ setUrlDelegate:pong.get()]; |
| 522 [first otherMouseUp:test_event_utils::MakeMouseEvent(NSOtherMouseUp, 0)]; | 522 [first otherMouseUp:test_event_utils::MakeMouseEvent(NSOtherMouseUp, 0)]; |
| 523 EXPECT_EQ(pong.get()->urls_.size(), 1U); | 523 EXPECT_EQ(pong.get()->urls_.size(), 1U); |
| 524 [bar_ setUrlDelegate:nil]; | 524 [bar_ setUrlDelegate:nil]; |
| 525 } | 525 } |
| 526 | 526 |
| 527 TEST_F(BookmarkBarControllerTest, TestBuildOffTheSideMenu) { |
| 528 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
| 529 NSMenu* menu = [bar_ offTheSideMenu]; |
| 530 ASSERT_TRUE(menu); |
| 531 |
| 532 // The bookmark bar should start out with nothing. |
| 533 EXPECT_EQ(0U, [[bar_ buttons] count]); |
| 534 |
| 535 // Make sure things work when there's nothing. Note that there should always |
| 536 // be a blank first menu item. |
| 537 [bar_ buildOffTheSideMenu]; |
| 538 EXPECT_EQ(1, [menu numberOfItems]); |
| 539 |
| 540 // We add lots of bookmarks. At first, we expect nothing to be added to the |
| 541 // off-the-side menu. But once they start getting added, we expect the |
| 542 // remaining ones to be added too. We expect a reasonably substantial number |
| 543 // of items to be added by the end. |
| 544 int num_off_the_side = 0; |
| 545 for (int i = 0; i < 50; i++) { |
| 546 const BookmarkNode* parent = model->GetBookmarkBarNode(); |
| 547 model->AddURL(parent, parent->GetChildCount(), |
| 548 L"very wide title", |
| 549 GURL("http://www.foobar.com/")); |
| 550 [bar_ buildOffTheSideMenu]; |
| 551 |
| 552 if (num_off_the_side) { |
| 553 num_off_the_side++; |
| 554 EXPECT_EQ(1 + num_off_the_side, [menu numberOfItems]); |
| 555 } else { |
| 556 EXPECT_TRUE([menu numberOfItems] == 1 || [menu numberOfItems] == 2); |
| 557 if ([menu numberOfItems] == 2) |
| 558 num_off_the_side++; |
| 559 } |
| 560 } |
| 561 EXPECT_GE(num_off_the_side, 20); |
| 562 |
| 563 // Reset, and check that the built menu is "empty" again. |
| 564 [bar_ clearBookmarkBar]; |
| 565 EXPECT_EQ(0U, [[bar_ buttons] count]); |
| 566 [bar_ buildOffTheSideMenu]; |
| 567 EXPECT_EQ(1, [menu numberOfItems]); |
| 568 } |
| 569 |
| 527 // Cannot test these methods since they simply call a single static | 570 // Cannot test these methods since they simply call a single static |
| 528 // method, BookmarkEditor::Show(), which is impossible to mock. | 571 // method, BookmarkEditor::Show(), which is impossible to mock. |
| 529 // editBookmark:, addPage: | 572 // editBookmark:, addPage: |
| 530 | 573 |
| 531 | 574 |
| 532 } // namespace | 575 } // namespace |
| OLD | NEW |