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

Unified Diff: base/memory/memory_pressure_listener_unittest.cc

Issue 1312163003: Add method for suppressing MemoryPressureListener notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address thestig's comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/memory_pressure_listener.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/memory_pressure_listener_unittest.cc
diff --git a/base/memory/memory_pressure_listener_unittest.cc b/base/memory/memory_pressure_listener_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1bcab2fd041f2707115608850de01c064fa705ac
--- /dev/null
+++ b/base/memory/memory_pressure_listener_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/memory_pressure_listener.h"
+
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace base {
+
+using MockCallback =
+ testing::MockFunction<void(MemoryPressureListener::MemoryPressureLevel)>;
+
+TEST(MemoryPressureListenerTest, NotifyMemoryPressure) {
+ MessageLoopForUI message_loop;
+ MockCallback callback;
+ scoped_ptr<MemoryPressureListener> listener(new MemoryPressureListener(
+ Bind(&MockCallback::Call, Unretained(&callback))));
+
+ // Memory pressure notifications are not suppressed by default.
+ EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed());
+ EXPECT_CALL(callback,
+ Call(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE))
+ .Times(1);
+ MemoryPressureListener::NotifyMemoryPressure(
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
+ message_loop.RunUntilIdle();
+
+ // Enable suppressing memory pressure notifications.
+ MemoryPressureListener::SetNotificationsSuppressed(true);
+ EXPECT_TRUE(MemoryPressureListener::AreNotificationsSuppressed());
+ EXPECT_CALL(callback, Call(testing::_)).Times(0);
+ MemoryPressureListener::NotifyMemoryPressure(
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
+ message_loop.RunUntilIdle();
+
+ // Disable suppressing memory pressure notifications.
+ MemoryPressureListener::SetNotificationsSuppressed(false);
+ EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed());
+ EXPECT_CALL(callback,
+ Call(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL))
+ .Times(1);
+ MemoryPressureListener::NotifyMemoryPressure(
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
+ message_loop.RunUntilIdle();
+
+ listener.reset();
+}
+
+} // namespace base
« no previous file with comments | « base/memory/memory_pressure_listener.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698