| Index: content/browser/memory/memory_pressure_controller_browsertest.cc
|
| diff --git a/content/browser/memory/memory_pressure_controller_browsertest.cc b/content/browser/memory/memory_pressure_controller_browsertest.cc
|
| index b1452d84ae122324a94d6658f33307e0d9d5f477..050277812ade7d80e25a455388be3622304d066f 100644
|
| --- a/content/browser/memory/memory_pressure_controller_browsertest.cc
|
| +++ b/content/browser/memory/memory_pressure_controller_browsertest.cc
|
| @@ -27,6 +27,17 @@ MATCHER_P(IsSetSuppressedMessage, suppressed, "") {
|
| return suppressed == base::get<0>(param);
|
| }
|
|
|
| +MATCHER_P(IsSimulateMessage, level, "") {
|
| + // Ensure that the message is deleted upon return.
|
| + scoped_ptr<IPC::Message> message(arg);
|
| + if (message == nullptr)
|
| + return false;
|
| + MemoryMsg_SimulatePressureNotification::Param param;
|
| + if (!MemoryMsg_SimulatePressureNotification::Read(message.get(), ¶m))
|
| + return false;
|
| + return level == base::get<0>(param);
|
| +}
|
| +
|
| class MemoryMessageFilterForTesting : public MemoryMessageFilter {
|
| public:
|
| MOCK_METHOD1(Send, bool(IPC::Message* message));
|
| @@ -62,6 +73,9 @@ class MemoryMessageFilterForTesting : public MemoryMessageFilter {
|
| };
|
|
|
| class MemoryPressureControllerBrowserTest : public ContentBrowserTest {
|
| + public:
|
| + MOCK_METHOD1(OnMemoryPressure, void(MemoryPressureLevel level));
|
| +
|
| protected:
|
| void SetPressureNotificationsSuppressedInAllProcessesAndWait(
|
| bool suppressed) {
|
| @@ -69,6 +83,13 @@ class MemoryPressureControllerBrowserTest : public ContentBrowserTest {
|
| ->SetPressureNotificationsSuppressedInAllProcesses(suppressed);
|
| RunAllPendingInMessageLoop(BrowserThread::IO);
|
| }
|
| +
|
| + void SimulatePressureNotificationInAllProcessesAndWait(
|
| + MemoryPressureLevel level) {
|
| + MemoryPressureController::GetInstance()
|
| + ->SimulatePressureNotificationInAllProcesses(level);
|
| + RunAllPendingInMessageLoop(BrowserThread::IO);
|
| + }
|
| };
|
|
|
| IN_PROC_BROWSER_TEST_F(MemoryPressureControllerBrowserTest,
|
| @@ -128,4 +149,56 @@ IN_PROC_BROWSER_TEST_F(MemoryPressureControllerBrowserTest,
|
| EXPECT_FALSE(base::MemoryPressureListener::AreNotificationsSuppressed());
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(MemoryPressureControllerBrowserTest,
|
| + SimulatePressureNotificationInAllProcesses) {
|
| + const auto MEMORY_PRESSURE_LEVEL_MODERATE =
|
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;
|
| + const auto MEMORY_PRESSURE_LEVEL_CRITICAL =
|
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
|
| +
|
| + scoped_refptr<MemoryMessageFilterForTesting> filter(
|
| + new MemoryMessageFilterForTesting);
|
| + scoped_ptr<base::MemoryPressureListener> listener(
|
| + new base::MemoryPressureListener(
|
| + base::Bind(&MemoryPressureControllerBrowserTest::OnMemoryPressure,
|
| + base::Unretained(this))));
|
| +
|
| + NavigateToURL(shell(), GetTestUrl("", "title.html"));
|
| +
|
| + filter->Add();
|
| +
|
| + EXPECT_CALL(*filter, Send(IsSimulateMessage(MEMORY_PRESSURE_LEVEL_CRITICAL)))
|
| + .Times(1);
|
| + EXPECT_CALL(*this, OnMemoryPressure(MEMORY_PRESSURE_LEVEL_CRITICAL)).Times(1);
|
| + SimulatePressureNotificationInAllProcessesAndWait(
|
| + MEMORY_PRESSURE_LEVEL_CRITICAL);
|
| + RunAllPendingInMessageLoop(); // Wait for the listener to run.
|
| +
|
| + // Enable suppressing memory pressure notifications in all processes. This
|
| + // should have no impact on simulating memory pressure notifications.
|
| + EXPECT_CALL(*filter, Send(IsSetSuppressedMessage(true))).Times(1);
|
| + SetPressureNotificationsSuppressedInAllProcessesAndWait(true);
|
| +
|
| + EXPECT_CALL(*filter, Send(IsSimulateMessage(MEMORY_PRESSURE_LEVEL_MODERATE)))
|
| + .Times(1);
|
| + EXPECT_CALL(*this, OnMemoryPressure(MEMORY_PRESSURE_LEVEL_MODERATE)).Times(1);
|
| + SimulatePressureNotificationInAllProcessesAndWait(
|
| + MEMORY_PRESSURE_LEVEL_MODERATE);
|
| + RunAllPendingInMessageLoop(); // Wait for the listener to run.
|
| +
|
| + // Disable suppressing memory pressure notifications in all processes. This
|
| + // should have no impact on simulating memory pressure notifications.
|
| + EXPECT_CALL(*filter, Send(IsSetSuppressedMessage(false))).Times(1);
|
| + SetPressureNotificationsSuppressedInAllProcessesAndWait(false);
|
| +
|
| + EXPECT_CALL(*filter, Send(IsSimulateMessage(MEMORY_PRESSURE_LEVEL_MODERATE)))
|
| + .Times(1);
|
| + EXPECT_CALL(*this, OnMemoryPressure(MEMORY_PRESSURE_LEVEL_MODERATE)).Times(1);
|
| + SimulatePressureNotificationInAllProcessesAndWait(
|
| + MEMORY_PRESSURE_LEVEL_MODERATE);
|
| + RunAllPendingInMessageLoop(); // Wait for the listener to run.
|
| +
|
| + filter->Remove();
|
| +}
|
| +
|
| } // namespace content
|
|
|