Index: mojo/edk/system/handle_table_unittest.cc |
diff --git a/mojo/edk/system/handle_table_unittest.cc b/mojo/edk/system/handle_table_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e55f0d8cc3aa175e724756ae7c5a4b7c3ecbf267 |
--- /dev/null |
+++ b/mojo/edk/system/handle_table_unittest.cc |
@@ -0,0 +1,78 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "mojo/edk/system/handle_table.h" |
+ |
+#include <memory> |
+ |
+#include "base/synchronization/lock.h" |
+#include "base/trace_event/memory_allocator_dump.h" |
+#include "base/trace_event/memory_dump_request_args.h" |
+#include "base/trace_event/process_memory_dump.h" |
+#include "base/trace_event/trace_event_argument.h" |
+#include "mojo/edk/system/dispatcher.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace mojo { |
+namespace edk { |
+namespace { |
+ |
+class FakeMessagePipeDispatcher : public Dispatcher { |
+ public: |
+ FakeMessagePipeDispatcher() {} |
+ |
+ Type GetType() const override { return Type::MESSAGE_PIPE; } |
+ |
+ MojoResult Close() override { return MOJO_RESULT_OK; } |
+ |
+ private: |
+ ~FakeMessagePipeDispatcher() override {} |
+ DISALLOW_COPY_AND_ASSIGN(FakeMessagePipeDispatcher); |
+}; |
+ |
+void CheckNameAndValue(base::DictionaryValue* dict, |
+ const std::string& name, |
+ const std::string& value) { |
+ base::Value* inner_value; |
+ ASSERT_TRUE(dict->Get(name, &inner_value)); |
+ |
+ base::DictionaryValue* inner_dict; |
+ ASSERT_TRUE(inner_value->GetAsDictionary(&inner_dict)); |
+ std::string output; |
+ EXPECT_TRUE(inner_dict->GetString("value", &output)); |
+ EXPECT_EQ(value, output); |
+} |
+ |
+} // namespace |
+ |
+TEST(HandleTableTest, OnMemoryDump) { |
+ HandleTable ht; |
+ |
+ { |
+ base::AutoLock auto_lock(ht.GetLock()); |
+ scoped_refptr<mojo::edk::Dispatcher> dispatcher( |
+ new FakeMessagePipeDispatcher); |
+ ht.AddDispatcher(dispatcher); |
+ } |
+ |
+ base::trace_event::MemoryDumpArgs args; |
+ base::trace_event::ProcessMemoryDump pmd(nullptr, args); |
+ ht.OnMemoryDump(args, &pmd); |
+ |
+ base::trace_event::MemoryAllocatorDump* mad = pmd.GetAllocatorDump("mojo"); |
+ ASSERT_TRUE(mad); |
+ |
+ std::unique_ptr<base::Value> value = |
+ mad->attributes_for_testing()->ToBaseValue(); |
+ ASSERT_TRUE(value->is_dict()); |
+ |
+ base::DictionaryValue* dict; |
+ ASSERT_TRUE(value->GetAsDictionary(&dict)); |
+ |
+ CheckNameAndValue(dict, "message_pipe", "1"); |
+ CheckNameAndValue(dict, "data_pipe_consumer", "0"); |
+} |
+ |
+} // namespace edk |
+} // namespace mojo |