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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/memory/memory_pressure_listener.cc ('k') | 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/memory_pressure_listener.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10
11 namespace base {
12
13 using MockCallback =
14 testing::MockFunction<void(MemoryPressureListener::MemoryPressureLevel)>;
15
16 TEST(MemoryPressureListenerTest, NotifyMemoryPressure) {
17 MessageLoopForUI message_loop;
18 MockCallback callback;
19 scoped_ptr<MemoryPressureListener> listener(new MemoryPressureListener(
20 Bind(&MockCallback::Call, Unretained(&callback))));
21
22 // Memory pressure notifications are not suppressed by default.
23 EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed());
24 EXPECT_CALL(callback,
25 Call(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE))
26 .Times(1);
27 MemoryPressureListener::NotifyMemoryPressure(
28 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
29 message_loop.RunUntilIdle();
30
31 // Enable suppressing memory pressure notifications.
32 MemoryPressureListener::SetNotificationsSuppressed(true);
33 EXPECT_TRUE(MemoryPressureListener::AreNotificationsSuppressed());
34 EXPECT_CALL(callback, Call(testing::_)).Times(0);
35 MemoryPressureListener::NotifyMemoryPressure(
36 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
37 message_loop.RunUntilIdle();
38
39 // Disable suppressing memory pressure notifications.
40 MemoryPressureListener::SetNotificationsSuppressed(false);
41 EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed());
42 EXPECT_CALL(callback,
43 Call(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL))
44 .Times(1);
45 MemoryPressureListener::NotifyMemoryPressure(
46 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
47 message_loop.RunUntilIdle();
48
49 listener.reset();
50 }
51
52 } // namespace base
OLDNEW
« 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