Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/tabs/tab_strip_model_unittest.cc

Issue 8983010: Convert WebContents to return a content::NavigationController instead of the implementation. Upda... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/tabs/tab_strip_model_delegate.h" 23 #include "chrome/browser/tabs/tab_strip_model_delegate.h"
24 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" 24 #include "chrome/browser/tabs/tab_strip_model_order_controller.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
28 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
29 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 30 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "content/browser/tab_contents/navigation_controller.h"
33 #include "content/browser/tab_contents/tab_contents.h" 32 #include "content/browser/tab_contents/tab_contents.h"
33 #include "content/public/browser/navigation_controller.h"
34 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
35 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
36 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
37 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
38 #include "content/public/browser/notification_types.h" 38 #include "content/public/browser/notification_types.h"
39 #include "content/test/notification_observer_mock.h" 39 #include "content/test/notification_observer_mock.h"
40 #include "content/test/test_browser_thread.h" 40 #include "content/test/test_browser_thread.h"
41 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
42 42
43 using content::BrowserThread; 43 using content::BrowserThread;
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 TEST_F(TabStripModelTest, TestBasicOpenerAPI) { 633 TEST_F(TabStripModelTest, TestBasicOpenerAPI) {
634 TabStripDummyDelegate delegate(NULL); 634 TabStripDummyDelegate delegate(NULL);
635 TabStripModel tabstrip(&delegate, profile()); 635 TabStripModel tabstrip(&delegate, profile());
636 EXPECT_TRUE(tabstrip.empty()); 636 EXPECT_TRUE(tabstrip.empty());
637 637
638 // This is a basic test of opener functionality. opener_contents is created 638 // This is a basic test of opener functionality. opener_contents is created
639 // as the first tab in the strip and then we create 5 other tabs in the 639 // as the first tab in the strip and then we create 5 other tabs in the
640 // background with opener_contents set as their opener. 640 // background with opener_contents set as their opener.
641 641
642 TabContentsWrapper* opener_contents = CreateTabContents(); 642 TabContentsWrapper* opener_contents = CreateTabContents();
643 NavigationController* opener = 643 content::NavigationController* opener =
644 &opener_contents->tab_contents()->GetController(); 644 &opener_contents->tab_contents()->GetController();
645 tabstrip.AppendTabContents(opener_contents, true); 645 tabstrip.AppendTabContents(opener_contents, true);
646 TabContentsWrapper* contents1 = CreateTabContents(); 646 TabContentsWrapper* contents1 = CreateTabContents();
647 TabContentsWrapper* contents2 = CreateTabContents(); 647 TabContentsWrapper* contents2 = CreateTabContents();
648 TabContentsWrapper* contents3 = CreateTabContents(); 648 TabContentsWrapper* contents3 = CreateTabContents();
649 TabContentsWrapper* contents4 = CreateTabContents(); 649 TabContentsWrapper* contents4 = CreateTabContents();
650 TabContentsWrapper* contents5 = CreateTabContents(); 650 TabContentsWrapper* contents5 = CreateTabContents();
651 651
652 // We use |InsertTabContentsAt| here instead of AppendTabContents so that 652 // We use |InsertTabContentsAt| here instead of AppendTabContents so that
653 // openership relationships are preserved. 653 // openership relationships are preserved.
(...skipping 18 matching lines...) Expand all
672 // group should be selected. 672 // group should be selected.
673 EXPECT_EQ(4, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); 673 EXPECT_EQ(4, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false));
674 674
675 // Tests the method that finds the last tab opened by the same opener in the 675 // Tests the method that finds the last tab opened by the same opener in the
676 // strip (this is the insertion index for the next background tab for the 676 // strip (this is the insertion index for the next background tab for the
677 // specified opener). 677 // specified opener).
678 EXPECT_EQ(5, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); 678 EXPECT_EQ(5, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1));
679 679
680 // For a tab that has opened no other tabs, the return value should always be 680 // For a tab that has opened no other tabs, the return value should always be
681 // -1... 681 // -1...
682 NavigationController* o1 = &contents1->tab_contents()->GetController(); 682 content::NavigationController* o1 =
683 &contents1->tab_contents()->GetController();
683 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(o1, 3, false)); 684 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(o1, 3, false));
684 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(o1, 3)); 685 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(o1, 3));
685 686
686 // ForgetAllOpeners should destroy all opener relationships. 687 // ForgetAllOpeners should destroy all opener relationships.
687 tabstrip.ForgetAllOpeners(); 688 tabstrip.ForgetAllOpeners();
688 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 1, false)); 689 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 1, false));
689 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); 690 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false));
690 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); 691 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1));
691 692
692 tabstrip.CloseAllTabs(); 693 tabstrip.CloseAllTabs();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // a new tab from the first tab in the foreground via a link click, verifies 786 // a new tab from the first tab in the foreground via a link click, verifies
786 // that this tab is opened adjacent to the opener, then closes it. 787 // that this tab is opened adjacent to the opener, then closes it.
787 // Finally it tests that a tab opened for some non-link purpose openes at the 788 // Finally it tests that a tab opened for some non-link purpose openes at the
788 // end of the strip, not bundled to any existing context. 789 // end of the strip, not bundled to any existing context.
789 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) { 790 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
790 TabStripDummyDelegate delegate(NULL); 791 TabStripDummyDelegate delegate(NULL);
791 TabStripModel tabstrip(&delegate, profile()); 792 TabStripModel tabstrip(&delegate, profile());
792 EXPECT_TRUE(tabstrip.empty()); 793 EXPECT_TRUE(tabstrip.empty());
793 794
794 TabContentsWrapper* opener_contents = CreateTabContents(); 795 TabContentsWrapper* opener_contents = CreateTabContents();
795 NavigationController* opener = 796 content::NavigationController* opener =
796 &opener_contents->tab_contents()->GetController(); 797 &opener_contents->tab_contents()->GetController();
797 tabstrip.AppendTabContents(opener_contents, true); 798 tabstrip.AppendTabContents(opener_contents, true);
798 799
799 // Open some other random unrelated tab in the background to monkey with our 800 // Open some other random unrelated tab in the background to monkey with our
800 // insertion index. 801 // insertion index.
801 TabContentsWrapper* other_contents = CreateTabContents(); 802 TabContentsWrapper* other_contents = CreateTabContents();
802 tabstrip.AppendTabContents(other_contents, false); 803 tabstrip.AppendTabContents(other_contents, false);
803 804
804 TabContentsWrapper* contents1 = CreateTabContents(); 805 TabContentsWrapper* contents1 = CreateTabContents();
805 TabContentsWrapper* contents2 = CreateTabContents(); 806 TabContentsWrapper* contents2 = CreateTabContents();
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 ASSERT_EQ(1, observer.GetStateCount()); 2381 ASSERT_EQ(1, observer.GetStateCount());
2381 MockTabStripModelObserver::State s( 2382 MockTabStripModelObserver::State s(
2382 contents2, 1, MockTabStripModelObserver::SELECT); 2383 contents2, 1, MockTabStripModelObserver::SELECT);
2383 s.src_contents = contents2; 2384 s.src_contents = contents2;
2384 s.src_index = 1; 2385 s.src_index = 1;
2385 s.user_gesture = false; 2386 s.user_gesture = false;
2386 EXPECT_TRUE(observer.StateEquals(0, s)); 2387 EXPECT_TRUE(observer.StateEquals(0, s));
2387 strip.RemoveObserver(&observer); 2388 strip.RemoveObserver(&observer);
2388 strip.CloseAllTabs(); 2389 strip.CloseAllTabs();
2389 } 2390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698