| Index: base/trace_event/blame_context_unittest.cc
|
| diff --git a/base/trace_event/blame_context_unittest.cc b/base/trace_event/blame_context_unittest.cc
|
| index 3ecf3e3fbd20a7af65bf49ff2b69fbaa79b99f45..d1da9138c8dea99616dcd5295d9032204f86f584 100644
|
| --- a/base/trace_event/blame_context_unittest.cc
|
| +++ b/base/trace_event/blame_context_unittest.cc
|
| @@ -41,6 +41,8 @@ class TestBlameContext : public BlameContext {
|
| id,
|
| &parent) {}
|
|
|
| + ~TestBlameContext() override { UnregisterFromTraceLog(); }
|
| +
|
| protected:
|
| void AsValueInto(trace_event::TracedValue* state) override {
|
| BlameContext::AsValueInto(state);
|
| @@ -57,6 +59,8 @@ class DisabledTestBlameContext : public BlameContext {
|
| kTestBlameContextScope,
|
| id,
|
| nullptr) {}
|
| +
|
| + ~DisabledTestBlameContext() override { UnregisterFromTraceLog(); }
|
| };
|
|
|
| void OnTraceDataCollected(Closure quit_closure,
|
| @@ -73,6 +77,8 @@ class BlameContextTest : public testing::Test {
|
| void StartTracing();
|
| void StopTracing();
|
| std::unique_ptr<trace_analyzer::TraceAnalyzer> CreateTraceAnalyzer();
|
| + protected:
|
| + MessageLoop loop_;
|
| };
|
|
|
| void BlameContextTest::StartTracing() {
|
| @@ -215,6 +221,52 @@ TEST_F(BlameContextTest, TakeSnapshot) {
|
| EXPECT_EQ(kExpectedSnapshotJson, snapshot_json);
|
| }
|
|
|
| +class TestBlameContextWithSleep : public BlameContext {
|
| + public:
|
| + TestBlameContextWithSleep()
|
| + : BlameContext(kTestBlameContextCategory,
|
| + kTestBlameContextName,
|
| + kTestBlameContextType,
|
| + kTestBlameContextScope,
|
| + 0,
|
| + nullptr),
|
| + callback_running_(false) {}
|
| +
|
| + ~TestBlameContextWithSleep() override {
|
| + UnregisterFromTraceLog();
|
| + CHECK(!callback_running_);
|
| + }
|
| +
|
| + void OnTraceLogEnabled() override {
|
| + callback_running_ = true;
|
| +
|
| + // Sleep for longer time than the Sleep() in RaceWithDTOR.
|
| + PlatformThread::Sleep(TimeDelta::FromMilliseconds(200));
|
| +
|
| + // Now the instance is already deleted, so it would crash inside.
|
| + BlameContext::OnTraceLogEnabled();
|
| + callback_running_ = false;
|
| + }
|
| +
|
| + private:
|
| + bool callback_running_;
|
| +};
|
| +
|
| +TEST_F(BlameContextTest, RaceWithDTOR) {
|
| + Thread thread("test thread");
|
| + CHECK(thread.Start());
|
| + CHECK(thread.message_loop());
|
| +
|
| + std::unique_ptr<TestBlameContextWithSleep> derived;
|
| + derived.reset(new TestBlameContextWithSleep());
|
| + derived->Initialize();
|
| + thread.task_runner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&BlameContextTest::StartTracing, base::Unretained(this)));
|
| + PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
|
| + derived.reset();
|
| +}
|
| +
|
| } // namepace
|
| } // namespace trace_event
|
| } // namespace base
|
|
|