#include "third_party/blink/renderer/core/dom/document.h"
#include <algorithm>
#include <memory>
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/network/public/mojom/referrer_policy.mojom-blink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/permissions_policy/document_policy_features.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/web/web_print_page_description.h"
#include "third_party/blink/renderer/bindings/core/v8/isolated_world_csp.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_tester.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_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/core/css/media_query_list_listener.h"
#include "third_party/blink/renderer/core/css/media_query_matcher.h"
#include "third_party/blink/renderer/core/dom/document_fragment.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/dom_implementation.h"
#include "third_party/blink/renderer/core/dom/node_with_index.h"
#include "third_party/blink/renderer/core/dom/range.h"
#include "third_party/blink/renderer/core/dom/scripted_animation_controller.h"
#include "third_party/blink/renderer/core/dom/synchronous_mutation_observer.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/reporting_context.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/viewport_data.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/custom/custom_element_test_helpers.h"
#include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/html/html_head_element.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/html/html_link_element.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/page_animator.h"
#include "third_party/blink/renderer/core/page/validation_message_client.h"
#include "third_party/blink/renderer/core/testing/color_scheme_helper.h"
#include "third_party/blink/renderer/core/testing/mock_policy_container_host.h"
#include "third_party/blink/renderer/core/testing/null_execution_context.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.h"
#include "third_party/blink/renderer/core/testing/sim/sim_request.h"
#include "third_party/blink/renderer/core/testing/sim/sim_test.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.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/weborigin/scheme_registry.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "url/url_util.h"
namespace blink {
ContentSecurityPolicySource;
ContentSecurityPolicyType;
_;
ElementsAre;
IsEmpty;
class DocumentTest : public PageTestBase { … };
void DocumentTest::SetHtmlInnerHTML(const char* html_content) { … }
class DocumentSimTest : public SimTest { … };
namespace {
class TestSynchronousMutationObserver
: public GarbageCollected<TestSynchronousMutationObserver>,
public SynchronousMutationObserver { … };
TestSynchronousMutationObserver::TestSynchronousMutationObserver(
Document& document) { … }
void TestSynchronousMutationObserver::ContextDestroyed() { … }
void TestSynchronousMutationObserver::DidChangeChildren(
const ContainerNode& container,
const ContainerNode::ChildrenChange&) { … }
void TestSynchronousMutationObserver::DidMergeTextNodes(
const Text& node,
const NodeWithIndex& node_with_index,
unsigned offset) { … }
void TestSynchronousMutationObserver::DidMoveTreeToNewDocument(
const Node& root) { … }
void TestSynchronousMutationObserver::DidSplitTextNode(const Text& node) { … }
void TestSynchronousMutationObserver::DidUpdateCharacterData(
CharacterData* character_data,
unsigned offset,
unsigned old_length,
unsigned new_length) { … }
void TestSynchronousMutationObserver::NodeChildrenWillBeRemoved(
ContainerNode& container) { … }
void TestSynchronousMutationObserver::NodeWillBeRemoved(Node& node) { … }
void TestSynchronousMutationObserver::Trace(Visitor* visitor) const { … }
class MockDocumentValidationMessageClient
: public GarbageCollected<MockDocumentValidationMessageClient>,
public ValidationMessageClient { … };
class PrefersColorSchemeTestListener final : public MediaQueryListListener { … };
bool IsDOMException(ScriptState* script_state,
ScriptValue value,
DOMExceptionCode code) { … }
}
TEST_F(DocumentTest, CreateRangeAdjustedToTreeScopeWithPositionInShadowTree) { … }
TEST_F(DocumentTest, DomTreeVersionForRemoval) { … }
TEST_F(DocumentTest, PrintRelayout) { … }
TEST_F(DocumentTest, MediaFeatureEvaluated) { … }
TEST_F(DocumentTest, LinkManifest) { … }
TEST_F(DocumentTest, StyleVersion) { … }
TEST_F(DocumentTest, SynchronousMutationNotifier) { … }
TEST_F(DocumentTest, SynchronousMutationNotifieAppendChild) { … }
TEST_F(DocumentTest, SynchronousMutationNotifieInsertBefore) { … }
TEST_F(DocumentTest, SynchronousMutationNotifierMergeTextNodes) { … }
TEST_F(DocumentTest, SynchronousMutationNotifierMoveTreeToNewDocument) { … }
TEST_F(DocumentTest, SynchronousMutationNotifieRemoveChild) { … }
TEST_F(DocumentTest, SynchronousMutationNotifieReplaceChild) { … }
TEST_F(DocumentTest, SynchronousMutationNotifierSplitTextNode) { … }
TEST_F(DocumentTest, SynchronousMutationNotifierUpdateCharacterData) { … }
TEST_F(DocumentTest, ThemeColor) { … }
TEST_F(DocumentTest, ValidationMessageCleanup) { … }
TEST_F(DocumentTest,
EnsurePaintLocationDataValidForNodeCompositingInputsOnlyWhenNecessary) { … }
TEST_F(DocumentTest, ViewportPropagationNoRecalc) { … }
TEST_F(DocumentTest, SandboxedSrcdocUserCounts_BasicRelativeUrl) { … }
TEST_F(DocumentTest,
SandboxedSrcdocUserCounts_BasicRelativeUrlWithBaseElement) { … }
TEST_F(DocumentTest, SandboxedSrcdocUserCounts_BasicAbsoluteUrl) { … }
TEST_F(DocumentTest, SandboxedSrcdocUserCounts_BasicRelativeUrlInIframe) { … }
TEST_F(DocumentTest,
SandboxedSrcdocUserCounts_BasicRelativeUrlInNonSandboxedIframe) { … }
TEST_F(DocumentTest, SandboxedSrcdocUserCounts_BasicAbsoluteUrlInIframe) { … }
TEST_F(DocumentTest, CanExecuteScriptsWithSandboxAndIsolatedWorld) { … }
TEST_F(DocumentTest, ElementFromPointOnScrollbar) { … }
TEST_F(DocumentTest, ElementFromPointWithPageZoom) { … }
TEST_F(DocumentTest, PrefersColorSchemeChanged) { … }
TEST_F(DocumentTest, FindInPageUkm) { … }
TEST_F(DocumentTest, FindInPageUkmInFrame) { … }
TEST_F(DocumentTest, AtPageMarginWithDeviceScaleFactor) { … }
TEST_F(DocumentTest, HandlesDisconnectDuringHasPrivateToken) { … }
TEST_F(DocumentTest, RejectsHasPrivateTokenCallFromNonHttpNonHttpsDocument) { … }
namespace {
class MockTrustTokenQueryAnswerer
: public network::mojom::blink::TrustTokenQueryAnswerer { … };
}
TEST_F(DocumentTest, HasPrivateTokenSuccess) { … }
TEST_F(DocumentTest, HasPrivateTokenSuccessWithFalseValue) { … }
TEST_F(DocumentTest, HasPrivateTokenOperationError) { … }
TEST_F(DocumentTest, HasPrivateTokenInvalidArgument) { … }
TEST_F(DocumentTest, HasPrivateTokenResourceExhausted) { … }
TEST_F(DocumentTest, HasRedemptionRecordSuccess) { … }
TEST_F(DocumentTest, HasRedemptionRecordSuccessWithFalseValue) { … }
TEST_F(DocumentTest, HasRedemptionRecordOperationError) { … }
TEST_F(DocumentTest, HasRedemptionRecordInvalidArgument) { … }
TEST_F(DocumentTest, HandlesDisconnectDuringHasRedemptionRecord) { … }
TEST_F(DocumentTest,
RejectsHasRedemptionRecordCallFromNonHttpNonHttpsDocument) { … }
class ViewportFitDocumentTest : public DocumentTest,
private ScopedDisplayCutoutAPIForTest { … };
TEST_F(ViewportFitDocumentTest, MetaViewportButNoFit) { … }
TEST_F(ViewportFitDocumentTest, ForceExpandIntoCutout) { … }
ViewportTestCase;
class ParameterizedViewportFitDocumentTest
: public ViewportFitDocumentTest,
public testing::WithParamInterface<ViewportTestCase> { … };
TEST_P(ParameterizedViewportFitDocumentTest, EffectiveViewportFit) { … }
INSTANTIATE_TEST_SUITE_P(…);
namespace {
class MockReportingContext final : public ReportingContext { … };
}
TEST_F(DocumentSimTest, LastModified) { … }
TEST_F(DocumentSimTest, DuplicatedDocumentPolicyViolationsAreIgnored) { … }
class UnassociatedListedElementTest : public DocumentTest { … };
TEST_F(UnassociatedListedElementTest, GetUnassociatedListedElements) { … }
TEST_F(UnassociatedListedElementTest,
GetUnassociatedListedElementsFromShadowTree) { … }
TEST_F(UnassociatedListedElementTest,
GetDynamicallyAddedUnassociatedListedElements) { … }
TEST_F(UnassociatedListedElementTest,
GetDynamicallyRemovedUnassociatedListedElement) { … }
TEST_F(UnassociatedListedElementTest,
GetUnassociatedListedElementAfterAddingFormAttr) { … }
TEST_F(UnassociatedListedElementTest,
GetUnassociatedListedElementAfterRemovingFormAttr) { … }
TEST_F(UnassociatedListedElementTest,
GetUnassociatedListedElementAfterSettingFormAttrToNonexistent) { … }
TEST_F(UnassociatedListedElementTest,
GeDynamicallyAddedUnassociatedListedElementThatIsNotInTheDocument) { … }
TEST_F(UnassociatedListedElementTest,
GetAttachedNestedUnassociatedFormFieldElements) { … }
TEST_F(UnassociatedListedElementTest,
GetDetachedNestedUnassociatedFormFieldElements) { … }
class TopLevelFormsListTest : public DocumentTest { … };
TEST_F(TopLevelFormsListTest, FormsInLightDom) { … }
TEST_F(TopLevelFormsListTest, FormsInLightDomInsertionAndRemoval) { … }
TEST_F(TopLevelFormsListTest, FormsInShadowDomInsertionAndRemoval) { … }
TEST_F(TopLevelFormsListTest, GetTopLevelFormsIgnoresNestedChildren) { … }
TEST_F(DocumentTest, DocumentDefiningElementWithMultipleBodies) { … }
TEST_F(DocumentTest, LayoutReplacedUseCounterNoStyles) { … }
TEST_F(DocumentTest, LayoutReplacedUseCounterExplicitlyHidden) { … }
TEST_F(DocumentTest, LayoutReplacedUseCounterExplicitlyVisible) { … }
TEST_F(DocumentTest, LayoutReplacedUseCounterExplicitlyVisibleWithObjectFit) { … }
TEST_F(DocumentTest, LayoutReplacedUseCounterExplicitlyVisibleLaterHidden) { … }
TEST_F(DocumentTest, LayoutReplacedUseCounterIframe) { … }
TEST_F(DocumentTest, LayoutReplacedUseCounterSvg) { … }
TEST_F(DocumentSimTest, HeaderPreloadRemoveReaddClient) { … }
TEST_F(DocumentTest, ActiveModalDialog) { … }
TEST_F(DocumentTest, LifecycleState_DirtyStyle_NoBody) { … }
class TestPaymentLinkHandler
: public payments::facilitated::mojom::blink::PaymentLinkHandler { … };
#if BUILDFLAG(IS_ANDROID)
TEST_F(DocumentTest, PaymentLinkHandling_SinglePaymentLink) {
TestPaymentLinkHandler test_payment_link_handler;
base::RunLoop run_loop;
test_payment_link_handler.set_on_link_handled_callback(
run_loop.QuitClosure());
GetDocument().GetFrame()->GetBrowserInterfaceBroker().SetBinderForTesting(
payments::facilitated::mojom::blink::PaymentLinkHandler::Name_,
base::BindRepeating(&TestPaymentLinkHandler::Bind,
base::Unretained(&test_payment_link_handler)));
ScopedPaymentLinkDetectionForTest payment_link_detection(true);
SetHtmlInnerHTML(R"HTML(
<head>
<link rel="payment" href="upi://payment_link_1">
</head>
)HTML");
run_loop.Run();
EXPECT_EQ(test_payment_link_handler.get_payment_link_handled_counter(), 1);
EXPECT_EQ(test_payment_link_handler.get_handled_url(),
KURL("upi://payment_link_1"));
}
TEST_F(DocumentTest, PaymentLinkHandling_MultiplePaymentLink) {
TestPaymentLinkHandler test_payment_link_handler;
base::RunLoop run_loop;
test_payment_link_handler.set_on_link_handled_callback(
run_loop.QuitClosure());
GetDocument().GetFrame()->GetBrowserInterfaceBroker().SetBinderForTesting(
payments::facilitated::mojom::blink::PaymentLinkHandler::Name_,
base::BindRepeating(&TestPaymentLinkHandler::Bind,
base::Unretained(&test_payment_link_handler)));
ScopedPaymentLinkDetectionForTest payment_link_detection(true);
SetHtmlInnerHTML(R"HTML(
<head>
<link rel="payment" href="upi://payment_link_1">
<link rel="payment" href="upi://payment_link_2">
</head>
)HTML");
run_loop.Run();
EXPECT_EQ(test_payment_link_handler.get_payment_link_handled_counter(), 1);
EXPECT_EQ(test_payment_link_handler.get_handled_url(),
KURL("upi://payment_link_1"));
}
#endif
}