Chromium Code Reviews| Index: components/tracing/child_trace_message_filter_browsertest.cc |
| diff --git a/components/tracing/child_trace_message_filter_browsertest.cc b/components/tracing/child_trace_message_filter_browsertest.cc |
| index a87e976cf235d641898f84513d6989c5c0e17453..914a48d36c9749c966a1a33c4c257a9c905881fc 100644 |
| --- a/components/tracing/child_trace_message_filter_browsertest.cc |
| +++ b/components/tracing/child_trace_message_filter_browsertest.cc |
| @@ -33,7 +33,7 @@ class MockDumpProvider : public base::trace_event::MemoryDumpProvider { |
| base::trace_event::ProcessMemoryDump* pmd)); |
| }; |
| -class ChildTracingTest : public content::RenderViewTest { |
| +class ChildTracingTest : public content::RenderViewTest, public IPC::Listener { |
| public: |
| // Used as callback argument for MemoryDumpManager::RequestGlobalDump(): |
| void OnMemoryDumpCallback(uint64 dump_guid, bool status) { |
| @@ -59,18 +59,24 @@ class ChildTracingTest : public content::RenderViewTest { |
| callback_call_count_ = 0; |
| last_callback_dump_guid_ = 0; |
| last_callback_status_ = false; |
| + wait_for_ipc_message_type_ = 0; |
| callback_ = base::Bind(&ChildTracingTest::OnMemoryDumpCallback, |
| base::Unretained(this)); |
| task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| ctmf_ = make_scoped_refptr(new ChildTraceMessageFilter(task_runner_.get())); |
| render_thread_->AddFilter(ctmf_.get()); |
| + // Add a filter to the TestSink which allows to WaitForIPCMessage() by |
| + // posting a nested RunLoop closure when a given IPC Message is seen. |
| + render_thread_->sink().AddFilter(this); |
| + |
| // Getting an instance of |ChildMemoryDumpManagerDelegateImpl| calls |
| // |MemoryDumpManager::Initialize| with the correct delegate. |
| ChildMemoryDumpManagerDelegateImpl::GetInstance(); |
| } |
| void TearDown() override { |
| + render_thread_->sink().RemoveFilter(this); |
| RenderViewTest::TearDown(); |
| MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| mock_dump_provider_.get()); |
| @@ -79,6 +85,26 @@ class ChildTracingTest : public content::RenderViewTest { |
| task_runner_ = nullptr; |
| } |
| + // IPC::Filter implementation. |
| + bool OnMessageReceived(const IPC::Message& message) override { |
| + if (message.type() == wait_for_ipc_message_type_ && |
|
petrcermak
2015/11/02 10:35:20
It might be a good idea to add something along the
Primiano Tucci (use gerrit)
2015/11/02 15:07:07
make sense. there is no point not seeing the closu
|
| + !wait_for_ipc_closure_.is_null()) { |
| + task_runner_->PostTask(FROM_HERE, wait_for_ipc_closure_); |
| + wait_for_ipc_closure_.Reset(); |
| + } |
| + return false; |
| + } |
| + |
| + const IPC::Message* WaitForIPCMessage(uint32_t message_type) { |
| + base::RunLoop run_loop; |
| + wait_for_ipc_message_type_ = message_type; |
| + wait_for_ipc_closure_ = run_loop.QuitClosure(); |
| + run_loop.Run(); |
| + wait_for_ipc_message_type_ = 0; |
| + wait_for_ipc_closure_.Reset(); |
| + return render_thread_->sink().GetUniqueMessageMatching(message_type); |
| + } |
| + |
| // Simulates a synthetic browser -> child (this process) IPC message. |
| void SimulateSyntheticMessageFromBrowser(const IPC::Message& msg) { |
| task_runner_->PostTask( |
| @@ -107,8 +133,8 @@ class ChildTracingTest : public content::RenderViewTest { |
| {dump_guid, MemoryDumpType::EXPLICITLY_TRIGGERED})); |
| // Check that a child -> browser response to the local dump request is sent. |
| - const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| - TracingHostMsg_ProcessMemoryDumpResponse::ID); |
| + const IPC::Message* msg = |
| + WaitForIPCMessage(TracingHostMsg_ProcessMemoryDumpResponse::ID); |
| EXPECT_NE(nullptr, msg); |
| // Check that the |dump_guid| and the |sucess| fields are properly set. |
| @@ -138,6 +164,8 @@ class ChildTracingTest : public content::RenderViewTest { |
| scoped_ptr<MockDumpProvider> mock_dump_provider_; |
| scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| base::trace_event::MemoryDumpCallback callback_; |
| + uint32_t wait_for_ipc_message_type_; |
| + base::Closure wait_for_ipc_closure_; |
| uint32 callback_call_count_; |
| uint64 last_callback_dump_guid_; |
| bool last_callback_status_; |