chromium/third_party/blink/renderer/core/page/context_menu_controller_test.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/page/context_menu_controller.h"

#include <algorithm>
#include <limits>
#include <memory>
#include <optional>
#include <utility>

#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "services/network/public/mojom/attribution.mojom-blink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/context_menu_data/context_menu_data.h"
#include "third_party/blink/public/common/context_menu_data/edit_flags.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/input/web_keyboard_event.h"
#include "third_party/blink/public/common/input/web_menu_source_type.h"
#include "third_party/blink/public/mojom/context_menu/context_menu.mojom-blink.h"
#include "third_party/blink/public/web/web_plugin.h"
#include "third_party/blink/renderer/core/dom/events/native_event_listener.h"
#include "third_party/blink/renderer/core/dom/xml_document.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/editing/selection_template.h"
#include "third_party/blink/renderer/core/exported/web_plugin_container_impl.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_impl.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/geometry/dom_rect.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_anchor_element.h"
#include "third_party/blink/renderer/core/html/html_document.h"
#include "third_party/blink/renderer/core/html/html_embed_element.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/input/context_menu_allowed_scope.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/testing/fake_web_plugin.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h"
#include "third_party/blink/renderer/platform/testing/empty_web_media_player.h"
#include "third_party/blink/renderer/platform/testing/scoped_mocked_url.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/testing/url_loader_mock.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock_factory_impl.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "ui/gfx/geometry/rect.h"

Return;

namespace blink {

namespace {

constexpr char kTestResourceFilename[] =;
constexpr char kTestResourceMimeType[] =;

class MockWebMediaPlayerForContextMenu : public EmptyWebMediaPlayer {};

class ContextMenuControllerTestPlugin : public FakeWebPlugin {};

class TestWebFrameClientImpl : public frame_test_helpers::TestWebFrameClient {};

void RegisterMockedImageURLLoad(const String& url) {}

}  // namespace

template <>
struct DowncastTraits<ContextMenuControllerTestPlugin> {};

class ContextMenuControllerTest : public testing::Test {};

TEST_F(ContextMenuControllerTest, CopyFromPlugin) {}

TEST_F(ContextMenuControllerTest, VideoNotLoaded) {}

TEST_F(ContextMenuControllerTest, VideoWithAudioOnly) {}

TEST_F(ContextMenuControllerTest, PictureInPictureEnabledVideoLoaded) {}

TEST_F(ContextMenuControllerTest, PictureInPictureDisabledVideoLoaded) {}

TEST_F(ContextMenuControllerTest, MediaStreamVideoLoaded) {}

TEST_F(ContextMenuControllerTest, InfiniteDurationVideoLoaded) {}

TEST_F(ContextMenuControllerTest, HitTestVideoChildElements) {}

TEST_F(ContextMenuControllerTest, EditingActionsEnabledInSVGDocument) {}

TEST_F(ContextMenuControllerTest, EditingActionsEnabledInXMLDocument) {}

TEST_F(ContextMenuControllerTest, ShowNonLocatedContextMenuEvent) {}

#if !BUILDFLAG(IS_MAC)
// Mac has no way to open a context menu based on a keyboard event.
TEST_F(ContextMenuControllerTest,
       ValidateNonLocatedContextMenuOnLargeImageElement) {}
#endif

TEST_F(ContextMenuControllerTest, ContextMenuImageHitTestSVGImageElement) {}

TEST_F(ContextMenuControllerTest, SelectionRectClipped) {}

class MockEventListener final : public NativeEventListener {};

// Test that a basic image hit test works and is no† impacted by
// penetrating image selection logic.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageHitTestStandardImageSelection) {}

// Test that image selection can penetrate through a fully transparent div
// above the target image.
TEST_F(ContextMenuControllerTest, ContextMenuImageHitTestSucceededPenetrating) {}

// Test that a basic image hit test works and is no† impacted by
// penetrating image selection logic.
TEST_F(ContextMenuControllerTest, ContextMenuImageHitTestStandardCanvas) {}

// Test that  an image node will not be selected through an opaque div
// above the target image.
TEST_F(ContextMenuControllerTest, ContextMenuImageHitTestOpaqueNodeBlocking) {}

// Test that an image node will not be selected if a node with a context menu
// listener is above the image node, but that we will still log the presence of
// the image.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageHitTestContextMenuListenerAboveImageBlocking) {}

// Test that an image node will not be selected if the image node itself has a
// context menu listener on it (and the image node is not the topmost element)
TEST_F(ContextMenuControllerTest,
       ContextMenuImageHitTestContextMenuListenerOnImageBlocking) {}

// Test that an image node will be selected if the image node itself has an
// unrelated event listener on it.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageHitTestNonBlockingNonContextMenuListenerOnImage) {}

// Test that an image node will still be selected if it is the topmost node
// despite an ancestor having a context menu listener attached to it.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageHitTestStandardContextMenuListenerAncestorNonBlocking) {}

// Test that an image node will not be selected if a non image node with a
// context listener ancestor is above it and verify that topmost context menu
// listener special logic only applies if the topmost node is an image.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageHitTestContextMenuListenerAncestorBlocking) {}

// Test that an image node is successfully cached and retrieved in the common
// case.
TEST_F(ContextMenuControllerTest, ContextMenuImageRetrievalCachedImageFound) {}

// Test that an image node is not successfully retrieved if a hit test was never
// conducted.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageRetrievalCachedImageNotFound) {}

// Test that the retrieved image node is null if another hit test has been
// conducted in the same controller before the retrieval occurred.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageRetrievalAfterCachedImageReset) {}

// Test that the retrieved image node is null if the retrieval frame is
// different than the one used in the initial context menu image selection.
TEST_F(ContextMenuControllerTest,
       ContextMenuImageRetrievalCachedImageCrossFrame) {}

TEST_F(ContextMenuControllerTest, OpenedFromHighlight) {}

// Test that opening context menu with keyboard does not change text selection.
TEST_F(ContextMenuControllerTest,
       KeyboardTriggeredContextMenuPreservesSelection) {}

TEST_F(ContextMenuControllerTest, CheckRendererIdFromContextMenuOnTextField) {}

TEST_F(ContextMenuControllerTest, AttributionSrc) {}

// Test that if text selection contains unselectable content, the opened context
// menu should omit the unselectable content.
TEST_F(ContextMenuControllerTest, SelectUnselectableContent) {}

class ContextMenuControllerRemoteParentFrameTest : public testing::Test {};

TEST_F(ContextMenuControllerRemoteParentFrameTest, ShowContextMenuInChild) {}

// Test the field of `context_menu_data` `is_password_type_by_heuristics` which
// should be set if a field's type is plain text but heuristics (e.g. the name
// attribute contains 'password' as a substring) recognize it as a password
// field.
TEST_F(ContextMenuControllerTest, IsPasswordTypeByHeuristic) {}

// Test the field of `context_menu_data` `is_password_type_by_heuristics` which
// should be set if a field's type is plain text and `HasBeenPassword` returns
// true (due to either server predictions or user's masking of input values).
TEST_F(ContextMenuControllerTest, HasBeenPasswordHeuristic) {}

}  // namespace blink