| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/memory_pressure_listener.h" | 5 #include "base/memory/memory_pressure_listener.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 MemoryPressureLevel level) { | 39 MemoryPressureLevel level) { |
| 40 EXPECT_CALL(*this, OnMemoryPressure(testing::_)).Times(0); | 40 EXPECT_CALL(*this, OnMemoryPressure(testing::_)).Times(0); |
| 41 notification_function(level); | 41 notification_function(level); |
| 42 message_loop_->RunUntilIdle(); | 42 message_loop_->RunUntilIdle(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 MOCK_METHOD1(OnMemoryPressure, | 46 MOCK_METHOD1(OnMemoryPressure, |
| 47 void(MemoryPressureListener::MemoryPressureLevel)); | 47 void(MemoryPressureListener::MemoryPressureLevel)); |
| 48 | 48 |
| 49 scoped_ptr<MessageLoopForUI> message_loop_; | 49 std::unique_ptr<MessageLoopForUI> message_loop_; |
| 50 scoped_ptr<MemoryPressureListener> listener_; | 50 std::unique_ptr<MemoryPressureListener> listener_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 TEST_F(MemoryPressureListenerTest, NotifyMemoryPressure) { | 53 TEST_F(MemoryPressureListenerTest, NotifyMemoryPressure) { |
| 54 // Memory pressure notifications are not suppressed by default. | 54 // Memory pressure notifications are not suppressed by default. |
| 55 EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed()); | 55 EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed()); |
| 56 ExpectNotification(&MemoryPressureListener::NotifyMemoryPressure, | 56 ExpectNotification(&MemoryPressureListener::NotifyMemoryPressure, |
| 57 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); | 57 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 58 ExpectNotification(&MemoryPressureListener::SimulatePressureNotification, | 58 ExpectNotification(&MemoryPressureListener::SimulatePressureNotification, |
| 59 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); | 59 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 60 | 60 |
| 61 // Enable suppressing memory pressure notifications. | 61 // Enable suppressing memory pressure notifications. |
| 62 MemoryPressureListener::SetNotificationsSuppressed(true); | 62 MemoryPressureListener::SetNotificationsSuppressed(true); |
| 63 EXPECT_TRUE(MemoryPressureListener::AreNotificationsSuppressed()); | 63 EXPECT_TRUE(MemoryPressureListener::AreNotificationsSuppressed()); |
| 64 ExpectNoNotification(&MemoryPressureListener::NotifyMemoryPressure, | 64 ExpectNoNotification(&MemoryPressureListener::NotifyMemoryPressure, |
| 65 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); | 65 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 66 ExpectNotification(&MemoryPressureListener::SimulatePressureNotification, | 66 ExpectNotification(&MemoryPressureListener::SimulatePressureNotification, |
| 67 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); | 67 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 68 | 68 |
| 69 // Disable suppressing memory pressure notifications. | 69 // Disable suppressing memory pressure notifications. |
| 70 MemoryPressureListener::SetNotificationsSuppressed(false); | 70 MemoryPressureListener::SetNotificationsSuppressed(false); |
| 71 EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed()); | 71 EXPECT_FALSE(MemoryPressureListener::AreNotificationsSuppressed()); |
| 72 ExpectNotification(&MemoryPressureListener::NotifyMemoryPressure, | 72 ExpectNotification(&MemoryPressureListener::NotifyMemoryPressure, |
| 73 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_CRITICAL); | 73 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 74 ExpectNotification(&MemoryPressureListener::SimulatePressureNotification, | 74 ExpectNotification(&MemoryPressureListener::SimulatePressureNotification, |
| 75 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_CRITICAL); | 75 MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 76 } | 76 } |
| 77 | 77 |
| 78 } // namespace base | 78 } // namespace base |
| OLD | NEW |