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

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorWebPerfAgentTest.cpp

Issue 2296923004: Track frame context URL using first script heuristic (Closed)
Patch Set: Created 4 years, 4 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/inspector/InspectorWebPerfAgentTest.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorWebPerfAgentTest.cpp b/third_party/WebKit/Source/core/inspector/InspectorWebPerfAgentTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6082d5c2fb1bff7b46d0a4ee8fe4a7245a331e41
--- /dev/null
+++ b/third_party/WebKit/Source/core/inspector/InspectorWebPerfAgentTest.cpp
@@ -0,0 +1,89 @@
+// 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/inspector/InspectorWebPerfAgent.h"
+
+#include "core/inspector/InspectedFrames.h"
+#include "core/testing/DummyPageHolder.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/PtrUtil.h"
+
+#include <memory>
+
+namespace blink {
+
+class InspectorWebPerfAgentTest : public ::testing::Test {
+protected:
+ void SetUp() override;
+ LocalFrame* frame() const { return m_pageHolder->document().frame(); }
+ ExecutionContext* executionContext() const { return &m_pageHolder->document(); }
+
+ std::string frameContextURL();
+ bool firstScriptSeen();
+
+ Persistent<InspectorWebPerfAgent> m_agent;
+ std::unique_ptr<DummyPageHolder> m_pageHolder;
+};
+
+void InspectorWebPerfAgentTest::SetUp()
+{
+ m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
+ m_pageHolder->document().setURL(KURL(KURL(), "https://example.com/foo"));
+ m_agent = new InspectorWebPerfAgent(InspectedFrames::create(frame()));
+}
+
+std::string InspectorWebPerfAgentTest::frameContextURL()
+{
+ return m_agent->m_frameContextURL;
+}
+
+bool InspectorWebPerfAgentTest::firstScriptSeen()
+{
+ return m_agent->m_firstScriptSeen;
+}
+
+TEST_F(InspectorWebPerfAgentTest, SingleScriptInTask)
+{
+ m_agent->willProcessTask();
+ EXPECT_FALSE(firstScriptSeen());
+ m_agent->willExecuteScript(executionContext());
+ EXPECT_TRUE(firstScriptSeen());
+ m_agent->didExecuteScript();
+ m_agent->didProcessTask();
+ m_agent->ReportTaskTime(3719349.445172, 3719349.5561923); // Long task
+ EXPECT_EQ("https://example.com/foo", frameContextURL());
+}
+
+TEST_F(InspectorWebPerfAgentTest, MultipleScriptsInTask)
+{
+ m_agent->willProcessTask();
+ EXPECT_FALSE(firstScriptSeen());
+ m_agent->willExecuteScript(executionContext());
+ EXPECT_TRUE(firstScriptSeen());
+ m_agent->didExecuteScript();
+ EXPECT_EQ("https://example.com/foo", frameContextURL());
+
+ m_agent->willExecuteScript(executionContext());
+ EXPECT_TRUE(firstScriptSeen());
+ m_agent->didExecuteScript();
+ m_agent->didProcessTask();
+ m_agent->ReportTaskTime(3719349.445172, 3719349.5561923); // Long task
+ EXPECT_EQ("https://example.com/foo", frameContextURL());
+}
+
+TEST_F(InspectorWebPerfAgentTest, NoScriptInLongTask)
+{
+ m_agent->willProcessTask();
+ m_agent->willExecuteScript(executionContext());
+ m_agent->didExecuteScript();
+ m_agent->didProcessTask();
+ m_agent->ReportTaskTime(3719349.445172, 3719349.445182);
+ m_agent->willProcessTask();
+ m_agent->didProcessTask();
+ m_agent->ReportTaskTime(3719349.445172, 3719349.5561923); // Long task
+ // Without presence of Script, FrameContext URL is not available
+ EXPECT_EQ("", frameContextURL());
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698