Chromium Code Reviews| 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..ff5fd7c4d11053dd51b4d6ab15f561692d6ee2f6 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorWebPerfAgentTest.cpp |
| @@ -0,0 +1,121 @@ |
| +// 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/frame/Location.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(); } |
| + ExecutionContext* anotherExecutionContext() const { return &m_anotherPageHolder->document(); } |
| + |
| + String frameContextURL(); |
| + int numUniqueFrameContextsSeen(); |
| + |
| + Persistent<InspectorWebPerfAgent> m_agent; |
| + std::unique_ptr<DummyPageHolder> m_pageHolder; |
| + std::unique_ptr<DummyPageHolder> m_anotherPageHolder; |
| +}; |
| + |
| +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())); |
| + |
| + // Create another dummy page holder and pretend this is the iframe. |
| + m_anotherPageHolder = DummyPageHolder::create(IntSize(400, 300)); |
| + m_anotherPageHolder->document().setURL(KURL(KURL(), "https://iframed.com/bar")); |
| +} |
| + |
| +String InspectorWebPerfAgentTest::frameContextURL() |
| +{ |
| + // This is reported only if there is a single frameContext URL. |
| + if (m_agent->m_frameContextLocations.size() != 1) |
| + return ""; |
| + Location* location = (*m_agent->m_frameContextLocations.begin()).get(); |
|
panicker
2016/09/16 01:22:52
this is the only line that changed in rollforward.
|
| + return String(location->protocol()) + "//" |
| + + location->hostname() + location->pathname(); |
| +} |
| + |
| +int InspectorWebPerfAgentTest::numUniqueFrameContextsSeen() |
| +{ |
| + return m_agent->m_frameContextLocations.size(); |
| +} |
| + |
| +TEST_F(InspectorWebPerfAgentTest, SingleScriptInTask) |
| +{ |
| + m_agent->willProcessTask(); |
| + EXPECT_EQ(0, numUniqueFrameContextsSeen()); |
| + m_agent->willExecuteScript(executionContext()); |
| + EXPECT_EQ(1, numUniqueFrameContextsSeen()); |
| + m_agent->didExecuteScript(); |
| + m_agent->didProcessTask(); |
| + m_agent->ReportTaskTime(3719349.445172, 3719349.5561923); // Long task |
| + EXPECT_EQ(1, numUniqueFrameContextsSeen()); |
| + EXPECT_EQ("https://example.com/foo", frameContextURL()); |
| +} |
| + |
| +TEST_F(InspectorWebPerfAgentTest, MultipleScriptsInTask_SingleContext) |
| +{ |
| + m_agent->willProcessTask(); |
| + EXPECT_EQ(0, numUniqueFrameContextsSeen()); |
| + m_agent->willExecuteScript(executionContext()); |
| + EXPECT_EQ(1, numUniqueFrameContextsSeen()); |
| + m_agent->didExecuteScript(); |
| + EXPECT_EQ("https://example.com/foo", frameContextURL()); |
| + |
| + m_agent->willExecuteScript(executionContext()); |
| + EXPECT_EQ(1, numUniqueFrameContextsSeen()); |
| + m_agent->didExecuteScript(); |
| + m_agent->didProcessTask(); |
| + m_agent->ReportTaskTime(3719349.445172, 3719349.5561923); // Long task |
| + EXPECT_EQ(1, numUniqueFrameContextsSeen()); |
| + EXPECT_EQ("https://example.com/foo", frameContextURL()); |
| +} |
| + |
| +TEST_F(InspectorWebPerfAgentTest, MultipleScriptsInTask_MultipleContexts) |
| +{ |
| + m_agent->willProcessTask(); |
| + EXPECT_EQ(0, numUniqueFrameContextsSeen()); |
| + m_agent->willExecuteScript(executionContext()); |
| + EXPECT_EQ(1, numUniqueFrameContextsSeen()); |
| + m_agent->didExecuteScript(); |
| + EXPECT_EQ("https://example.com/foo", frameContextURL()); |
| + |
| + m_agent->willExecuteScript(anotherExecutionContext()); |
| + EXPECT_EQ(2, numUniqueFrameContextsSeen()); |
| + m_agent->didExecuteScript(); |
| + m_agent->didProcessTask(); |
| + m_agent->ReportTaskTime(3719349.445172, 3719349.5561923); // Long task |
| + EXPECT_EQ(2, numUniqueFrameContextsSeen()); |
| + EXPECT_EQ("", 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(0, numUniqueFrameContextsSeen()); |
| +} |
| + |
| +} // namespace blink |