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

Side by Side Diff: content/browser/memory/memory_pressure_controller_impl_browsertest.cc

Issue 1641813002: Provide renderers with memory pressure signals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@contentapi
Patch Set: Addressed creis' comments. Created 4 years, 10 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 | « content/browser/memory/memory_pressure_controller_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.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, "") {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return; 82 return;
83 } 83 }
84 OnChannelClosing(); 84 OnChannelClosing();
85 OnFilterRemoved(); 85 OnFilterRemoved();
86 } 86 }
87 87
88 protected: 88 protected:
89 ~MemoryMessageFilterForTesting() override {} 89 ~MemoryMessageFilterForTesting() override {}
90 }; 90 };
91 91
92 class MemoryPressureControllerBrowserTest : public ContentBrowserTest { 92 class MemoryPressureControllerImplBrowserTest : public ContentBrowserTest {
93 public: 93 public:
94 MOCK_METHOD1(OnMemoryPressure, 94 MOCK_METHOD1(OnMemoryPressure,
95 void(base::MemoryPressureListener::MemoryPressureLevel level)); 95 void(base::MemoryPressureListener::MemoryPressureLevel level));
96 96
97 protected: 97 protected:
98 void SetPressureNotificationsSuppressedInAllProcessesAndWait( 98 void SetPressureNotificationsSuppressedInAllProcessesAndWait(
99 bool suppressed) { 99 bool suppressed) {
100 MemoryPressureController::GetInstance() 100 MemoryPressureControllerImpl::GetInstance()
101 ->SetPressureNotificationsSuppressedInAllProcesses(suppressed); 101 ->SetPressureNotificationsSuppressedInAllProcesses(suppressed);
102 RunAllPendingInMessageLoop(BrowserThread::IO); 102 RunAllPendingInMessageLoop(BrowserThread::IO);
103 } 103 }
104 104
105 void SimulatePressureNotificationInAllProcessesAndWait( 105 void SimulatePressureNotificationInAllProcessesAndWait(
106 base::MemoryPressureListener::MemoryPressureLevel level) { 106 base::MemoryPressureListener::MemoryPressureLevel level) {
107 MemoryPressureController::GetInstance() 107 MemoryPressureControllerImpl::GetInstance()
108 ->SimulatePressureNotificationInAllProcesses(level); 108 ->SimulatePressureNotificationInAllProcesses(level);
109 RunAllPendingInMessageLoop(BrowserThread::IO); 109 RunAllPendingInMessageLoop(BrowserThread::IO);
110 } 110 }
111 111
112 void SendPressureNotificationAndWait( 112 void SendPressureNotificationAndWait(
113 const void* fake_process_host, 113 const void* fake_process_host,
114 base::MemoryPressureListener::MemoryPressureLevel level) { 114 base::MemoryPressureListener::MemoryPressureLevel level) {
115 MemoryPressureController::GetInstance()->SendPressureNotification( 115 MemoryPressureControllerImpl::GetInstance()->SendPressureNotification(
116 reinterpret_cast<const RenderProcessHost*>(fake_process_host), level); 116 reinterpret_cast<const RenderProcessHost*>(fake_process_host), level);
117 RunAllPendingInMessageLoop(BrowserThread::IO); 117 RunAllPendingInMessageLoop(BrowserThread::IO);
118 } 118 }
119 }; 119 };
120 120
121 const auto MEMORY_PRESSURE_LEVEL_MODERATE = 121 const auto MEMORY_PRESSURE_LEVEL_MODERATE =
122 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE; 122 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;
123 const auto MEMORY_PRESSURE_LEVEL_CRITICAL = 123 const auto MEMORY_PRESSURE_LEVEL_CRITICAL =
124 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; 124 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
125 125
126 IN_PROC_BROWSER_TEST_F(MemoryPressureControllerBrowserTest, 126 IN_PROC_BROWSER_TEST_F(MemoryPressureControllerImplBrowserTest,
127 SetPressureNotificationsSuppressedInAllProcesses) { 127 SetPressureNotificationsSuppressedInAllProcesses) {
128 scoped_refptr<MemoryMessageFilterForTesting> filter1( 128 scoped_refptr<MemoryMessageFilterForTesting> filter1(
129 new MemoryMessageFilterForTesting); 129 new MemoryMessageFilterForTesting);
130 scoped_refptr<MemoryMessageFilterForTesting> filter2( 130 scoped_refptr<MemoryMessageFilterForTesting> filter2(
131 new MemoryMessageFilterForTesting); 131 new MemoryMessageFilterForTesting);
132 132
133 NavigateToURL(shell(), GetTestUrl("", "title.html")); 133 NavigateToURL(shell(), GetTestUrl("", "title.html"));
134 134
135 // Add the first filter. No messages should be sent because notifications are 135 // Add the first filter. No messages should be sent because notifications are
136 // not suppressed. 136 // not suppressed.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Remove the second filter and disable suppressing memory pressure 205 // Remove the second filter and disable suppressing memory pressure
206 // notifications in all processes. No messages should be sent. 206 // notifications in all processes. No messages should be sent.
207 EXPECT_CALL(*filter1, Send(testing::_)).Times(0); 207 EXPECT_CALL(*filter1, Send(testing::_)).Times(0);
208 EXPECT_CALL(*filter2, Send(testing::_)).Times(0); 208 EXPECT_CALL(*filter2, Send(testing::_)).Times(0);
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(MemoryPressureControllerBrowserTest, 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 scoped_ptr<base::MemoryPressureListener> listener(
220 new base::MemoryPressureListener( 220 new base::MemoryPressureListener(
221 base::Bind(&MemoryPressureControllerBrowserTest::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.
230 EXPECT_CALL(*filter, Send(IsPressureMessage(MEMORY_PRESSURE_LEVEL_MODERATE))) 230 EXPECT_CALL(*filter, Send(IsPressureMessage(MEMORY_PRESSURE_LEVEL_MODERATE)))
231 .Times(1); 231 .Times(1);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « content/browser/memory/memory_pressure_controller_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698