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

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

Issue 2245133002: set_minimum_protection_time_for_tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/memory_pressure_listener.h" 7 #include "base/memory/memory_pressure_listener.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 }; 46 };
47 47
48 IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { 48 IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
49 using content::WindowedNotificationObserver; 49 using content::WindowedNotificationObserver;
50 TabManager* tab_manager = g_browser_process->GetTabManager(); 50 TabManager* tab_manager = g_browser_process->GetTabManager();
51 ASSERT_TRUE(tab_manager); 51 ASSERT_TRUE(tab_manager);
52 EXPECT_FALSE(tab_manager->recent_tab_discard()); 52 EXPECT_FALSE(tab_manager->recent_tab_discard());
53 53
54 // Disable the protection of recent tabs. 54 // Disable the protection of recent tabs.
55 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); 55 tab_manager->set_minimum_protection_time_for_tests(
56 base::TimeDelta::FromMinutes(0));
56 57
57 // Get three tabs open. 58 // Get three tabs open.
58 WindowedNotificationObserver load1( 59 WindowedNotificationObserver load1(
59 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 60 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
60 content::NotificationService::AllSources()); 61 content::NotificationService::AllSources());
61 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 62 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
62 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); 63 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
63 browser()->OpenURL(open1); 64 browser()->OpenURL(open1);
64 load1.Wait(); 65 load1.Wait();
65 66
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // On Linux, memory pressure listener is not implemented yet. 185 // On Linux, memory pressure listener is not implemented yet.
185 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 186 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
186 187
187 // Test that the MemoryPressureListener event is properly triggering a tab 188 // Test that the MemoryPressureListener event is properly triggering a tab
188 // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event. 189 // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event.
189 IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) { 190 IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) {
190 TabManager* tab_manager = g_browser_process->GetTabManager(); 191 TabManager* tab_manager = g_browser_process->GetTabManager();
191 ASSERT_TRUE(tab_manager); 192 ASSERT_TRUE(tab_manager);
192 193
193 // Disable the protection of recent tabs. 194 // Disable the protection of recent tabs.
194 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); 195 tab_manager->set_minimum_protection_time_for_tests(
196 base::TimeDelta::FromMinutes(0));
195 197
196 // Get three tabs open. 198 // Get three tabs open.
197 content::WindowedNotificationObserver load1( 199 content::WindowedNotificationObserver load1(
198 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 200 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
199 content::NotificationService::AllSources()); 201 content::NotificationService::AllSources());
200 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 202 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
201 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); 203 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
202 browser()->OpenURL(open1); 204 browser()->OpenURL(open1);
203 load1.Wait(); 205 load1.Wait();
204 206
(...skipping 29 matching lines...) Expand all
234 EXPECT_TRUE(tab_manager->recent_tab_discard()); 236 EXPECT_TRUE(tab_manager->recent_tab_discard());
235 } 237 }
236 238
237 #endif 239 #endif
238 240
239 IN_PROC_BROWSER_TEST_F(TabManagerTest, InvalidOrEmptyURL) { 241 IN_PROC_BROWSER_TEST_F(TabManagerTest, InvalidOrEmptyURL) {
240 TabManager* tab_manager = g_browser_process->GetTabManager(); 242 TabManager* tab_manager = g_browser_process->GetTabManager();
241 ASSERT_TRUE(tab_manager); 243 ASSERT_TRUE(tab_manager);
242 244
243 // Disable the protection of recent tabs. 245 // Disable the protection of recent tabs.
244 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); 246 tab_manager->set_minimum_protection_time_for_tests(
247 base::TimeDelta::FromMinutes(0));
245 248
246 // Open two tabs. Wait for the foreground one to load but do not wait for the 249 // Open two tabs. Wait for the foreground one to load but do not wait for the
247 // background one. 250 // background one.
248 content::WindowedNotificationObserver load1( 251 content::WindowedNotificationObserver load1(
249 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 252 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
250 content::NotificationService::AllSources()); 253 content::NotificationService::AllSources());
251 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 254 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
252 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); 255 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
253 browser()->OpenURL(open1); 256 browser()->OpenURL(open1);
254 load1.Wait(); 257 load1.Wait();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 const int kProtectionTime = 5; 307 const int kProtectionTime = 5;
305 TabManager* tab_manager = g_browser_process->GetTabManager(); 308 TabManager* tab_manager = g_browser_process->GetTabManager();
306 ASSERT_TRUE(tab_manager); 309 ASSERT_TRUE(tab_manager);
307 310
308 base::SimpleTestTickClock test_clock_; 311 base::SimpleTestTickClock test_clock_;
309 tab_manager->set_test_tick_clock(&test_clock_); 312 tab_manager->set_test_tick_clock(&test_clock_);
310 313
311 auto* tsm = browser()->tab_strip_model(); 314 auto* tsm = browser()->tab_strip_model();
312 315
313 // Set the minimum time of protection. 316 // Set the minimum time of protection.
314 tab_manager->minimum_protection_time_ = 317 tab_manager->set_minimum_protection_time_for_tests(
315 base::TimeDelta::FromMinutes(kProtectionTime); 318 base::TimeDelta::FromMinutes(kProtectionTime));
316 319
317 // Open 2 tabs, the second one being in the background. 320 // Open 2 tabs, the second one being in the background.
318 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); 321 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
319 ui_test_utils::NavigateToURLWithDisposition( 322 ui_test_utils::NavigateToURLWithDisposition(
320 browser(), GURL(chrome::kChromeUIAboutURL), NEW_BACKGROUND_TAB, 323 browser(), GURL(chrome::kChromeUIAboutURL), NEW_BACKGROUND_TAB,
321 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 324 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
322 EXPECT_EQ(2, tsm->count()); 325 EXPECT_EQ(2, tsm->count());
323 326
324 // Advance the clock for less than the protection time. 327 // Advance the clock for less than the protection time.
325 test_clock_.Advance(base::TimeDelta::FromMinutes(kProtectionTime / 2)); 328 test_clock_.Advance(base::TimeDelta::FromMinutes(kProtectionTime / 2));
(...skipping 27 matching lines...) Expand all
353 // WebContentsData::WebContentsDestroyed. 356 // WebContentsData::WebContentsDestroyed.
354 tsm->CloseAllTabs(); 357 tsm->CloseAllTabs();
355 } 358 }
356 359
357 // Makes sure that tabs using media devices are protected. 360 // Makes sure that tabs using media devices are protected.
358 IN_PROC_BROWSER_TEST_F(TabManagerTest, ProtectVideoTabs) { 361 IN_PROC_BROWSER_TEST_F(TabManagerTest, ProtectVideoTabs) {
359 TabManager* tab_manager = g_browser_process->GetTabManager(); 362 TabManager* tab_manager = g_browser_process->GetTabManager();
360 ASSERT_TRUE(tab_manager); 363 ASSERT_TRUE(tab_manager);
361 364
362 // Disable the protection of recent tabs. 365 // Disable the protection of recent tabs.
363 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); 366 tab_manager->set_minimum_protection_time_for_tests(
367 base::TimeDelta::FromMinutes(0));
364 368
365 // Open 2 tabs, the second one being in the background. 369 // Open 2 tabs, the second one being in the background.
366 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); 370 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
367 ui_test_utils::NavigateToURLWithDisposition( 371 ui_test_utils::NavigateToURLWithDisposition(
368 browser(), GURL(chrome::kChromeUIAboutURL), NEW_BACKGROUND_TAB, 372 browser(), GURL(chrome::kChromeUIAboutURL), NEW_BACKGROUND_TAB,
369 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 373 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
370 374
371 auto* tab = browser()->tab_strip_model()->GetWebContentsAt(1); 375 auto* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
372 376
373 // Simulate that a video stream is now being captured. 377 // Simulate that a video stream is now being captured.
(...skipping 17 matching lines...) Expand all
391 395
392 // Should be able to discard the background tab now. 396 // Should be able to discard the background tab now.
393 EXPECT_TRUE(tab_manager->DiscardTabImpl()); 397 EXPECT_TRUE(tab_manager->DiscardTabImpl());
394 } 398 }
395 399
396 IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) { 400 IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) {
397 using content::WindowedNotificationObserver; 401 using content::WindowedNotificationObserver;
398 TabManager* tab_manager = g_browser_process->GetTabManager(); 402 TabManager* tab_manager = g_browser_process->GetTabManager();
399 403
400 // Disable the protection of recent tabs. 404 // Disable the protection of recent tabs.
401 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); 405 tab_manager->set_minimum_protection_time_for_tests(
406 base::TimeDelta::FromMinutes(0));
402 407
403 // Get two tabs open. 408 // Get two tabs open.
404 WindowedNotificationObserver load1( 409 WindowedNotificationObserver load1(
405 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 410 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
406 content::NotificationService::AllSources()); 411 content::NotificationService::AllSources());
407 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 412 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
408 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); 413 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
409 browser()->OpenURL(open1); 414 browser()->OpenURL(open1);
410 load1.Wait(); 415 load1.Wait();
411 416
(...skipping 17 matching lines...) Expand all
429 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true); 434 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true);
430 435
431 // Now it should be able to discard the tab. 436 // Now it should be able to discard the tab.
432 EXPECT_TRUE(tab_manager->DiscardTabImpl()); 437 EXPECT_TRUE(tab_manager->DiscardTabImpl());
433 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); 438 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0)));
434 } 439 }
435 440
436 } // namespace memory 441 } // namespace memory
437 442
438 #endif // OS_WIN || OS_MAXOSX || OS_LINUX 443 #endif // OS_WIN || OS_MAXOSX || OS_LINUX
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698