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

Unified Diff: memory/memory_pressure_listener_unittest.cc

Issue 2050803003: Update to Chromium //base at Chromium commit e3a753f17bac62738b0dbf0b36510f767b081e4b. (Closed) Base URL: https://github.com/domokit/base.git@master
Patch Set: Created 4 years, 6 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 | « memory/memory_pressure_listener.cc ('k') | memory/shared_memory_handle.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: memory/memory_pressure_listener_unittest.cc
diff --git a/memory/memory_pressure_listener_unittest.cc b/memory/memory_pressure_listener_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1bcab2fd041f2707115608850de01c064fa705ac
--- /dev/null
+++ b/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 | « memory/memory_pressure_listener.cc ('k') | memory/shared_memory_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698