| OLD | NEW |
| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/memory_pressure_listener.h" | 6 #include "base/memory/memory_pressure_listener.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/memory/tab_manager.h" | 8 #include "chrome/browser/memory/tab_manager.h" |
| 9 #include "chrome/browser/memory/tab_manager_web_contents_data.h" | 9 #include "chrome/browser/memory/tab_manager_web_contents_data.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ui::PAGE_TRANSITION_TYPED, false); | 88 ui::PAGE_TRANSITION_TYPED, false); |
| 89 browser()->OpenURL(open5); | 89 browser()->OpenURL(open5); |
| 90 load5.Wait(); | 90 load5.Wait(); |
| 91 | 91 |
| 92 EXPECT_EQ(3, tsm->count()); | 92 EXPECT_EQ(3, tsm->count()); |
| 93 | 93 |
| 94 // Discard a tab. It should kill the first tab, since it was the oldest | 94 // Discard a tab. It should kill the first tab, since it was the oldest |
| 95 // and was not selected. | 95 // and was not selected. |
| 96 EXPECT_TRUE(tab_manager->DiscardTab()); | 96 EXPECT_TRUE(tab_manager->DiscardTab()); |
| 97 EXPECT_EQ(3, tsm->count()); | 97 EXPECT_EQ(3, tsm->count()); |
| 98 EXPECT_TRUE( | 98 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); |
| 99 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(0))); | 99 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); |
| 100 EXPECT_FALSE( | 100 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); |
| 101 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(1))); | |
| 102 EXPECT_FALSE( | |
| 103 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(2))); | |
| 104 EXPECT_TRUE(tab_manager->recent_tab_discard()); | 101 EXPECT_TRUE(tab_manager->recent_tab_discard()); |
| 105 | 102 |
| 106 // Run discard again, make sure it kills the second tab. | 103 // Run discard again, make sure it kills the second tab. |
| 107 EXPECT_TRUE(tab_manager->DiscardTab()); | 104 EXPECT_TRUE(tab_manager->DiscardTab()); |
| 108 EXPECT_EQ(3, tsm->count()); | 105 EXPECT_EQ(3, tsm->count()); |
| 109 EXPECT_TRUE( | 106 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); |
| 110 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(0))); | 107 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); |
| 111 EXPECT_TRUE( | 108 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); |
| 112 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(1))); | |
| 113 EXPECT_FALSE( | |
| 114 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(2))); | |
| 115 | 109 |
| 116 // Kill the third tab. It should not kill the last tab, since it is active | 110 // Kill the third tab. It should not kill the last tab, since it is active |
| 117 // tab. | 111 // tab. |
| 118 EXPECT_FALSE(tab_manager->DiscardTab()); | 112 EXPECT_FALSE(tab_manager->DiscardTab()); |
| 119 EXPECT_TRUE( | 113 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); |
| 120 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(0))); | 114 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); |
| 121 EXPECT_TRUE( | 115 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); |
| 122 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(1))); | |
| 123 EXPECT_FALSE( | |
| 124 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(2))); | |
| 125 | 116 |
| 126 // Kill the third tab after making second tab active. | 117 // Kill the third tab after making second tab active. |
| 127 tsm->ActivateTabAt(1, true); | 118 tsm->ActivateTabAt(1, true); |
| 128 EXPECT_EQ(1, tsm->active_index()); | 119 EXPECT_EQ(1, tsm->active_index()); |
| 129 EXPECT_FALSE( | 120 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); |
| 130 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(1))); | |
| 131 tab_manager->DiscardWebContentsAt(2, tsm); | 121 tab_manager->DiscardWebContentsAt(2, tsm); |
| 132 EXPECT_TRUE( | 122 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); |
| 133 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(2))); | |
| 134 | 123 |
| 135 // Force creation of the FindBarController. | 124 // Force creation of the FindBarController. |
| 136 browser()->GetFindBarController(); | 125 browser()->GetFindBarController(); |
| 137 | 126 |
| 138 // Select the first tab. It should reload. | 127 // Select the first tab. It should reload. |
| 139 WindowedNotificationObserver reload1( | 128 WindowedNotificationObserver reload1( |
| 140 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 129 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 141 content::NotificationService::AllSources()); | 130 content::NotificationService::AllSources()); |
| 142 chrome::SelectNumberedTab(browser(), 0); | 131 chrome::SelectNumberedTab(browser(), 0); |
| 143 reload1.Wait(); | 132 reload1.Wait(); |
| 144 // Make sure the FindBarController gets the right WebContents. | 133 // Make sure the FindBarController gets the right WebContents. |
| 145 EXPECT_EQ(browser()->GetFindBarController()->web_contents(), | 134 EXPECT_EQ(browser()->GetFindBarController()->web_contents(), |
| 146 tsm->GetActiveWebContents()); | 135 tsm->GetActiveWebContents()); |
| 147 EXPECT_EQ(0, tsm->active_index()); | 136 EXPECT_EQ(0, tsm->active_index()); |
| 148 EXPECT_FALSE( | 137 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); |
| 149 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(0))); | 138 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); |
| 150 EXPECT_FALSE( | 139 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); |
| 151 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(1))); | |
| 152 EXPECT_TRUE( | |
| 153 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(2))); | |
| 154 | 140 |
| 155 // Select the third tab. It should reload. | 141 // Select the third tab. It should reload. |
| 156 WindowedNotificationObserver reload2( | 142 WindowedNotificationObserver reload2( |
| 157 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 143 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 158 content::NotificationService::AllSources()); | 144 content::NotificationService::AllSources()); |
| 159 chrome::SelectNumberedTab(browser(), 2); | 145 chrome::SelectNumberedTab(browser(), 2); |
| 160 reload2.Wait(); | 146 reload2.Wait(); |
| 161 EXPECT_EQ(2, tsm->active_index()); | 147 EXPECT_EQ(2, tsm->active_index()); |
| 162 EXPECT_FALSE( | 148 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); |
| 163 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(0))); | 149 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); |
| 164 EXPECT_FALSE( | 150 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); |
| 165 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(1))); | |
| 166 EXPECT_FALSE( | |
| 167 TabManager::WebContentsData::IsDiscarded(tsm->GetWebContentsAt(2))); | |
| 168 | 151 |
| 169 // Navigate the third tab back twice. We used to crash here due to | 152 // Navigate the third tab back twice. We used to crash here due to |
| 170 // crbug.com/121373. | 153 // crbug.com/121373. |
| 171 EXPECT_TRUE(chrome::CanGoBack(browser())); | 154 EXPECT_TRUE(chrome::CanGoBack(browser())); |
| 172 EXPECT_FALSE(chrome::CanGoForward(browser())); | 155 EXPECT_FALSE(chrome::CanGoForward(browser())); |
| 173 WindowedNotificationObserver back1( | 156 WindowedNotificationObserver back1( |
| 174 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 157 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 175 content::NotificationService::AllSources()); | 158 content::NotificationService::AllSources()); |
| 176 chrome::GoBack(browser(), CURRENT_TAB); | 159 chrome::GoBack(browser(), CURRENT_TAB); |
| 177 back1.Wait(); | 160 back1.Wait(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 base::RunLoop().RunUntilIdle(); | 212 base::RunLoop().RunUntilIdle(); |
| 230 if (tab_manager->recent_tab_discard()) | 213 if (tab_manager->recent_tab_discard()) |
| 231 break; | 214 break; |
| 232 } | 215 } |
| 233 EXPECT_TRUE(tab_manager->recent_tab_discard()); | 216 EXPECT_TRUE(tab_manager->recent_tab_discard()); |
| 234 } | 217 } |
| 235 | 218 |
| 236 } // namespace memory | 219 } // namespace memory |
| 237 | 220 |
| 238 #endif // OS_WIN || OS_CHROMEOS | 221 #endif // OS_WIN || OS_CHROMEOS |
| OLD | NEW |