From 03c549e0392f92c02536d3f86d5e1d8dfa3435ac Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 1 Sep 2021 11:08:40 +0200 Subject: BASELINE: Update Chromium to 91.0.4472.160 Change-Id: I0def1f08a2412aeed79a9ab95dd50eb5c3f65f31 Reviewed-by: Allan Sandfeld Jensen --- .../page/scrolling/text_fragment_anchor_test.cc | 314 +++++++++++++++++++-- 1 file changed, 283 insertions(+), 31 deletions(-) (limited to 'chromium/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_test.cc') diff --git a/chromium/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_test.cc b/chromium/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_test.cc index a21b452b331..b3ddbadfcfb 100644 --- a/chromium/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_test.cc +++ b/chromium/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_test.cc @@ -2,11 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/test/scoped_feature_list.h" #include "build/build_config.h" +#include "components/shared_highlighting/core/common/shared_highlighting_features.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/public/common/input/web_menu_source_type.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" +#include "third_party/blink/renderer/bindings/core/v8/v8_mouse_event_init.h" #include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/editing/ephemeral_range.h" +#include "third_party/blink/renderer/core/editing/frame_selection.h" #include "third_party/blink/renderer/core/editing/markers/document_marker_controller.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_frame.h" @@ -15,8 +20,11 @@ #include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" #include "third_party/blink/renderer/core/html/html_element.h" #include "third_party/blink/renderer/core/html/html_frame_owner_element.h" +#include "third_party/blink/renderer/core/input/context_menu_allowed_scope.h" #include "third_party/blink/renderer/core/input/event_handler.h" #include "third_party/blink/renderer/core/layout/layout_object.h" +#include "third_party/blink/renderer/core/loader/document_loader.h" +#include "third_party/blink/renderer/core/page/context_menu_controller.h" #include "third_party/blink/renderer/core/page/scrolling/text_fragment_finder.h" #include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h" #include "third_party/blink/renderer/core/scroll/scrollable_area.h" @@ -922,37 +930,12 @@ TEST_P(TextFragmentAnchorScrollTest, ScrollCancelled) { GetDocument().View()->UpdateAllLifecyclePhasesForTest(); mojom::blink::ScrollType scroll_type = GetParam(); - if (!RuntimeEnabledFeatures::BlockHTMLParserOnStyleSheetsEnabled()) { - GetDocument().View()->LayoutViewport()->ScrollBy(ScrollOffset(0, 100), - scroll_type); - // Set the target text to visible and change its position to cause a layout - // and invoke the fragment anchor in the next begin frame. - css_request.Complete("p { visibility: visible; top: 1001px; }"); - img_request.Complete(""); - } else { - // Set the target text to visible and change its position to cause a layout - // and invoke the fragment anchor in the next begin frame. - css_request.Complete("p { visibility: visible; top: 1001px; }"); - RunPendingTasks(); - Compositor().BeginFrame(); - Element& p = *GetDocument().getElementById("text"); - - // We should have invoked the fragment and scrolled the

into view, but - // load should not yet be complete due to the image. - EXPECT_TRUE(ViewportRect().Contains(BoundingRectInFrame(p))); - ASSERT_FALSE(GetDocument().IsLoadCompleted()); - - // Before invoking again, perform a user scroll. This should abort future - // scrolls during fragment invocation. - GetDocument().View()->LayoutViewport()->SetScrollOffset(ScrollOffset(0, 0), - scroll_type); - ASSERT_FALSE(ViewportRect().Contains(BoundingRectInFrame(p))); - - img_request.Complete(""); - RunPendingTasks(); - ASSERT_TRUE(GetDocument().IsLoadCompleted()); - } - + GetDocument().View()->LayoutViewport()->ScrollBy(ScrollOffset(0, 100), + scroll_type); + // Set the target text to visible and change its position to cause a layout + // and invoke the fragment anchor in the next begin frame. + css_request.Complete("p { visibility: visible; top: 1001px; }"); + img_request.Complete(""); RunAsyncMatchingTasks(); // Render two frames to handle the async step added by the beforematch event. @@ -983,6 +966,9 @@ TEST_P(TextFragmentAnchorScrollTest, ScrollCancelled) { // Test that user scrolling dismisses the highlight. TEST_P(TextFragmentAnchorScrollTest, DismissTextHighlightOnUserScroll) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndDisableFeature( + shared_highlighting::kSharedHighlightingV2); SimRequest request( "https://example.com/" "test.html#:~:text=test%20page&text=more%20text", @@ -1030,6 +1016,54 @@ TEST_P(TextFragmentAnchorScrollTest, DismissTextHighlightOnUserScroll) { } } +// Test that user scrolling doesn't dismiss the highlight, when the +// SharedHighlightingV2 flag is enabled. +TEST_P(TextFragmentAnchorScrollTest, DontDismissTextHighlightOnUserScroll) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndEnableFeature( + shared_highlighting::kSharedHighlightingV2); + SimRequest request( + "https://example.com/" + "test.html#:~:text=test%20page&text=more%20text", + "text/html"); + LoadURL( + "https://example.com/" + "test.html#:~:text=test%20page&text=more%20text"); + request.Complete(R"HTML( + + +

This is a test page

+

With some more text

+ )HTML"); + RunAsyncMatchingTasks(); + + // Render two frames to handle the async step added by the beforematch event. + Compositor().BeginFrame(); + Compositor().BeginFrame(); + + ASSERT_EQ(2u, GetDocument().Markers().Markers().size()); + + mojom::blink::ScrollType scroll_type = GetParam(); + LayoutViewport()->ScrollBy(ScrollOffset(0, -10), scroll_type); + + Compositor().BeginFrame(); + + EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); + EXPECT_TRUE(GetDocument().View()->GetFragmentAnchor()); +} + // Ensure that the text fragment anchor has no effect in an iframe. This is // disabled in iframes by design, for security reasons. TEST_F(TextFragmentAnchorTest, DisabledInIframes) { @@ -1482,6 +1516,9 @@ TEST_F(TextFragmentAnchorTest, CheckForWordBoundaryWithPartialWord) { // Test dismissing the text highlight with a click TEST_F(TextFragmentAnchorTest, DismissTextHighlightWithClick) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndDisableFeature( + shared_highlighting::kSharedHighlightingV2); SimRequest request( "https://example.com/" "test.html#:~:text=test%20page&text=more%20text", @@ -1513,6 +1550,15 @@ TEST_F(TextFragmentAnchorTest, DismissTextHighlightWithClick) { Compositor().BeginFrame(); Compositor().BeginFrame(); + KURL url = GetDocument() + .GetFrame() + ->Loader() + .GetDocumentLoader() + ->GetHistoryItem() + ->Url(); + EXPECT_EQ( + "https://example.com/test.html#:~:text=test%20page&text=more%20text", + url.GetString()); EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); SimulateClick(100, 100); @@ -1521,10 +1567,67 @@ TEST_F(TextFragmentAnchorTest, DismissTextHighlightWithClick) { // Ensure the fragment is uninstalled EXPECT_FALSE(GetDocument().View()->GetFragmentAnchor()); + url = GetDocument() + .GetFrame() + ->Loader() + .GetDocumentLoader() + ->GetHistoryItem() + ->Url(); + EXPECT_EQ("https://example.com/test.html", url.GetString()); +} + +// Test not dismissing the text highlight with a click, if the +// SharedHighlightingV2 flag is enabled. +TEST_F(TextFragmentAnchorTest, DontDismissTextHighlightWithClick) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndEnableFeature( + shared_highlighting::kSharedHighlightingV2); + SimRequest request( + "https://example.com/" + "test.html#:~:text=test%20page&text=more%20text", + "text/html"); + LoadURL( + "https://example.com/" + "test.html#:~:text=test%20page&text=more%20text"); + request.Complete(R"HTML( + + +

This is a test page

+

With some more text

+ )HTML"); + RunAsyncMatchingTasks(); + + // Render two frames to handle the async step added by the beforematch event. + Compositor().BeginFrame(); + Compositor().BeginFrame(); + + EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); + + SimulateClick(100, 100); + + EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); + + // Ensure the fragment is still installed + EXPECT_TRUE(GetDocument().View()->GetFragmentAnchor()); } // Test dismissing the text highlight with a tap TEST_F(TextFragmentAnchorTest, DismissTextHighlightWithTap) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndDisableFeature( + shared_highlighting::kSharedHighlightingV2); SimRequest request( "https://example.com/" "test.html#:~:text=test%20page&text=more%20text", @@ -1556,6 +1659,15 @@ TEST_F(TextFragmentAnchorTest, DismissTextHighlightWithTap) { Compositor().BeginFrame(); Compositor().BeginFrame(); + KURL url = GetDocument() + .GetFrame() + ->Loader() + .GetDocumentLoader() + ->GetHistoryItem() + ->Url(); + EXPECT_EQ( + "https://example.com/test.html#:~:text=test%20page&text=more%20text", + url.GetString()); EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); SimulateTap(100, 100); @@ -1564,10 +1676,67 @@ TEST_F(TextFragmentAnchorTest, DismissTextHighlightWithTap) { // Ensure the fragment is uninstalled EXPECT_FALSE(GetDocument().View()->GetFragmentAnchor()); + url = GetDocument() + .GetFrame() + ->Loader() + .GetDocumentLoader() + ->GetHistoryItem() + ->Url(); + EXPECT_EQ("https://example.com/test.html", url.GetString()); +} + +// Test not dismissing the text highlight with a tap, if the +// SharedHighlightingV2 flag is enabled. +TEST_F(TextFragmentAnchorTest, DontDismissTextHighlightWithTap) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndEnableFeature( + shared_highlighting::kSharedHighlightingV2); + SimRequest request( + "https://example.com/" + "test.html#:~:text=test%20page&text=more%20text", + "text/html"); + LoadURL( + "https://example.com/" + "test.html#:~:text=test%20page&text=more%20text"); + request.Complete(R"HTML( + + +

This is a test page

+

With some more text

+ )HTML"); + RunAsyncMatchingTasks(); + + // Render two frames to handle the async step added by the beforematch event. + Compositor().BeginFrame(); + Compositor().BeginFrame(); + + EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); + + SimulateTap(100, 100); + + EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); + + // Ensure the fragment is installed + EXPECT_TRUE(GetDocument().View()->GetFragmentAnchor()); } // Test that we don't dismiss a text highlight before it's scrolled into view TEST_F(TextFragmentAnchorTest, DismissTextHighlightOutOfView) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndDisableFeature( + shared_highlighting::kSharedHighlightingV2); SimRequest request("https://example.com/test.html#:~:text=test", "text/html"); SimSubresourceRequest css_request("https://example.com/test.css", "text/css"); LoadURL("https://example.com/test.html#:~:text=test"); @@ -1609,6 +1778,9 @@ TEST_F(TextFragmentAnchorTest, DismissTextHighlightOutOfView) { // Test dismissing a text highlight that didn't require a scroll into view TEST_F(TextFragmentAnchorTest, DismissTextHighlightInView) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndDisableFeature( + shared_highlighting::kSharedHighlightingV2); SimRequest request( "https://example.com/" "test.html#:~:text=test%20page&text=more%20text", @@ -2127,6 +2299,86 @@ TEST_F(TextFragmentAnchorTest, IsInSameUninterruptedBlock_BlockInterruption) { EXPECT_FALSE(TextFragmentFinder::IsInSameUninterruptedBlock(start, end)); } +TEST_F(TextFragmentAnchorTest, OpenedFromHighlightDoesNotSelectAdditionalText) { + base::test::ScopedFeatureList feature_list_; + feature_list_.InitAndEnableFeature( + shared_highlighting::kSharedHighlightingV2); + SimRequest request("https://www.test.com/#:~:text=First%20test,page%20three", + "text/html"); + LoadURL("https://www.test.com/#:~:text=First%20test,page%20three"); + request.Complete(R"HTML( + + +

First test page one

+

Second test page two

+

Third test page three

+

Fourth test page four

+ )HTML"); + RunAsyncMatchingTasks(); + + // Render two frames to handle the async step added by the beforematch event. + Compositor().BeginFrame(); + Compositor().BeginFrame(); + + Element* middle_element = GetDocument().getElementById("two"); + Element* last_element = GetDocument().getElementById("four"); + + WebView().GetSettings()->SetEditingBehavior( + mojom::EditingBehavior::kEditingMacBehavior); + + // Create a mouse event in the middle of

two. + WebMouseEvent mouse_down_event(WebInputEvent::Type::kMouseDown, + WebInputEvent::kNoModifiers, + WebInputEvent::GetStaticTimeStampForTests()); + const DOMRect* middle_rect = middle_element->getBoundingClientRect(); + gfx::PointF middle_elem_point(((middle_rect->left() + 1)), + ((middle_rect->top() + 1))); + mouse_down_event.SetPositionInWidget(middle_elem_point.x(), + middle_elem_point.y()); + mouse_down_event.SetPositionInScreen(middle_elem_point.x(), + middle_elem_point.y()); + mouse_down_event.click_count = 1; + mouse_down_event.button = WebMouseEvent::Button::kRight; + + // Corresponding release event (Windows shows context menu on release). + WebMouseEvent mouse_up_event(mouse_down_event); + mouse_up_event.SetType(WebInputEvent::Type::kMouseUp); + + WebView().MainFrameViewWidget()->HandleInputEvent( + WebCoalescedInputEvent(mouse_down_event, ui::LatencyInfo())); + WebView().MainFrameViewWidget()->HandleInputEvent( + WebCoalescedInputEvent(mouse_up_event, ui::LatencyInfo())); + + // No additional text should be selected. + FrameSelection& selection = GetDocument().GetFrame()->Selection(); + EXPECT_TRUE(selection.SelectedText().IsEmpty()); + + // Create a mouse event at the center of

four. + const DOMRect* last_rect = last_element->getBoundingClientRect(); + gfx::PointF last_elem_point(((last_rect->left() + 1)), + ((last_rect->top() + 1))); + mouse_down_event.SetPositionInWidget(last_elem_point.x(), + last_elem_point.y()); + mouse_down_event.SetPositionInScreen(last_elem_point.x(), + last_elem_point.y()); + + // Corresponding release event (Windows shows context menu on release). + WebMouseEvent last_mouse_up_event(mouse_down_event); + last_mouse_up_event.SetType(WebInputEvent::Type::kMouseUp); + + WebView().MainFrameViewWidget()->HandleInputEvent( + WebCoalescedInputEvent(mouse_down_event, ui::LatencyInfo())); + WebView().MainFrameViewWidget()->HandleInputEvent( + WebCoalescedInputEvent(last_mouse_up_event, ui::LatencyInfo())); + + // The text underneath the cursor should be selected. + EXPECT_FALSE(selection.SelectedText().IsEmpty()); +} + } // namespace } // namespace blink -- cgit v1.2.1