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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 virtual void ContinueDraggingDetachedTab(TabContentsWrapper* contents, | 98 virtual void ContinueDraggingDetachedTab(TabContentsWrapper* contents, |
99 const gfx::Rect& window_bounds, | 99 const gfx::Rect& window_bounds, |
100 const gfx::Rect& tab_bounds) { | 100 const gfx::Rect& tab_bounds) { |
101 } | 101 } |
102 virtual int GetDragActions() const { return 0; } | 102 virtual int GetDragActions() const { return 0; } |
103 virtual TabContentsWrapper* CreateTabContentsForURL( | 103 virtual TabContentsWrapper* CreateTabContentsForURL( |
104 const GURL& url, | 104 const GURL& url, |
105 const GURL& referrer, | 105 const GURL& referrer, |
106 Profile* profile, | 106 Profile* profile, |
107 PageTransition::Type transition, | 107 content::PageTransition transition, |
108 bool defer_load, | 108 bool defer_load, |
109 SiteInstance* instance) const { | 109 SiteInstance* instance) const { |
110 if (url == GURL(chrome::kChromeUINewTabURL)) | 110 if (url == GURL(chrome::kChromeUINewTabURL)) |
111 return dummy_contents_; | 111 return dummy_contents_; |
112 return NULL; | 112 return NULL; |
113 } | 113 } |
114 virtual bool CanDuplicateContentsAt(int index) { return false; } | 114 virtual bool CanDuplicateContentsAt(int index) { return false; } |
115 virtual void DuplicateContentsAt(int index) {} | 115 virtual void DuplicateContentsAt(int index) {} |
116 virtual void CloseFrameAfterDragSession() {} | 116 virtual void CloseFrameAfterDragSession() {} |
117 virtual void CreateHistoricalTab(TabContentsWrapper* contents) {} | 117 virtual void CreateHistoricalTab(TabContentsWrapper* contents) {} |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 tab_contents->render_view_host()->site_instance(), MSG_ROUTING_NONE, | 159 tab_contents->render_view_host()->site_instance(), MSG_ROUTING_NONE, |
160 NULL, NULL); | 160 NULL, NULL); |
161 EXPECT_EQ(retval->tab_contents()->GetRenderProcessHost(), | 161 EXPECT_EQ(retval->tab_contents()->GetRenderProcessHost(), |
162 tab_contents->GetRenderProcessHost()); | 162 tab_contents->GetRenderProcessHost()); |
163 return retval; | 163 return retval; |
164 } | 164 } |
165 | 165 |
166 // Forwards a URL "load" request through to our dummy TabContents | 166 // Forwards a URL "load" request through to our dummy TabContents |
167 // implementation. | 167 // implementation. |
168 void LoadURL(TabContents* con, const std::wstring& url) { | 168 void LoadURL(TabContents* con, const std::wstring& url) { |
169 controller().LoadURL(GURL(WideToUTF16(url)), GURL(), PageTransition::LINK, | 169 controller().LoadURL(GURL(WideToUTF16(url)), GURL(), |
170 std::string()); | 170 content::PAGE_TRANSITION_LINK, std::string()); |
171 } | 171 } |
172 | 172 |
173 void GoBack(TabContents* contents) { | 173 void GoBack(TabContents* contents) { |
174 controller().GoBack(); | 174 controller().GoBack(); |
175 } | 175 } |
176 | 176 |
177 void GoForward(TabContents* contents) { | 177 void GoForward(TabContents* contents) { |
178 controller().GoForward(); | 178 controller().GoForward(); |
179 } | 179 } |
180 | 180 |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); | 682 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); |
683 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); | 683 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); |
684 | 684 |
685 tabstrip.CloseAllTabs(); | 685 tabstrip.CloseAllTabs(); |
686 EXPECT_TRUE(tabstrip.empty()); | 686 EXPECT_TRUE(tabstrip.empty()); |
687 } | 687 } |
688 | 688 |
689 static int GetInsertionIndex(TabStripModel* tabstrip, | 689 static int GetInsertionIndex(TabStripModel* tabstrip, |
690 TabContentsWrapper* contents) { | 690 TabContentsWrapper* contents) { |
691 return tabstrip->order_controller()->DetermineInsertionIndex( | 691 return tabstrip->order_controller()->DetermineInsertionIndex( |
692 contents, PageTransition::LINK, false); | 692 contents, content::PAGE_TRANSITION_LINK, false); |
693 } | 693 } |
694 | 694 |
695 static void InsertTabContentses(TabStripModel* tabstrip, | 695 static void InsertTabContentses(TabStripModel* tabstrip, |
696 TabContentsWrapper* contents1, | 696 TabContentsWrapper* contents1, |
697 TabContentsWrapper* contents2, | 697 TabContentsWrapper* contents2, |
698 TabContentsWrapper* contents3) { | 698 TabContentsWrapper* contents3) { |
699 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents1), | 699 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents1), |
700 contents1, TabStripModel::ADD_INHERIT_GROUP); | 700 contents1, TabStripModel::ADD_INHERIT_GROUP); |
701 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents2), | 701 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents2), |
702 contents2, TabStripModel::ADD_INHERIT_GROUP); | 702 contents2, TabStripModel::ADD_INHERIT_GROUP); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 | 807 |
808 // The opener API should work... | 808 // The opener API should work... |
809 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 2, false)); | 809 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 2, false)); |
810 EXPECT_EQ(2, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 3, false)); | 810 EXPECT_EQ(2, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 3, false)); |
811 EXPECT_EQ(3, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); | 811 EXPECT_EQ(3, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); |
812 | 812 |
813 // Now open a foreground tab from a link. It should be opened adjacent to the | 813 // Now open a foreground tab from a link. It should be opened adjacent to the |
814 // opener tab. | 814 // opener tab. |
815 TabContentsWrapper* fg_link_contents = CreateTabContents(); | 815 TabContentsWrapper* fg_link_contents = CreateTabContents(); |
816 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex( | 816 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex( |
817 fg_link_contents, PageTransition::LINK, true); | 817 fg_link_contents, content::PAGE_TRANSITION_LINK, true); |
818 EXPECT_EQ(1, insert_index); | 818 EXPECT_EQ(1, insert_index); |
819 tabstrip.InsertTabContentsAt(insert_index, fg_link_contents, | 819 tabstrip.InsertTabContentsAt(insert_index, fg_link_contents, |
820 TabStripModel::ADD_ACTIVE | | 820 TabStripModel::ADD_ACTIVE | |
821 TabStripModel::ADD_INHERIT_GROUP); | 821 TabStripModel::ADD_INHERIT_GROUP); |
822 EXPECT_EQ(1, tabstrip.active_index()); | 822 EXPECT_EQ(1, tabstrip.active_index()); |
823 EXPECT_EQ(fg_link_contents, tabstrip.GetActiveTabContents()); | 823 EXPECT_EQ(fg_link_contents, tabstrip.GetActiveTabContents()); |
824 | 824 |
825 // Now close this contents. The selection should move to the opener contents. | 825 // Now close this contents. The selection should move to the opener contents. |
826 tabstrip.CloseSelectedTabs(); | 826 tabstrip.CloseSelectedTabs(); |
827 EXPECT_EQ(0, tabstrip.active_index()); | 827 EXPECT_EQ(0, tabstrip.active_index()); |
828 | 828 |
829 // Now open a new empty tab. It should open at the end of the strip. | 829 // Now open a new empty tab. It should open at the end of the strip. |
830 TabContentsWrapper* fg_nonlink_contents = CreateTabContents(); | 830 TabContentsWrapper* fg_nonlink_contents = CreateTabContents(); |
831 insert_index = tabstrip.order_controller()->DetermineInsertionIndex( | 831 insert_index = tabstrip.order_controller()->DetermineInsertionIndex( |
832 fg_nonlink_contents, PageTransition::AUTO_BOOKMARK, true); | 832 fg_nonlink_contents, content::PAGE_TRANSITION_AUTO_BOOKMARK, true); |
833 EXPECT_EQ(tabstrip.count(), insert_index); | 833 EXPECT_EQ(tabstrip.count(), insert_index); |
834 // We break the opener relationship... | 834 // We break the opener relationship... |
835 tabstrip.InsertTabContentsAt(insert_index, fg_nonlink_contents, | 835 tabstrip.InsertTabContentsAt(insert_index, fg_nonlink_contents, |
836 TabStripModel::ADD_NONE); | 836 TabStripModel::ADD_NONE); |
837 // Now select it, so that user_gesture == true causes the opener relationship | 837 // Now select it, so that user_gesture == true causes the opener relationship |
838 // to be forgotten... | 838 // to be forgotten... |
839 tabstrip.ActivateTabAt(tabstrip.count() - 1, true); | 839 tabstrip.ActivateTabAt(tabstrip.count() - 1, true); |
840 EXPECT_EQ(tabstrip.count() - 1, tabstrip.active_index()); | 840 EXPECT_EQ(tabstrip.count() - 1, tabstrip.active_index()); |
841 EXPECT_EQ(fg_nonlink_contents, tabstrip.GetActiveTabContents()); | 841 EXPECT_EQ(fg_nonlink_contents, tabstrip.GetActiveTabContents()); |
842 | 842 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 // using this "smart" function with a simulated middle click action on a series | 1204 // using this "smart" function with a simulated middle click action on a series |
1205 // of links on the home page. | 1205 // of links on the home page. |
1206 TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) { | 1206 TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) { |
1207 TabStripDummyDelegate delegate(NULL); | 1207 TabStripDummyDelegate delegate(NULL); |
1208 TabStripModel tabstrip(&delegate, profile()); | 1208 TabStripModel tabstrip(&delegate, profile()); |
1209 EXPECT_TRUE(tabstrip.empty()); | 1209 EXPECT_TRUE(tabstrip.empty()); |
1210 | 1210 |
1211 // Open the Home Page | 1211 // Open the Home Page |
1212 TabContentsWrapper* homepage_contents = CreateTabContents(); | 1212 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1213 tabstrip.AddTabContents( | 1213 tabstrip.AddTabContents( |
1214 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1214 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1215 TabStripModel::ADD_ACTIVE); | 1215 TabStripModel::ADD_ACTIVE); |
1216 | 1216 |
1217 // Open some other tab, by user typing. | 1217 // Open some other tab, by user typing. |
1218 TabContentsWrapper* typed_page_contents = CreateTabContents(); | 1218 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1219 tabstrip.AddTabContents( | 1219 tabstrip.AddTabContents( |
1220 typed_page_contents, -1, PageTransition::TYPED, | 1220 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, |
1221 TabStripModel::ADD_ACTIVE); | 1221 TabStripModel::ADD_ACTIVE); |
1222 | 1222 |
1223 EXPECT_EQ(2, tabstrip.count()); | 1223 EXPECT_EQ(2, tabstrip.count()); |
1224 | 1224 |
1225 // Re-select the home page. | 1225 // Re-select the home page. |
1226 tabstrip.ActivateTabAt(0, true); | 1226 tabstrip.ActivateTabAt(0, true); |
1227 | 1227 |
1228 // Open a bunch of tabs by simulating middle clicking on links on the home | 1228 // Open a bunch of tabs by simulating middle clicking on links on the home |
1229 // page. | 1229 // page. |
1230 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); | 1230 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); |
1231 tabstrip.AddTabContents( | 1231 tabstrip.AddTabContents( |
1232 middle_click_contents1, -1, PageTransition::LINK, | 1232 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK, |
1233 TabStripModel::ADD_NONE); | 1233 TabStripModel::ADD_NONE); |
1234 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); | 1234 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); |
1235 tabstrip.AddTabContents( | 1235 tabstrip.AddTabContents( |
1236 middle_click_contents2, -1, PageTransition::LINK, | 1236 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK, |
1237 TabStripModel::ADD_NONE); | 1237 TabStripModel::ADD_NONE); |
1238 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); | 1238 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); |
1239 tabstrip.AddTabContents( | 1239 tabstrip.AddTabContents( |
1240 middle_click_contents3, -1, PageTransition::LINK, | 1240 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK, |
1241 TabStripModel::ADD_NONE); | 1241 TabStripModel::ADD_NONE); |
1242 | 1242 |
1243 EXPECT_EQ(5, tabstrip.count()); | 1243 EXPECT_EQ(5, tabstrip.count()); |
1244 | 1244 |
1245 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1245 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1246 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1)); | 1246 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1)); |
1247 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2)); | 1247 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2)); |
1248 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3)); | 1248 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3)); |
1249 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); | 1249 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); |
1250 | 1250 |
(...skipping 22 matching lines...) Expand all Loading... |
1273 // Tests whether or not a TabContents created by a left click on a link that | 1273 // Tests whether or not a TabContents created by a left click on a link that |
1274 // opens a new tab is inserted correctly adjacent to the tab that spawned it. | 1274 // opens a new tab is inserted correctly adjacent to the tab that spawned it. |
1275 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) { | 1275 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) { |
1276 TabStripDummyDelegate delegate(NULL); | 1276 TabStripDummyDelegate delegate(NULL); |
1277 TabStripModel tabstrip(&delegate, profile()); | 1277 TabStripModel tabstrip(&delegate, profile()); |
1278 EXPECT_TRUE(tabstrip.empty()); | 1278 EXPECT_TRUE(tabstrip.empty()); |
1279 | 1279 |
1280 // Open the Home Page | 1280 // Open the Home Page |
1281 TabContentsWrapper* homepage_contents = CreateTabContents(); | 1281 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1282 tabstrip.AddTabContents( | 1282 tabstrip.AddTabContents( |
1283 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1283 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1284 TabStripModel::ADD_ACTIVE); | 1284 TabStripModel::ADD_ACTIVE); |
1285 | 1285 |
1286 // Open some other tab, by user typing. | 1286 // Open some other tab, by user typing. |
1287 TabContentsWrapper* typed_page_contents = CreateTabContents(); | 1287 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1288 tabstrip.AddTabContents( | 1288 tabstrip.AddTabContents( |
1289 typed_page_contents, -1, PageTransition::TYPED, | 1289 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, |
1290 TabStripModel::ADD_ACTIVE); | 1290 TabStripModel::ADD_ACTIVE); |
1291 | 1291 |
1292 EXPECT_EQ(2, tabstrip.count()); | 1292 EXPECT_EQ(2, tabstrip.count()); |
1293 | 1293 |
1294 // Re-select the home page. | 1294 // Re-select the home page. |
1295 tabstrip.ActivateTabAt(0, true); | 1295 tabstrip.ActivateTabAt(0, true); |
1296 | 1296 |
1297 // Open a tab by simulating a left click on a link that opens in a new tab. | 1297 // Open a tab by simulating a left click on a link that opens in a new tab. |
1298 TabContentsWrapper* left_click_contents = CreateTabContents(); | 1298 TabContentsWrapper* left_click_contents = CreateTabContents(); |
1299 tabstrip.AddTabContents(left_click_contents, -1, PageTransition::LINK, | 1299 tabstrip.AddTabContents(left_click_contents, -1, |
| 1300 content::PAGE_TRANSITION_LINK, |
1300 TabStripModel::ADD_ACTIVE); | 1301 TabStripModel::ADD_ACTIVE); |
1301 | 1302 |
1302 // Verify the state meets our expectations. | 1303 // Verify the state meets our expectations. |
1303 EXPECT_EQ(3, tabstrip.count()); | 1304 EXPECT_EQ(3, tabstrip.count()); |
1304 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1305 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1305 EXPECT_EQ(left_click_contents, tabstrip.GetTabContentsAt(1)); | 1306 EXPECT_EQ(left_click_contents, tabstrip.GetTabContentsAt(1)); |
1306 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(2)); | 1307 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(2)); |
1307 | 1308 |
1308 // The newly created tab should be selected. | 1309 // The newly created tab should be selected. |
1309 EXPECT_EQ(left_click_contents, tabstrip.GetActiveTabContents()); | 1310 EXPECT_EQ(left_click_contents, tabstrip.GetActiveTabContents()); |
(...skipping 13 matching lines...) Expand all Loading... |
1323 // generated urls, also blank tabs) open at the end of the tabstrip instead of | 1324 // generated urls, also blank tabs) open at the end of the tabstrip instead of |
1324 // in the middle. | 1325 // in the middle. |
1325 TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) { | 1326 TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) { |
1326 TabStripDummyDelegate delegate(NULL); | 1327 TabStripDummyDelegate delegate(NULL); |
1327 TabStripModel tabstrip(&delegate, profile()); | 1328 TabStripModel tabstrip(&delegate, profile()); |
1328 EXPECT_TRUE(tabstrip.empty()); | 1329 EXPECT_TRUE(tabstrip.empty()); |
1329 | 1330 |
1330 // Open the Home Page | 1331 // Open the Home Page |
1331 TabContentsWrapper* homepage_contents = CreateTabContents(); | 1332 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1332 tabstrip.AddTabContents( | 1333 tabstrip.AddTabContents( |
1333 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1334 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1334 TabStripModel::ADD_ACTIVE); | 1335 TabStripModel::ADD_ACTIVE); |
1335 | 1336 |
1336 // Open some other tab, by user typing. | 1337 // Open some other tab, by user typing. |
1337 TabContentsWrapper* typed_page_contents = CreateTabContents(); | 1338 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1338 tabstrip.AddTabContents( | 1339 tabstrip.AddTabContents( |
1339 typed_page_contents, -1, PageTransition::TYPED, | 1340 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, |
1340 TabStripModel::ADD_ACTIVE); | 1341 TabStripModel::ADD_ACTIVE); |
1341 | 1342 |
1342 EXPECT_EQ(2, tabstrip.count()); | 1343 EXPECT_EQ(2, tabstrip.count()); |
1343 | 1344 |
1344 // Re-select the home page. | 1345 // Re-select the home page. |
1345 tabstrip.ActivateTabAt(0, true); | 1346 tabstrip.ActivateTabAt(0, true); |
1346 | 1347 |
1347 // Open a new blank tab in the foreground. | 1348 // Open a new blank tab in the foreground. |
1348 TabContentsWrapper* new_blank_contents = CreateTabContents(); | 1349 TabContentsWrapper* new_blank_contents = CreateTabContents(); |
1349 tabstrip.AddTabContents(new_blank_contents, -1, PageTransition::TYPED, | 1350 tabstrip.AddTabContents(new_blank_contents, -1, |
| 1351 content::PAGE_TRANSITION_TYPED, |
1350 TabStripModel::ADD_ACTIVE); | 1352 TabStripModel::ADD_ACTIVE); |
1351 | 1353 |
1352 // Verify the state of the tabstrip. | 1354 // Verify the state of the tabstrip. |
1353 EXPECT_EQ(3, tabstrip.count()); | 1355 EXPECT_EQ(3, tabstrip.count()); |
1354 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1356 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1355 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); | 1357 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); |
1356 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); | 1358 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); |
1357 | 1359 |
1358 // Now open a couple more blank tabs in the background. | 1360 // Now open a couple more blank tabs in the background. |
1359 TabContentsWrapper* background_blank_contents1 = CreateTabContents(); | 1361 TabContentsWrapper* background_blank_contents1 = CreateTabContents(); |
1360 tabstrip.AddTabContents( | 1362 tabstrip.AddTabContents( |
1361 background_blank_contents1, -1, PageTransition::TYPED, | 1363 background_blank_contents1, -1, content::PAGE_TRANSITION_TYPED, |
1362 TabStripModel::ADD_NONE); | 1364 TabStripModel::ADD_NONE); |
1363 TabContentsWrapper* background_blank_contents2 = CreateTabContents(); | 1365 TabContentsWrapper* background_blank_contents2 = CreateTabContents(); |
1364 tabstrip.AddTabContents( | 1366 tabstrip.AddTabContents( |
1365 background_blank_contents2, -1, PageTransition::GENERATED, | 1367 background_blank_contents2, -1, content::PAGE_TRANSITION_GENERATED, |
1366 TabStripModel::ADD_NONE); | 1368 TabStripModel::ADD_NONE); |
1367 EXPECT_EQ(5, tabstrip.count()); | 1369 EXPECT_EQ(5, tabstrip.count()); |
1368 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1370 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1369 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); | 1371 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); |
1370 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); | 1372 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); |
1371 EXPECT_EQ(background_blank_contents1, tabstrip.GetTabContentsAt(3)); | 1373 EXPECT_EQ(background_blank_contents1, tabstrip.GetTabContentsAt(3)); |
1372 EXPECT_EQ(background_blank_contents2, tabstrip.GetTabContentsAt(4)); | 1374 EXPECT_EQ(background_blank_contents2, tabstrip.GetTabContentsAt(4)); |
1373 | 1375 |
1374 tabstrip.CloseAllTabs(); | 1376 tabstrip.CloseAllTabs(); |
1375 EXPECT_TRUE(tabstrip.empty()); | 1377 EXPECT_TRUE(tabstrip.empty()); |
1376 } | 1378 } |
1377 | 1379 |
1378 // Tests whether opener state is correctly forgotten when the user switches | 1380 // Tests whether opener state is correctly forgotten when the user switches |
1379 // context. | 1381 // context. |
1380 TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) { | 1382 TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) { |
1381 TabStripDummyDelegate delegate(NULL); | 1383 TabStripDummyDelegate delegate(NULL); |
1382 TabStripModel tabstrip(&delegate, profile()); | 1384 TabStripModel tabstrip(&delegate, profile()); |
1383 EXPECT_TRUE(tabstrip.empty()); | 1385 EXPECT_TRUE(tabstrip.empty()); |
1384 | 1386 |
1385 // Open the Home Page | 1387 // Open the Home Page |
1386 TabContentsWrapper* homepage_contents = CreateTabContents(); | 1388 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1387 tabstrip.AddTabContents( | 1389 tabstrip.AddTabContents( |
1388 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1390 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1389 TabStripModel::ADD_ACTIVE); | 1391 TabStripModel::ADD_ACTIVE); |
1390 | 1392 |
1391 // Open some other tab, by user typing. | 1393 // Open some other tab, by user typing. |
1392 TabContentsWrapper* typed_page_contents = CreateTabContents(); | 1394 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1393 tabstrip.AddTabContents( | 1395 tabstrip.AddTabContents( |
1394 typed_page_contents, -1, PageTransition::TYPED, | 1396 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, |
1395 TabStripModel::ADD_ACTIVE); | 1397 TabStripModel::ADD_ACTIVE); |
1396 | 1398 |
1397 EXPECT_EQ(2, tabstrip.count()); | 1399 EXPECT_EQ(2, tabstrip.count()); |
1398 | 1400 |
1399 // Re-select the home page. | 1401 // Re-select the home page. |
1400 tabstrip.ActivateTabAt(0, true); | 1402 tabstrip.ActivateTabAt(0, true); |
1401 | 1403 |
1402 // Open a bunch of tabs by simulating middle clicking on links on the home | 1404 // Open a bunch of tabs by simulating middle clicking on links on the home |
1403 // page. | 1405 // page. |
1404 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); | 1406 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); |
1405 tabstrip.AddTabContents( | 1407 tabstrip.AddTabContents( |
1406 middle_click_contents1, -1, PageTransition::LINK, | 1408 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK, |
1407 TabStripModel::ADD_NONE); | 1409 TabStripModel::ADD_NONE); |
1408 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); | 1410 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); |
1409 tabstrip.AddTabContents( | 1411 tabstrip.AddTabContents( |
1410 middle_click_contents2, -1, PageTransition::LINK, | 1412 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK, |
1411 TabStripModel::ADD_NONE); | 1413 TabStripModel::ADD_NONE); |
1412 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); | 1414 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); |
1413 tabstrip.AddTabContents( | 1415 tabstrip.AddTabContents( |
1414 middle_click_contents3, -1, PageTransition::LINK, | 1416 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK, |
1415 TabStripModel::ADD_NONE); | 1417 TabStripModel::ADD_NONE); |
1416 | 1418 |
1417 // Break out of the context by selecting a tab in a different context. | 1419 // Break out of the context by selecting a tab in a different context. |
1418 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); | 1420 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); |
1419 tabstrip.SelectLastTab(); | 1421 tabstrip.SelectLastTab(); |
1420 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents()); | 1422 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents()); |
1421 | 1423 |
1422 // Step back into the context by selecting a tab inside it. | 1424 // Step back into the context by selecting a tab inside it. |
1423 tabstrip.ActivateTabAt(2, true); | 1425 tabstrip.ActivateTabAt(2, true); |
1424 EXPECT_EQ(middle_click_contents2, tabstrip.GetActiveTabContents()); | 1426 EXPECT_EQ(middle_click_contents2, tabstrip.GetActiveTabContents()); |
(...skipping 21 matching lines...) Expand all Loading... |
1446 TabContents* fake_destinations_tab = | 1448 TabContents* fake_destinations_tab = |
1447 new TabContents(profile(), NULL, 0, NULL, NULL); | 1449 new TabContents(profile(), NULL, 0, NULL, NULL); |
1448 TabContentsWrapper wrapper(fake_destinations_tab); | 1450 TabContentsWrapper wrapper(fake_destinations_tab); |
1449 TabStripDummyDelegate delegate(&wrapper); | 1451 TabStripDummyDelegate delegate(&wrapper); |
1450 TabStripModel tabstrip(&delegate, profile()); | 1452 TabStripModel tabstrip(&delegate, profile()); |
1451 EXPECT_TRUE(tabstrip.empty()); | 1453 EXPECT_TRUE(tabstrip.empty()); |
1452 | 1454 |
1453 // Open the Home Page | 1455 // Open the Home Page |
1454 TabContentsWrapper* homepage_contents = CreateTabContents(); | 1456 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1455 tabstrip.AddTabContents( | 1457 tabstrip.AddTabContents( |
1456 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1458 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1457 TabStripModel::ADD_ACTIVE); | 1459 TabStripModel::ADD_ACTIVE); |
1458 | 1460 |
1459 // Open some other tab, by user typing. | 1461 // Open some other tab, by user typing. |
1460 TabContentsWrapper* typed_page_contents = CreateTabContents(); | 1462 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1461 tabstrip.AddTabContents( | 1463 tabstrip.AddTabContents( |
1462 typed_page_contents, -1, PageTransition::TYPED, | 1464 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, |
1463 TabStripModel::ADD_NONE); | 1465 TabStripModel::ADD_NONE); |
1464 | 1466 |
1465 // The selected tab should still be the first. | 1467 // The selected tab should still be the first. |
1466 EXPECT_EQ(0, tabstrip.active_index()); | 1468 EXPECT_EQ(0, tabstrip.active_index()); |
1467 | 1469 |
1468 // Now simulate a link click that opens a new tab (by virtue of target=_blank) | 1470 // Now simulate a link click that opens a new tab (by virtue of target=_blank) |
1469 // and make sure the right tab gets selected when the new tab is closed. | 1471 // and make sure the right tab gets selected when the new tab is closed. |
1470 TabContentsWrapper* target_blank_contents = CreateTabContents(); | 1472 TabContentsWrapper* target_blank_contents = CreateTabContents(); |
1471 tabstrip.AppendTabContents(target_blank_contents, true); | 1473 tabstrip.AppendTabContents(target_blank_contents, true); |
1472 EXPECT_EQ(2, tabstrip.active_index()); | 1474 EXPECT_EQ(2, tabstrip.active_index()); |
1473 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); | 1475 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); |
1474 EXPECT_EQ(0, tabstrip.active_index()); | 1476 EXPECT_EQ(0, tabstrip.active_index()); |
1475 | 1477 |
1476 // clean up after ourselves | 1478 // clean up after ourselves |
1477 tabstrip.CloseAllTabs(); | 1479 tabstrip.CloseAllTabs(); |
1478 } | 1480 } |
1479 | 1481 |
1480 // Added for http://b/issue?id=1027661 | 1482 // Added for http://b/issue?id=1027661 |
1481 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) { | 1483 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) { |
1482 TabStripDummyDelegate delegate(NULL); | 1484 TabStripDummyDelegate delegate(NULL); |
1483 TabStripModel strip(&delegate, profile()); | 1485 TabStripModel strip(&delegate, profile()); |
1484 | 1486 |
1485 // Open page A | 1487 // Open page A |
1486 TabContentsWrapper* page_a_contents = CreateTabContents(); | 1488 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1487 strip.AddTabContents( | 1489 strip.AddTabContents( |
1488 page_a_contents, -1, PageTransition::AUTO_BOOKMARK, | 1490 page_a_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1489 TabStripModel::ADD_ACTIVE); | 1491 TabStripModel::ADD_ACTIVE); |
1490 | 1492 |
1491 // Simulate middle click to open page A.A and A.B | 1493 // Simulate middle click to open page A.A and A.B |
1492 TabContentsWrapper* page_a_a_contents = CreateTabContents(); | 1494 TabContentsWrapper* page_a_a_contents = CreateTabContents(); |
1493 strip.AddTabContents(page_a_a_contents, -1, PageTransition::LINK, | 1495 strip.AddTabContents(page_a_a_contents, -1, content::PAGE_TRANSITION_LINK, |
1494 TabStripModel::ADD_NONE); | 1496 TabStripModel::ADD_NONE); |
1495 TabContentsWrapper* page_a_b_contents = CreateTabContents(); | 1497 TabContentsWrapper* page_a_b_contents = CreateTabContents(); |
1496 strip.AddTabContents(page_a_b_contents, -1, PageTransition::LINK, | 1498 strip.AddTabContents(page_a_b_contents, -1, content::PAGE_TRANSITION_LINK, |
1497 TabStripModel::ADD_NONE); | 1499 TabStripModel::ADD_NONE); |
1498 | 1500 |
1499 // Select page A.A | 1501 // Select page A.A |
1500 strip.ActivateTabAt(1, true); | 1502 strip.ActivateTabAt(1, true); |
1501 EXPECT_EQ(page_a_a_contents, strip.GetActiveTabContents()); | 1503 EXPECT_EQ(page_a_a_contents, strip.GetActiveTabContents()); |
1502 | 1504 |
1503 // Simulate a middle click to open page A.A.A | 1505 // Simulate a middle click to open page A.A.A |
1504 TabContentsWrapper* page_a_a_a_contents = CreateTabContents(); | 1506 TabContentsWrapper* page_a_a_a_contents = CreateTabContents(); |
1505 strip.AddTabContents(page_a_a_a_contents, -1, PageTransition::LINK, | 1507 strip.AddTabContents(page_a_a_a_contents, -1, content::PAGE_TRANSITION_LINK, |
1506 TabStripModel::ADD_NONE); | 1508 TabStripModel::ADD_NONE); |
1507 | 1509 |
1508 EXPECT_EQ(page_a_a_a_contents, strip.GetTabContentsAt(2)); | 1510 EXPECT_EQ(page_a_a_a_contents, strip.GetTabContentsAt(2)); |
1509 | 1511 |
1510 // Close page A.A | 1512 // Close page A.A |
1511 strip.CloseTabContentsAt(strip.active_index(), TabStripModel::CLOSE_NONE); | 1513 strip.CloseTabContentsAt(strip.active_index(), TabStripModel::CLOSE_NONE); |
1512 | 1514 |
1513 // Page A.A.A should be selected, NOT A.B | 1515 // Page A.A.A should be selected, NOT A.B |
1514 EXPECT_EQ(page_a_a_a_contents, strip.GetActiveTabContents()); | 1516 EXPECT_EQ(page_a_a_a_contents, strip.GetActiveTabContents()); |
1515 | 1517 |
(...skipping 12 matching lines...) Expand all Loading... |
1528 // Clean up. | 1530 // Clean up. |
1529 strip.CloseAllTabs(); | 1531 strip.CloseAllTabs(); |
1530 } | 1532 } |
1531 | 1533 |
1532 TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) { | 1534 TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) { |
1533 TabStripDummyDelegate delegate(NULL); | 1535 TabStripDummyDelegate delegate(NULL); |
1534 TabStripModel strip(&delegate, profile()); | 1536 TabStripModel strip(&delegate, profile()); |
1535 | 1537 |
1536 // Open page A | 1538 // Open page A |
1537 TabContentsWrapper* page_a_contents = CreateTabContents(); | 1539 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1538 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, | 1540 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE, |
1539 TabStripModel::ADD_ACTIVE); | 1541 TabStripModel::ADD_ACTIVE); |
1540 | 1542 |
1541 // Open pages B, C and D in the background from links on page A... | 1543 // Open pages B, C and D in the background from links on page A... |
1542 TabContentsWrapper* page_b_contents = CreateTabContents(); | 1544 TabContentsWrapper* page_b_contents = CreateTabContents(); |
1543 TabContentsWrapper* page_c_contents = CreateTabContents(); | 1545 TabContentsWrapper* page_c_contents = CreateTabContents(); |
1544 TabContentsWrapper* page_d_contents = CreateTabContents(); | 1546 TabContentsWrapper* page_d_contents = CreateTabContents(); |
1545 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, | 1547 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, |
1546 TabStripModel::ADD_NONE); | 1548 TabStripModel::ADD_NONE); |
1547 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, | 1549 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, |
1548 TabStripModel::ADD_NONE); | 1550 TabStripModel::ADD_NONE); |
1549 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, | 1551 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, |
1550 TabStripModel::ADD_NONE); | 1552 TabStripModel::ADD_NONE); |
1551 | 1553 |
1552 // Switch to page B's tab. | 1554 // Switch to page B's tab. |
1553 strip.ActivateTabAt(1, true); | 1555 strip.ActivateTabAt(1, true); |
1554 | 1556 |
1555 // Open a New Tab at the end of the strip (simulate Ctrl+T) | 1557 // Open a New Tab at the end of the strip (simulate Ctrl+T) |
1556 TabContentsWrapper* new_tab_contents = CreateTabContents(); | 1558 TabContentsWrapper* new_tab_contents = CreateTabContents(); |
1557 strip.AddTabContents(new_tab_contents, -1, PageTransition::TYPED, | 1559 strip.AddTabContents(new_tab_contents, -1, content::PAGE_TRANSITION_TYPED, |
1558 TabStripModel::ADD_ACTIVE); | 1560 TabStripModel::ADD_ACTIVE); |
1559 | 1561 |
1560 EXPECT_EQ(4, strip.GetIndexOfTabContents(new_tab_contents)); | 1562 EXPECT_EQ(4, strip.GetIndexOfTabContents(new_tab_contents)); |
1561 EXPECT_EQ(4, strip.active_index()); | 1563 EXPECT_EQ(4, strip.active_index()); |
1562 | 1564 |
1563 // Close the New Tab that was just opened. We should be returned to page B's | 1565 // Close the New Tab that was just opened. We should be returned to page B's |
1564 // Tab... | 1566 // Tab... |
1565 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); | 1567 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); |
1566 | 1568 |
1567 EXPECT_EQ(1, strip.active_index()); | 1569 EXPECT_EQ(1, strip.active_index()); |
1568 | 1570 |
1569 // Open a non-New Tab tab at the end of the strip, with a TYPED transition. | 1571 // Open a non-New Tab tab at the end of the strip, with a TYPED transition. |
1570 // This is like typing a URL in the address bar and pressing Alt+Enter. The | 1572 // This is like typing a URL in the address bar and pressing Alt+Enter. The |
1571 // behavior should be the same as above. | 1573 // behavior should be the same as above. |
1572 TabContentsWrapper* page_e_contents = CreateTabContents(); | 1574 TabContentsWrapper* page_e_contents = CreateTabContents(); |
1573 strip.AddTabContents(page_e_contents, -1, PageTransition::TYPED, | 1575 strip.AddTabContents(page_e_contents, -1, content::PAGE_TRANSITION_TYPED, |
1574 TabStripModel::ADD_ACTIVE); | 1576 TabStripModel::ADD_ACTIVE); |
1575 | 1577 |
1576 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_e_contents)); | 1578 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_e_contents)); |
1577 EXPECT_EQ(4, strip.active_index()); | 1579 EXPECT_EQ(4, strip.active_index()); |
1578 | 1580 |
1579 // Close the Tab. Selection should shift back to page B's Tab. | 1581 // Close the Tab. Selection should shift back to page B's Tab. |
1580 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); | 1582 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); |
1581 | 1583 |
1582 EXPECT_EQ(1, strip.active_index()); | 1584 EXPECT_EQ(1, strip.active_index()); |
1583 | 1585 |
1584 // Open a non-New Tab tab at the end of the strip, with some other | 1586 // Open a non-New Tab tab at the end of the strip, with some other |
1585 // transition. This is like right clicking on a bookmark and choosing "Open | 1587 // transition. This is like right clicking on a bookmark and choosing "Open |
1586 // in New Tab". No opener relationship should be preserved between this Tab | 1588 // in New Tab". No opener relationship should be preserved between this Tab |
1587 // and the one that was active when the gesture was performed. | 1589 // and the one that was active when the gesture was performed. |
1588 TabContentsWrapper* page_f_contents = CreateTabContents(); | 1590 TabContentsWrapper* page_f_contents = CreateTabContents(); |
1589 strip.AddTabContents(page_f_contents, -1, PageTransition::AUTO_BOOKMARK, | 1591 strip.AddTabContents(page_f_contents, -1, |
| 1592 content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1590 TabStripModel::ADD_ACTIVE); | 1593 TabStripModel::ADD_ACTIVE); |
1591 | 1594 |
1592 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_f_contents)); | 1595 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_f_contents)); |
1593 EXPECT_EQ(4, strip.active_index()); | 1596 EXPECT_EQ(4, strip.active_index()); |
1594 | 1597 |
1595 // Close the Tab. The next-adjacent should be selected. | 1598 // Close the Tab. The next-adjacent should be selected. |
1596 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); | 1599 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); |
1597 | 1600 |
1598 EXPECT_EQ(3, strip.active_index()); | 1601 EXPECT_EQ(3, strip.active_index()); |
1599 | 1602 |
1600 // Clean up. | 1603 // Clean up. |
1601 strip.CloseAllTabs(); | 1604 strip.CloseAllTabs(); |
1602 } | 1605 } |
1603 | 1606 |
1604 // A test of navigations in a tab that is part of a group of opened from some | 1607 // A test of navigations in a tab that is part of a group of opened from some |
1605 // parent tab. If the navigations are link clicks, the group relationship of | 1608 // parent tab. If the navigations are link clicks, the group relationship of |
1606 // the tab to its parent are preserved. If they are of any other type, they are | 1609 // the tab to its parent are preserved. If they are of any other type, they are |
1607 // not preserved. | 1610 // not preserved. |
1608 TEST_F(TabStripModelTest, NavigationForgetsOpeners) { | 1611 TEST_F(TabStripModelTest, NavigationForgetsOpeners) { |
1609 TabStripDummyDelegate delegate(NULL); | 1612 TabStripDummyDelegate delegate(NULL); |
1610 TabStripModel strip(&delegate, profile()); | 1613 TabStripModel strip(&delegate, profile()); |
1611 | 1614 |
1612 // Open page A | 1615 // Open page A |
1613 TabContentsWrapper* page_a_contents = CreateTabContents(); | 1616 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1614 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, | 1617 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE, |
1615 TabStripModel::ADD_ACTIVE); | 1618 TabStripModel::ADD_ACTIVE); |
1616 | 1619 |
1617 // Open pages B, C and D in the background from links on page A... | 1620 // Open pages B, C and D in the background from links on page A... |
1618 TabContentsWrapper* page_b_contents = CreateTabContents(); | 1621 TabContentsWrapper* page_b_contents = CreateTabContents(); |
1619 TabContentsWrapper* page_c_contents = CreateTabContents(); | 1622 TabContentsWrapper* page_c_contents = CreateTabContents(); |
1620 TabContentsWrapper* page_d_contents = CreateTabContents(); | 1623 TabContentsWrapper* page_d_contents = CreateTabContents(); |
1621 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, | 1624 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, |
1622 TabStripModel::ADD_NONE); | 1625 TabStripModel::ADD_NONE); |
1623 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, | 1626 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, |
1624 TabStripModel::ADD_NONE); | 1627 TabStripModel::ADD_NONE); |
1625 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, | 1628 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, |
1626 TabStripModel::ADD_NONE); | 1629 TabStripModel::ADD_NONE); |
1627 | 1630 |
1628 // Open page E in a different opener group from page A. | 1631 // Open page E in a different opener group from page A. |
1629 TabContentsWrapper* page_e_contents = CreateTabContents(); | 1632 TabContentsWrapper* page_e_contents = CreateTabContents(); |
1630 strip.AddTabContents(page_e_contents, -1, PageTransition::START_PAGE, | 1633 strip.AddTabContents(page_e_contents, -1, content::PAGE_TRANSITION_START_PAGE, |
1631 TabStripModel::ADD_NONE); | 1634 TabStripModel::ADD_NONE); |
1632 | 1635 |
1633 // Tell the TabStripModel that we are navigating page D via a link click. | 1636 // Tell the TabStripModel that we are navigating page D via a link click. |
1634 strip.ActivateTabAt(3, true); | 1637 strip.ActivateTabAt(3, true); |
1635 strip.TabNavigating(page_d_contents, PageTransition::LINK); | 1638 strip.TabNavigating(page_d_contents, content::PAGE_TRANSITION_LINK); |
1636 | 1639 |
1637 // Close page D, page C should be selected. (part of same group). | 1640 // Close page D, page C should be selected. (part of same group). |
1638 strip.CloseTabContentsAt(3, TabStripModel::CLOSE_NONE); | 1641 strip.CloseTabContentsAt(3, TabStripModel::CLOSE_NONE); |
1639 EXPECT_EQ(2, strip.active_index()); | 1642 EXPECT_EQ(2, strip.active_index()); |
1640 | 1643 |
1641 // Tell the TabStripModel that we are navigating in page C via a bookmark. | 1644 // Tell the TabStripModel that we are navigating in page C via a bookmark. |
1642 strip.TabNavigating(page_c_contents, PageTransition::AUTO_BOOKMARK); | 1645 strip.TabNavigating(page_c_contents, content::PAGE_TRANSITION_AUTO_BOOKMARK); |
1643 | 1646 |
1644 // Close page C, page E should be selected. (C is no longer part of the | 1647 // Close page C, page E should be selected. (C is no longer part of the |
1645 // A-B-C-D group, selection moves to the right). | 1648 // A-B-C-D group, selection moves to the right). |
1646 strip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); | 1649 strip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); |
1647 EXPECT_EQ(page_e_contents, strip.GetTabContentsAt(strip.active_index())); | 1650 EXPECT_EQ(page_e_contents, strip.GetTabContentsAt(strip.active_index())); |
1648 | 1651 |
1649 strip.CloseAllTabs(); | 1652 strip.CloseAllTabs(); |
1650 } | 1653 } |
1651 | 1654 |
1652 // A test that the forgetting behavior tested in NavigationForgetsOpeners above | 1655 // A test that the forgetting behavior tested in NavigationForgetsOpeners above |
1653 // doesn't cause the opener relationship for a New Tab opened at the end of the | 1656 // doesn't cause the opener relationship for a New Tab opened at the end of the |
1654 // TabStrip to be reset (Test 1 below), unless another any other tab is | 1657 // TabStrip to be reset (Test 1 below), unless another any other tab is |
1655 // seelcted (Test 2 below). | 1658 // seelcted (Test 2 below). |
1656 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) { | 1659 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) { |
1657 TabStripDummyDelegate delegate(NULL); | 1660 TabStripDummyDelegate delegate(NULL); |
1658 TabStripModel strip(&delegate, profile()); | 1661 TabStripModel strip(&delegate, profile()); |
1659 | 1662 |
1660 // Open a tab and several tabs from it, then select one of the tabs that was | 1663 // Open a tab and several tabs from it, then select one of the tabs that was |
1661 // opened. | 1664 // opened. |
1662 TabContentsWrapper* page_a_contents = CreateTabContents(); | 1665 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1663 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, | 1666 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE, |
1664 TabStripModel::ADD_ACTIVE); | 1667 TabStripModel::ADD_ACTIVE); |
1665 | 1668 |
1666 TabContentsWrapper* page_b_contents = CreateTabContents(); | 1669 TabContentsWrapper* page_b_contents = CreateTabContents(); |
1667 TabContentsWrapper* page_c_contents = CreateTabContents(); | 1670 TabContentsWrapper* page_c_contents = CreateTabContents(); |
1668 TabContentsWrapper* page_d_contents = CreateTabContents(); | 1671 TabContentsWrapper* page_d_contents = CreateTabContents(); |
1669 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, | 1672 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, |
1670 TabStripModel::ADD_NONE); | 1673 TabStripModel::ADD_NONE); |
1671 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, | 1674 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, |
1672 TabStripModel::ADD_NONE); | 1675 TabStripModel::ADD_NONE); |
1673 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, | 1676 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, |
1674 TabStripModel::ADD_NONE); | 1677 TabStripModel::ADD_NONE); |
1675 | 1678 |
1676 strip.ActivateTabAt(2, true); | 1679 strip.ActivateTabAt(2, true); |
1677 | 1680 |
1678 // TEST 1: If the user is in a group of tabs and opens a new tab at the end | 1681 // TEST 1: If the user is in a group of tabs and opens a new tab at the end |
1679 // of the strip, closing that new tab will select the tab that they were | 1682 // of the strip, closing that new tab will select the tab that they were |
1680 // last on. | 1683 // last on. |
1681 | 1684 |
1682 // Now simulate opening a new tab at the end of the TabStrip. | 1685 // Now simulate opening a new tab at the end of the TabStrip. |
1683 TabContentsWrapper* new_tab_contents1 = CreateTabContents(); | 1686 TabContentsWrapper* new_tab_contents1 = CreateTabContents(); |
1684 strip.AddTabContents(new_tab_contents1, -1, PageTransition::TYPED, | 1687 strip.AddTabContents(new_tab_contents1, -1, content::PAGE_TRANSITION_TYPED, |
1685 TabStripModel::ADD_ACTIVE); | 1688 TabStripModel::ADD_ACTIVE); |
1686 | 1689 |
1687 // At this point, if we close this tab the last selected one should be | 1690 // At this point, if we close this tab the last selected one should be |
1688 // re-selected. | 1691 // re-selected. |
1689 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); | 1692 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); |
1690 EXPECT_EQ(page_c_contents, strip.GetTabContentsAt(strip.active_index())); | 1693 EXPECT_EQ(page_c_contents, strip.GetTabContentsAt(strip.active_index())); |
1691 | 1694 |
1692 // TEST 2: If the user is in a group of tabs and opens a new tab at the end | 1695 // TEST 2: If the user is in a group of tabs and opens a new tab at the end |
1693 // of the strip, selecting any other tab in the strip will cause that new | 1696 // of the strip, selecting any other tab in the strip will cause that new |
1694 // tab's opener relationship to be forgotten. | 1697 // tab's opener relationship to be forgotten. |
1695 | 1698 |
1696 // Open a new tab again. | 1699 // Open a new tab again. |
1697 TabContentsWrapper* new_tab_contents2 = CreateTabContents(); | 1700 TabContentsWrapper* new_tab_contents2 = CreateTabContents(); |
1698 strip.AddTabContents(new_tab_contents2, -1, PageTransition::TYPED, | 1701 strip.AddTabContents(new_tab_contents2, -1, content::PAGE_TRANSITION_TYPED, |
1699 TabStripModel::ADD_ACTIVE); | 1702 TabStripModel::ADD_ACTIVE); |
1700 | 1703 |
1701 // Now select the first tab. | 1704 // Now select the first tab. |
1702 strip.ActivateTabAt(0, true); | 1705 strip.ActivateTabAt(0, true); |
1703 | 1706 |
1704 // Now select the last tab. | 1707 // Now select the last tab. |
1705 strip.ActivateTabAt(strip.count() - 1, true); | 1708 strip.ActivateTabAt(strip.count() - 1, true); |
1706 | 1709 |
1707 // Now close the last tab. The next adjacent should be selected. | 1710 // Now close the last tab. The next adjacent should be selected. |
1708 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); | 1711 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2064 | 2067 |
2065 // Makes sure the TabStripModel calls the right observer methods during a | 2068 // Makes sure the TabStripModel calls the right observer methods during a |
2066 // replace. | 2069 // replace. |
2067 TEST_F(TabStripModelTest, ReplaceSendsSelected) { | 2070 TEST_F(TabStripModelTest, ReplaceSendsSelected) { |
2068 typedef MockTabStripModelObserver::State State; | 2071 typedef MockTabStripModelObserver::State State; |
2069 | 2072 |
2070 TabStripDummyDelegate delegate(NULL); | 2073 TabStripDummyDelegate delegate(NULL); |
2071 TabStripModel strip(&delegate, profile()); | 2074 TabStripModel strip(&delegate, profile()); |
2072 | 2075 |
2073 TabContentsWrapper* first_contents = CreateTabContents(); | 2076 TabContentsWrapper* first_contents = CreateTabContents(); |
2074 strip.AddTabContents(first_contents, -1, PageTransition::TYPED, | 2077 strip.AddTabContents(first_contents, -1, content::PAGE_TRANSITION_TYPED, |
2075 TabStripModel::ADD_ACTIVE); | 2078 TabStripModel::ADD_ACTIVE); |
2076 | 2079 |
2077 MockTabStripModelObserver tabstrip_observer; | 2080 MockTabStripModelObserver tabstrip_observer; |
2078 strip.AddObserver(&tabstrip_observer); | 2081 strip.AddObserver(&tabstrip_observer); |
2079 | 2082 |
2080 TabContentsWrapper* new_contents = CreateTabContents(); | 2083 TabContentsWrapper* new_contents = CreateTabContents(); |
2081 delete strip.ReplaceTabContentsAt(0, new_contents); | 2084 delete strip.ReplaceTabContentsAt(0, new_contents); |
2082 | 2085 |
2083 ASSERT_EQ(2, tabstrip_observer.GetStateCount()); | 2086 ASSERT_EQ(2, tabstrip_observer.GetStateCount()); |
2084 | 2087 |
2085 // First event should be for replaced. | 2088 // First event should be for replaced. |
2086 State state(new_contents, 0, MockTabStripModelObserver::REPLACED); | 2089 State state(new_contents, 0, MockTabStripModelObserver::REPLACED); |
2087 state.src_contents = first_contents; | 2090 state.src_contents = first_contents; |
2088 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); | 2091 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); |
2089 | 2092 |
2090 // And the second for selected. | 2093 // And the second for selected. |
2091 state = State(new_contents, 0, MockTabStripModelObserver::ACTIVATE); | 2094 state = State(new_contents, 0, MockTabStripModelObserver::ACTIVATE); |
2092 state.src_contents = first_contents; | 2095 state.src_contents = first_contents; |
2093 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state)); | 2096 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state)); |
2094 | 2097 |
2095 // Now add another tab and replace it, making sure we don't get a selected | 2098 // Now add another tab and replace it, making sure we don't get a selected |
2096 // event this time. | 2099 // event this time. |
2097 TabContentsWrapper* third_contents = CreateTabContents(); | 2100 TabContentsWrapper* third_contents = CreateTabContents(); |
2098 strip.AddTabContents(third_contents, 1, PageTransition::TYPED, | 2101 strip.AddTabContents(third_contents, 1, content::PAGE_TRANSITION_TYPED, |
2099 TabStripModel::ADD_NONE); | 2102 TabStripModel::ADD_NONE); |
2100 | 2103 |
2101 tabstrip_observer.ClearStates(); | 2104 tabstrip_observer.ClearStates(); |
2102 | 2105 |
2103 // And replace it. | 2106 // And replace it. |
2104 new_contents = CreateTabContents(); | 2107 new_contents = CreateTabContents(); |
2105 delete strip.ReplaceTabContentsAt(1, new_contents); | 2108 delete strip.ReplaceTabContentsAt(1, new_contents); |
2106 | 2109 |
2107 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); | 2110 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); |
2108 | 2111 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2369 ASSERT_EQ(1, observer.GetStateCount()); | 2372 ASSERT_EQ(1, observer.GetStateCount()); |
2370 MockTabStripModelObserver::State s( | 2373 MockTabStripModelObserver::State s( |
2371 contents2, 1, MockTabStripModelObserver::SELECT); | 2374 contents2, 1, MockTabStripModelObserver::SELECT); |
2372 s.src_contents = contents2; | 2375 s.src_contents = contents2; |
2373 s.src_index = 1; | 2376 s.src_index = 1; |
2374 s.user_gesture = false; | 2377 s.user_gesture = false; |
2375 EXPECT_TRUE(observer.StateEquals(0, s)); | 2378 EXPECT_TRUE(observer.StateEquals(0, s)); |
2376 strip.RemoveObserver(&observer); | 2379 strip.RemoveObserver(&observer); |
2377 strip.CloseAllTabs(); | 2380 strip.CloseAllTabs(); |
2378 } | 2381 } |
OLD | NEW |