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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/system/handle_table.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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/edk/system/handle_table.h"
6
7 #include <memory>
8
9 #include "base/synchronization/lock.h"
10 #include "base/trace_event/memory_allocator_dump.h"
11 #include "base/trace_event/memory_dump_request_args.h"
12 #include "base/trace_event/process_memory_dump.h"
13 #include "base/trace_event/trace_event_argument.h"
14 #include "mojo/edk/system/dispatcher.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace mojo {
18 namespace edk {
19 namespace {
20
21 class FakeMessagePipeDispatcher : public Dispatcher {
22 public:
23 FakeMessagePipeDispatcher() {}
24
25 Type GetType() const override { return Type::MESSAGE_PIPE; }
26
27 MojoResult Close() override { return MOJO_RESULT_OK; }
28
29 private:
30 ~FakeMessagePipeDispatcher() override {}
31 DISALLOW_COPY_AND_ASSIGN(FakeMessagePipeDispatcher);
32 };
33
34 void CheckNameAndValue(base::trace_event::ProcessMemoryDump* pmd,
35 const std::string& name,
36 const std::string& value) {
37 base::trace_event::MemoryAllocatorDump* mad = pmd->GetAllocatorDump(name);
38 ASSERT_TRUE(mad);
39
40 std::unique_ptr<base::Value> dict_value =
41 mad->attributes_for_testing()->ToBaseValue();
42 ASSERT_TRUE(dict_value->is_dict());
43
44 base::DictionaryValue* dict;
45 ASSERT_TRUE(dict_value->GetAsDictionary(&dict));
46
47 base::DictionaryValue* inner_dict;
48 ASSERT_TRUE(dict->GetDictionary("object_count", &inner_dict));
49
50 std::string output;
51 ASSERT_TRUE(inner_dict->GetString("value", &output));
52 EXPECT_EQ(value, output);
53 }
54
55 } // namespace
56
57 TEST(HandleTableTest, OnMemoryDump) {
58 HandleTable ht;
59
60 {
61 base::AutoLock auto_lock(ht.GetLock());
62 scoped_refptr<mojo::edk::Dispatcher> dispatcher(
63 new FakeMessagePipeDispatcher);
64 ht.AddDispatcher(dispatcher);
65 }
66
67 base::trace_event::MemoryDumpArgs args;
68 base::trace_event::ProcessMemoryDump pmd(nullptr, args);
69 ht.OnMemoryDump(args, &pmd);
70
71 CheckNameAndValue(&pmd, "mojo/message_pipe", "1");
72 CheckNameAndValue(&pmd, "mojo/data_pipe_consumer", "0");
73 }
74
75 } // namespace edk
76 } // namespace mojo
OLDNEW
« 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