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

Unified 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, 2 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
« no previous file with comments | « content/common/host_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/host_discardable_shared_memory_manager_unittest.cc
diff --git a/content/common/host_discardable_shared_memory_manager_unittest.cc b/content/common/host_discardable_shared_memory_manager_unittest.cc
index 8f09ef05f12962437fa59f091077a8df1eded31d..3adbc72aca1f564f00674a4c107deba3c941aacf 100644
--- a/content/common/host_discardable_shared_memory_manager_unittest.cc
+++ b/content/common/host_discardable_shared_memory_manager_unittest.cc
@@ -4,6 +4,7 @@
#include "content/common/host_discardable_shared_memory_manager.h"
+#include "base/threading/simple_thread.h"
#include "content/public/common/child_process_host.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -232,5 +233,50 @@ TEST_F(HostDiscardableSharedMemoryManagerTest,
memory2.Unlock(0, 0);
}
+class HostDiscardableSharedMemoryManagerScheduleEnforceMemoryPolicyTest
+ : public testing::Test {
+ protected:
+ // Overridden from testing::Test:
+ void SetUp() override {
+ manager_.reset(new HostDiscardableSharedMemoryManager);
+ }
+
+ // This test requires a message loop.
+ base::MessageLoop message_loop_;
+ scoped_ptr<HostDiscardableSharedMemoryManager> manager_;
+};
+
+class SetMemoryLimitRunner : public base::DelegateSimpleThread::Delegate {
+ public:
+ SetMemoryLimitRunner(HostDiscardableSharedMemoryManager* manager,
+ size_t limit)
+ : manager_(manager), limit_(limit) {}
+ ~SetMemoryLimitRunner() override {}
+
+ void Run() override { manager_->SetMemoryLimit(limit_); }
+
+ private:
+ HostDiscardableSharedMemoryManager* const manager_;
+ const size_t limit_;
+};
+
+TEST_F(HostDiscardableSharedMemoryManagerScheduleEnforceMemoryPolicyTest,
+ SetMemoryLimitOnSimpleThread) {
+ const int kDataSize = 1024;
+
+ base::SharedMemoryHandle shared_handle;
+ manager_->AllocateLockedDiscardableSharedMemoryForChild(
+ base::GetCurrentProcessHandle(), ChildProcessHost::kInvalidUniqueID,
+ kDataSize, 0, &shared_handle);
+ ASSERT_TRUE(base::SharedMemory::IsHandleValid(shared_handle));
+
+ // Set the memory limit to a value that will require EnforceMemoryPolicy()
+ // to be schedule on a thread without a message loop.
+ SetMemoryLimitRunner runner(manager_.get(), kDataSize - 1);
+ base::DelegateSimpleThread thread(&runner, "memory_limit_setter");
+ thread.Start();
+ thread.Join();
+}
+
} // namespace
} // namespace content
« 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