#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/timing/window_performance.h"
#include <cstdint>
#include "base/numerics/safe_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/test/trace_event_analyzer.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/viz/common/frame_timing_details.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/responsiveness_metrics/user_interaction_latency.h"
#include "third_party/blink/public/mojom/page/page_visibility_state.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_keyboard_event_init.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_pointer_event_init.h"
#include "third_party/blink/renderer/core/dom/document_init.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/events/input_event.h"
#include "third_party/blink/renderer/core/events/keyboard_event.h"
#include "third_party/blink/renderer/core/events/pointer_event.h"
#include "third_party/blink/renderer/core/execution_context/security_context_init.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/performance_monitor.h"
#include "third_party/blink/renderer/core/loader/document_load_timing.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/performance_entry_names.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/testing/mock_policy_container_host.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
#include "third_party/blink/renderer/core/timing/performance_event_timing.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/testing/scoped_fake_ukm_recorder.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/wtf_size_t.h"
namespace blink {
RunPendingTasks;
namespace {
base::TimeTicks GetTimeOrigin() { … }
base::TimeTicks GetTimeStamp(int64_t time) { … }
}
class WindowPerformanceTest : public testing::Test,
public ::testing::WithParamInterface<bool> { … };
TEST_P(WindowPerformanceTest, SanitizedLongTaskName) { … }
TEST_P(WindowPerformanceTest, SanitizedLongTaskName_CrossOrigin) { … }
TEST_P(WindowPerformanceTest, NavigateAway) { … }
TEST(PerformanceLifetimeTest, SurviveContextSwitch) { … }
TEST_P(WindowPerformanceTest, EnsureEntryListOrder) { … }
TEST_P(WindowPerformanceTest, EventTimingEntryBuffering) { … }
TEST_P(WindowPerformanceTest, Expose100MsEvents) { … }
TEST_P(WindowPerformanceTest, EventTimingDuration) { … }
TEST_P(WindowPerformanceTest, MultipleEventsThenPresent) { … }
TEST_P(WindowPerformanceTest,
CommitFinishTimeRecordedOnAllPendingEventTimings) { … }
TEST_P(WindowPerformanceTest, NewCommitNotOverwritePreviousEventTimings) { … }
TEST_P(WindowPerformanceTest, FirstInput) { … }
TEST_P(WindowPerformanceTest, FirstInputAfterIgnored) { … }
TEST_P(WindowPerformanceTest, FirstPointerUp) { … }
TEST_P(WindowPerformanceTest, PointerdownOptimizedOut) { … }
TEST_P(WindowPerformanceTest, PointerdownOnDesktop) { … }
TEST_P(WindowPerformanceTest, OneKeyboardInteraction) { … }
TEST_P(WindowPerformanceTest, HoldingDownAKey) { … }
TEST_P(WindowPerformanceTest, PressMultipleKeys) { … }
TEST_P(WindowPerformanceTest, KeyupFinishLastButCallbackInvokedFirst) { … }
TEST_P(WindowPerformanceTest, TapOrClick) { … }
TEST_P(WindowPerformanceTest, PageVisibilityChanged) { … }
TEST_P(WindowPerformanceTest, Drag) { … }
TEST_P(WindowPerformanceTest, Scroll) { … }
TEST_P(WindowPerformanceTest, TouchesWithoutClick) { … }
#if BUILDFLAG(IS_MAC)
TEST_P(WindowPerformanceTest, ArtificialPointerupOrClick) {
PointerId pointer_id = 4;
base::TimeTicks pointerdown_timestamp = GetTimeOrigin();
base::TimeTicks processing_start_pointerdown = GetTimeStamp(1);
base::TimeTicks processing_end_pointerdown = GetTimeStamp(2);
base::TimeTicks presentation_time_pointerdown = GetTimeStamp(3);
RegisterPointerEvent(event_type_names::kPointerdown, pointerdown_timestamp,
processing_start_pointerdown, processing_end_pointerdown,
pointer_id);
SimulatePaintAndResolvePresentationPromise(presentation_time_pointerdown);
base::TimeTicks pointerup_timestamp = pointerdown_timestamp;
base::TimeTicks processing_start_pointerup = GetTimeStamp(5);
base::TimeTicks processing_end_pointerup = GetTimeStamp(6);
base::TimeTicks presentation_time_pointerup = GetTimeStamp(10);
RegisterPointerEvent(event_type_names::kPointerup, pointerup_timestamp,
processing_start_pointerup, processing_end_pointerup,
pointer_id);
SimulatePaintAndResolvePresentationPromise(presentation_time_pointerup);
base::TimeTicks click_timestamp = pointerup_timestamp;
base::TimeTicks processing_start_click = GetTimeStamp(11);
base::TimeTicks processing_end_click = GetTimeStamp(12);
base::TimeTicks presentation_time_click = GetTimeStamp(20);
RegisterPointerEvent(event_type_names::kClick, click_timestamp,
processing_start_click, processing_end_click,
pointer_id);
SimulatePaintAndResolvePresentationPromise(presentation_time_click);
RunPendingTasks();
auto entries = GetUkmRecorder()->GetEntriesByName(
ukm::builders::Responsiveness_UserInteraction::kEntryName);
EXPECT_EQ(1u, entries.size());
const ukm::mojom::UkmEntry* ukm_entry = entries[0];
GetUkmRecorder()->ExpectEntryMetric(
ukm_entry,
ukm::builders::Responsiveness_UserInteraction::kMaxEventDurationName, 12);
GetUkmRecorder()->ExpectEntryMetric(
ukm_entry,
ukm::builders::Responsiveness_UserInteraction::kTotalEventDurationName,
12);
GetUkmRecorder()->ExpectEntryMetric(
ukm_entry,
ukm::builders::Responsiveness_UserInteraction::kInteractionTypeName, 1);
GetHistogramTester().ExpectTotalCount(
"Blink.Responsiveness.UserInteraction.MaxEventDuration.AllTypes", 1);
GetHistogramTester().ExpectTotalCount(
"Blink.Responsiveness.UserInteraction.MaxEventDuration.Keyboard", 0);
GetHistogramTester().ExpectTotalCount(
"Blink.Responsiveness.UserInteraction.MaxEventDuration.TapOrClick", 1);
GetHistogramTester().ExpectTotalCount(
"Blink.Responsiveness.UserInteraction.MaxEventDuration.Drag", 0);
}
#endif
TEST_P(WindowPerformanceTest, PerformanceMarkTraceEvent) { … }
TEST_P(WindowPerformanceTest, ElementTimingTraceEvent) { … }
TEST_P(WindowPerformanceTest, EventTimingTraceEvents) { … }
TEST_P(WindowPerformanceTest, SlowInteractionToNextPaintTraceEvents) { … }
TEST_P(WindowPerformanceTest, InteractionID) { … }
INSTANTIATE_TEST_SUITE_P(…);
class InteractionIdTest : public WindowPerformanceTest { … };
TEST_P(InteractionIdTest, InputOutsideComposition) { … }
TEST_P(InteractionIdTest, CompositionSingleKeydown) { … }
TEST_P(InteractionIdTest, CompositionToFinalInput) { … }
TEST_P(InteractionIdTest, CompositionToFinalInputMultipleKeyUps) { … }
TEST_P(InteractionIdTest, SmartSuggestion) { … }
TEST_P(InteractionIdTest, TapWithoutClick) { … }
TEST_P(InteractionIdTest, PointerupClick) { … }
TEST_P(InteractionIdTest, JustClick) { … }
TEST_P(InteractionIdTest, PointerdownClick) { … }
TEST_P(InteractionIdTest, MultiTouch) { … }
TEST_P(InteractionIdTest, ClickIncorrectPointerId) { … }
INSTANTIATE_TEST_SUITE_P(…);
}