| 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" | 
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" | 
| 12 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 13 #include "base/memory/memory_pressure_listener.h" | 13 #include "base/memory/memory_pressure_listener.h" | 
| 14 #include "base/process/launch.h" | 14 #include "base/process/launch.h" | 
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" | 
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" | 
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" | 
| 18 #include "chrome/browser/browser_process.h" |  | 
| 19 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" | 
| 20 #include "chrome/browser/first_run/first_run.h" | 19 #include "chrome/browser/first_run/first_run.h" | 
|  | 20 #include "chrome/browser/lifetime/keep_alive_types.h" | 
|  | 21 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 
| 21 #include "chrome/browser/prefs/session_startup_pref.h" | 22 #include "chrome/browser/prefs/session_startup_pref.h" | 
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" | 
| 23 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" | 
| 24 #include "chrome/browser/sessions/session_restore.h" | 25 #include "chrome/browser/sessions/session_restore.h" | 
| 25 #include "chrome/browser/sessions/session_restore_test_helper.h" | 26 #include "chrome/browser/sessions/session_restore_test_helper.h" | 
| 26 #include "chrome/browser/sessions/session_service.h" | 27 #include "chrome/browser/sessions/session_service.h" | 
| 27 #include "chrome/browser/sessions/session_service_factory.h" | 28 #include "chrome/browser/sessions/session_service_factory.h" | 
| 28 #include "chrome/browser/sessions/session_service_test_helper.h" | 29 #include "chrome/browser/sessions/session_service_test_helper.h" | 
| 29 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 30 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 
| 30 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 122         browser, expected_tab_count, GURL(), true); | 123         browser, expected_tab_count, GURL(), true); | 
| 123   } | 124   } | 
| 124 | 125 | 
| 125   Browser* QuitBrowserAndRestoreWithURL(Browser* browser, | 126   Browser* QuitBrowserAndRestoreWithURL(Browser* browser, | 
| 126                                         int expected_tab_count, | 127                                         int expected_tab_count, | 
| 127                                         const GURL& url, | 128                                         const GURL& url, | 
| 128                                         bool no_memory_pressure) { | 129                                         bool no_memory_pressure) { | 
| 129     Profile* profile = browser->profile(); | 130     Profile* profile = browser->profile(); | 
| 130 | 131 | 
| 131     // Close the browser. | 132     // Close the browser. | 
| 132     g_browser_process->AddRefModule(); | 133     scoped_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive( | 
|  | 134         KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED)); | 
| 133     CloseBrowserSynchronously(browser); | 135     CloseBrowserSynchronously(browser); | 
| 134 | 136 | 
| 135     // Create a new window, which should trigger session restore. | 137     // Create a new window, which should trigger session restore. | 
| 136     ui_test_utils::BrowserAddedObserver window_observer; | 138     ui_test_utils::BrowserAddedObserver window_observer; | 
| 137     SessionRestoreTestHelper restore_observer; | 139     SessionRestoreTestHelper restore_observer; | 
| 138     if (url.is_empty()) { | 140     if (url.is_empty()) { | 
| 139       chrome::NewEmptyWindow(profile); | 141       chrome::NewEmptyWindow(profile); | 
| 140     } else { | 142     } else { | 
| 141       chrome::NavigateParams params(profile, | 143       chrome::NavigateParams params(profile, | 
| 142                                     url, | 144                                     url, | 
| 143                                     ui::PAGE_TRANSITION_LINK); | 145                                     ui::PAGE_TRANSITION_LINK); | 
| 144       chrome::Navigate(¶ms); | 146       chrome::Navigate(¶ms); | 
| 145     } | 147     } | 
| 146     Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 148     Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 
| 147     // Stop loading anything more if we are running out of space. | 149     // Stop loading anything more if we are running out of space. | 
| 148     if (!no_memory_pressure) { | 150     if (!no_memory_pressure) { | 
| 149       base::MemoryPressureListener::NotifyMemoryPressure( | 151       base::MemoryPressureListener::NotifyMemoryPressure( | 
| 150           base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | 152           base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | 
| 151     } | 153     } | 
| 152     restore_observer.Wait(); | 154     restore_observer.Wait(); | 
| 153 | 155 | 
| 154     if (no_memory_pressure) | 156     if (no_memory_pressure) | 
| 155       WaitForTabsToLoad(new_browser); | 157       WaitForTabsToLoad(new_browser); | 
| 156 | 158 | 
| 157     g_browser_process->ReleaseModule(); | 159     keep_alive.reset(); | 
| 158 | 160 | 
| 159     return new_browser; | 161     return new_browser; | 
| 160   } | 162   } | 
| 161 | 163 | 
| 162   void GoBack(Browser* browser) { | 164   void GoBack(Browser* browser) { | 
| 163     content::TestNavigationObserver observer( | 165     content::TestNavigationObserver observer( | 
| 164         browser->tab_strip_model()->GetActiveWebContents()); | 166         browser->tab_strip_model()->GetActiveWebContents()); | 
| 165     chrome::GoBack(browser, CURRENT_TAB); | 167     chrome::GoBack(browser, CURRENT_TAB); | 
| 166     observer.Wait(); | 168     observer.Wait(); | 
| 167   } | 169   } | 
| (...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1400   } | 1402   } | 
| 1401 | 1403 | 
| 1402   ASSERT_EQ(static_cast<int>(kExpectedNumTabs), | 1404   ASSERT_EQ(static_cast<int>(kExpectedNumTabs), | 
| 1403             browser()->tab_strip_model()->count()); | 1405             browser()->tab_strip_model()->count()); | 
| 1404 | 1406 | 
| 1405   // Activate the tabs one by one following the specified activation order. | 1407   // Activate the tabs one by one following the specified activation order. | 
| 1406   for (int i : activation_order) | 1408   for (int i : activation_order) | 
| 1407     browser()->tab_strip_model()->ActivateTabAt(i, true); | 1409     browser()->tab_strip_model()->ActivateTabAt(i, true); | 
| 1408 | 1410 | 
| 1409   // Close the browser. | 1411   // Close the browser. | 
| 1410   g_browser_process->AddRefModule(); | 1412   scoped_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive( | 
|  | 1413       KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED)); | 
| 1411   CloseBrowserSynchronously(browser()); | 1414   CloseBrowserSynchronously(browser()); | 
| 1412 | 1415 | 
| 1413   StartObserving(kExpectedNumTabs); | 1416   StartObserving(kExpectedNumTabs); | 
| 1414 | 1417 | 
| 1415   // Create a new window, which should trigger session restore. | 1418   // Create a new window, which should trigger session restore. | 
| 1416   ui_test_utils::BrowserAddedObserver window_observer; | 1419   ui_test_utils::BrowserAddedObserver window_observer; | 
| 1417   chrome::NewEmptyWindow(profile); | 1420   chrome::NewEmptyWindow(profile); | 
| 1418   Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 1421   Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 
| 1419   ASSERT_TRUE(new_browser); | 1422   ASSERT_TRUE(new_browser); | 
| 1420   WaitForAllTabsToStartLoading(); | 1423   WaitForAllTabsToStartLoading(); | 
| 1421   g_browser_process->ReleaseModule(); | 1424   keep_alive.reset(); | 
| 1422 | 1425 | 
| 1423   ASSERT_EQ(kExpectedNumTabs, web_contents().size()); | 1426   ASSERT_EQ(kExpectedNumTabs, web_contents().size()); | 
| 1424   // Test that we have observed the tabs being loaded in the inverse order of | 1427   // Test that we have observed the tabs being loaded in the inverse order of | 
| 1425   // their activation (MRU). Also validate that their last active time is in the | 1428   // their activation (MRU). Also validate that their last active time is in the | 
| 1426   // correct order. | 1429   // correct order. | 
| 1427   for (size_t i = 0; i < web_contents().size(); i++) { | 1430   for (size_t i = 0; i < web_contents().size(); i++) { | 
| 1428     GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i - 1]]); | 1431     GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i - 1]]); | 
| 1429     ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 1432     ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 
| 1430     if (i > 0) { | 1433     if (i > 0) { | 
| 1431       ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 1434       ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 1443 #define MAYBE_CorrectLoadingOrder DISABLED_CorrectLoadingOrder | 1446 #define MAYBE_CorrectLoadingOrder DISABLED_CorrectLoadingOrder | 
| 1444 #else | 1447 #else | 
| 1445 #define MAYBE_CorrectLoadingOrder CorrectLoadingOrder | 1448 #define MAYBE_CorrectLoadingOrder CorrectLoadingOrder | 
| 1446 #endif | 1449 #endif | 
| 1447 IN_PROC_BROWSER_TEST_F(SmartSessionRestoreTest, MAYBE_CorrectLoadingOrder) { | 1450 IN_PROC_BROWSER_TEST_F(SmartSessionRestoreTest, MAYBE_CorrectLoadingOrder) { | 
| 1448   const int activation_order[] = {4, 2, 5, 0, 3, 1}; | 1451   const int activation_order[] = {4, 2, 5, 0, 3, 1}; | 
| 1449   Profile* profile = browser()->profile(); | 1452   Profile* profile = browser()->profile(); | 
| 1450 | 1453 | 
| 1451   // Close the browser that gets opened automatically so we can track the order | 1454   // Close the browser that gets opened automatically so we can track the order | 
| 1452   // of loading of the tabs. | 1455   // of loading of the tabs. | 
| 1453   g_browser_process->AddRefModule(); | 1456   scoped_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive( | 
|  | 1457       KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED)); | 
| 1454   CloseBrowserSynchronously(browser()); | 1458   CloseBrowserSynchronously(browser()); | 
| 1455   // 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 | 
| 1456   // later when we test for proper order. | 1460   // later when we test for proper order. | 
| 1457   StartObserving(kExpectedNumTabs + 1); | 1461   StartObserving(kExpectedNumTabs + 1); | 
| 1458 | 1462 | 
| 1459   // Create a new window, which should trigger session restore. | 1463   // Create a new window, which should trigger session restore. | 
| 1460   ui_test_utils::BrowserAddedObserver window_observer; | 1464   ui_test_utils::BrowserAddedObserver window_observer; | 
| 1461   chrome::NewEmptyWindow(profile); | 1465   chrome::NewEmptyWindow(profile); | 
| 1462   Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 1466   Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 
| 1463   ASSERT_TRUE(new_browser); | 1467   ASSERT_TRUE(new_browser); | 
| 1464   WaitForAllTabsToStartLoading(); | 1468   WaitForAllTabsToStartLoading(); | 
| 1465   g_browser_process->ReleaseModule(); | 1469   keep_alive.reset(); | 
| 1466 | 1470 | 
| 1467   ASSERT_EQ(kExpectedNumTabs + 1, web_contents().size()); | 1471   ASSERT_EQ(kExpectedNumTabs + 1, web_contents().size()); | 
| 1468 | 1472 | 
| 1469   // 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 | 
| 1470   // 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 | 
| 1471   // correct order. | 1475   // correct order. | 
| 1472   // | 1476   // | 
| 1473   // 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 | 
| 1474   // automatically at the start of the test. | 1478   // automatically at the start of the test. | 
| 1475   for (size_t i = 1; i < web_contents().size(); i++) { | 1479   for (size_t i = 1; i < web_contents().size(); i++) { | 
| 1476     GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); | 1480     GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); | 
| 1477     ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 1481     ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 
| 1478     if (i > 0) { | 1482     if (i > 0) { | 
| 1479       ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 1483       ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 
| 1480                 web_contents()[i]->GetLastActiveTime()); | 1484                 web_contents()[i]->GetLastActiveTime()); | 
| 1481     } | 1485     } | 
| 1482   } | 1486   } | 
| 1483 } | 1487 } | 
| OLD | NEW | 
|---|