OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/tabs/tab_strip_model.h" | 5 #include "chrome/browser/tabs/tab_strip_model.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 observer.ClearStates(); | 576 observer.ClearStates(); |
577 } | 577 } |
578 | 578 |
579 // Test Getters | 579 // Test Getters |
580 { | 580 { |
581 EXPECT_EQ(contents2, tabstrip.GetActiveTabContents()); | 581 EXPECT_EQ(contents2, tabstrip.GetActiveTabContents()); |
582 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(0)); | 582 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(0)); |
583 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); | 583 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); |
584 EXPECT_EQ(0, tabstrip.GetIndexOfTabContents(contents2)); | 584 EXPECT_EQ(0, tabstrip.GetIndexOfTabContents(contents2)); |
585 EXPECT_EQ(1, tabstrip.GetIndexOfTabContents(contents1)); | 585 EXPECT_EQ(1, tabstrip.GetIndexOfTabContents(contents1)); |
586 EXPECT_EQ(0, tabstrip.GetIndexOfController(&contents2->controller())); | 586 EXPECT_EQ(0, tabstrip.GetIndexOfController( |
587 EXPECT_EQ(1, tabstrip.GetIndexOfController(&contents1->controller())); | 587 &contents2->tab_contents()->controller())); |
| 588 EXPECT_EQ(1, tabstrip.GetIndexOfController( |
| 589 &contents1->tab_contents()->controller())); |
588 } | 590 } |
589 | 591 |
590 // Test UpdateTabContentsStateAt | 592 // Test UpdateTabContentsStateAt |
591 { | 593 { |
592 tabstrip.UpdateTabContentsStateAt(0, TabStripModelObserver::ALL); | 594 tabstrip.UpdateTabContentsStateAt(0, TabStripModelObserver::ALL); |
593 EXPECT_EQ(1, observer.GetStateCount()); | 595 EXPECT_EQ(1, observer.GetStateCount()); |
594 State s1(contents2, 0, MockTabStripModelObserver::CHANGE); | 596 State s1(contents2, 0, MockTabStripModelObserver::CHANGE); |
595 EXPECT_TRUE(observer.StateEquals(0, s1)); | 597 EXPECT_TRUE(observer.StateEquals(0, s1)); |
596 observer.ClearStates(); | 598 observer.ClearStates(); |
597 } | 599 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 TEST_F(TabStripModelTest, TestBasicOpenerAPI) { | 632 TEST_F(TabStripModelTest, TestBasicOpenerAPI) { |
631 TabStripDummyDelegate delegate(NULL); | 633 TabStripDummyDelegate delegate(NULL); |
632 TabStripModel tabstrip(&delegate, profile()); | 634 TabStripModel tabstrip(&delegate, profile()); |
633 EXPECT_TRUE(tabstrip.empty()); | 635 EXPECT_TRUE(tabstrip.empty()); |
634 | 636 |
635 // This is a basic test of opener functionality. opener_contents is created | 637 // This is a basic test of opener functionality. opener_contents is created |
636 // as the first tab in the strip and then we create 5 other tabs in the | 638 // as the first tab in the strip and then we create 5 other tabs in the |
637 // background with opener_contents set as their opener. | 639 // background with opener_contents set as their opener. |
638 | 640 |
639 TabContentsWrapper* opener_contents = CreateTabContents(); | 641 TabContentsWrapper* opener_contents = CreateTabContents(); |
640 NavigationController* opener = &opener_contents->controller(); | 642 NavigationController* opener = &opener_contents->tab_contents()->controller(); |
641 tabstrip.AppendTabContents(opener_contents, true); | 643 tabstrip.AppendTabContents(opener_contents, true); |
642 TabContentsWrapper* contents1 = CreateTabContents(); | 644 TabContentsWrapper* contents1 = CreateTabContents(); |
643 TabContentsWrapper* contents2 = CreateTabContents(); | 645 TabContentsWrapper* contents2 = CreateTabContents(); |
644 TabContentsWrapper* contents3 = CreateTabContents(); | 646 TabContentsWrapper* contents3 = CreateTabContents(); |
645 TabContentsWrapper* contents4 = CreateTabContents(); | 647 TabContentsWrapper* contents4 = CreateTabContents(); |
646 TabContentsWrapper* contents5 = CreateTabContents(); | 648 TabContentsWrapper* contents5 = CreateTabContents(); |
647 | 649 |
648 // We use |InsertTabContentsAt| here instead of AppendTabContents so that | 650 // We use |InsertTabContentsAt| here instead of AppendTabContents so that |
649 // openership relationships are preserved. | 651 // openership relationships are preserved. |
650 tabstrip.InsertTabContentsAt(tabstrip.count(), contents1, | 652 tabstrip.InsertTabContentsAt(tabstrip.count(), contents1, |
(...skipping 17 matching lines...) Expand all Loading... |
668 // group should be selected. | 670 // group should be selected. |
669 EXPECT_EQ(4, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); | 671 EXPECT_EQ(4, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); |
670 | 672 |
671 // Tests the method that finds the last tab opened by the same opener in the | 673 // Tests the method that finds the last tab opened by the same opener in the |
672 // strip (this is the insertion index for the next background tab for the | 674 // strip (this is the insertion index for the next background tab for the |
673 // specified opener). | 675 // specified opener). |
674 EXPECT_EQ(5, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); | 676 EXPECT_EQ(5, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); |
675 | 677 |
676 // For a tab that has opened no other tabs, the return value should always be | 678 // For a tab that has opened no other tabs, the return value should always be |
677 // -1... | 679 // -1... |
678 NavigationController* o1 = &contents1->controller(); | 680 NavigationController* o1 = &contents1->tab_contents()->controller(); |
679 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(o1, 3, false)); | 681 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(o1, 3, false)); |
680 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(o1, 3)); | 682 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(o1, 3)); |
681 | 683 |
682 // ForgetAllOpeners should destroy all opener relationships. | 684 // ForgetAllOpeners should destroy all opener relationships. |
683 tabstrip.ForgetAllOpeners(); | 685 tabstrip.ForgetAllOpeners(); |
684 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 1, false)); | 686 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 1, false)); |
685 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); | 687 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); |
686 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); | 688 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); |
687 | 689 |
688 tabstrip.CloseAllTabs(); | 690 tabstrip.CloseAllTabs(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 // a new tab from the first tab in the foreground via a link click, verifies | 783 // a new tab from the first tab in the foreground via a link click, verifies |
782 // that this tab is opened adjacent to the opener, then closes it. | 784 // that this tab is opened adjacent to the opener, then closes it. |
783 // Finally it tests that a tab opened for some non-link purpose openes at the | 785 // Finally it tests that a tab opened for some non-link purpose openes at the |
784 // end of the strip, not bundled to any existing context. | 786 // end of the strip, not bundled to any existing context. |
785 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) { | 787 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) { |
786 TabStripDummyDelegate delegate(NULL); | 788 TabStripDummyDelegate delegate(NULL); |
787 TabStripModel tabstrip(&delegate, profile()); | 789 TabStripModel tabstrip(&delegate, profile()); |
788 EXPECT_TRUE(tabstrip.empty()); | 790 EXPECT_TRUE(tabstrip.empty()); |
789 | 791 |
790 TabContentsWrapper* opener_contents = CreateTabContents(); | 792 TabContentsWrapper* opener_contents = CreateTabContents(); |
791 NavigationController* opener = &opener_contents->controller(); | 793 NavigationController* opener = &opener_contents->tab_contents()->controller(); |
792 tabstrip.AppendTabContents(opener_contents, true); | 794 tabstrip.AppendTabContents(opener_contents, true); |
793 | 795 |
794 // Open some other random unrelated tab in the background to monkey with our | 796 // Open some other random unrelated tab in the background to monkey with our |
795 // insertion index. | 797 // insertion index. |
796 TabContentsWrapper* other_contents = CreateTabContents(); | 798 TabContentsWrapper* other_contents = CreateTabContents(); |
797 tabstrip.AppendTabContents(other_contents, false); | 799 tabstrip.AppendTabContents(other_contents, false); |
798 | 800 |
799 TabContentsWrapper* contents1 = CreateTabContents(); | 801 TabContentsWrapper* contents1 = CreateTabContents(); |
800 TabContentsWrapper* contents2 = CreateTabContents(); | 802 TabContentsWrapper* contents2 = CreateTabContents(); |
801 TabContentsWrapper* contents3 = CreateTabContents(); | 803 TabContentsWrapper* contents3 = CreateTabContents(); |
(...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2375 ASSERT_EQ(1, observer.GetStateCount()); | 2377 ASSERT_EQ(1, observer.GetStateCount()); |
2376 MockTabStripModelObserver::State s( | 2378 MockTabStripModelObserver::State s( |
2377 contents2, 1, MockTabStripModelObserver::SELECT); | 2379 contents2, 1, MockTabStripModelObserver::SELECT); |
2378 s.src_contents = contents2; | 2380 s.src_contents = contents2; |
2379 s.src_index = 1; | 2381 s.src_index = 1; |
2380 s.user_gesture = false; | 2382 s.user_gesture = false; |
2381 EXPECT_TRUE(observer.StateEquals(0, s)); | 2383 EXPECT_TRUE(observer.StateEquals(0, s)); |
2382 strip.RemoveObserver(&observer); | 2384 strip.RemoveObserver(&observer); |
2383 strip.CloseAllTabs(); | 2385 strip.CloseAllTabs(); |
2384 } | 2386 } |
OLD | NEW |