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

Unified Diff: third_party/WebKit/Source/core/timing/PerformanceTest.cpp

Issue 2343553005: enable / disable Long Task instrumentation based on presence of LongTask observer (Closed)
Patch Set: 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
Index: third_party/WebKit/Source/core/timing/PerformanceTest.cpp
diff --git a/third_party/WebKit/Source/core/timing/PerformanceTest.cpp b/third_party/WebKit/Source/core/timing/PerformanceTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..983360ef1ed2c22faf0a99e238f9fca801460b8e
--- /dev/null
+++ b/third_party/WebKit/Source/core/timing/PerformanceTest.cpp
@@ -0,0 +1,62 @@
+// Copyright 2016 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 "core/timing/Performance.h"
+
+#include "core/testing/DummyPageHolder.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class PerformanceTest : public ::testing::Test {
+protected:
+ void SetUp() override
+ {
+ m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
+ m_pageHolder->document().setURL(KURL(KURL(), "https://example.com"));
+ m_performance = Performance::create(&m_pageHolder->frame());
+ }
+
+ bool hasLongTaskInspectorAgent()
+ {
+ return m_performance->m_longTaskInspectorAgent;
+ }
+
+ void addLongTaskObserver()
+ {
+ // simulate with filter options.
+ m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask;
+ }
+
+ void removeLongTaskObserver()
+ {
+ // simulate with filter options.
+ m_performance->m_observerFilterOptions = PerformanceEntry::Invalid;
+ }
+
+ Persistent<Performance> m_performance;
+ std::unique_ptr<DummyPageHolder> m_pageHolder;
+};
+
+TEST_F(PerformanceTest, LongTaskObserverInstrumentation)
+{
+ m_performance->enableLongTaskInstrumentation();
+ EXPECT_FALSE(hasLongTaskInspectorAgent());
+
+ // Adding LongTask observer (with filer option) enables instrumentation.
+ addLongTaskObserver();
+ m_performance->enableLongTaskInstrumentation();
+ EXPECT_TRUE(hasLongTaskInspectorAgent());
+
+ // While LongTask observer is present, disableLongTaskInstrumentation has no effect.
+ m_performance->disableLongTaskInstrumentation();
+ EXPECT_TRUE(hasLongTaskInspectorAgent());
+
+ // Removing LongTask observer disables instrumentation.
+ removeLongTaskObserver();
+ m_performance->disableLongTaskInstrumentation();
+ EXPECT_FALSE(hasLongTaskInspectorAgent());
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698