OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 Profile* profile = browser->profile(); | 129 Profile* profile = browser->profile(); |
130 | 130 |
131 // Close the browser. | 131 // Close the browser. |
132 g_browser_process->AddRefModule(); | 132 g_browser_process->AddRefModule(); |
133 CloseBrowserSynchronously(browser); | 133 CloseBrowserSynchronously(browser); |
134 | 134 |
135 // Create a new window, which should trigger session restore. | 135 // Create a new window, which should trigger session restore. |
136 ui_test_utils::BrowserAddedObserver window_observer; | 136 ui_test_utils::BrowserAddedObserver window_observer; |
137 SessionRestoreTestHelper restore_observer; | 137 SessionRestoreTestHelper restore_observer; |
138 if (url.is_empty()) { | 138 if (url.is_empty()) { |
139 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 139 chrome::NewEmptyWindow(profile); |
140 } else { | 140 } else { |
141 chrome::NavigateParams params(profile, | 141 chrome::NavigateParams params(profile, |
142 url, | 142 url, |
143 ui::PAGE_TRANSITION_LINK); | 143 ui::PAGE_TRANSITION_LINK); |
144 chrome::Navigate(¶ms); | 144 chrome::Navigate(¶ms); |
145 } | 145 } |
146 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 146 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
147 // Stop loading anything more if we are running out of space. | 147 // Stop loading anything more if we are running out of space. |
148 if (!no_memory_pressure) { | 148 if (!no_memory_pressure) { |
149 base::MemoryPressureListener::NotifyMemoryPressure( | 149 base::MemoryPressureListener::NotifyMemoryPressure( |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 ui_test_utils::NavigateToURL(browser(), url); | 476 ui_test_utils::NavigateToURL(browser(), url); |
477 | 477 |
478 // Turn on session restore. | 478 // Turn on session restore. |
479 SessionStartupPref::SetStartupPref( | 479 SessionStartupPref::SetStartupPref( |
480 browser()->profile(), | 480 browser()->profile(), |
481 SessionStartupPref(SessionStartupPref::LAST)); | 481 SessionStartupPref(SessionStartupPref::LAST)); |
482 | 482 |
483 // Create a new popup. | 483 // Create a new popup. |
484 Profile* profile = browser()->profile(); | 484 Profile* profile = browser()->profile(); |
485 Browser* popup = | 485 Browser* popup = |
486 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile, | 486 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile)); |
487 browser()->host_desktop_type())); | |
488 popup->window()->Show(); | 487 popup->window()->Show(); |
489 | 488 |
490 // Close the browser. | 489 // Close the browser. |
491 CloseBrowserSynchronously(browser()); | 490 CloseBrowserSynchronously(browser()); |
492 | 491 |
493 // Create a new window, which should trigger session restore. | 492 // Create a new window, which should trigger session restore. |
494 ui_test_utils::BrowserAddedObserver observer; | 493 ui_test_utils::BrowserAddedObserver observer; |
495 chrome::NewWindow(popup); | 494 chrome::NewWindow(popup); |
496 Browser* new_browser = observer.WaitForSingleNewBrowser(); | 495 Browser* new_browser = observer.WaitForSingleNewBrowser(); |
497 | 496 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 } | 807 } |
809 window.tabs.push_back(&tab2); | 808 window.tabs.push_back(&tab2); |
810 | 809 |
811 // Leave tab3 empty. Should have no effect on restored session, but simulates | 810 // Leave tab3 empty. Should have no effect on restored session, but simulates |
812 // partially complete foreign session data. | 811 // partially complete foreign session data. |
813 sessions::SessionTab tab3; | 812 sessions::SessionTab tab3; |
814 window.tabs.push_back(&tab3); | 813 window.tabs.push_back(&tab3); |
815 | 814 |
816 session.push_back(static_cast<const sessions::SessionWindow*>(&window)); | 815 session.push_back(static_cast<const sessions::SessionWindow*>(&window)); |
817 ui_test_utils::BrowserAddedObserver window_observer; | 816 ui_test_utils::BrowserAddedObserver window_observer; |
818 std::vector<Browser*> browsers = | 817 std::vector<Browser*> browsers = SessionRestore::RestoreForeignSessionWindows( |
819 SessionRestore::RestoreForeignSessionWindows( | 818 profile, session.begin(), session.end()); |
820 profile, browser()->host_desktop_type(), session.begin(), | |
821 session.end()); | |
822 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 819 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
823 ASSERT_TRUE(new_browser); | 820 ASSERT_TRUE(new_browser); |
824 ASSERT_EQ(2u, active_browser_list_->size()); | 821 ASSERT_EQ(2u, active_browser_list_->size()); |
825 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 822 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
826 | 823 |
827 ASSERT_EQ(1u, browsers.size()); | 824 ASSERT_EQ(1u, browsers.size()); |
828 ASSERT_TRUE(browsers[0]); | 825 ASSERT_TRUE(browsers[0]); |
829 ASSERT_EQ(2, browsers[0]->tab_strip_model()->count()); | 826 ASSERT_EQ(2, browsers[0]->tab_strip_model()->count()); |
830 | 827 |
831 content::WebContents* web_contents_1 = | 828 content::WebContents* web_contents_1 = |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 chrome::CloseTab(new_browser); | 1255 chrome::CloseTab(new_browser); |
1259 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | 1256 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); |
1260 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); | 1257 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); |
1261 // Use the existing tab to navigate away, so that we can verify it was really | 1258 // Use the existing tab to navigate away, so that we can verify it was really |
1262 // clobbered. | 1259 // clobbered. |
1263 ui_test_utils::NavigateToURL(new_browser, url3_); | 1260 ui_test_utils::NavigateToURL(new_browser, url3_); |
1264 | 1261 |
1265 // Restore the session again, clobbering the existing tab. | 1262 // Restore the session again, clobbering the existing tab. |
1266 SessionRestore::RestoreSession( | 1263 SessionRestore::RestoreSession( |
1267 profile, new_browser, | 1264 profile, new_browser, |
1268 new_browser->host_desktop_type(), | |
1269 SessionRestore::CLOBBER_CURRENT_TAB | SessionRestore::SYNCHRONOUS, | 1265 SessionRestore::CLOBBER_CURRENT_TAB | SessionRestore::SYNCHRONOUS, |
1270 std::vector<GURL>()); | 1266 std::vector<GURL>()); |
1271 | 1267 |
1272 // The pinned tab is the selected tab. | 1268 // The pinned tab is the selected tab. |
1273 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 1269 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
1274 EXPECT_EQ(0, new_browser->tab_strip_model()->active_index()); | 1270 EXPECT_EQ(0, new_browser->tab_strip_model()->active_index()); |
1275 EXPECT_EQ(url1_, | 1271 EXPECT_EQ(url1_, |
1276 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 1272 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
1277 EXPECT_EQ(url2_, | 1273 EXPECT_EQ(url2_, |
1278 new_browser->tab_strip_model()->GetWebContentsAt(1)->GetURL()); | 1274 new_browser->tab_strip_model()->GetWebContentsAt(1)->GetURL()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 // Close the first tab. | 1313 // Close the first tab. |
1318 chrome::CloseTab(new_browser); | 1314 chrome::CloseTab(new_browser); |
1319 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | 1315 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); |
1320 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); | 1316 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); |
1321 // Use the existing tab to navigate to the NTP. | 1317 // Use the existing tab to navigate to the NTP. |
1322 ui_test_utils::NavigateToURL(new_browser, GURL(chrome::kChromeUINewTabURL)); | 1318 ui_test_utils::NavigateToURL(new_browser, GURL(chrome::kChromeUINewTabURL)); |
1323 | 1319 |
1324 // Restore the session again, clobbering the existing tab. | 1320 // Restore the session again, clobbering the existing tab. |
1325 SessionRestore::RestoreSession( | 1321 SessionRestore::RestoreSession( |
1326 profile, new_browser, | 1322 profile, new_browser, |
1327 new_browser->host_desktop_type(), | |
1328 SessionRestore::CLOBBER_CURRENT_TAB | SessionRestore::SYNCHRONOUS, | 1323 SessionRestore::CLOBBER_CURRENT_TAB | SessionRestore::SYNCHRONOUS, |
1329 std::vector<GURL>()); | 1324 std::vector<GURL>()); |
1330 | 1325 |
1331 // 2 tabs should have been restored, with the existing tab clobbered, giving | 1326 // 2 tabs should have been restored, with the existing tab clobbered, giving |
1332 // us a total of 2 tabs. | 1327 // us a total of 2 tabs. |
1333 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 1328 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
1334 EXPECT_EQ(1, new_browser->tab_strip_model()->active_index()); | 1329 EXPECT_EQ(1, new_browser->tab_strip_model()->active_index()); |
1335 EXPECT_EQ(url1_, | 1330 EXPECT_EQ(url1_, |
1336 new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL()); | 1331 new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL()); |
1337 EXPECT_EQ(url2_, | 1332 EXPECT_EQ(url2_, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 browser()->tab_strip_model()->ActivateTabAt(i, true); | 1411 browser()->tab_strip_model()->ActivateTabAt(i, true); |
1417 | 1412 |
1418 // Close the browser. | 1413 // Close the browser. |
1419 g_browser_process->AddRefModule(); | 1414 g_browser_process->AddRefModule(); |
1420 CloseBrowserSynchronously(browser()); | 1415 CloseBrowserSynchronously(browser()); |
1421 | 1416 |
1422 StartObserving(kExpectedNumTabs); | 1417 StartObserving(kExpectedNumTabs); |
1423 | 1418 |
1424 // Create a new window, which should trigger session restore. | 1419 // Create a new window, which should trigger session restore. |
1425 ui_test_utils::BrowserAddedObserver window_observer; | 1420 ui_test_utils::BrowserAddedObserver window_observer; |
1426 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 1421 chrome::NewEmptyWindow(profile); |
1427 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 1422 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
1428 ASSERT_TRUE(new_browser); | 1423 ASSERT_TRUE(new_browser); |
1429 WaitForAllTabsToStartLoading(); | 1424 WaitForAllTabsToStartLoading(); |
1430 g_browser_process->ReleaseModule(); | 1425 g_browser_process->ReleaseModule(); |
1431 | 1426 |
1432 ASSERT_EQ(kExpectedNumTabs, web_contents().size()); | 1427 ASSERT_EQ(kExpectedNumTabs, web_contents().size()); |
1433 // Test that we have observed the tabs being loaded in the inverse order of | 1428 // Test that we have observed the tabs being loaded in the inverse order of |
1434 // their activation (MRU). Also validate that their last active time is in the | 1429 // their activation (MRU). Also validate that their last active time is in the |
1435 // correct order. | 1430 // correct order. |
1436 for (size_t i = 0; i < web_contents().size(); i++) { | 1431 for (size_t i = 0; i < web_contents().size(); i++) { |
(...skipping 23 matching lines...) Expand all Loading... |
1460 // Close the browser that gets opened automatically so we can track the order | 1455 // Close the browser that gets opened automatically so we can track the order |
1461 // of loading of the tabs. | 1456 // of loading of the tabs. |
1462 g_browser_process->AddRefModule(); | 1457 g_browser_process->AddRefModule(); |
1463 CloseBrowserSynchronously(browser()); | 1458 CloseBrowserSynchronously(browser()); |
1464 // We have an extra tab that is added when the test starts, which gets ignored | 1459 // We have an extra tab that is added when the test starts, which gets ignored |
1465 // later when we test for proper order. | 1460 // later when we test for proper order. |
1466 StartObserving(kExpectedNumTabs + 1); | 1461 StartObserving(kExpectedNumTabs + 1); |
1467 | 1462 |
1468 // Create a new window, which should trigger session restore. | 1463 // Create a new window, which should trigger session restore. |
1469 ui_test_utils::BrowserAddedObserver window_observer; | 1464 ui_test_utils::BrowserAddedObserver window_observer; |
1470 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 1465 chrome::NewEmptyWindow(profile); |
1471 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 1466 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
1472 ASSERT_TRUE(new_browser); | 1467 ASSERT_TRUE(new_browser); |
1473 WaitForAllTabsToStartLoading(); | 1468 WaitForAllTabsToStartLoading(); |
1474 g_browser_process->ReleaseModule(); | 1469 g_browser_process->ReleaseModule(); |
1475 | 1470 |
1476 ASSERT_EQ(kExpectedNumTabs + 1, web_contents().size()); | 1471 ASSERT_EQ(kExpectedNumTabs + 1, web_contents().size()); |
1477 | 1472 |
1478 // Test that we have observed the tabs being loaded in the inverse order of | 1473 // Test that we have observed the tabs being loaded in the inverse order of |
1479 // their activation (MRU). Also validate that their last active time is in the | 1474 // their activation (MRU). Also validate that their last active time is in the |
1480 // correct order. | 1475 // correct order. |
1481 // | 1476 // |
1482 // Note that we ignore the first tab as it's an empty one that is added | 1477 // Note that we ignore the first tab as it's an empty one that is added |
1483 // automatically at the start of the test. | 1478 // automatically at the start of the test. |
1484 for (size_t i = 1; i < web_contents().size(); i++) { | 1479 for (size_t i = 1; i < web_contents().size(); i++) { |
1485 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); | 1480 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); |
1486 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 1481 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); |
1487 if (i > 0) { | 1482 if (i > 0) { |
1488 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 1483 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), |
1489 web_contents()[i]->GetLastActiveTime()); | 1484 web_contents()[i]->GetLastActiveTime()); |
1490 } | 1485 } |
1491 } | 1486 } |
1492 } | 1487 } |
OLD | NEW |