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

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

Issue 836223004: Fix tab insertion position after moving tab or nesting openers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test Created 5 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
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/tabs/tab_strip_model.h" 5 #include "chrome/browser/ui/tabs/tab_strip_model.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 // Verify that all opener relationships are forgotten. 856 // Verify that all opener relationships are forgotten.
857 EXPECT_EQ(-1, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 2, false)); 857 EXPECT_EQ(-1, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 2, false));
858 EXPECT_EQ(-1, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 3, false)); 858 EXPECT_EQ(-1, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 3, false));
859 EXPECT_EQ(-1, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 3, false)); 859 EXPECT_EQ(-1, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 3, false));
860 EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener, 1)); 860 EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener, 1));
861 861
862 tabstrip.CloseAllTabs(); 862 tabstrip.CloseAllTabs();
863 EXPECT_TRUE(tabstrip.empty()); 863 EXPECT_TRUE(tabstrip.empty());
864 } 864 }
865 865
866 // Tests that non-adjacent tabs with an opener are ignored when deciding where
867 // to position tabs.
868 TEST_F(TabStripModelTest, TestInsertionIndexDeterminationAfterDragged) {
869 TabStripDummyDelegate delegate;
870 TabStripModel tabstrip(&delegate, profile());
871 EXPECT_TRUE(tabstrip.empty());
872
873 // Start with three tabs, of which the first is active.
874 WebContents* opener1 = CreateWebContentsWithID(1);
875 tabstrip.AppendWebContents(opener1, true /* foreground */);
876 tabstrip.AppendWebContents(CreateWebContentsWithID(2), false);
877 tabstrip.AppendWebContents(CreateWebContentsWithID(3), false);
878 EXPECT_EQ("1 2 3", GetTabStripStateString(tabstrip));
879 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
880 EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
881
882 // Open a link in a new background tab.
883 tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
884 CreateWebContentsWithID(11),
885 TabStripModel::ADD_INHERIT_GROUP);
886 EXPECT_EQ("1 11 2 3", GetTabStripStateString(tabstrip));
887 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
888 EXPECT_EQ(1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
889
890 // Drag that tab (which activates it) one to the right.
891 tabstrip.MoveWebContentsAt(1, 2, true /* select_after_move */);
892 EXPECT_EQ("1 2 11 3", GetTabStripStateString(tabstrip));
893 EXPECT_EQ(11, GetID(tabstrip.GetActiveWebContents()));
894 // It should no longer be counted by GetIndexOfLastWebContentsOpenedBy,
895 // since there is a tab in between, even though its opener is unchanged.
896 // TODO(johnme): Maybe its opener should be reset when it's dragged away.
897 EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
898 EXPECT_EQ(opener1, tabstrip.GetOpenerOfWebContentsAt(2));
899
900 // Activate the parent tab again.
901 tabstrip.ActivateTabAt(0, true /* user_gesture */);
902 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
903
904 // Open another link in a new background tab.
905 tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
906 CreateWebContentsWithID(12),
907 TabStripModel::ADD_INHERIT_GROUP);
908 // Tab 12 should be next to 1, and considered opened by it.
909 EXPECT_EQ("1 12 2 11 3", GetTabStripStateString(tabstrip));
910 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
911 EXPECT_EQ(1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
912
913 tabstrip.CloseAllTabs();
914 EXPECT_TRUE(tabstrip.empty());
915 }
916
917 // Tests that grandchild tabs are considered to be opened by their grandparent
918 // tab when deciding where to position tabs.
919 TEST_F(TabStripModelTest, TestInsertionIndexDeterminationNestedOpener) {
920 TabStripDummyDelegate delegate;
921 TabStripModel tabstrip(&delegate, profile());
922 EXPECT_TRUE(tabstrip.empty());
923
924 // Start with two tabs, of which the first is active:
925 WebContents* opener1 = CreateWebContentsWithID(1);
926 tabstrip.AppendWebContents(opener1, true /* foreground */);
927 tabstrip.AppendWebContents(CreateWebContentsWithID(2), false);
928 EXPECT_EQ("1 2", GetTabStripStateString(tabstrip));
929 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
930 EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
931
932 // Open a link in a new background child tab.
933 WebContents* child11 = CreateWebContentsWithID(11);
934 tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
935 child11,
936 TabStripModel::ADD_INHERIT_GROUP);
937 EXPECT_EQ("1 11 2", GetTabStripStateString(tabstrip));
938 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
939 EXPECT_EQ(1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
940
941 // Activate the child tab:
942 tabstrip.ActivateTabAt(1, true /* user_gesture */);
943 EXPECT_EQ(11, GetID(tabstrip.GetActiveWebContents()));
944
945 // Open a link in a new background grandchild tab.
946 tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
947 CreateWebContentsWithID(111),
948 TabStripModel::ADD_INHERIT_GROUP);
949 EXPECT_EQ("1 11 111 2", GetTabStripStateString(tabstrip));
950 EXPECT_EQ(11, GetID(tabstrip.GetActiveWebContents()));
951 // The grandchild tab should be counted by GetIndexOfLastWebContentsOpenedBy
952 // as opened by both its parent (child11) and grandparent (opener1).
953 EXPECT_EQ(2, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
954 EXPECT_EQ(2, tabstrip.GetIndexOfLastWebContentsOpenedBy(child11, 1));
955
956 // Activate the parent tab again:
957 tabstrip.ActivateTabAt(0, true /* user_gesture */);
958 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
959
960 // Open another link in a new background child tab (a sibling of child11).
961 tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
962 CreateWebContentsWithID(12),
963 TabStripModel::ADD_INHERIT_GROUP);
964 EXPECT_EQ("1 11 111 12 2", GetTabStripStateString(tabstrip));
965 EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
966 // opener1 has three adjacent descendants (11, 111, 12)
967 EXPECT_EQ(3, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
968 // child11 has only one adjacent descendant (111)
969 EXPECT_EQ(2, tabstrip.GetIndexOfLastWebContentsOpenedBy(child11, 1));
970
971 tabstrip.CloseAllTabs();
972 EXPECT_TRUE(tabstrip.empty());
973 }
974
866 // Tests that selection is shifted to the correct tab when a tab is closed. 975 // Tests that selection is shifted to the correct tab when a tab is closed.
867 // If a tab is in the background when it is closed, the selection does not 976 // If a tab is in the background when it is closed, the selection does not
868 // change. 977 // change.
869 // If a tab is in the foreground (selected), 978 // If a tab is in the foreground (selected),
870 // If that tab does not have an opener, selection shifts to the right. 979 // If that tab does not have an opener, selection shifts to the right.
871 // If the tab has an opener, 980 // If the tab has an opener,
872 // The next tab (scanning LTR) in the entire strip that has the same opener 981 // The next tab (scanning LTR) in the entire strip that has the same opener
873 // is selected 982 // is selected
874 // If there are no other tabs that have the same opener, 983 // If there are no other tabs that have the same opener,
875 // The opener is selected 984 // The opener is selected
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 WebContents* moved_contents = strip_src.DetachWebContentsAt(1); 2672 WebContents* moved_contents = strip_src.DetachWebContentsAt(1);
2564 EXPECT_EQ(contents2, moved_contents); 2673 EXPECT_EQ(contents2, moved_contents);
2565 2674
2566 // Attach the tab to the destination tab strip. 2675 // Attach the tab to the destination tab strip.
2567 strip_dst.AppendWebContents(moved_contents, true); 2676 strip_dst.AppendWebContents(moved_contents, true);
2568 EXPECT_TRUE(strip_dst.IsTabBlocked(0)); 2677 EXPECT_TRUE(strip_dst.IsTabBlocked(0));
2569 2678
2570 strip_dst.CloseAllTabs(); 2679 strip_dst.CloseAllTabs();
2571 strip_src.CloseAllTabs(); 2680 strip_src.CloseAllTabs();
2572 } 2681 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698