Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Unified Diff: test/cctest/libplatform/test-tracing.cc

Issue 2369073003: [tracing] Implement Add/RemoveTraceStateObserver for default platform. (Closed)
Patch Set: addressing comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/libplatform/tracing/tracing-controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/libplatform/test-tracing.cc
diff --git a/test/cctest/libplatform/test-tracing.cc b/test/cctest/libplatform/test-tracing.cc
index 2e15d6af9e0e356f256b00eb0784fb248db196d3..2e707faf2c2d598a5ff72c789c4aa34f2b62039c 100644
--- a/test/cctest/libplatform/test-tracing.cc
+++ b/test/cctest/libplatform/test-tracing.cc
@@ -307,6 +307,66 @@ TEST(TestTracingControllerMultipleArgsAndCopy) {
i::V8::SetPlatformForTesting(old_platform);
}
+namespace {
+
+class TraceStateObserverImpl : public Platform::TraceStateObserver {
+ public:
+ void OnTraceEnabled() override { ++enabled_count; }
+ void OnTraceDisabled() override { ++disabled_count; }
+
+ int enabled_count = 0;
+ int disabled_count = 0;
+};
+
+} // namespace
+
+TEST(TracingObservers) {
+ v8::Platform* old_platform = i::V8::GetCurrentPlatform();
+ v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
+ i::V8::SetPlatformForTesting(default_platform);
+
+ v8::platform::tracing::TracingController tracing_controller;
+ v8::platform::SetTracingController(default_platform, &tracing_controller);
+ MockTraceWriter* writer = new MockTraceWriter();
+ v8::platform::tracing::TraceBuffer* ring_buffer =
+ v8::platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer(1,
+ writer);
+ tracing_controller.Initialize(ring_buffer);
+ v8::platform::tracing::TraceConfig* trace_config =
+ new v8::platform::tracing::TraceConfig();
+ trace_config->AddIncludedCategory("v8");
+
+ TraceStateObserverImpl observer;
+ default_platform->AddTraceStateObserver(&observer);
+
+ CHECK_EQ(0, observer.enabled_count);
+ CHECK_EQ(0, observer.disabled_count);
+
+ tracing_controller.StartTracing(trace_config);
+
+ CHECK_EQ(1, observer.enabled_count);
+ CHECK_EQ(0, observer.disabled_count);
+
+ tracing_controller.StopTracing();
+
+ CHECK_EQ(1, observer.enabled_count);
+ CHECK_EQ(1, observer.disabled_count);
+
+ default_platform->RemoveTraceStateObserver(&observer);
+
+ CHECK_EQ(1, observer.enabled_count);
+ CHECK_EQ(1, observer.disabled_count);
+
+ trace_config = new v8::platform::tracing::TraceConfig();
+ tracing_controller.StartTracing(trace_config);
+ tracing_controller.StopTracing();
+
+ CHECK_EQ(1, observer.enabled_count);
+ CHECK_EQ(1, observer.disabled_count);
+
+ i::V8::SetPlatformForTesting(old_platform);
+}
+
} // namespace tracing
} // namespace platform
} // namespace v8
« no previous file with comments | « src/libplatform/tracing/tracing-controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698