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

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

Issue 562603002: Move PageTransition from //content/public/common to //ui/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 // If the last tab in the group is closed, the preceding tab in the same 750 // If the last tab in the group is closed, the preceding tab in the same
751 // group should be selected. 751 // group should be selected.
752 EXPECT_EQ(3, tabstrip.GetIndexOfNextWebContentsOpenedBy(contents5, 4, false)); 752 EXPECT_EQ(3, tabstrip.GetIndexOfNextWebContentsOpenedBy(contents5, 4, false));
753 753
754 tabstrip.CloseAllTabs(); 754 tabstrip.CloseAllTabs();
755 EXPECT_TRUE(tabstrip.empty()); 755 EXPECT_TRUE(tabstrip.empty());
756 } 756 }
757 757
758 static int GetInsertionIndex(TabStripModel* tabstrip) { 758 static int GetInsertionIndex(TabStripModel* tabstrip) {
759 return tabstrip->order_controller()->DetermineInsertionIndex( 759 return tabstrip->order_controller()->DetermineInsertionIndex(
760 content::PAGE_TRANSITION_LINK, false); 760 ui::PAGE_TRANSITION_LINK, false);
761 } 761 }
762 762
763 static void InsertWebContentses(TabStripModel* tabstrip, 763 static void InsertWebContentses(TabStripModel* tabstrip,
764 WebContents* contents1, 764 WebContents* contents1,
765 WebContents* contents2, 765 WebContents* contents2,
766 WebContents* contents3) { 766 WebContents* contents3) {
767 tabstrip->InsertWebContentsAt(GetInsertionIndex(tabstrip), 767 tabstrip->InsertWebContentsAt(GetInsertionIndex(tabstrip),
768 contents1, 768 contents1,
769 TabStripModel::ADD_INHERIT_GROUP); 769 TabStripModel::ADD_INHERIT_GROUP);
770 tabstrip->InsertWebContentsAt(GetInsertionIndex(tabstrip), 770 tabstrip->InsertWebContentsAt(GetInsertionIndex(tabstrip),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 831
832 // The opener API should work... 832 // The opener API should work...
833 EXPECT_EQ(3, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 2, false)); 833 EXPECT_EQ(3, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 2, false));
834 EXPECT_EQ(2, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 3, false)); 834 EXPECT_EQ(2, tabstrip.GetIndexOfNextWebContentsOpenedBy(opener, 3, false));
835 EXPECT_EQ(3, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener, 1)); 835 EXPECT_EQ(3, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener, 1));
836 836
837 // Now open a foreground tab from a link. It should be opened adjacent to the 837 // Now open a foreground tab from a link. It should be opened adjacent to the
838 // opener tab. 838 // opener tab.
839 WebContents* fg_link_contents = CreateWebContents(); 839 WebContents* fg_link_contents = CreateWebContents();
840 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex( 840 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex(
841 content::PAGE_TRANSITION_LINK, true); 841 ui::PAGE_TRANSITION_LINK, true);
842 EXPECT_EQ(1, insert_index); 842 EXPECT_EQ(1, insert_index);
843 tabstrip.InsertWebContentsAt(insert_index, fg_link_contents, 843 tabstrip.InsertWebContentsAt(insert_index, fg_link_contents,
844 TabStripModel::ADD_ACTIVE | 844 TabStripModel::ADD_ACTIVE |
845 TabStripModel::ADD_INHERIT_GROUP); 845 TabStripModel::ADD_INHERIT_GROUP);
846 EXPECT_EQ(1, tabstrip.active_index()); 846 EXPECT_EQ(1, tabstrip.active_index());
847 EXPECT_EQ(fg_link_contents, tabstrip.GetActiveWebContents()); 847 EXPECT_EQ(fg_link_contents, tabstrip.GetActiveWebContents());
848 848
849 // Now close this contents. The selection should move to the opener contents. 849 // Now close this contents. The selection should move to the opener contents.
850 tabstrip.CloseSelectedTabs(); 850 tabstrip.CloseSelectedTabs();
851 EXPECT_EQ(0, tabstrip.active_index()); 851 EXPECT_EQ(0, tabstrip.active_index());
852 852
853 // Now open a new empty tab. It should open at the end of the strip. 853 // Now open a new empty tab. It should open at the end of the strip.
854 WebContents* fg_nonlink_contents = CreateWebContents(); 854 WebContents* fg_nonlink_contents = CreateWebContents();
855 insert_index = tabstrip.order_controller()->DetermineInsertionIndex( 855 insert_index = tabstrip.order_controller()->DetermineInsertionIndex(
856 content::PAGE_TRANSITION_AUTO_BOOKMARK, true); 856 ui::PAGE_TRANSITION_AUTO_BOOKMARK, true);
857 EXPECT_EQ(tabstrip.count(), insert_index); 857 EXPECT_EQ(tabstrip.count(), insert_index);
858 // We break the opener relationship... 858 // We break the opener relationship...
859 tabstrip.InsertWebContentsAt(insert_index, 859 tabstrip.InsertWebContentsAt(insert_index,
860 fg_nonlink_contents, 860 fg_nonlink_contents,
861 TabStripModel::ADD_NONE); 861 TabStripModel::ADD_NONE);
862 // Now select it, so that user_gesture == true causes the opener relationship 862 // Now select it, so that user_gesture == true causes the opener relationship
863 // to be forgotten... 863 // to be forgotten...
864 tabstrip.ActivateTabAt(tabstrip.count() - 1, true); 864 tabstrip.ActivateTabAt(tabstrip.count() - 1, true);
865 EXPECT_EQ(tabstrip.count() - 1, tabstrip.active_index()); 865 EXPECT_EQ(tabstrip.count() - 1, tabstrip.active_index());
866 EXPECT_EQ(fg_nonlink_contents, tabstrip.GetActiveWebContents()); 866 EXPECT_EQ(fg_nonlink_contents, tabstrip.GetActiveWebContents());
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 // using this "smart" function with a simulated middle click action on a series 1226 // using this "smart" function with a simulated middle click action on a series
1227 // of links on the home page. 1227 // of links on the home page.
1228 TEST_F(TabStripModelTest, AddWebContents_MiddleClickLinksAndClose) { 1228 TEST_F(TabStripModelTest, AddWebContents_MiddleClickLinksAndClose) {
1229 TabStripDummyDelegate delegate; 1229 TabStripDummyDelegate delegate;
1230 TabStripModel tabstrip(&delegate, profile()); 1230 TabStripModel tabstrip(&delegate, profile());
1231 EXPECT_TRUE(tabstrip.empty()); 1231 EXPECT_TRUE(tabstrip.empty());
1232 1232
1233 // Open the Home Page. 1233 // Open the Home Page.
1234 WebContents* homepage_contents = CreateWebContents(); 1234 WebContents* homepage_contents = CreateWebContents();
1235 tabstrip.AddWebContents( 1235 tabstrip.AddWebContents(
1236 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1236 homepage_contents, -1, ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1237 TabStripModel::ADD_ACTIVE); 1237 TabStripModel::ADD_ACTIVE);
1238 1238
1239 // Open some other tab, by user typing. 1239 // Open some other tab, by user typing.
1240 WebContents* typed_page_contents = CreateWebContents(); 1240 WebContents* typed_page_contents = CreateWebContents();
1241 tabstrip.AddWebContents( 1241 tabstrip.AddWebContents(
1242 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1242 typed_page_contents, -1, ui::PAGE_TRANSITION_TYPED,
1243 TabStripModel::ADD_ACTIVE); 1243 TabStripModel::ADD_ACTIVE);
1244 1244
1245 EXPECT_EQ(2, tabstrip.count()); 1245 EXPECT_EQ(2, tabstrip.count());
1246 1246
1247 // Re-select the home page. 1247 // Re-select the home page.
1248 tabstrip.ActivateTabAt(0, true); 1248 tabstrip.ActivateTabAt(0, true);
1249 1249
1250 // Open a bunch of tabs by simulating middle clicking on links on the home 1250 // Open a bunch of tabs by simulating middle clicking on links on the home
1251 // page. 1251 // page.
1252 WebContents* middle_click_contents1 = CreateWebContents(); 1252 WebContents* middle_click_contents1 = CreateWebContents();
1253 tabstrip.AddWebContents( 1253 tabstrip.AddWebContents(
1254 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK, 1254 middle_click_contents1, -1, ui::PAGE_TRANSITION_LINK,
1255 TabStripModel::ADD_NONE); 1255 TabStripModel::ADD_NONE);
1256 WebContents* middle_click_contents2 = CreateWebContents(); 1256 WebContents* middle_click_contents2 = CreateWebContents();
1257 tabstrip.AddWebContents( 1257 tabstrip.AddWebContents(
1258 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK, 1258 middle_click_contents2, -1, ui::PAGE_TRANSITION_LINK,
1259 TabStripModel::ADD_NONE); 1259 TabStripModel::ADD_NONE);
1260 WebContents* middle_click_contents3 = CreateWebContents(); 1260 WebContents* middle_click_contents3 = CreateWebContents();
1261 tabstrip.AddWebContents( 1261 tabstrip.AddWebContents(
1262 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK, 1262 middle_click_contents3, -1, ui::PAGE_TRANSITION_LINK,
1263 TabStripModel::ADD_NONE); 1263 TabStripModel::ADD_NONE);
1264 1264
1265 EXPECT_EQ(5, tabstrip.count()); 1265 EXPECT_EQ(5, tabstrip.count());
1266 1266
1267 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0)); 1267 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0));
1268 EXPECT_EQ(middle_click_contents1, tabstrip.GetWebContentsAt(1)); 1268 EXPECT_EQ(middle_click_contents1, tabstrip.GetWebContentsAt(1));
1269 EXPECT_EQ(middle_click_contents2, tabstrip.GetWebContentsAt(2)); 1269 EXPECT_EQ(middle_click_contents2, tabstrip.GetWebContentsAt(2));
1270 EXPECT_EQ(middle_click_contents3, tabstrip.GetWebContentsAt(3)); 1270 EXPECT_EQ(middle_click_contents3, tabstrip.GetWebContentsAt(3));
1271 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(4)); 1271 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(4));
1272 1272
(...skipping 23 matching lines...) Expand all
1296 // that opens a new tab is inserted correctly adjacent to the tab that spawned 1296 // that opens a new tab is inserted correctly adjacent to the tab that spawned
1297 // it. 1297 // it.
1298 TEST_F(TabStripModelTest, AddWebContents_LeftClickPopup) { 1298 TEST_F(TabStripModelTest, AddWebContents_LeftClickPopup) {
1299 TabStripDummyDelegate delegate; 1299 TabStripDummyDelegate delegate;
1300 TabStripModel tabstrip(&delegate, profile()); 1300 TabStripModel tabstrip(&delegate, profile());
1301 EXPECT_TRUE(tabstrip.empty()); 1301 EXPECT_TRUE(tabstrip.empty());
1302 1302
1303 // Open the Home Page. 1303 // Open the Home Page.
1304 WebContents* homepage_contents = CreateWebContents(); 1304 WebContents* homepage_contents = CreateWebContents();
1305 tabstrip.AddWebContents( 1305 tabstrip.AddWebContents(
1306 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1306 homepage_contents, -1, ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1307 TabStripModel::ADD_ACTIVE); 1307 TabStripModel::ADD_ACTIVE);
1308 1308
1309 // Open some other tab, by user typing. 1309 // Open some other tab, by user typing.
1310 WebContents* typed_page_contents = CreateWebContents(); 1310 WebContents* typed_page_contents = CreateWebContents();
1311 tabstrip.AddWebContents( 1311 tabstrip.AddWebContents(
1312 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1312 typed_page_contents, -1, ui::PAGE_TRANSITION_TYPED,
1313 TabStripModel::ADD_ACTIVE); 1313 TabStripModel::ADD_ACTIVE);
1314 1314
1315 EXPECT_EQ(2, tabstrip.count()); 1315 EXPECT_EQ(2, tabstrip.count());
1316 1316
1317 // Re-select the home page. 1317 // Re-select the home page.
1318 tabstrip.ActivateTabAt(0, true); 1318 tabstrip.ActivateTabAt(0, true);
1319 1319
1320 // Open a tab by simulating a left click on a link that opens in a new tab. 1320 // Open a tab by simulating a left click on a link that opens in a new tab.
1321 WebContents* left_click_contents = CreateWebContents(); 1321 WebContents* left_click_contents = CreateWebContents();
1322 tabstrip.AddWebContents(left_click_contents, -1, 1322 tabstrip.AddWebContents(left_click_contents, -1,
1323 content::PAGE_TRANSITION_LINK, 1323 ui::PAGE_TRANSITION_LINK,
1324 TabStripModel::ADD_ACTIVE); 1324 TabStripModel::ADD_ACTIVE);
1325 1325
1326 // Verify the state meets our expectations. 1326 // Verify the state meets our expectations.
1327 EXPECT_EQ(3, tabstrip.count()); 1327 EXPECT_EQ(3, tabstrip.count());
1328 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0)); 1328 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0));
1329 EXPECT_EQ(left_click_contents, tabstrip.GetWebContentsAt(1)); 1329 EXPECT_EQ(left_click_contents, tabstrip.GetWebContentsAt(1));
1330 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(2)); 1330 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(2));
1331 1331
1332 // The newly created tab should be selected. 1332 // The newly created tab should be selected.
1333 EXPECT_EQ(left_click_contents, tabstrip.GetActiveWebContents()); 1333 EXPECT_EQ(left_click_contents, tabstrip.GetActiveWebContents());
(...skipping 13 matching lines...) Expand all
1347 // generated urls, also blank tabs) open at the end of the tabstrip instead of 1347 // generated urls, also blank tabs) open at the end of the tabstrip instead of
1348 // in the middle. 1348 // in the middle.
1349 TEST_F(TabStripModelTest, AddWebContents_CreateNewBlankTab) { 1349 TEST_F(TabStripModelTest, AddWebContents_CreateNewBlankTab) {
1350 TabStripDummyDelegate delegate; 1350 TabStripDummyDelegate delegate;
1351 TabStripModel tabstrip(&delegate, profile()); 1351 TabStripModel tabstrip(&delegate, profile());
1352 EXPECT_TRUE(tabstrip.empty()); 1352 EXPECT_TRUE(tabstrip.empty());
1353 1353
1354 // Open the Home Page. 1354 // Open the Home Page.
1355 WebContents* homepage_contents = CreateWebContents(); 1355 WebContents* homepage_contents = CreateWebContents();
1356 tabstrip.AddWebContents( 1356 tabstrip.AddWebContents(
1357 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1357 homepage_contents, -1, ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1358 TabStripModel::ADD_ACTIVE); 1358 TabStripModel::ADD_ACTIVE);
1359 1359
1360 // Open some other tab, by user typing. 1360 // Open some other tab, by user typing.
1361 WebContents* typed_page_contents = CreateWebContents(); 1361 WebContents* typed_page_contents = CreateWebContents();
1362 tabstrip.AddWebContents( 1362 tabstrip.AddWebContents(
1363 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1363 typed_page_contents, -1, ui::PAGE_TRANSITION_TYPED,
1364 TabStripModel::ADD_ACTIVE); 1364 TabStripModel::ADD_ACTIVE);
1365 1365
1366 EXPECT_EQ(2, tabstrip.count()); 1366 EXPECT_EQ(2, tabstrip.count());
1367 1367
1368 // Re-select the home page. 1368 // Re-select the home page.
1369 tabstrip.ActivateTabAt(0, true); 1369 tabstrip.ActivateTabAt(0, true);
1370 1370
1371 // Open a new blank tab in the foreground. 1371 // Open a new blank tab in the foreground.
1372 WebContents* new_blank_contents = CreateWebContents(); 1372 WebContents* new_blank_contents = CreateWebContents();
1373 tabstrip.AddWebContents(new_blank_contents, -1, 1373 tabstrip.AddWebContents(new_blank_contents, -1,
1374 content::PAGE_TRANSITION_TYPED, 1374 ui::PAGE_TRANSITION_TYPED,
1375 TabStripModel::ADD_ACTIVE); 1375 TabStripModel::ADD_ACTIVE);
1376 1376
1377 // Verify the state of the tabstrip. 1377 // Verify the state of the tabstrip.
1378 EXPECT_EQ(3, tabstrip.count()); 1378 EXPECT_EQ(3, tabstrip.count());
1379 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0)); 1379 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0));
1380 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(1)); 1380 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(1));
1381 EXPECT_EQ(new_blank_contents, tabstrip.GetWebContentsAt(2)); 1381 EXPECT_EQ(new_blank_contents, tabstrip.GetWebContentsAt(2));
1382 1382
1383 // Now open a couple more blank tabs in the background. 1383 // Now open a couple more blank tabs in the background.
1384 WebContents* background_blank_contents1 = CreateWebContents(); 1384 WebContents* background_blank_contents1 = CreateWebContents();
1385 tabstrip.AddWebContents( 1385 tabstrip.AddWebContents(
1386 background_blank_contents1, -1, content::PAGE_TRANSITION_TYPED, 1386 background_blank_contents1, -1, ui::PAGE_TRANSITION_TYPED,
1387 TabStripModel::ADD_NONE); 1387 TabStripModel::ADD_NONE);
1388 WebContents* background_blank_contents2 = CreateWebContents(); 1388 WebContents* background_blank_contents2 = CreateWebContents();
1389 tabstrip.AddWebContents( 1389 tabstrip.AddWebContents(
1390 background_blank_contents2, -1, content::PAGE_TRANSITION_GENERATED, 1390 background_blank_contents2, -1, ui::PAGE_TRANSITION_GENERATED,
1391 TabStripModel::ADD_NONE); 1391 TabStripModel::ADD_NONE);
1392 EXPECT_EQ(5, tabstrip.count()); 1392 EXPECT_EQ(5, tabstrip.count());
1393 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0)); 1393 EXPECT_EQ(homepage_contents, tabstrip.GetWebContentsAt(0));
1394 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(1)); 1394 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(1));
1395 EXPECT_EQ(new_blank_contents, tabstrip.GetWebContentsAt(2)); 1395 EXPECT_EQ(new_blank_contents, tabstrip.GetWebContentsAt(2));
1396 EXPECT_EQ(background_blank_contents1, tabstrip.GetWebContentsAt(3)); 1396 EXPECT_EQ(background_blank_contents1, tabstrip.GetWebContentsAt(3));
1397 EXPECT_EQ(background_blank_contents2, tabstrip.GetWebContentsAt(4)); 1397 EXPECT_EQ(background_blank_contents2, tabstrip.GetWebContentsAt(4));
1398 1398
1399 tabstrip.CloseAllTabs(); 1399 tabstrip.CloseAllTabs();
1400 EXPECT_TRUE(tabstrip.empty()); 1400 EXPECT_TRUE(tabstrip.empty());
1401 } 1401 }
1402 1402
1403 // Tests whether opener state is correctly forgotten when the user switches 1403 // Tests whether opener state is correctly forgotten when the user switches
1404 // context. 1404 // context.
1405 TEST_F(TabStripModelTest, AddWebContents_ForgetOpeners) { 1405 TEST_F(TabStripModelTest, AddWebContents_ForgetOpeners) {
1406 TabStripDummyDelegate delegate; 1406 TabStripDummyDelegate delegate;
1407 TabStripModel tabstrip(&delegate, profile()); 1407 TabStripModel tabstrip(&delegate, profile());
1408 EXPECT_TRUE(tabstrip.empty()); 1408 EXPECT_TRUE(tabstrip.empty());
1409 1409
1410 // Open the Home Page 1410 // Open the Home Page
1411 WebContents* homepage_contents = CreateWebContents(); 1411 WebContents* homepage_contents = CreateWebContents();
1412 tabstrip.AddWebContents( 1412 tabstrip.AddWebContents(
1413 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1413 homepage_contents, -1, ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1414 TabStripModel::ADD_ACTIVE); 1414 TabStripModel::ADD_ACTIVE);
1415 1415
1416 // Open some other tab, by user typing. 1416 // Open some other tab, by user typing.
1417 WebContents* typed_page_contents = CreateWebContents(); 1417 WebContents* typed_page_contents = CreateWebContents();
1418 tabstrip.AddWebContents( 1418 tabstrip.AddWebContents(
1419 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1419 typed_page_contents, -1, ui::PAGE_TRANSITION_TYPED,
1420 TabStripModel::ADD_ACTIVE); 1420 TabStripModel::ADD_ACTIVE);
1421 1421
1422 EXPECT_EQ(2, tabstrip.count()); 1422 EXPECT_EQ(2, tabstrip.count());
1423 1423
1424 // Re-select the home page. 1424 // Re-select the home page.
1425 tabstrip.ActivateTabAt(0, true); 1425 tabstrip.ActivateTabAt(0, true);
1426 1426
1427 // Open a bunch of tabs by simulating middle clicking on links on the home 1427 // Open a bunch of tabs by simulating middle clicking on links on the home
1428 // page. 1428 // page.
1429 WebContents* middle_click_contents1 = CreateWebContents(); 1429 WebContents* middle_click_contents1 = CreateWebContents();
1430 tabstrip.AddWebContents( 1430 tabstrip.AddWebContents(
1431 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK, 1431 middle_click_contents1, -1, ui::PAGE_TRANSITION_LINK,
1432 TabStripModel::ADD_NONE); 1432 TabStripModel::ADD_NONE);
1433 WebContents* middle_click_contents2 = CreateWebContents(); 1433 WebContents* middle_click_contents2 = CreateWebContents();
1434 tabstrip.AddWebContents( 1434 tabstrip.AddWebContents(
1435 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK, 1435 middle_click_contents2, -1, ui::PAGE_TRANSITION_LINK,
1436 TabStripModel::ADD_NONE); 1436 TabStripModel::ADD_NONE);
1437 WebContents* middle_click_contents3 = CreateWebContents(); 1437 WebContents* middle_click_contents3 = CreateWebContents();
1438 tabstrip.AddWebContents( 1438 tabstrip.AddWebContents(
1439 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK, 1439 middle_click_contents3, -1, ui::PAGE_TRANSITION_LINK,
1440 TabStripModel::ADD_NONE); 1440 TabStripModel::ADD_NONE);
1441 1441
1442 // Break out of the context by selecting a tab in a different context. 1442 // Break out of the context by selecting a tab in a different context.
1443 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(4)); 1443 EXPECT_EQ(typed_page_contents, tabstrip.GetWebContentsAt(4));
1444 tabstrip.SelectLastTab(); 1444 tabstrip.SelectLastTab();
1445 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveWebContents()); 1445 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveWebContents());
1446 1446
1447 // Step back into the context by selecting a tab inside it. 1447 // Step back into the context by selecting a tab inside it.
1448 tabstrip.ActivateTabAt(2, true); 1448 tabstrip.ActivateTabAt(2, true);
1449 EXPECT_EQ(middle_click_contents2, tabstrip.GetActiveWebContents()); 1449 EXPECT_EQ(middle_click_contents2, tabstrip.GetActiveWebContents());
(...skipping 18 matching lines...) Expand all
1468 1468
1469 // Added for http://b/issue?id=958960 1469 // Added for http://b/issue?id=958960
1470 TEST_F(TabStripModelTest, AppendContentsReselectionTest) { 1470 TEST_F(TabStripModelTest, AppendContentsReselectionTest) {
1471 TabStripDummyDelegate delegate; 1471 TabStripDummyDelegate delegate;
1472 TabStripModel tabstrip(&delegate, profile()); 1472 TabStripModel tabstrip(&delegate, profile());
1473 EXPECT_TRUE(tabstrip.empty()); 1473 EXPECT_TRUE(tabstrip.empty());
1474 1474
1475 // Open the Home Page. 1475 // Open the Home Page.
1476 WebContents* homepage_contents = CreateWebContents(); 1476 WebContents* homepage_contents = CreateWebContents();
1477 tabstrip.AddWebContents( 1477 tabstrip.AddWebContents(
1478 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1478 homepage_contents, -1, ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1479 TabStripModel::ADD_ACTIVE); 1479 TabStripModel::ADD_ACTIVE);
1480 1480
1481 // Open some other tab, by user typing. 1481 // Open some other tab, by user typing.
1482 WebContents* typed_page_contents = CreateWebContents(); 1482 WebContents* typed_page_contents = CreateWebContents();
1483 tabstrip.AddWebContents( 1483 tabstrip.AddWebContents(
1484 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1484 typed_page_contents, -1, ui::PAGE_TRANSITION_TYPED,
1485 TabStripModel::ADD_NONE); 1485 TabStripModel::ADD_NONE);
1486 1486
1487 // The selected tab should still be the first. 1487 // The selected tab should still be the first.
1488 EXPECT_EQ(0, tabstrip.active_index()); 1488 EXPECT_EQ(0, tabstrip.active_index());
1489 1489
1490 // Now simulate a link click that opens a new tab (by virtue of target=_blank) 1490 // Now simulate a link click that opens a new tab (by virtue of target=_blank)
1491 // and make sure the correct tab gets selected when the new tab is closed. 1491 // and make sure the correct tab gets selected when the new tab is closed.
1492 WebContents* target_blank = CreateWebContents(); 1492 WebContents* target_blank = CreateWebContents();
1493 tabstrip.AppendWebContents(target_blank, true); 1493 tabstrip.AppendWebContents(target_blank, true);
1494 EXPECT_EQ(2, tabstrip.active_index()); 1494 EXPECT_EQ(2, tabstrip.active_index());
1495 tabstrip.CloseWebContentsAt(2, TabStripModel::CLOSE_NONE); 1495 tabstrip.CloseWebContentsAt(2, TabStripModel::CLOSE_NONE);
1496 EXPECT_EQ(0, tabstrip.active_index()); 1496 EXPECT_EQ(0, tabstrip.active_index());
1497 1497
1498 // Clean up after ourselves. 1498 // Clean up after ourselves.
1499 tabstrip.CloseAllTabs(); 1499 tabstrip.CloseAllTabs();
1500 } 1500 }
1501 1501
1502 // Added for http://b/issue?id=1027661 1502 // Added for http://b/issue?id=1027661
1503 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) { 1503 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) {
1504 TabStripDummyDelegate delegate; 1504 TabStripDummyDelegate delegate;
1505 TabStripModel strip(&delegate, profile()); 1505 TabStripModel strip(&delegate, profile());
1506 1506
1507 // Open page A 1507 // Open page A
1508 WebContents* page_a_contents = CreateWebContents(); 1508 WebContents* page_a_contents = CreateWebContents();
1509 strip.AddWebContents( 1509 strip.AddWebContents(
1510 page_a_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1510 page_a_contents, -1, ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1511 TabStripModel::ADD_ACTIVE); 1511 TabStripModel::ADD_ACTIVE);
1512 1512
1513 // Simulate middle click to open page A.A and A.B 1513 // Simulate middle click to open page A.A and A.B
1514 WebContents* page_a_a_contents = CreateWebContents(); 1514 WebContents* page_a_a_contents = CreateWebContents();
1515 strip.AddWebContents(page_a_a_contents, -1, content::PAGE_TRANSITION_LINK, 1515 strip.AddWebContents(page_a_a_contents, -1, ui::PAGE_TRANSITION_LINK,
1516 TabStripModel::ADD_NONE); 1516 TabStripModel::ADD_NONE);
1517 WebContents* page_a_b_contents = CreateWebContents(); 1517 WebContents* page_a_b_contents = CreateWebContents();
1518 strip.AddWebContents(page_a_b_contents, -1, content::PAGE_TRANSITION_LINK, 1518 strip.AddWebContents(page_a_b_contents, -1, ui::PAGE_TRANSITION_LINK,
1519 TabStripModel::ADD_NONE); 1519 TabStripModel::ADD_NONE);
1520 1520
1521 // Select page A.A 1521 // Select page A.A
1522 strip.ActivateTabAt(1, true); 1522 strip.ActivateTabAt(1, true);
1523 EXPECT_EQ(page_a_a_contents, strip.GetActiveWebContents()); 1523 EXPECT_EQ(page_a_a_contents, strip.GetActiveWebContents());
1524 1524
1525 // Simulate a middle click to open page A.A.A 1525 // Simulate a middle click to open page A.A.A
1526 WebContents* page_a_a_a_contents = CreateWebContents(); 1526 WebContents* page_a_a_a_contents = CreateWebContents();
1527 strip.AddWebContents(page_a_a_a_contents, -1, content::PAGE_TRANSITION_LINK, 1527 strip.AddWebContents(page_a_a_a_contents, -1, ui::PAGE_TRANSITION_LINK,
1528 TabStripModel::ADD_NONE); 1528 TabStripModel::ADD_NONE);
1529 1529
1530 EXPECT_EQ(page_a_a_a_contents, strip.GetWebContentsAt(2)); 1530 EXPECT_EQ(page_a_a_a_contents, strip.GetWebContentsAt(2));
1531 1531
1532 // Close page A.A 1532 // Close page A.A
1533 strip.CloseWebContentsAt(strip.active_index(), TabStripModel::CLOSE_NONE); 1533 strip.CloseWebContentsAt(strip.active_index(), TabStripModel::CLOSE_NONE);
1534 1534
1535 // Page A.A.A should be selected, NOT A.B 1535 // Page A.A.A should be selected, NOT A.B
1536 EXPECT_EQ(page_a_a_a_contents, strip.GetActiveWebContents()); 1536 EXPECT_EQ(page_a_a_a_contents, strip.GetActiveWebContents());
1537 1537
(...skipping 13 matching lines...) Expand all
1551 strip.CloseAllTabs(); 1551 strip.CloseAllTabs();
1552 } 1552 }
1553 1553
1554 TEST_F(TabStripModelTest, AddWebContents_NewTabAtEndOfStripInheritsGroup) { 1554 TEST_F(TabStripModelTest, AddWebContents_NewTabAtEndOfStripInheritsGroup) {
1555 TabStripDummyDelegate delegate; 1555 TabStripDummyDelegate delegate;
1556 TabStripModel strip(&delegate, profile()); 1556 TabStripModel strip(&delegate, profile());
1557 1557
1558 // Open page A 1558 // Open page A
1559 WebContents* page_a_contents = CreateWebContents(); 1559 WebContents* page_a_contents = CreateWebContents();
1560 strip.AddWebContents(page_a_contents, -1, 1560 strip.AddWebContents(page_a_contents, -1,
1561 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1561 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1562 TabStripModel::ADD_ACTIVE); 1562 TabStripModel::ADD_ACTIVE);
1563 1563
1564 // Open pages B, C and D in the background from links on page A... 1564 // Open pages B, C and D in the background from links on page A...
1565 WebContents* page_b_contents = CreateWebContents(); 1565 WebContents* page_b_contents = CreateWebContents();
1566 WebContents* page_c_contents = CreateWebContents(); 1566 WebContents* page_c_contents = CreateWebContents();
1567 WebContents* page_d_contents = CreateWebContents(); 1567 WebContents* page_d_contents = CreateWebContents();
1568 strip.AddWebContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, 1568 strip.AddWebContents(page_b_contents, -1, ui::PAGE_TRANSITION_LINK,
1569 TabStripModel::ADD_NONE); 1569 TabStripModel::ADD_NONE);
1570 strip.AddWebContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, 1570 strip.AddWebContents(page_c_contents, -1, ui::PAGE_TRANSITION_LINK,
1571 TabStripModel::ADD_NONE); 1571 TabStripModel::ADD_NONE);
1572 strip.AddWebContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, 1572 strip.AddWebContents(page_d_contents, -1, ui::PAGE_TRANSITION_LINK,
1573 TabStripModel::ADD_NONE); 1573 TabStripModel::ADD_NONE);
1574 1574
1575 // Switch to page B's tab. 1575 // Switch to page B's tab.
1576 strip.ActivateTabAt(1, true); 1576 strip.ActivateTabAt(1, true);
1577 1577
1578 // Open a New Tab at the end of the strip (simulate Ctrl+T) 1578 // Open a New Tab at the end of the strip (simulate Ctrl+T)
1579 WebContents* new_contents = CreateWebContents(); 1579 WebContents* new_contents = CreateWebContents();
1580 strip.AddWebContents(new_contents, -1, content::PAGE_TRANSITION_TYPED, 1580 strip.AddWebContents(new_contents, -1, ui::PAGE_TRANSITION_TYPED,
1581 TabStripModel::ADD_ACTIVE); 1581 TabStripModel::ADD_ACTIVE);
1582 1582
1583 EXPECT_EQ(4, strip.GetIndexOfWebContents(new_contents)); 1583 EXPECT_EQ(4, strip.GetIndexOfWebContents(new_contents));
1584 EXPECT_EQ(4, strip.active_index()); 1584 EXPECT_EQ(4, strip.active_index());
1585 1585
1586 // Close the New Tab that was just opened. We should be returned to page B's 1586 // Close the New Tab that was just opened. We should be returned to page B's
1587 // Tab... 1587 // Tab...
1588 strip.CloseWebContentsAt(4, TabStripModel::CLOSE_NONE); 1588 strip.CloseWebContentsAt(4, TabStripModel::CLOSE_NONE);
1589 1589
1590 EXPECT_EQ(1, strip.active_index()); 1590 EXPECT_EQ(1, strip.active_index());
1591 1591
1592 // Open a non-New Tab tab at the end of the strip, with a TYPED transition. 1592 // Open a non-New Tab tab at the end of the strip, with a TYPED transition.
1593 // This is like typing a URL in the address bar and pressing Alt+Enter. The 1593 // This is like typing a URL in the address bar and pressing Alt+Enter. The
1594 // behavior should be the same as above. 1594 // behavior should be the same as above.
1595 WebContents* page_e_contents = CreateWebContents(); 1595 WebContents* page_e_contents = CreateWebContents();
1596 strip.AddWebContents(page_e_contents, -1, content::PAGE_TRANSITION_TYPED, 1596 strip.AddWebContents(page_e_contents, -1, ui::PAGE_TRANSITION_TYPED,
1597 TabStripModel::ADD_ACTIVE); 1597 TabStripModel::ADD_ACTIVE);
1598 1598
1599 EXPECT_EQ(4, strip.GetIndexOfWebContents(page_e_contents)); 1599 EXPECT_EQ(4, strip.GetIndexOfWebContents(page_e_contents));
1600 EXPECT_EQ(4, strip.active_index()); 1600 EXPECT_EQ(4, strip.active_index());
1601 1601
1602 // Close the Tab. Selection should shift back to page B's Tab. 1602 // Close the Tab. Selection should shift back to page B's Tab.
1603 strip.CloseWebContentsAt(4, TabStripModel::CLOSE_NONE); 1603 strip.CloseWebContentsAt(4, TabStripModel::CLOSE_NONE);
1604 1604
1605 EXPECT_EQ(1, strip.active_index()); 1605 EXPECT_EQ(1, strip.active_index());
1606 1606
1607 // Open a non-New Tab tab at the end of the strip, with some other 1607 // Open a non-New Tab tab at the end of the strip, with some other
1608 // transition. This is like right clicking on a bookmark and choosing "Open 1608 // transition. This is like right clicking on a bookmark and choosing "Open
1609 // in New Tab". No opener relationship should be preserved between this Tab 1609 // in New Tab". No opener relationship should be preserved between this Tab
1610 // and the one that was active when the gesture was performed. 1610 // and the one that was active when the gesture was performed.
1611 WebContents* page_f_contents = CreateWebContents(); 1611 WebContents* page_f_contents = CreateWebContents();
1612 strip.AddWebContents(page_f_contents, -1, 1612 strip.AddWebContents(page_f_contents, -1,
1613 content::PAGE_TRANSITION_AUTO_BOOKMARK, 1613 ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1614 TabStripModel::ADD_ACTIVE); 1614 TabStripModel::ADD_ACTIVE);
1615 1615
1616 EXPECT_EQ(4, strip.GetIndexOfWebContents(page_f_contents)); 1616 EXPECT_EQ(4, strip.GetIndexOfWebContents(page_f_contents));
1617 EXPECT_EQ(4, strip.active_index()); 1617 EXPECT_EQ(4, strip.active_index());
1618 1618
1619 // Close the Tab. The next-adjacent should be selected. 1619 // Close the Tab. The next-adjacent should be selected.
1620 strip.CloseWebContentsAt(4, TabStripModel::CLOSE_NONE); 1620 strip.CloseWebContentsAt(4, TabStripModel::CLOSE_NONE);
1621 1621
1622 EXPECT_EQ(3, strip.active_index()); 1622 EXPECT_EQ(3, strip.active_index());
1623 1623
1624 // Clean up. 1624 // Clean up.
1625 strip.CloseAllTabs(); 1625 strip.CloseAllTabs();
1626 } 1626 }
1627 1627
1628 // A test of navigations in a tab that is part of a group of opened from some 1628 // A test of navigations in a tab that is part of a group of opened from some
1629 // parent tab. If the navigations are link clicks, the group relationship of 1629 // parent tab. If the navigations are link clicks, the group relationship of
1630 // the tab to its parent are preserved. If they are of any other type, they are 1630 // the tab to its parent are preserved. If they are of any other type, they are
1631 // not preserved. 1631 // not preserved.
1632 TEST_F(TabStripModelTest, NavigationForgetsOpeners) { 1632 TEST_F(TabStripModelTest, NavigationForgetsOpeners) {
1633 TabStripDummyDelegate delegate; 1633 TabStripDummyDelegate delegate;
1634 TabStripModel strip(&delegate, profile()); 1634 TabStripModel strip(&delegate, profile());
1635 1635
1636 // Open page A 1636 // Open page A
1637 WebContents* page_a_contents = CreateWebContents(); 1637 WebContents* page_a_contents = CreateWebContents();
1638 strip.AddWebContents(page_a_contents, -1, 1638 strip.AddWebContents(page_a_contents, -1,
1639 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1639 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1640 TabStripModel::ADD_ACTIVE); 1640 TabStripModel::ADD_ACTIVE);
1641 1641
1642 // Open pages B, C and D in the background from links on page A... 1642 // Open pages B, C and D in the background from links on page A...
1643 WebContents* page_b_contents = CreateWebContents(); 1643 WebContents* page_b_contents = CreateWebContents();
1644 WebContents* page_c_contents = CreateWebContents(); 1644 WebContents* page_c_contents = CreateWebContents();
1645 WebContents* page_d_contents = CreateWebContents(); 1645 WebContents* page_d_contents = CreateWebContents();
1646 strip.AddWebContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, 1646 strip.AddWebContents(page_b_contents, -1, ui::PAGE_TRANSITION_LINK,
1647 TabStripModel::ADD_NONE); 1647 TabStripModel::ADD_NONE);
1648 strip.AddWebContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, 1648 strip.AddWebContents(page_c_contents, -1, ui::PAGE_TRANSITION_LINK,
1649 TabStripModel::ADD_NONE); 1649 TabStripModel::ADD_NONE);
1650 strip.AddWebContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, 1650 strip.AddWebContents(page_d_contents, -1, ui::PAGE_TRANSITION_LINK,
1651 TabStripModel::ADD_NONE); 1651 TabStripModel::ADD_NONE);
1652 1652
1653 // Open page E in a different opener group from page A. 1653 // Open page E in a different opener group from page A.
1654 WebContents* page_e_contents = CreateWebContents(); 1654 WebContents* page_e_contents = CreateWebContents();
1655 strip.AddWebContents(page_e_contents, -1, 1655 strip.AddWebContents(page_e_contents, -1,
1656 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1656 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1657 TabStripModel::ADD_NONE); 1657 TabStripModel::ADD_NONE);
1658 1658
1659 // Tell the TabStripModel that we are navigating page D via a link click. 1659 // Tell the TabStripModel that we are navigating page D via a link click.
1660 strip.ActivateTabAt(3, true); 1660 strip.ActivateTabAt(3, true);
1661 strip.TabNavigating(page_d_contents, content::PAGE_TRANSITION_LINK); 1661 strip.TabNavigating(page_d_contents, ui::PAGE_TRANSITION_LINK);
1662 1662
1663 // Close page D, page C should be selected. (part of same group). 1663 // Close page D, page C should be selected. (part of same group).
1664 strip.CloseWebContentsAt(3, TabStripModel::CLOSE_NONE); 1664 strip.CloseWebContentsAt(3, TabStripModel::CLOSE_NONE);
1665 EXPECT_EQ(2, strip.active_index()); 1665 EXPECT_EQ(2, strip.active_index());
1666 1666
1667 // Tell the TabStripModel that we are navigating in page C via a bookmark. 1667 // Tell the TabStripModel that we are navigating in page C via a bookmark.
1668 strip.TabNavigating(page_c_contents, content::PAGE_TRANSITION_AUTO_BOOKMARK); 1668 strip.TabNavigating(page_c_contents, ui::PAGE_TRANSITION_AUTO_BOOKMARK);
1669 1669
1670 // Close page C, page E should be selected. (C is no longer part of the 1670 // Close page C, page E should be selected. (C is no longer part of the
1671 // A-B-C-D group, selection moves to the right). 1671 // A-B-C-D group, selection moves to the right).
1672 strip.CloseWebContentsAt(2, TabStripModel::CLOSE_NONE); 1672 strip.CloseWebContentsAt(2, TabStripModel::CLOSE_NONE);
1673 EXPECT_EQ(page_e_contents, strip.GetWebContentsAt(strip.active_index())); 1673 EXPECT_EQ(page_e_contents, strip.GetWebContentsAt(strip.active_index()));
1674 1674
1675 strip.CloseAllTabs(); 1675 strip.CloseAllTabs();
1676 } 1676 }
1677 1677
1678 // A test that the forgetting behavior tested in NavigationForgetsOpeners above 1678 // A test that the forgetting behavior tested in NavigationForgetsOpeners above
1679 // doesn't cause the opener relationship for a New Tab opened at the end of the 1679 // doesn't cause the opener relationship for a New Tab opened at the end of the
1680 // TabStrip to be reset (Test 1 below), unless another any other tab is 1680 // TabStrip to be reset (Test 1 below), unless another any other tab is
1681 // selected (Test 2 below). 1681 // selected (Test 2 below).
1682 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) { 1682 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
1683 TabStripDummyDelegate delegate; 1683 TabStripDummyDelegate delegate;
1684 TabStripModel strip(&delegate, profile()); 1684 TabStripModel strip(&delegate, profile());
1685 1685
1686 // Open a tab and several tabs from it, then select one of the tabs that was 1686 // Open a tab and several tabs from it, then select one of the tabs that was
1687 // opened. 1687 // opened.
1688 WebContents* page_a_contents = CreateWebContents(); 1688 WebContents* page_a_contents = CreateWebContents();
1689 strip.AddWebContents(page_a_contents, -1, 1689 strip.AddWebContents(page_a_contents, -1,
1690 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1690 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1691 TabStripModel::ADD_ACTIVE); 1691 TabStripModel::ADD_ACTIVE);
1692 1692
1693 WebContents* page_b_contents = CreateWebContents(); 1693 WebContents* page_b_contents = CreateWebContents();
1694 WebContents* page_c_contents = CreateWebContents(); 1694 WebContents* page_c_contents = CreateWebContents();
1695 WebContents* page_d_contents = CreateWebContents(); 1695 WebContents* page_d_contents = CreateWebContents();
1696 strip.AddWebContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, 1696 strip.AddWebContents(page_b_contents, -1, ui::PAGE_TRANSITION_LINK,
1697 TabStripModel::ADD_NONE); 1697 TabStripModel::ADD_NONE);
1698 strip.AddWebContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, 1698 strip.AddWebContents(page_c_contents, -1, ui::PAGE_TRANSITION_LINK,
1699 TabStripModel::ADD_NONE); 1699 TabStripModel::ADD_NONE);
1700 strip.AddWebContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, 1700 strip.AddWebContents(page_d_contents, -1, ui::PAGE_TRANSITION_LINK,
1701 TabStripModel::ADD_NONE); 1701 TabStripModel::ADD_NONE);
1702 1702
1703 strip.ActivateTabAt(2, true); 1703 strip.ActivateTabAt(2, true);
1704 1704
1705 // TEST 1: If the user is in a group of tabs and opens a new tab at the end 1705 // TEST 1: If the user is in a group of tabs and opens a new tab at the end
1706 // of the strip, closing that new tab will select the tab that they were 1706 // of the strip, closing that new tab will select the tab that they were
1707 // last on. 1707 // last on.
1708 1708
1709 // Now simulate opening a new tab at the end of the TabStrip. 1709 // Now simulate opening a new tab at the end of the TabStrip.
1710 WebContents* new_contents1 = CreateWebContents(); 1710 WebContents* new_contents1 = CreateWebContents();
1711 strip.AddWebContents(new_contents1, -1, content::PAGE_TRANSITION_TYPED, 1711 strip.AddWebContents(new_contents1, -1, ui::PAGE_TRANSITION_TYPED,
1712 TabStripModel::ADD_ACTIVE); 1712 TabStripModel::ADD_ACTIVE);
1713 1713
1714 // At this point, if we close this tab the last selected one should be 1714 // At this point, if we close this tab the last selected one should be
1715 // re-selected. 1715 // re-selected.
1716 strip.CloseWebContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); 1716 strip.CloseWebContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE);
1717 EXPECT_EQ(page_c_contents, strip.GetWebContentsAt(strip.active_index())); 1717 EXPECT_EQ(page_c_contents, strip.GetWebContentsAt(strip.active_index()));
1718 1718
1719 // TEST 2: If the user is in a group of tabs and opens a new tab at the end 1719 // TEST 2: If the user is in a group of tabs and opens a new tab at the end
1720 // of the strip, selecting any other tab in the strip will cause that new 1720 // of the strip, selecting any other tab in the strip will cause that new
1721 // tab's opener relationship to be forgotten. 1721 // tab's opener relationship to be forgotten.
1722 1722
1723 // Open a new tab again. 1723 // Open a new tab again.
1724 WebContents* new_contents2 = CreateWebContents(); 1724 WebContents* new_contents2 = CreateWebContents();
1725 strip.AddWebContents(new_contents2, -1, content::PAGE_TRANSITION_TYPED, 1725 strip.AddWebContents(new_contents2, -1, ui::PAGE_TRANSITION_TYPED,
1726 TabStripModel::ADD_ACTIVE); 1726 TabStripModel::ADD_ACTIVE);
1727 1727
1728 // Now select the first tab. 1728 // Now select the first tab.
1729 strip.ActivateTabAt(0, true); 1729 strip.ActivateTabAt(0, true);
1730 1730
1731 // Now select the last tab. 1731 // Now select the last tab.
1732 strip.ActivateTabAt(strip.count() - 1, true); 1732 strip.ActivateTabAt(strip.count() - 1, true);
1733 1733
1734 // Now close the last tab. The next adjacent should be selected. 1734 // Now close the last tab. The next adjacent should be selected.
1735 strip.CloseWebContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); 1735 strip.CloseWebContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE);
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 2106
2107 // Makes sure the TabStripModel calls the right observer methods during a 2107 // Makes sure the TabStripModel calls the right observer methods during a
2108 // replace. 2108 // replace.
2109 TEST_F(TabStripModelTest, ReplaceSendsSelected) { 2109 TEST_F(TabStripModelTest, ReplaceSendsSelected) {
2110 typedef MockTabStripModelObserver::State State; 2110 typedef MockTabStripModelObserver::State State;
2111 2111
2112 TabStripDummyDelegate delegate; 2112 TabStripDummyDelegate delegate;
2113 TabStripModel strip(&delegate, profile()); 2113 TabStripModel strip(&delegate, profile());
2114 2114
2115 WebContents* first_contents = CreateWebContents(); 2115 WebContents* first_contents = CreateWebContents();
2116 strip.AddWebContents(first_contents, -1, content::PAGE_TRANSITION_TYPED, 2116 strip.AddWebContents(first_contents, -1, ui::PAGE_TRANSITION_TYPED,
2117 TabStripModel::ADD_ACTIVE); 2117 TabStripModel::ADD_ACTIVE);
2118 2118
2119 MockTabStripModelObserver tabstrip_observer(&strip); 2119 MockTabStripModelObserver tabstrip_observer(&strip);
2120 strip.AddObserver(&tabstrip_observer); 2120 strip.AddObserver(&tabstrip_observer);
2121 2121
2122 WebContents* new_contents = CreateWebContents(); 2122 WebContents* new_contents = CreateWebContents();
2123 delete strip.ReplaceWebContentsAt(0, new_contents); 2123 delete strip.ReplaceWebContentsAt(0, new_contents);
2124 2124
2125 ASSERT_EQ(2, tabstrip_observer.GetStateCount()); 2125 ASSERT_EQ(2, tabstrip_observer.GetStateCount());
2126 2126
2127 // First event should be for replaced. 2127 // First event should be for replaced.
2128 State state(new_contents, 0, MockTabStripModelObserver::REPLACED); 2128 State state(new_contents, 0, MockTabStripModelObserver::REPLACED);
2129 state.src_contents = first_contents; 2129 state.src_contents = first_contents;
2130 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); 2130 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state));
2131 2131
2132 // And the second for selected. 2132 // And the second for selected.
2133 state = State(new_contents, 0, MockTabStripModelObserver::ACTIVATE); 2133 state = State(new_contents, 0, MockTabStripModelObserver::ACTIVATE);
2134 state.src_contents = first_contents; 2134 state.src_contents = first_contents;
2135 state.change_reason = TabStripModelObserver::CHANGE_REASON_REPLACED; 2135 state.change_reason = TabStripModelObserver::CHANGE_REASON_REPLACED;
2136 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state)); 2136 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state));
2137 2137
2138 // Now add another tab and replace it, making sure we don't get a selected 2138 // Now add another tab and replace it, making sure we don't get a selected
2139 // event this time. 2139 // event this time.
2140 WebContents* third_contents = CreateWebContents(); 2140 WebContents* third_contents = CreateWebContents();
2141 strip.AddWebContents(third_contents, 1, content::PAGE_TRANSITION_TYPED, 2141 strip.AddWebContents(third_contents, 1, ui::PAGE_TRANSITION_TYPED,
2142 TabStripModel::ADD_NONE); 2142 TabStripModel::ADD_NONE);
2143 2143
2144 tabstrip_observer.ClearStates(); 2144 tabstrip_observer.ClearStates();
2145 2145
2146 // And replace it. 2146 // And replace it.
2147 new_contents = CreateWebContents(); 2147 new_contents = CreateWebContents();
2148 delete strip.ReplaceWebContentsAt(1, new_contents); 2148 delete strip.ReplaceWebContentsAt(1, new_contents);
2149 2149
2150 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); 2150 ASSERT_EQ(1, tabstrip_observer.GetStateCount());
2151 2151
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 } 2324 }
2325 2325
2326 // Tests that moving a tab forgets all groups referencing it. 2326 // Tests that moving a tab forgets all groups referencing it.
2327 TEST_F(TabStripModelTest, MoveSelectedTabsTo_ForgetGroups) { 2327 TEST_F(TabStripModelTest, MoveSelectedTabsTo_ForgetGroups) {
2328 TabStripDummyDelegate delegate; 2328 TabStripDummyDelegate delegate;
2329 TabStripModel strip(&delegate, profile()); 2329 TabStripModel strip(&delegate, profile());
2330 2330
2331 // Open page A as a new tab and then A1 in the background from A. 2331 // Open page A as a new tab and then A1 in the background from A.
2332 WebContents* page_a_contents = CreateWebContents(); 2332 WebContents* page_a_contents = CreateWebContents();
2333 strip.AddWebContents(page_a_contents, -1, 2333 strip.AddWebContents(page_a_contents, -1,
2334 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 2334 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
2335 TabStripModel::ADD_ACTIVE); 2335 TabStripModel::ADD_ACTIVE);
2336 WebContents* page_a1_contents = CreateWebContents(); 2336 WebContents* page_a1_contents = CreateWebContents();
2337 strip.AddWebContents(page_a1_contents, -1, content::PAGE_TRANSITION_LINK, 2337 strip.AddWebContents(page_a1_contents, -1, ui::PAGE_TRANSITION_LINK,
2338 TabStripModel::ADD_NONE); 2338 TabStripModel::ADD_NONE);
2339 2339
2340 // Likewise, open pages B and B1. 2340 // Likewise, open pages B and B1.
2341 WebContents* page_b_contents = CreateWebContents(); 2341 WebContents* page_b_contents = CreateWebContents();
2342 strip.AddWebContents(page_b_contents, -1, 2342 strip.AddWebContents(page_b_contents, -1,
2343 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 2343 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
2344 TabStripModel::ADD_ACTIVE); 2344 TabStripModel::ADD_ACTIVE);
2345 WebContents* page_b1_contents = CreateWebContents(); 2345 WebContents* page_b1_contents = CreateWebContents();
2346 strip.AddWebContents(page_b1_contents, -1, content::PAGE_TRANSITION_LINK, 2346 strip.AddWebContents(page_b1_contents, -1, ui::PAGE_TRANSITION_LINK,
2347 TabStripModel::ADD_NONE); 2347 TabStripModel::ADD_NONE);
2348 2348
2349 EXPECT_EQ(page_a_contents, strip.GetWebContentsAt(0)); 2349 EXPECT_EQ(page_a_contents, strip.GetWebContentsAt(0));
2350 EXPECT_EQ(page_a1_contents, strip.GetWebContentsAt(1)); 2350 EXPECT_EQ(page_a1_contents, strip.GetWebContentsAt(1));
2351 EXPECT_EQ(page_b_contents, strip.GetWebContentsAt(2)); 2351 EXPECT_EQ(page_b_contents, strip.GetWebContentsAt(2));
2352 EXPECT_EQ(page_b1_contents, strip.GetWebContentsAt(3)); 2352 EXPECT_EQ(page_b1_contents, strip.GetWebContentsAt(3));
2353 2353
2354 // Move page B to the start of the tab strip. 2354 // Move page B to the start of the tab strip.
2355 strip.MoveSelectedTabsTo(0); 2355 strip.MoveSelectedTabsTo(0);
2356 2356
2357 // Open page B2 in the background from B. It should end up after B. 2357 // Open page B2 in the background from B. It should end up after B.
2358 WebContents* page_b2_contents = CreateWebContents(); 2358 WebContents* page_b2_contents = CreateWebContents();
2359 strip.AddWebContents(page_b2_contents, -1, content::PAGE_TRANSITION_LINK, 2359 strip.AddWebContents(page_b2_contents, -1, ui::PAGE_TRANSITION_LINK,
2360 TabStripModel::ADD_NONE); 2360 TabStripModel::ADD_NONE);
2361 EXPECT_EQ(page_b_contents, strip.GetWebContentsAt(0)); 2361 EXPECT_EQ(page_b_contents, strip.GetWebContentsAt(0));
2362 EXPECT_EQ(page_b2_contents, strip.GetWebContentsAt(1)); 2362 EXPECT_EQ(page_b2_contents, strip.GetWebContentsAt(1));
2363 EXPECT_EQ(page_a_contents, strip.GetWebContentsAt(2)); 2363 EXPECT_EQ(page_a_contents, strip.GetWebContentsAt(2));
2364 EXPECT_EQ(page_a1_contents, strip.GetWebContentsAt(3)); 2364 EXPECT_EQ(page_a1_contents, strip.GetWebContentsAt(3));
2365 EXPECT_EQ(page_b1_contents, strip.GetWebContentsAt(4)); 2365 EXPECT_EQ(page_b1_contents, strip.GetWebContentsAt(4));
2366 2366
2367 // Switch to A. 2367 // Switch to A.
2368 strip.ActivateTabAt(2, true); 2368 strip.ActivateTabAt(2, true);
2369 EXPECT_EQ(page_a_contents, strip.GetActiveWebContents()); 2369 EXPECT_EQ(page_a_contents, strip.GetActiveWebContents());
2370 2370
2371 // Open page A2 in the background from A. It should end up after A1. 2371 // Open page A2 in the background from A. It should end up after A1.
2372 WebContents* page_a2_contents = CreateWebContents(); 2372 WebContents* page_a2_contents = CreateWebContents();
2373 strip.AddWebContents(page_a2_contents, -1, content::PAGE_TRANSITION_LINK, 2373 strip.AddWebContents(page_a2_contents, -1, ui::PAGE_TRANSITION_LINK,
2374 TabStripModel::ADD_NONE); 2374 TabStripModel::ADD_NONE);
2375 EXPECT_EQ(page_b_contents, strip.GetWebContentsAt(0)); 2375 EXPECT_EQ(page_b_contents, strip.GetWebContentsAt(0));
2376 EXPECT_EQ(page_b2_contents, strip.GetWebContentsAt(1)); 2376 EXPECT_EQ(page_b2_contents, strip.GetWebContentsAt(1));
2377 EXPECT_EQ(page_a_contents, strip.GetWebContentsAt(2)); 2377 EXPECT_EQ(page_a_contents, strip.GetWebContentsAt(2));
2378 EXPECT_EQ(page_a1_contents, strip.GetWebContentsAt(3)); 2378 EXPECT_EQ(page_a1_contents, strip.GetWebContentsAt(3));
2379 EXPECT_EQ(page_a2_contents, strip.GetWebContentsAt(4)); 2379 EXPECT_EQ(page_a2_contents, strip.GetWebContentsAt(4));
2380 EXPECT_EQ(page_b1_contents, strip.GetWebContentsAt(5)); 2380 EXPECT_EQ(page_b1_contents, strip.GetWebContentsAt(5));
2381 2381
2382 strip.CloseAllTabs(); 2382 strip.CloseAllTabs();
2383 } 2383 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2584 WebContents* moved_contents = strip_src.DetachWebContentsAt(1); 2584 WebContents* moved_contents = strip_src.DetachWebContentsAt(1);
2585 EXPECT_EQ(contents2, moved_contents); 2585 EXPECT_EQ(contents2, moved_contents);
2586 2586
2587 // Attach the tab to the destination tab strip. 2587 // Attach the tab to the destination tab strip.
2588 strip_dst.AppendWebContents(moved_contents, true); 2588 strip_dst.AppendWebContents(moved_contents, true);
2589 EXPECT_TRUE(strip_dst.IsTabBlocked(0)); 2589 EXPECT_TRUE(strip_dst.IsTabBlocked(0));
2590 2590
2591 strip_dst.CloseAllTabs(); 2591 strip_dst.CloseAllTabs();
2592 strip_src.CloseAllTabs(); 2592 strip_src.CloseAllTabs();
2593 } 2593 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model_order_controller.cc ('k') | chrome/browser/ui/toolbar/toolbar_model_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698