| Index: base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
|
| diff --git a/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc b/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
|
| index 6349ec0c007e7b5317bcbe6417d8e62a3b5f0426..05c60c722c317cca7bf6e52453a5faba1d7b1903 100644
|
| --- a/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
|
| +++ b/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
|
| @@ -7,6 +7,7 @@
|
| #include <iterator>
|
|
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/pending_task.h"
|
| #include "base/trace_event/heap_profiler_allocation_context.h"
|
| #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
|
| #include "base/trace_event/trace_event.h"
|
| @@ -251,5 +252,31 @@ TEST_F(AllocationContextTrackerTest, SetCurrentThreadName) {
|
| ASSERT_EQ(kCupcake, ctx2.backtrace.frames[1]);
|
| }
|
|
|
| +TEST_F(AllocationContextTrackerTest, TrackTaskContext) {
|
| + const char kContext1[] = "context1";
|
| + const char kContext2[] = "context2";
|
| + {
|
| + // The context from the scoped task event should be used as type name.
|
| + TRACE_EVENT_API_SCOPED_TASK_EXECUTION_EVENT event1(kContext1);
|
| + AllocationContext ctx1 =
|
| + AllocationContextTracker::GetInstanceForCurrentThread()
|
| + ->GetContextSnapshot();
|
| + ASSERT_EQ(kContext1, ctx1.type_name);
|
| +
|
| + // In case of nested events, the last event's context should be used.
|
| + TRACE_EVENT_API_SCOPED_TASK_EXECUTION_EVENT event2(kContext2);
|
| + AllocationContext ctx2 =
|
| + AllocationContextTracker::GetInstanceForCurrentThread()
|
| + ->GetContextSnapshot();
|
| + ASSERT_EQ(kContext2, ctx2.type_name);
|
| + }
|
| +
|
| + // Type should be nullptr without task event.
|
| + AllocationContext ctx =
|
| + AllocationContextTracker::GetInstanceForCurrentThread()
|
| + ->GetContextSnapshot();
|
| + ASSERT_FALSE(ctx.type_name);
|
| +}
|
| +
|
| } // namespace trace_event
|
| } // namespace base
|
|
|