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 |