summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/exported/web_view_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/exported/web_view_test.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/exported/web_view_test.cc408
1 files changed, 349 insertions, 59 deletions
diff --git a/chromium/third_party/blink/renderer/core/exported/web_view_test.cc b/chromium/third_party/blink/renderer/core/exported/web_view_test.cc
index 4aa77f1c7b7..c92036ebe57 100644
--- a/chromium/third_party/blink/renderer/core/exported/web_view_test.cc
+++ b/chromium/third_party/blink/renderer/core/exported/web_view_test.cc
@@ -35,6 +35,7 @@
#include <string>
#include "build/build_config.h"
+#include "cc/trees/layer_tree_host.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
@@ -61,11 +62,11 @@
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/web/web_frame.h"
-#include "third_party/blink/public/web/web_frame_client.h"
#include "third_party/blink/public/web/web_frame_content_dumper.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_hit_test_result.h"
#include "third_party/blink/public/web/web_input_method_controller.h"
+#include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/public/web/web_print_params.h"
#include "third_party/blink/public/web/web_script_source.h"
#include "third_party/blink/public/web/web_settings.h"
@@ -104,10 +105,12 @@
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/page.h"
+#include "third_party/blink/renderer/core/page/page_visibility_state.h"
#include "third_party/blink/renderer/core/page/print_context.h"
#include "third_party/blink/renderer/core/page/scoped_page_pauser.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_painter.h"
+#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
#include "third_party/blink/renderer/core/timing/window_performance.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h"
@@ -118,6 +121,7 @@
#include "third_party/blink/renderer/platform/graphics/paint/paint_record_builder.h"
#include "third_party/blink/renderer/platform/keyboard_codes.h"
#include "third_party/blink/renderer/platform/scroll/scroll_types.h"
+#include "third_party/blink/renderer/platform/testing/histogram_tester.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/wtf/scoped_mock_clock.h"
@@ -254,7 +258,11 @@ class WebViewTest : public testing::Test {
protected:
void SetViewportSize(const WebSize& size) {
- web_view_helper_.SetViewportSize(size);
+ content::LayerTreeView* layer_tree_view =
+ web_view_helper_.GetLayerTreeView();
+ layer_tree_view->SetViewportSizeAndScale(
+ static_cast<gfx::Size>(size), /*device_scale_factor=*/1.f,
+ layer_tree_view->layer_tree_host()->local_surface_id_from_parent());
}
std::string RegisterMockedHttpURLLoad(const std::string& file_name) {
@@ -465,8 +473,9 @@ TEST_F(WebViewTest, SetBaseBackgroundColorBeforeMainFrame) {
// Note: this test doesn't use WebViewHelper since it intentionally runs
// initialization code between WebView and WebLocalFrame creation.
FrameTestHelpers::TestWebViewClient web_view_client;
- WebViewImpl* web_view = static_cast<WebViewImpl*>(WebView::Create(
- &web_view_client, mojom::PageVisibilityState::kVisible, nullptr));
+ WebViewImpl* web_view = static_cast<WebViewImpl*>(
+ WebView::Create(&web_view_client, &web_view_client,
+ mojom::PageVisibilityState::kVisible, nullptr));
EXPECT_NE(SK_ColorBLUE, web_view->BackgroundColor());
// webView does not have a frame yet, but we should still be able to set the
// background color.
@@ -2265,18 +2274,15 @@ TEST_F(WebViewTest, BackForwardRestoreScroll) {
main_frame_local->Loader().GetDocumentLoader()->GetHistoryItem();
// Go back, then forward, then back again.
- main_frame_local->Loader().CommitNavigation(
- FrameLoadRequest(nullptr, item1->GenerateResourceRequest(
- mojom::FetchCacheMode::kDefault)),
- kFrameLoadTypeBackForward, item1.Get(), kHistorySameDocumentLoad);
- main_frame_local->Loader().CommitNavigation(
- FrameLoadRequest(nullptr, item2->GenerateResourceRequest(
- mojom::FetchCacheMode::kDefault)),
- kFrameLoadTypeBackForward, item2.Get(), kHistorySameDocumentLoad);
- main_frame_local->Loader().CommitNavigation(
- FrameLoadRequest(nullptr, item1->GenerateResourceRequest(
- mojom::FetchCacheMode::kDefault)),
- kFrameLoadTypeBackForward, item1.Get(), kHistorySameDocumentLoad);
+ main_frame_local->Loader().CommitSameDocumentNavigation(
+ item1->Url(), WebFrameLoadType::kBackForward, item1.Get(),
+ ClientRedirectPolicy::kNotClientRedirect, nullptr, false);
+ main_frame_local->Loader().CommitSameDocumentNavigation(
+ item2->Url(), WebFrameLoadType::kBackForward, item2.Get(),
+ ClientRedirectPolicy::kNotClientRedirect, nullptr, false);
+ main_frame_local->Loader().CommitSameDocumentNavigation(
+ item1->Url(), WebFrameLoadType::kBackForward, item1.Get(),
+ ClientRedirectPolicy::kNotClientRedirect, nullptr, false);
// Click a different anchor
main_frame_local->Loader().StartNavigation(FrameLoadRequest(
@@ -2287,14 +2293,12 @@ TEST_F(WebViewTest, BackForwardRestoreScroll) {
// Go back, then forward. The scroll position should be properly set on the
// forward navigation.
- main_frame_local->Loader().CommitNavigation(
- FrameLoadRequest(nullptr, item1->GenerateResourceRequest(
- mojom::FetchCacheMode::kDefault)),
- kFrameLoadTypeBackForward, item1.Get(), kHistorySameDocumentLoad);
- main_frame_local->Loader().CommitNavigation(
- FrameLoadRequest(nullptr, item3->GenerateResourceRequest(
- mojom::FetchCacheMode::kDefault)),
- kFrameLoadTypeBackForward, item3.Get(), kHistorySameDocumentLoad);
+ main_frame_local->Loader().CommitSameDocumentNavigation(
+ item1->Url(), WebFrameLoadType::kBackForward, item1.Get(),
+ ClientRedirectPolicy::kNotClientRedirect, nullptr, false);
+ main_frame_local->Loader().CommitSameDocumentNavigation(
+ item3->Url(), WebFrameLoadType::kBackForward, item3.Get(),
+ ClientRedirectPolicy::kNotClientRedirect, nullptr, false);
EXPECT_EQ(0, web_view_impl->MainFrameImpl()->GetScrollOffset().width);
EXPECT_GT(web_view_impl->MainFrameImpl()->GetScrollOffset().height, 2000);
}
@@ -2325,6 +2329,7 @@ TEST_F(WebViewTest, FullscreenResetScrollAndScaleFullscreenStyles) {
ASSERT_EQ(0, web_view_impl->MainFrameImpl()->GetScrollOffset().height);
ASSERT_EQ(0, web_view_impl->MainFrameImpl()
->GetFrameView()
+ ->LayoutViewport()
->MaximumScrollOffset()
.Height());
@@ -2365,6 +2370,7 @@ TEST_F(WebViewTest, FullscreenResetScrollAndScaleExitAndReenter) {
ASSERT_EQ(0, web_view_impl->MainFrameImpl()->GetScrollOffset().height);
ASSERT_EQ(0, web_view_impl->MainFrameImpl()
->GetFrameView()
+ ->LayoutViewport()
->MaximumScrollOffset()
.Height());
@@ -2380,6 +2386,7 @@ TEST_F(WebViewTest, FullscreenResetScrollAndScaleExitAndReenter) {
ASSERT_EQ(0, web_view_impl->MainFrameImpl()->GetScrollOffset().height);
ASSERT_EQ(0, web_view_impl->MainFrameImpl()
->GetFrameView()
+ ->LayoutViewport()
->MaximumScrollOffset()
.Height());
@@ -2477,7 +2484,7 @@ static void DragAndDropURL(WebViewImpl* web_view, const std::string& url) {
widget->DragTargetDragEnter(drag_data, client_point, screen_point,
kWebDragOperationCopy, 0);
widget->DragTargetDrop(drag_data, client_point, screen_point, 0);
- FrameTestHelpers::PumpPendingRequestsForFrameToLoad(web_view->MainFrame());
+ FrameTestHelpers::PumpPendingRequestsForFrameToLoad();
}
TEST_F(WebViewTest, DragDropURL) {
@@ -2524,8 +2531,7 @@ bool WebViewTest::TapElement(WebInputEvent::Type type, Element* element) {
web_view_helper_.GetWebView()
->MainFrameImpl()
->GetFrameView()
- ->ContentsToScreen(
- element->GetLayoutObject()->AbsoluteBoundingBoxRect())
+ ->FrameToScreen(element->GetLayoutObject()->AbsoluteBoundingBoxRect())
.Center());
WebGestureEvent event(type, WebInputEvent::kNoModifiers,
@@ -2585,8 +2591,8 @@ TEST_F(WebViewTest, ClientTapHandling) {
TEST_F(WebViewTest, ClientTapHandlingNullWebViewClient) {
// Note: this test doesn't use WebViewHelper since WebViewHelper creates an
// internal WebViewClient on demand if the supplied WebViewClient is null.
- WebViewImpl* web_view = static_cast<WebViewImpl*>(
- WebView::Create(nullptr, mojom::PageVisibilityState::kVisible, nullptr));
+ WebViewImpl* web_view = static_cast<WebViewImpl*>(WebView::Create(
+ nullptr, nullptr, mojom::PageVisibilityState::kVisible, nullptr));
FrameTestHelpers::TestWebFrameClient web_frame_client;
FrameTestHelpers::TestWebWidgetClient web_widget_client;
WebLocalFrame* local_frame = WebLocalFrame::CreateMainFrame(
@@ -3381,7 +3387,7 @@ TEST_F(WebViewTest, FinishComposingTextDoesntTriggerAutofillTextChange) {
EXPECT_EQ(0, info.composition_start);
EXPECT_EQ((int)composition_text.length(), info.composition_end);
- form->SetAutofilled(true);
+ form->SetAutofillState(blink::WebAutofillState::kAutofilled);
client.ClearChangeCounts();
active_input_method_controller->FinishComposingText(
@@ -4743,7 +4749,7 @@ TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll) {
// Initial transform takes current page scale and scroll position into
// account.
web_view_impl->SetPageScaleFactor(1.5f);
- frame_view->LayoutViewportScrollableArea()->SetScrollOffset(
+ frame_view->LayoutViewport()->SetScrollOffset(
ScrollOffset(100, 150), kProgrammaticScroll, kScrollBehaviorInstant);
dev_tools_emulator->ForceViewport(WebFloatPoint(50, 55), 2.f);
expected_matrix.MakeIdentity()
@@ -4758,7 +4764,7 @@ TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll) {
*dev_tools_emulator->VisibleContentRectForPainting());
// Transform adapts to scroll changes.
- frame_view->LayoutViewportScrollableArea()->SetScrollOffset(
+ frame_view->LayoutViewport()->SetScrollOffset(
ScrollOffset(50, 55), kProgrammaticScroll, kScrollBehaviorInstant);
expected_matrix.MakeIdentity()
.Scale(2.f)
@@ -4920,8 +4926,7 @@ TEST_F(WebViewTest, DeviceEmulationResetScrollbars) {
WebLocalFrameImpl* frame = web_view->MainFrameImpl();
auto* frame_view = frame->GetFrameView();
EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars());
- EXPECT_NE(nullptr,
- frame_view->LayoutViewportScrollableArea()->VerticalScrollbar());
+ EXPECT_NE(nullptr, frame_view->LayoutViewport()->VerticalScrollbar());
WebDeviceEmulationParams params;
params.screen_position = WebDeviceEmulationParams::kMobile;
@@ -4932,21 +4937,20 @@ TEST_F(WebViewTest, DeviceEmulationResetScrollbars) {
// The visual viewport should now proivde the scrollbars instead of the view.
EXPECT_TRUE(frame_view->VisualViewportSuppliesScrollbars());
- EXPECT_EQ(nullptr, frame_view->VerticalScrollbar());
+ EXPECT_EQ(nullptr, frame_view->LayoutViewport()->VerticalScrollbar());
web_view->DisableDeviceEmulation();
// The view should once again provide the scrollbars.
EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars());
- EXPECT_NE(nullptr,
- frame_view->LayoutViewportScrollableArea()->VerticalScrollbar());
+ EXPECT_NE(nullptr, frame_view->LayoutViewport()->VerticalScrollbar());
}
TEST_F(WebViewTest, SetZoomLevelWhilePluginFocused) {
class PluginCreatingWebFrameClient
: public FrameTestHelpers::TestWebFrameClient {
public:
- // WebFrameClient overrides:
+ // WebLocalFrameClient overrides:
WebPlugin* CreatePlugin(const WebPluginParams& params) override {
return new FakeWebPlugin(params);
}
@@ -4997,7 +5001,7 @@ TEST_F(WebViewTest, DetachPluginInLayout) {
class PluginCreatingWebFrameClient
: public FrameTestHelpers::TestWebFrameClient {
public:
- // WebFrameClient overrides:
+ // WebLocalFrameClient overrides:
WebPlugin* CreatePlugin(const WebPluginParams& params) override {
return new ScriptInDestroyPlugin(Frame(), params);
}
@@ -5093,6 +5097,245 @@ TEST_F(WebViewTest, FirstInputDelayReported) {
.InMillisecondsF());
}
+// Check that longest input delay is correctly reported to the document.
+TEST_F(WebViewTest, LongestInputDelayReported) {
+ WebViewImpl* web_view = web_view_helper_.Initialize();
+ WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
+ FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
+ "<html><body></body></html>", base_url);
+
+ LocalFrame* main_frame = web_view->MainFrameImpl()->GetFrame();
+ ASSERT_NE(nullptr, main_frame);
+
+ Document* document = main_frame->GetDocument();
+ ASSERT_NE(nullptr, document);
+
+ WTF::ScopedMockClock clock;
+ clock.Advance(TimeDelta::FromMilliseconds(70));
+
+ InteractiveDetector* interactive_detector(
+ InteractiveDetector::From(*document));
+ ASSERT_NE(nullptr, interactive_detector);
+
+ EXPECT_TRUE(interactive_detector->GetLongestInputDelay().is_zero());
+
+ WebKeyboardEvent key_event1(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event1.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event1.windows_key_code = VKEY_SPACE;
+ key_event1.SetTimeStamp(CurrentTimeTicks());
+ clock.Advance(TimeDelta::FromMilliseconds(50));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event1));
+
+ TimeTicks longest_input_timestamp = CurrentTimeTicks();
+
+ WebKeyboardEvent key_event2(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event2.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event2.windows_key_code = VKEY_SPACE;
+ key_event2.SetTimeStamp(longest_input_timestamp);
+ clock.Advance(TimeDelta::FromMilliseconds(100));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event2));
+
+ WebKeyboardEvent key_event3(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event3.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event3.windows_key_code = VKEY_SPACE;
+ key_event3.SetTimeStamp(CurrentTimeTicks());
+ clock.Advance(TimeDelta::FromMilliseconds(70));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event3));
+
+ EXPECT_NEAR(100,
+ interactive_detector->GetLongestInputDelay().InMillisecondsF(),
+ 0.01);
+ EXPECT_EQ(longest_input_timestamp,
+ interactive_detector->GetLongestInputTimestamp());
+}
+
+TEST_F(WebViewTest, InputDelayReported) {
+ WTF::ScopedMockClock clock;
+ clock.Advance(TimeDelta::FromMilliseconds(50));
+
+ WebViewImpl* web_view = web_view_helper_.Initialize();
+
+ WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
+ FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
+ "<html><body></body></html>", base_url);
+
+ clock.Advance(TimeDelta::FromMilliseconds(70));
+
+ HistogramTester histogram_tester;
+ WebKeyboardEvent key_event1(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event1.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event1.windows_key_code = VKEY_SPACE;
+ key_event1.SetTimeStamp(CurrentTimeTicks());
+ clock.Advance(TimeDelta::FromMilliseconds(50));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event1));
+
+ WebKeyboardEvent key_event2(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event2.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event2.windows_key_code = VKEY_SPACE;
+ key_event2.SetTimeStamp(CurrentTimeTicks());
+ clock.Advance(TimeDelta::FromMilliseconds(50));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event2));
+
+ WebKeyboardEvent key_event3(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event3.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event3.windows_key_code = VKEY_SPACE;
+ key_event3.SetTimeStamp(CurrentTimeTicks());
+ clock.Advance(TimeDelta::FromMilliseconds(70));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event3));
+
+ histogram_tester.ExpectTotalCount("PageLoad.InteractiveTiming.InputDelay", 3);
+ histogram_tester.ExpectBucketCount("PageLoad.InteractiveTiming.InputDelay", 50, 2);
+ histogram_tester.ExpectBucketCount("PageLoad.InteractiveTiming.InputDelay", 70, 1);
+
+ histogram_tester.ExpectTotalCount("PageLoad.InteractiveTiming.InputTimestamp", 3);
+ histogram_tester.ExpectBucketCount("PageLoad.InteractiveTiming.InputTimestamp", 70, 1);
+ histogram_tester.ExpectBucketCount("PageLoad.InteractiveTiming.InputTimestamp", 120, 1);
+ histogram_tester.ExpectBucketCount("PageLoad.InteractiveTiming.InputTimestamp", 170, 1);
+}
+
+// Tests that if the page was backgrounded while an input event was queued,
+// we do not count its delay to calculate longest input delay.
+TEST_F(WebViewTest, LongestInputDelayPageBackgroundedDuringQueuing) {
+ WebViewImpl* web_view = web_view_helper_.Initialize();
+ WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
+ FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
+ "<html><body></body></html>", base_url);
+
+ LocalFrame* main_frame = web_view->MainFrameImpl()->GetFrame();
+ ASSERT_NE(nullptr, main_frame);
+
+ Document* document = main_frame->GetDocument();
+ ASSERT_NE(nullptr, document);
+
+ WTF::ScopedMockClock clock;
+ clock.Advance(TimeDelta::FromMilliseconds(70));
+
+ InteractiveDetector* interactive_detector(
+ InteractiveDetector::From(*document));
+ ASSERT_NE(nullptr, interactive_detector);
+
+ EXPECT_TRUE(interactive_detector->GetLongestInputDelay().is_zero());
+
+ WebKeyboardEvent key_event1(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event1.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event1.windows_key_code = VKEY_SPACE;
+ TimeTicks key_event1_time = CurrentTimeTicks();
+ key_event1.SetTimeStamp(key_event1_time);
+ clock.Advance(TimeDelta::FromMilliseconds(50));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event1));
+
+ WebKeyboardEvent key_event2(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event2.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event2.windows_key_code = VKEY_SPACE;
+ key_event2.SetTimeStamp(CurrentTimeTicks());
+ clock.Advance(TimeDelta::FromMilliseconds(100));
+ web_view->SetVisibilityState(mojom::PageVisibilityState::kHidden, false);
+ clock.Advance(TimeDelta::FromMilliseconds(100));
+ web_view->SetVisibilityState(mojom::PageVisibilityState::kVisible, false);
+ clock.Advance(TimeDelta::FromMilliseconds(100));
+ // Total input delay is >300ms.
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event2));
+
+ EXPECT_NEAR(
+ 50, interactive_detector->GetLongestInputDelay().InMillisecondsF(), 0.01);
+ EXPECT_EQ(key_event1_time, interactive_detector->GetLongestInputTimestamp());
+}
+
+// Tests that if the page was backgrounded at navigation start and an input
+// event was queued before it was foregrounded, we do not count its delay to
+// calculate longest input delay.
+TEST_F(WebViewTest, LongestInputDelayPageBackgroundedAtNavStart) {
+ WebViewImpl* web_view = web_view_helper_.Initialize();
+ web_view->SetVisibilityState(mojom::PageVisibilityState::kHidden, false);
+ WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
+ FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
+ "<html><body></body></html>", base_url);
+
+ LocalFrame* main_frame = web_view->MainFrameImpl()->GetFrame();
+ ASSERT_NE(nullptr, main_frame);
+
+ Document* document = main_frame->GetDocument();
+ ASSERT_NE(nullptr, document);
+
+ WTF::ScopedMockClock clock;
+ clock.Advance(TimeDelta::FromMilliseconds(70));
+
+ InteractiveDetector* interactive_detector(
+ InteractiveDetector::From(*document));
+ ASSERT_NE(nullptr, interactive_detector);
+
+ WebKeyboardEvent key_event(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event.windows_key_code = VKEY_SPACE;
+ key_event.SetTimeStamp(CurrentTimeTicks());
+ clock.Advance(TimeDelta::FromMilliseconds(100));
+ web_view->SetVisibilityState(mojom::PageVisibilityState::kVisible, false);
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event));
+
+ EXPECT_TRUE(interactive_detector->GetLongestInputDelay().is_zero());
+}
+
+// Tests page backgrounding outside of input queuing time does not affect
+// longest input delay.
+TEST_F(WebViewTest, LongestInputDelayPageBackgroundedNotDuringQueuing) {
+ WebViewImpl* web_view = web_view_helper_.Initialize();
+ WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
+ FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
+ "<html><body></body></html>", base_url);
+
+ LocalFrame* main_frame = web_view->MainFrameImpl()->GetFrame();
+ ASSERT_NE(nullptr, main_frame);
+
+ Document* document = main_frame->GetDocument();
+ ASSERT_NE(nullptr, document);
+
+ WTF::ScopedMockClock clock;
+ clock.Advance(TimeDelta::FromMilliseconds(70));
+
+ InteractiveDetector* interactive_detector(
+ InteractiveDetector::From(*document));
+ ASSERT_NE(nullptr, interactive_detector);
+
+ EXPECT_TRUE(interactive_detector->GetLongestInputDelay().is_zero());
+
+ web_view->SetVisibilityState(mojom::PageVisibilityState::kHidden, false);
+ clock.Advance(TimeDelta::FromMilliseconds(100));
+ web_view->SetVisibilityState(mojom::PageVisibilityState::kVisible, false);
+ clock.Advance(TimeDelta::FromMilliseconds(1));
+
+ WebKeyboardEvent key_event(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event.windows_key_code = VKEY_SPACE;
+ TimeTicks key_event_time = CurrentTimeTicks();
+ key_event.SetTimeStamp(key_event_time);
+ clock.Advance(TimeDelta::FromMilliseconds(50));
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event));
+
+ EXPECT_NEAR(
+ 50, interactive_detector->GetLongestInputDelay().InMillisecondsF(), 0.01);
+ EXPECT_EQ(key_event_time, interactive_detector->GetLongestInputTimestamp());
+}
+
// Check that first input delay is correctly reported to the document when the
// first input is a pointer down event, and we receive a pointer up event.
TEST_F(WebViewTest, PointerDownUpFirstInputDelay) {
@@ -5185,31 +5428,34 @@ TEST_F(WebViewTest, PointerDownCancelFirstInputDelay) {
EXPECT_TRUE(interactive_detector->GetFirstInputTimestamp().is_null());
}
-// Check that the input delay is correctly reported to the document.
-TEST_F(WebViewTest, FirstInputDelayExcludesProcessingTime) {
- // We need a way for JS to advance the mock clock. Hook into console.log, so
- // that logging advances the clock by 6 seconds.
- class MockClockAdvancingWebFrameClient
- : public FrameTestHelpers::TestWebFrameClient {
- public:
- MockClockAdvancingWebFrameClient(WTF::ScopedMockClock* mock_clock)
- : mock_clock_(mock_clock) {}
- // WebFrameClient overrides:
- void DidAddMessageToConsole(const WebConsoleMessage& message,
- const WebString& source_name,
- unsigned source_line,
- const WebString& stack_trace) override {
- mock_clock_->Advance(TimeDelta::FromMilliseconds(6000));
- }
+// We need a way for JS to advance the mock clock. Hook into console.log, so
+// that logging advances the clock by |event_handling_delay| seconds.
+class MockClockAdvancingWebFrameClient
+ : public FrameTestHelpers::TestWebFrameClient {
+ public:
+ MockClockAdvancingWebFrameClient(WTF::ScopedMockClock* mock_clock,
+ TimeDelta event_handling_delay)
+ : mock_clock_(mock_clock), event_handling_delay_(event_handling_delay) {}
+ // WebLocalFrameClient overrides:
+ void DidAddMessageToConsole(const WebConsoleMessage& message,
+ const WebString& source_name,
+ unsigned source_line,
+ const WebString& stack_trace) override {
+ mock_clock_->Advance(event_handling_delay_);
+ }
- private:
- WTF::ScopedMockClock* mock_clock_;
- };
+ private:
+ WTF::ScopedMockClock* mock_clock_;
+ TimeDelta event_handling_delay_;
+};
+// Check that the input delay is correctly reported to the document.
+TEST_F(WebViewTest, FirstInputDelayExcludesProcessingTime) {
WTF::ScopedMockClock clock;
// Page load timing logic depends on the time not being zero.
clock.Advance(TimeDelta::FromMilliseconds(1));
- MockClockAdvancingWebFrameClient frame_client(&clock);
+ MockClockAdvancingWebFrameClient frame_client(
+ &clock, TimeDelta::FromMilliseconds(6000));
WebViewImpl* web_view = web_view_helper_.Initialize(&frame_client);
WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
@@ -5248,4 +5494,48 @@ TEST_F(WebViewTest, FirstInputDelayExcludesProcessingTime) {
web_view_helper_.Reset(); // Remove dependency on locally scoped client.
}
+// Check that the longest input delay is correctly reported to the document.
+TEST_F(WebViewTest, LongestInputDelayExcludesProcessingTime) {
+ WTF::ScopedMockClock clock;
+ // Page load timing logic depends on the time not being zero.
+ clock.Advance(TimeDelta::FromMilliseconds(1));
+ MockClockAdvancingWebFrameClient frame_client(
+ &clock, TimeDelta::FromMilliseconds(6000));
+ WebViewImpl* web_view = web_view_helper_.Initialize(&frame_client);
+ WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
+ FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
+ "<html><body></body></html>", base_url);
+
+ LocalFrame* main_frame = web_view->MainFrameImpl()->GetFrame();
+ ASSERT_NE(nullptr, main_frame);
+
+ Document* document = main_frame->GetDocument();
+ ASSERT_NE(nullptr, document);
+
+ WebLocalFrame* frame = web_view_helper_.LocalMainFrame();
+ // console.log will advance the mock clock.
+ frame->ExecuteScript(
+ WebScriptSource("document.addEventListener('keydown', "
+ "() => {console.log('advancing timer');})"));
+
+ InteractiveDetector* interactive_detector(
+ InteractiveDetector::From(*document));
+ ASSERT_NE(nullptr, interactive_detector);
+
+ WebKeyboardEvent key_event(WebInputEvent::kRawKeyDown,
+ WebInputEvent::kNoModifiers,
+ WebInputEvent::GetStaticTimeStampForTests());
+ key_event.dom_key = Platform::Current()->DomKeyEnumFromString(" ");
+ key_event.windows_key_code = VKEY_SPACE;
+ key_event.SetTimeStamp(CurrentTimeTicks());
+
+ clock.Advance(TimeDelta::FromMilliseconds(5000));
+
+ web_view->HandleInputEvent(WebCoalescedInputEvent(key_event));
+
+ TimeDelta longest_input_delay = interactive_detector->GetLongestInputDelay();
+ EXPECT_EQ(5000, longest_input_delay.InMillisecondsF());
+
+ web_view_helper_.Reset(); // Remove dependency on locally scoped client.
+}
} // namespace blink