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

Side by Side Diff: chrome/browser/memory/oom_priority_manager_browsertest.cc

Issue 1332003002: Add option to disallow the discarding of a tab that was previously discarded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky@ comments + fix tests. Created 5 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 "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/oom_priority_manager.h" 8 #include "chrome/browser/memory/oom_priority_manager.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 11 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
12 #include "chrome/browser/ui/tabs/tab_discard_state.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
18 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 using content::OpenURLParams; 22 using content::OpenURLParams;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 content::NotificationService::AllSources()); 88 content::NotificationService::AllSources());
88 OpenURLParams open5(GURL("chrome://dns"), content::Referrer(), CURRENT_TAB, 89 OpenURLParams open5(GURL("chrome://dns"), content::Referrer(), CURRENT_TAB,
89 ui::PAGE_TRANSITION_TYPED, false); 90 ui::PAGE_TRANSITION_TYPED, false);
90 browser()->OpenURL(open5); 91 browser()->OpenURL(open5);
91 load5.Wait(); 92 load5.Wait();
92 93
93 EXPECT_EQ(3, browser()->tab_strip_model()->count()); 94 EXPECT_EQ(3, browser()->tab_strip_model()->count());
94 95
95 // Discard a tab. It should kill the first tab, since it was the oldest 96 // Discard a tab. It should kill the first tab, since it was the oldest
96 // and was not selected. 97 // and was not selected.
98 auto tsm = browser()->tab_strip_model();
97 EXPECT_TRUE(oom_priority_manager->DiscardTab()); 99 EXPECT_TRUE(oom_priority_manager->DiscardTab());
98 EXPECT_EQ(3, browser()->tab_strip_model()->count()); 100 EXPECT_EQ(3, tsm->count());
99 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); 101 EXPECT_TRUE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(0)));
100 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1)); 102 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(1)));
101 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); 103 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(2)));
102 EXPECT_TRUE(oom_priority_manager->recent_tab_discard());
103 104
104 // Run discard again, make sure it kills the second tab. 105 // Run discard again, make sure it kills the second tab.
105 EXPECT_TRUE(oom_priority_manager->DiscardTab()); 106 EXPECT_TRUE(oom_priority_manager->DiscardTab());
106 EXPECT_EQ(3, browser()->tab_strip_model()->count()); 107 EXPECT_EQ(3, tsm->count());
107 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); 108 EXPECT_TRUE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(0)));
108 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); 109 EXPECT_TRUE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(1)));
109 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); 110 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(2)));
110 111
111 // Kill the third tab. It should not kill the last tab, since it is active 112 // Kill the third tab. It should not kill the last tab, since it is active
112 // tab. 113 // tab.
113 EXPECT_FALSE(oom_priority_manager->DiscardTab()); 114 EXPECT_FALSE(oom_priority_manager->DiscardTab());
114 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); 115 EXPECT_TRUE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(0)));
115 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); 116 EXPECT_TRUE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(1)));
116 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); 117 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(2)));
117 118
118 // Kill the third tab after making second tab active. 119 // Kill the third tab after making second tab active.
119 browser()->tab_strip_model()->ActivateTabAt(1, true); 120 tsm->ActivateTabAt(1, true);
120 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 121 EXPECT_EQ(1, tsm->active_index());
121 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1)); 122 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(1)));
122 browser()->tab_strip_model()->DiscardWebContentsAt(2); 123 tsm->DiscardWebContentsAt(2);
123 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2)); 124 EXPECT_TRUE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(2)));
124 125
125 // Force creation of the FindBarController. 126 // Force creation of the FindBarController.
126 browser()->GetFindBarController(); 127 browser()->GetFindBarController();
127 128
128 // Select the first tab. It should reload. 129 // Select the first tab. It should reload.
129 WindowedNotificationObserver reload1( 130 WindowedNotificationObserver reload1(
130 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 131 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
131 content::NotificationService::AllSources()); 132 content::NotificationService::AllSources());
132 chrome::SelectNumberedTab(browser(), 0); 133 chrome::SelectNumberedTab(browser(), 0);
133 reload1.Wait(); 134 reload1.Wait();
134 // Make sure the FindBarController gets the right WebContents. 135 // Make sure the FindBarController gets the right WebContents.
135 EXPECT_EQ(browser()->GetFindBarController()->web_contents(), 136 EXPECT_EQ(browser()->GetFindBarController()->web_contents(),
136 browser()->tab_strip_model()->GetActiveWebContents()); 137 tsm->GetActiveWebContents());
137 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 138 EXPECT_EQ(0, tsm->active_index());
138 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0)); 139 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(0)));
139 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1)); 140 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(1)));
140 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2)); 141 EXPECT_TRUE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(2)));
141 142
142 // Select the third tab. It should reload. 143 // Select the third tab. It should reload.
143 WindowedNotificationObserver reload2( 144 WindowedNotificationObserver reload2(
144 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 145 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
145 content::NotificationService::AllSources()); 146 content::NotificationService::AllSources());
146 chrome::SelectNumberedTab(browser(), 2); 147 chrome::SelectNumberedTab(browser(), 2);
147 reload2.Wait(); 148 reload2.Wait();
148 EXPECT_EQ(2, browser()->tab_strip_model()->active_index()); 149 EXPECT_EQ(2, tsm->active_index());
149 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0)); 150 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(0)));
150 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1)); 151 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(1)));
151 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); 152 EXPECT_FALSE(TabDiscardState::IsDiscarded(tsm->GetWebContentsAt(2)));
152 153
153 // Navigate the third tab back twice. We used to crash here due to 154 // Navigate the third tab back twice. We used to crash here due to
154 // crbug.com/121373. 155 // crbug.com/121373.
155 EXPECT_TRUE(chrome::CanGoBack(browser())); 156 EXPECT_TRUE(chrome::CanGoBack(browser()));
156 EXPECT_FALSE(chrome::CanGoForward(browser())); 157 EXPECT_FALSE(chrome::CanGoForward(browser()));
157 WindowedNotificationObserver back1( 158 WindowedNotificationObserver back1(
158 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 159 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
159 content::NotificationService::AllSources()); 160 content::NotificationService::AllSources());
160 chrome::GoBack(browser(), CURRENT_TAB); 161 chrome::GoBack(browser(), CURRENT_TAB);
161 back1.Wait(); 162 back1.Wait();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (oom_priority_manager->recent_tab_discard()) 216 if (oom_priority_manager->recent_tab_discard())
216 break; 217 break;
217 } 218 }
218 EXPECT_TRUE(oom_priority_manager->recent_tab_discard()); 219 EXPECT_TRUE(oom_priority_manager->recent_tab_discard());
219 } 220 }
220 221
221 } // namespace 222 } // namespace
222 } // namespace memory 223 } // namespace memory
223 224
224 #endif // OS_WIN || OS_CHROMEOS 225 #endif // OS_WIN || OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698