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

Unified Diff: gin/v8_platform_unittest.cc

Issue 2650943008: [gin] Fire observer after added when recording is in progress. (Closed)
Patch Set: update Created 3 years, 11 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 | « gin/v8_platform.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/v8_platform_unittest.cc
diff --git a/gin/v8_platform_unittest.cc b/gin/v8_platform_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..52d5862400336572f306de10b4531acfb04606ad
--- /dev/null
+++ b/gin/v8_platform_unittest.cc
@@ -0,0 +1,62 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gin/public/v8_platform.h"
+
+#include "base/trace_event/trace_event.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class TestTraceStateObserver
+ : public NON_EXPORTED_BASE(v8::Platform::TraceStateObserver) {
+ public:
+ void OnTraceEnabled() final { ++enabled_; }
+ void OnTraceDisabled() final { ++disabled_; }
+ int Enabled() { return enabled_; }
+ int Disabled() { return disabled_; }
+
+ private:
+ int enabled_ = 0;
+ int disabled_ = 0;
+};
+
+namespace gin {
+
+TEST(V8PlatformTest, TraceStateObserverAPI) {
+ TestTraceStateObserver* test_observer = new TestTraceStateObserver();
+ ASSERT_EQ(0, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+
+ V8Platform::Get()->AddTraceStateObserver(test_observer);
+ base::trace_event::TraceLog::GetInstance()->SetEnabled(
+ base::trace_event::TraceConfig("*", ""),
+ base::trace_event::TraceLog::RECORDING_MODE);
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+ base::trace_event::TraceLog::GetInstance()->SetDisabled();
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(1, test_observer->Disabled());
+
+ V8Platform::Get()->RemoveTraceStateObserver(test_observer);
+ base::trace_event::TraceLog::GetInstance()->SetEnabled(
+ base::trace_event::TraceConfig("*", ""),
+ base::trace_event::TraceLog::RECORDING_MODE);
+ base::trace_event::TraceLog::GetInstance()->SetDisabled();
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(1, test_observer->Disabled());
+}
+
+TEST(V8PlatformTest, TraceStateObserverFired) {
+ TestTraceStateObserver* test_observer = new TestTraceStateObserver();
+ ASSERT_EQ(0, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+
+ base::trace_event::TraceLog::GetInstance()->SetEnabled(
+ base::trace_event::TraceConfig("*", ""),
+ base::trace_event::TraceLog::RECORDING_MODE);
+ V8Platform::Get()->AddTraceStateObserver(test_observer);
+ ASSERT_EQ(1, test_observer->Enabled());
+ ASSERT_EQ(0, test_observer->Disabled());
+}
+
+} // namespace gin
« no previous file with comments | « gin/v8_platform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698