OLD | NEW |
(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::DictionaryValue* dict, |
| 35 const std::string& name, |
| 36 const std::string& value) { |
| 37 base::Value* inner_value; |
| 38 ASSERT_TRUE(dict->Get(name, &inner_value)); |
| 39 |
| 40 base::DictionaryValue* inner_dict; |
| 41 ASSERT_TRUE(inner_value->GetAsDictionary(&inner_dict)); |
| 42 std::string output; |
| 43 EXPECT_TRUE(inner_dict->GetString("value", &output)); |
| 44 EXPECT_EQ(value, output); |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 TEST(HandleTableTest, OnMemoryDump) { |
| 50 HandleTable ht; |
| 51 |
| 52 { |
| 53 base::AutoLock auto_lock(ht.GetLock()); |
| 54 scoped_refptr<mojo::edk::Dispatcher> dispatcher( |
| 55 new FakeMessagePipeDispatcher); |
| 56 ht.AddDispatcher(dispatcher); |
| 57 } |
| 58 |
| 59 base::trace_event::MemoryDumpArgs args; |
| 60 base::trace_event::ProcessMemoryDump pmd(nullptr, args); |
| 61 ht.OnMemoryDump(args, &pmd); |
| 62 |
| 63 base::trace_event::MemoryAllocatorDump* mad = pmd.GetAllocatorDump("mojo"); |
| 64 ASSERT_TRUE(mad); |
| 65 |
| 66 std::unique_ptr<base::Value> value = |
| 67 mad->attributes_for_testing()->ToBaseValue(); |
| 68 ASSERT_TRUE(value->is_dict()); |
| 69 |
| 70 base::DictionaryValue* dict; |
| 71 ASSERT_TRUE(value->GetAsDictionary(&dict)); |
| 72 |
| 73 CheckNameAndValue(dict, "message_pipe", "1"); |
| 74 CheckNameAndValue(dict, "data_pipe_consumer", "0"); |
| 75 } |
| 76 |
| 77 } // namespace edk |
| 78 } // namespace mojo |
OLD | NEW |