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

Unified Diff: content/browser/memory/memory_pressure_controller_browsertest.cc

Issue 1362233003: Add architecture for simulating memory pressure notifications in all processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nasko'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 side-by-side diff with in-line comments
Download patch
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..c0d4069c6947bd6855bb4d398f2ce12ec1e8a7c3 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(), &param))
+ return false;
+ return level == base::get<0>(param);
+}
+
class MemoryMessageFilterForTesting : public MemoryMessageFilter {
public:
MOCK_METHOD1(Send, bool(IPC::Message* message));
@@ -62,6 +73,10 @@ class MemoryMessageFilterForTesting : public MemoryMessageFilter {
};
class MemoryPressureControllerBrowserTest : public ContentBrowserTest {
+ public:
+ MOCK_METHOD1(OnMemoryPressure,
+ void(base::MemoryPressureListener::MemoryPressureLevel level));
+
protected:
void SetPressureNotificationsSuppressedInAllProcessesAndWait(
bool suppressed) {
@@ -69,6 +84,13 @@ class MemoryPressureControllerBrowserTest : public ContentBrowserTest {
->SetPressureNotificationsSuppressedInAllProcesses(suppressed);
RunAllPendingInMessageLoop(BrowserThread::IO);
}
+
+ void SimulatePressureNotificationInAllProcessesAndWait(
+ base::MemoryPressureListener::MemoryPressureLevel level) {
+ MemoryPressureController::GetInstance()
+ ->SimulatePressureNotificationInAllProcesses(level);
+ RunAllPendingInMessageLoop(BrowserThread::IO);
+ }
};
IN_PROC_BROWSER_TEST_F(MemoryPressureControllerBrowserTest,
@@ -128,4 +150,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
« no previous file with comments | « content/browser/memory/memory_pressure_controller.cc ('k') | content/child/memory/child_memory_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698