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

Unified Diff: chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc

Issue 815183002: Using the new MemoryPressureListener instead of the LowMemoryObserver when the enhanced memory mana… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed flaky unit test Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/memory/oom_priority_manager.cc ('k') | content/browser/memory_pressure_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc
diff --git a/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc b/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc
index 8376de345841b58b78e72780cd8b8a3f70e9b88e..f9f2f7913093a579189f41c49a506bd522ecbe6e 100644
--- a/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc
+++ b/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
+#include "base/memory/memory_pressure_listener.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/memory/oom_priority_manager.h"
@@ -11,6 +13,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "chromeos/chromeos_switches.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/test/test_utils.h"
@@ -22,6 +25,22 @@ namespace {
typedef InProcessBrowserTest OomPriorityManagerTest;
+class OomPriorityManagerUsingPressureListenerTest
+ : public InProcessBrowserTest {
+ public:
+ OomPriorityManagerUsingPressureListenerTest() {}
+ ~OomPriorityManagerUsingPressureListenerTest() override {}
+
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ command_line->AppendSwitch(
+ chromeos::switches::kUseMemoryPressureSystemChromeOS);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(OomPriorityManagerUsingPressureListenerTest);
+};
+
+
IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) {
using content::WindowedNotificationObserver;
@@ -159,4 +178,51 @@ IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) {
EXPECT_TRUE(chrome::CanGoForward(browser()));
}
+// Test that the MemoryPressureListener event is properly triggering a tab
+// discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event.
+IN_PROC_BROWSER_TEST_F(OomPriorityManagerUsingPressureListenerTest,
+ OomPressureListener) {
+ chromeos::OomPriorityManager* oom_priority_manager =
+ g_browser_process->platform_part()->oom_priority_manager();
+ // Get three tabs open.
+ content::WindowedNotificationObserver load1(
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
+ CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
+ browser()->OpenURL(open1);
+ load1.Wait();
+
+ content::WindowedNotificationObserver load2(
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
+ NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED,
+ false);
+ browser()->OpenURL(open2);
+ load2.Wait();
+ EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
+
+ // Nothing should happen with a moderate memory pressure event.
+ base::MemoryPressureListener::NotifyMemoryPressure(
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
+ EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
+
+ // A critical memory pressure event should discard a tab.
+ base::MemoryPressureListener::NotifyMemoryPressure(
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
+ // Coming here, an asynchronous operation will collect system stats. Once in,
+ // a tab should get discarded. As such we need to give it 10s time to discard.
+ const int kTimeoutTimeInMS = 10000;
+ const int kIntervalTimeInMS = 5;
+ int timeout = kTimeoutTimeInMS / kIntervalTimeInMS;
+ while (--timeout) {
+ usleep(kIntervalTimeInMS * 1000);
+ base::RunLoop().RunUntilIdle();
+ if (oom_priority_manager->recent_tab_discard())
+ break;
+ }
+ EXPECT_TRUE(oom_priority_manager->recent_tab_discard());
+}
+
} // namespace
« no previous file with comments | « chrome/browser/chromeos/memory/oom_priority_manager.cc ('k') | content/browser/memory_pressure_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698