| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" | 5 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 base::ThreadTaskRunnerHandle::Get()->PostTask( | 40 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 41 FROM_HERE, | 41 FROM_HERE, |
| 42 base::Bind(&CoordinatorImpl::RequestGlobalMemoryDump, | 42 base::Bind(&CoordinatorImpl::RequestGlobalMemoryDump, |
| 43 base::Unretained(coordinator_.get()), args, | 43 base::Unretained(coordinator_.get()), args, |
| 44 base::Bind(&CoordinatorImplTest::OnGlobalMemoryDumpResponse, | 44 base::Bind(&CoordinatorImplTest::OnGlobalMemoryDumpResponse, |
| 45 base::Unretained(this), closure))); | 45 base::Unretained(this), closure))); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void OnGlobalMemoryDumpResponse(base::Closure closure, | 48 void OnGlobalMemoryDumpResponse(base::Closure closure, |
| 49 uint64_t dump_guid, | 49 uint64_t dump_guid, |
| 50 bool success) { | 50 bool success, |
| 51 mojom::GlobalMemoryDumpPtr) { |
| 51 dump_response_args_ = {dump_guid, success}; | 52 dump_response_args_ = {dump_guid, success}; |
| 52 closure.Run(); | 53 closure.Run(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 protected: | 56 protected: |
| 56 struct DumpResponseArgs { | 57 struct DumpResponseArgs { |
| 57 uint64_t dump_guid; | 58 uint64_t dump_guid; |
| 58 bool success; | 59 bool success; |
| 59 }; | 60 }; |
| 60 | 61 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 test_coordinator->RegisterProcessLocalDumpManager( | 76 test_coordinator->RegisterProcessLocalDumpManager( |
| 76 std::move(process_manager)); | 77 std::move(process_manager)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 ~MockDumpManager() override { EXPECT_EQ(0, expected_calls_); } | 80 ~MockDumpManager() override { EXPECT_EQ(0, expected_calls_); } |
| 80 | 81 |
| 81 void RequestProcessMemoryDump( | 82 void RequestProcessMemoryDump( |
| 82 const base::trace_event::MemoryDumpRequestArgs& args, | 83 const base::trace_event::MemoryDumpRequestArgs& args, |
| 83 const RequestProcessMemoryDumpCallback& callback) override { | 84 const RequestProcessMemoryDumpCallback& callback) override { |
| 84 expected_calls_--; | 85 expected_calls_--; |
| 85 base::trace_event::MemoryDumpCallbackResult result; | 86 callback.Run(args.dump_guid, true, mojom::ProcessMemoryDumpPtr()); |
| 86 callback.Run(args.dump_guid, true, result); | |
| 87 } | 87 } |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; | 90 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; |
| 91 int expected_calls_; | 91 int expected_calls_; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 TEST_F(CoordinatorImplTest, NoProcessLocalManagers) { | 94 TEST_F(CoordinatorImplTest, NoProcessLocalManagers) { |
| 95 base::RunLoop run_loop; | 95 base::RunLoop run_loop; |
| 96 base::trace_event::MemoryDumpRequestArgs args = { | 96 base::trace_event::MemoryDumpRequestArgs args = { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 base::ThreadTaskRunnerHandle::Get()->PostTask( | 134 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 135 FROM_HERE, base::Bind([](std::unique_ptr<MockDumpManager> dm) {}, | 135 FROM_HERE, base::Bind([](std::unique_ptr<MockDumpManager> dm) {}, |
| 136 base::Passed(&dump_manager_2))); | 136 base::Passed(&dump_manager_2))); |
| 137 | 137 |
| 138 run_loop.Run(); | 138 run_loop.Run(); |
| 139 | 139 |
| 140 EXPECT_EQ(3456U, dump_response_args_.dump_guid); | 140 EXPECT_EQ(3456U, dump_response_args_.dump_guid); |
| 141 EXPECT_FALSE(dump_response_args_.success); | 141 EXPECT_FALSE(dump_response_args_.success); |
| 142 } | 142 } |
| 143 } // namespace memory_instrumentation | 143 } // namespace memory_instrumentation |
| OLD | NEW |