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

Side by Side Diff: content/common/host_discardable_shared_memory_manager_unittest.cc

Issue 1430743002: content: Always run EnforceMemoryPolicy() callbacks on the same thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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/common/host_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/common/host_discardable_shared_memory_manager.h" 5 #include "content/common/host_discardable_shared_memory_manager.h"
6 6
7 #include "base/threading/simple_thread.h"
7 #include "content/public/common/child_process_host.h" 8 #include "content/public/common/child_process_host.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace content { 11 namespace content {
11 namespace { 12 namespace {
12 13
13 class TestDiscardableSharedMemory : public base::DiscardableSharedMemory { 14 class TestDiscardableSharedMemory : public base::DiscardableSharedMemory {
14 public: 15 public:
15 TestDiscardableSharedMemory() {} 16 TestDiscardableSharedMemory() {}
16 17
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // Make sure the manager is able to reduce memory after the segment 1 was 226 // Make sure the manager is able to reduce memory after the segment 1 was
226 // deleted. 227 // deleted.
227 manager_->SetNow(base::Time::FromDoubleT(2)); 228 manager_->SetNow(base::Time::FromDoubleT(2));
228 manager_->SetMemoryLimit(0); 229 manager_->SetMemoryLimit(0);
229 230
230 // Unlock segment 2. 231 // Unlock segment 2.
231 memory2.SetNow(base::Time::FromDoubleT(3)); 232 memory2.SetNow(base::Time::FromDoubleT(3));
232 memory2.Unlock(0, 0); 233 memory2.Unlock(0, 0);
233 } 234 }
234 235
236 class HostDiscardableSharedMemoryManagerScheduleEnforceMemoryPolicyTest
237 : public testing::Test {
238 protected:
239 // Overridden from testing::Test:
240 void SetUp() override {
241 manager_.reset(new HostDiscardableSharedMemoryManager);
242 }
243
244 // This test requires a message loop.
245 base::MessageLoop message_loop_;
246 scoped_ptr<HostDiscardableSharedMemoryManager> manager_;
247 };
248
249 class SetMemoryLimitRunner : public base::DelegateSimpleThread::Delegate {
250 public:
251 SetMemoryLimitRunner(HostDiscardableSharedMemoryManager* manager,
252 size_t limit)
253 : manager_(manager), limit_(limit) {}
254 ~SetMemoryLimitRunner() override {}
255
256 void Run() override { manager_->SetMemoryLimit(limit_); }
257
258 private:
259 HostDiscardableSharedMemoryManager* const manager_;
260 const size_t limit_;
261 };
262
263 TEST_F(HostDiscardableSharedMemoryManagerScheduleEnforceMemoryPolicyTest,
264 SetMemoryLimitOnSimpleThread) {
265 const int kDataSize = 1024;
266
267 base::SharedMemoryHandle shared_handle;
268 manager_->AllocateLockedDiscardableSharedMemoryForChild(
269 base::GetCurrentProcessHandle(), ChildProcessHost::kInvalidUniqueID,
270 kDataSize, 0, &shared_handle);
271 ASSERT_TRUE(base::SharedMemory::IsHandleValid(shared_handle));
272
273 // Set the memory limit to a value that will require EnforceMemoryPolicy()
274 // to be schedule on a thread without a message loop.
275 SetMemoryLimitRunner runner(manager_.get(), kDataSize - 1);
276 base::DelegateSimpleThread thread(&runner, "memory_limit_setter");
277 thread.Start();
278 thread.Join();
279 }
280
235 } // namespace 281 } // namespace
236 } // namespace content 282 } // namespace content
OLDNEW
« no previous file with comments | « content/common/host_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698