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

Unified Diff: mojo/edk/system/handle_table_unittest.cc

Issue 2930533003: Minor fixes to Mojo MemoryDumpProvider. (Closed)
Patch Set: comments from ssid. Created 3 years, 6 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 | « mojo/edk/system/handle_table.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..15bace0144913235d95a2fb3276b7375f4c2b1e4
--- /dev/null
+++ b/mojo/edk/system/handle_table_unittest.cc
@@ -0,0 +1,76 @@
+// 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::trace_event::ProcessMemoryDump* pmd,
+ const std::string& name,
+ const std::string& value) {
+ base::trace_event::MemoryAllocatorDump* mad = pmd->GetAllocatorDump(name);
+ ASSERT_TRUE(mad);
+
+ std::unique_ptr<base::Value> dict_value =
+ mad->attributes_for_testing()->ToBaseValue();
+ ASSERT_TRUE(dict_value->is_dict());
+
+ base::DictionaryValue* dict;
+ ASSERT_TRUE(dict_value->GetAsDictionary(&dict));
+
+ base::DictionaryValue* inner_dict;
+ ASSERT_TRUE(dict->GetDictionary("object_count", &inner_dict));
+
+ std::string output;
+ ASSERT_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);
+
+ CheckNameAndValue(&pmd, "mojo/message_pipe", "1");
+ CheckNameAndValue(&pmd, "mojo/data_pipe_consumer", "0");
+}
+
+} // namespace edk
+} // namespace mojo
« no previous file with comments | « mojo/edk/system/handle_table.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698