| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/memory_pressure_listener.h" | 6 #include "base/memory/memory_pressure_listener.h" |
| 7 #include "content/browser/memory/memory_message_filter.h" | 7 #include "content/browser/memory/memory_message_filter.h" |
| 8 #include "content/browser/memory/memory_pressure_controller_impl.h" | 8 #include "content/browser/memory/memory_pressure_controller_impl.h" |
| 9 #include "content/common/memory_messages.h" | 9 #include "content/common/memory_messages.h" |
| 10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| 11 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
| 12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 MATCHER_P(IsSetSuppressedMessage, suppressed, "") { | 18 MATCHER_P(IsSetSuppressedMessage, suppressed, "") { |
| 19 // Ensure that the message is deleted upon return. | 19 // Ensure that the message is deleted upon return. |
| 20 scoped_ptr<IPC::Message> message(arg); | 20 std::unique_ptr<IPC::Message> message(arg); |
| 21 if (message == nullptr) | 21 if (message == nullptr) |
| 22 return false; | 22 return false; |
| 23 MemoryMsg_SetPressureNotificationsSuppressed::Param param; | 23 MemoryMsg_SetPressureNotificationsSuppressed::Param param; |
| 24 if (!MemoryMsg_SetPressureNotificationsSuppressed::Read(message.get(), | 24 if (!MemoryMsg_SetPressureNotificationsSuppressed::Read(message.get(), |
| 25 ¶m)) | 25 ¶m)) |
| 26 return false; | 26 return false; |
| 27 return suppressed == base::get<0>(param); | 27 return suppressed == base::get<0>(param); |
| 28 } | 28 } |
| 29 | 29 |
| 30 MATCHER_P(IsSimulateMessage, level, "") { | 30 MATCHER_P(IsSimulateMessage, level, "") { |
| 31 // Ensure that the message is deleted upon return. | 31 // Ensure that the message is deleted upon return. |
| 32 scoped_ptr<IPC::Message> message(arg); | 32 std::unique_ptr<IPC::Message> message(arg); |
| 33 if (message == nullptr) | 33 if (message == nullptr) |
| 34 return false; | 34 return false; |
| 35 MemoryMsg_SimulatePressureNotification::Param param; | 35 MemoryMsg_SimulatePressureNotification::Param param; |
| 36 if (!MemoryMsg_SimulatePressureNotification::Read(message.get(), ¶m)) | 36 if (!MemoryMsg_SimulatePressureNotification::Read(message.get(), ¶m)) |
| 37 return false; | 37 return false; |
| 38 return level == base::get<0>(param); | 38 return level == base::get<0>(param); |
| 39 } | 39 } |
| 40 | 40 |
| 41 MATCHER_P(IsPressureMessage, level, "") { | 41 MATCHER_P(IsPressureMessage, level, "") { |
| 42 // Ensure that the message is deleted upon return. | 42 // Ensure that the message is deleted upon return. |
| 43 scoped_ptr<IPC::Message> message(arg); | 43 std::unique_ptr<IPC::Message> message(arg); |
| 44 if (message == nullptr) | 44 if (message == nullptr) |
| 45 return false; | 45 return false; |
| 46 MemoryMsg_PressureNotification::Param param; | 46 MemoryMsg_PressureNotification::Param param; |
| 47 if (!MemoryMsg_PressureNotification::Read(message.get(), ¶m)) | 47 if (!MemoryMsg_PressureNotification::Read(message.get(), ¶m)) |
| 48 return false; | 48 return false; |
| 49 return level == base::get<0>(param); | 49 return level == base::get<0>(param); |
| 50 } | 50 } |
| 51 | 51 |
| 52 class MemoryMessageFilterForTesting : public MemoryMessageFilter { | 52 class MemoryMessageFilterForTesting : public MemoryMessageFilter { |
| 53 public: | 53 public: |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 filter2->Remove(); | 209 filter2->Remove(); |
| 210 SetPressureNotificationsSuppressedInAllProcessesAndWait(false); | 210 SetPressureNotificationsSuppressedInAllProcessesAndWait(false); |
| 211 EXPECT_FALSE(base::MemoryPressureListener::AreNotificationsSuppressed()); | 211 EXPECT_FALSE(base::MemoryPressureListener::AreNotificationsSuppressed()); |
| 212 testing::Mock::VerifyAndClearExpectations(this); | 212 testing::Mock::VerifyAndClearExpectations(this); |
| 213 } | 213 } |
| 214 | 214 |
| 215 IN_PROC_BROWSER_TEST_F(MemoryPressureControllerImplBrowserTest, | 215 IN_PROC_BROWSER_TEST_F(MemoryPressureControllerImplBrowserTest, |
| 216 SimulatePressureNotificationInAllProcesses) { | 216 SimulatePressureNotificationInAllProcesses) { |
| 217 scoped_refptr<MemoryMessageFilterForTesting> filter( | 217 scoped_refptr<MemoryMessageFilterForTesting> filter( |
| 218 new MemoryMessageFilterForTesting); | 218 new MemoryMessageFilterForTesting); |
| 219 scoped_ptr<base::MemoryPressureListener> listener( | 219 std::unique_ptr<base::MemoryPressureListener> listener( |
| 220 new base::MemoryPressureListener( | 220 new base::MemoryPressureListener( |
| 221 base::Bind(&MemoryPressureControllerImplBrowserTest::OnMemoryPressure, | 221 base::Bind(&MemoryPressureControllerImplBrowserTest::OnMemoryPressure, |
| 222 base::Unretained(this)))); | 222 base::Unretained(this)))); |
| 223 | 223 |
| 224 NavigateToURL(shell(), GetTestUrl("", "title.html")); | 224 NavigateToURL(shell(), GetTestUrl("", "title.html")); |
| 225 | 225 |
| 226 filter->Add(); | 226 filter->Add(); |
| 227 | 227 |
| 228 // Send a memory pressure event to the first child process. It should send a | 228 // Send a memory pressure event to the first child process. It should send a |
| 229 // pressure notification message. | 229 // pressure notification message. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 EXPECT_CALL(*this, OnMemoryPressure(MEMORY_PRESSURE_LEVEL_MODERATE)).Times(1); | 265 EXPECT_CALL(*this, OnMemoryPressure(MEMORY_PRESSURE_LEVEL_MODERATE)).Times(1); |
| 266 SimulatePressureNotificationInAllProcessesAndWait( | 266 SimulatePressureNotificationInAllProcessesAndWait( |
| 267 MEMORY_PRESSURE_LEVEL_MODERATE); | 267 MEMORY_PRESSURE_LEVEL_MODERATE); |
| 268 RunAllPendingInMessageLoop(); // Wait for the listener to run. | 268 RunAllPendingInMessageLoop(); // Wait for the listener to run. |
| 269 testing::Mock::VerifyAndClearExpectations(this); | 269 testing::Mock::VerifyAndClearExpectations(this); |
| 270 | 270 |
| 271 filter->Remove(); | 271 filter->Remove(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace content | 274 } // namespace content |
| OLD | NEW |