chromium/third_party/blink/renderer/core/css/style_engine_test.cc

// Copyright 2016 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/css/style_engine.h"

#include <algorithm>
#include <limits>
#include <memory>

#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/css/forced_colors.h"
#include "third_party/blink/public/common/css/navigation_controls.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/platform/web_theme_engine.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_shadow_root_init.h"
#include "third_party/blink/renderer/core/animation/animation_clock.h"
#include "third_party/blink/renderer/core/animation/element_animations.h"
#include "third_party/blink/renderer/core/css/cascade_layer.h"
#include "third_party/blink/renderer/core/css/cascade_layer_map.h"
#include "third_party/blink/renderer/core/css/counter_style.h"
#include "third_party/blink/renderer/core/css/css_font_selector.h"
#include "third_party/blink/renderer/core/css/css_media_rule.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/css_style_rule.h"
#include "third_party/blink/renderer/core/css/css_style_sheet.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/css/media_query_list.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/css/parser/css_parser_context.h"
#include "third_party/blink/renderer/core/css/parser/css_tokenizer.h"
#include "third_party/blink/renderer/core/css/properties/css_property_ref.h"
#include "third_party/blink/renderer/core/css/properties/longhands.h"
#include "third_party/blink/renderer/core/css/resolver/scoped_style_resolver.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver_stats.h"
#include "third_party/blink/renderer/core/css/style_scope_frame.h"
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/first_letter_pseudo_element.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/scriptable_document_parser.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/dom/slot_assignment_engine.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/execution_context/security_context.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.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/viewport_data.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/html/html_anchor_element.h"
#include "third_party/blink/renderer/core/html/html_collection.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/html/html_span_element.h"
#include "third_party/blink/renderer/core/html/html_style_element.h"
#include "third_party/blink/renderer/core/layout/custom_scrollbar.h"
#include "third_party/blink/renderer/core/layout/layout_counter.h"
#include "third_party/blink/renderer/core/layout/layout_custom_scrollbar_part.h"
#include "third_party/blink/renderer/core/layout/layout_text_fragment.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/layout/list/list_marker.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/page_animator.h"
#include "third_party/blink/renderer/core/page/viewport_description.h"
#include "third_party/blink/renderer/core/testing/color_scheme_helper.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/testing/page_test_base.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/heap/thread_state.h"
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/geometry/size_f.h"

namespace blink {

class StyleEngineTest : public PageTestBase {};

class StyleEngineContainerQueryTest : public StyleEngineTest {};

void StyleEngineTest::ApplyRuleSetInvalidation(TreeScope& tree_scope,
                                               const String& css_text) {}

TEST_F(StyleEngineTest, DocumentDirtyAfterInject) {}

TEST_F(StyleEngineTest, AnalyzedInject) {}

TEST_F(StyleEngineTest, InjectedUserNoAuthorFontFace) {}

TEST_F(StyleEngineTest, InjectedFontFace) {}

TEST_F(StyleEngineTest, IgnoreInvalidPropertyValue) {}

TEST_F(StyleEngineTest, TextToSheetCache) {}

TEST_F(StyleEngineTest, RuleSetInvalidationTypeSelectors) {}

TEST_F(StyleEngineTest, RuleSetInvalidationCustomPseudo) {}

TEST_F(StyleEngineTest, RuleSetInvalidationHost) {}

TEST_F(StyleEngineTest, RuleSetInvalidationSlotted) {}

TEST_F(StyleEngineTest, RuleSetInvalidationHostContext) {}

TEST_F(StyleEngineTest, HasViewportDependentMediaQueries) {}

TEST_F(StyleEngineTest, StyleMediaAttributeStyleChange) {}

TEST_F(StyleEngineTest, StyleMediaAttributeNoStyleChange) {}

TEST_F(StyleEngineTest, ModifyStyleRuleMatchedPropertiesCache) {}

TEST_F(StyleEngineTest, VisitedExplicitInheritanceMatchedPropertiesCache) {}

TEST_F(StyleEngineTest, ScheduleInvalidationAfterSubtreeRecalc) {}

TEST_F(StyleEngineTest, EmptyHttpEquivDefaultStyle) {}

TEST_F(StyleEngineTest, StyleSheetsForStyleSheetList_Document) {}

TEST_F(StyleEngineTest, StyleSheetsForStyleSheetList_ShadowRoot) {}

TEST_F(StyleEngineTest, ViewportDescription) {}

TEST_F(StyleEngineTest, MediaQueryAffectingValueChanged_StyleElementNoMedia) {}

TEST_F(StyleEngineTest,
       MediaQueryAffectingValueChanged_StyleElementMediaNoValue) {}

TEST_F(StyleEngineTest,
       MediaQueryAffectingValueChanged_StyleElementMediaEmpty) {}

// TODO([email protected]): The test cases below where all queries are either
// "all" or "not all", we could have detected those and not trigger an active
// stylesheet update for those cases.

TEST_F(StyleEngineTest,
       MediaQueryAffectingValueChanged_StyleElementMediaNoValid) {}

TEST_F(StyleEngineTest, MediaQueryAffectingValueChanged_StyleElementMediaAll) {}

TEST_F(StyleEngineTest,
       MediaQueryAffectingValueChanged_StyleElementMediaNotAll) {}

TEST_F(StyleEngineTest, MediaQueryAffectingValueChanged_StyleElementMediaType) {}

TEST_F(StyleEngineTest, EmptyPseudo_RemoveLast) {}

TEST_F(StyleEngineTest, EmptyPseudo_RemoveNotLast) {}

TEST_F(StyleEngineTest, EmptyPseudo_InsertFirst) {}

TEST_F(StyleEngineTest, EmptyPseudo_InsertNotFirst) {}

TEST_F(StyleEngineTest, EmptyPseudo_ModifyTextData_SingleNode) {}

TEST_F(StyleEngineTest, EmptyPseudo_ModifyTextData_HasSiblings) {}

TEST_F(StyleEngineTest, MediaQueriesChangeDefaultFontSize) {}

TEST_F(StyleEngineTest, MediaQueriesChangeColorScheme) {}

TEST_F(StyleEngineTest, MediaQueriesChangeColorSchemeForcedDarkMode) {}

TEST_F(StyleEngineTest, MediaQueriesChangePrefersContrast) {}

TEST_F(StyleEngineTest, MediaQueriesChangeSpecificPrefersContrast) {}

TEST_F(StyleEngineTest, MediaQueriesChangePrefersContrastOverride) {}

TEST_F(StyleEngineTest, MediaQueriesChangePrefersReducedMotion) {}

TEST_F(StyleEngineTest, MediaQueriesChangePrefersReducedTransparency) {}

TEST_F(StyleEngineTest, MediaQueriesChangePrefersReducedDataOn) {}

TEST_F(StyleEngineTest, MediaQueriesChangePrefersReducedDataOff) {}

TEST_F(StyleEngineTest, MediaQueriesChangeForcedColors) {}

TEST_F(StyleEngineTest, MediaQueriesChangeForcedColorsAndPreferredColorScheme) {}

TEST_F(StyleEngineTest, MediaQueriesForcedColorsOverride) {}

TEST_F(StyleEngineTest, MediaQueriesColorSchemeOverride) {}

TEST_F(StyleEngineTest, MediaQueriesReducedTransparencyOverride) {}

TEST_F(StyleEngineTest, MediaQueriesReducedDataOverride) {}

TEST_F(StyleEngineTest, PreferredColorSchemeMetric) {}

// The preferred color scheme setting used to differ from the preferred color
// scheme when forced dark mode was enabled. Test that it is no longer the case.
TEST_F(StyleEngineTest, PreferredColorSchemeSettingMetric) {}

TEST_F(StyleEngineTest, ForcedDarkModeMetric) {}

TEST_F(StyleEngineTest, ColorSchemeDarkSupportedOnRootMetricFromMetaDark) {}

TEST_F(StyleEngineTest, ColorSchemeDarkSupportedOnRootMetricFromMetaLightDark) {}

TEST_F(StyleEngineTest, ColorSchemeDarkSupportedOnRootMetricFromCSSDark) {}

TEST_F(StyleEngineTest, ColorSchemeDarkSupportedOnRootMetricFromCSSLightDark) {}

TEST_F(StyleEngineTest, ColorSchemeDarkSupportedOnRootMetricFromChildCSSDark) {}

TEST_F(StyleEngineTest, ColorSchemeDarkSupportedOnRootMetricFromLight) {}

TEST_F(StyleEngineTest, MediaQueriesReducedMotionOverride) {}

TEST_F(StyleEngineTest, MediaQueriesChangeNavigationControls) {}

TEST_F(StyleEngineTest, MediaQueriesChangeInvertedColors) {}

TEST_F(StyleEngineTest, ShadowRootStyleRecalcCrash) {}

TEST_F(StyleEngineTest, GetComputedStyleOutsideFlatTreeCrash) {}

TEST_F(StyleEngineTest, RejectSelectorForPseudoElement) {}

TEST_F(StyleEngineTest, FirstLetterRemoved) {}

TEST_F(StyleEngineTest, InitialDataCreation) {}

TEST_F(StyleEngineTest, CSSSelectorEmptyWhitespaceOnlyFail) {}

TEST_F(StyleEngineTest, EnsuredComputedStyleRecalc) {}

TEST_F(StyleEngineTest, EnsureCustomComputedStyle) {}

// Via HTMLFormControlElement, it's possible to enter
// Node::MarkAncestorsWithChildNeedsStyleRecalc for nodes which have
// isConnected==true, but an ancestor with isConnected==false. This is because
// we mark the ancestor chain for style recalc via HTMLFormElement::
// InvalidateDefaultButtonStyle while the subtree disconnection
// is taking place.
TEST_F(StyleEngineTest, NoCrashWhenMarkingPartiallyRemovedSubtree) {}

TEST_F(StyleEngineTest, ColorSchemeBaseBackgroundChange) {}

TEST_F(StyleEngineTest, ColorSchemeOverride) {}

TEST_F(StyleEngineTest, PseudoElementBaseComputedStyle) {}

TEST_F(StyleEngineTest, NeedsLayoutTreeRebuild) {}

TEST_F(StyleEngineTest, ForceReattachLayoutTreeStyleRecalcRoot) {}

TEST_F(StyleEngineTest, ForceReattachNoStyleForElement) {}

TEST_F(StyleEngineTest, RecalcPropagatedWritingMode) {}

TEST_F(StyleEngineTest, GetComputedStyleOutsideFlatTree) {}

TEST_F(StyleEngineTest, MoveSlottedOutsideFlatTree) {}

TEST_F(StyleEngineTest, StyleRecalcRootInShadowTree) {}

TEST_F(StyleEngineTest, StyleRecalcRootOutsideFlatTree) {}

TEST_F(StyleEngineTest, RemoveStyleRecalcRootFromFlatTree) {}

TEST_F(StyleEngineTest, SlottedWithEnsuredStyleOutsideFlatTree) {}

TEST_F(StyleEngineTest, ForceReattachRecalcRootAttachShadow) {}

TEST_F(StyleEngineTest, InitialColorChange) {}

TEST_F(StyleEngineTest,
       MediaQueryAffectingValueChanged_InvalidateForChangedSizeQueries) {}

TEST_F(StyleEngineTest,
       MediaQueryAffectingValueChanged_InvalidateForChangedTypeQuery) {}

TEST_F(StyleEngineTest,
       MediaQueryAffectingValueChanged_InvalidateForChangedReducedMotionQuery) {}

TEST_F(StyleEngineTest, RevertUseCount) {}

TEST_F(StyleEngineTest, RevertUseCountForCustomProperties) {}

TEST_F(StyleEngineTest, NoRevertUseCountForForcedColors) {}

TEST_F(StyleEngineTest, PrintNoDarkColorScheme) {}

TEST_F(StyleEngineTest, PrintNoForceDarkMode) {}

TEST_F(StyleEngineTest, PrintScriptingEnabled) {}

TEST_F(StyleEngineTest, MediaQueriesChangeScripting) {}

TEST_F(StyleEngineTest, AtPropertyUseCount) {}

TEST_F(StyleEngineTest, AtScopeUseCount) {}

TEST_F(StyleEngineTest, RemoveDeclaredPropertiesEmptyRegistry) {}

TEST_F(StyleEngineTest, AtPropertyInUserOrigin) {}

// https://crbug.com/1050564
TEST_F(StyleEngineTest, MediaAttributeChangeUpdatesFontCacheVersion) {}

// Properties stored for forced colors mode should only be usable by the UA.
TEST_F(StyleEngineTest, InternalForcedProperties) {}

TEST_F(StyleEngineTest, HasViewportUnitFlags) {}

TEST_F(StyleEngineTest, DynamicViewportUnitInvalidation) {}

TEST_F(StyleEngineTest, DynamicViewportUnitsInMediaQuery) {}

TEST_F(StyleEngineTest, MediaQueriesChangeDisplayState) {}

TEST_F(StyleEngineTest, MediaQueriesChangeResizable) {}

namespace {

class TestMediaQueryListListener : public MediaQueryListListener {};

}  // namespace

TEST_F(StyleEngineTest, DynamicViewportUnitsInMediaQueryMatcher) {}

class StyleEngineSimTest : public SimTest {};

TEST_F(StyleEngineSimTest, OwnerColorScheme) {}

TEST_F(StyleEngineSimTest, OwnerColorSchemeBaseBackground) {}

TEST_F(StyleEngineSimTest, ColorSchemeBaseBackgroundWhileRenderBlocking) {}

TEST_F(StyleEngineContainerQueryTest, UpdateStyleAndLayoutTreeForContainer) {}

TEST_F(StyleEngineContainerQueryTest, ContainerQueriesContainmentNotApplying) {}

TEST_F(StyleEngineContainerQueryTest, PseudoElementContainerQueryRecalc) {}

TEST_F(StyleEngineContainerQueryTest, MarkStyleDirtyFromContainerRecalc) {}

TEST_F(StyleEngineContainerQueryTest,
       UpdateStyleAndLayoutTreeWithoutLayoutDependency) {}

TEST_F(StyleEngineContainerQueryTest,
       UpdateStyleAndLayoutTreeWithLayoutDependency) {}

// https://crbug.com/1343570
TEST_F(StyleEngineContainerQueryTest,
       UpdateStyleAndLayoutTreeWithUpgradeInDisplayNone) {}

TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeWithAnchorQuery) {}

TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeForElementWithAnchorQuery) {}

TEST_F(StyleEngineTest, AnchorQueryComputed) {}

TEST_F(StyleEngineTest, AnchorQueryComputedChild) {}

TEST_F(StyleEngineTest, VideoControlsReject) {}

TEST_F(StyleEngineTest, FastRejectForHostChild) {}

TEST_F(StyleEngineTest, RejectSlottedSelector) {}

TEST_F(StyleEngineTest, FastRejectForNesting) {}

TEST_F(StyleEngineTest, FastRejectForComplexSingleIs) {}

TEST_F(StyleEngineTest, NoFastRejectForMultipleIs) {}

TEST_F(StyleEngineTest, ScrollbarPartPseudoDoesNotMatchElement) {}

TEST_F(StyleEngineTest, AudioUAStyleNameSpace) {}

TEST_F(StyleEngineTest, TargetTextUseCount) {}

TEST_F(StyleEngineTest, NonDirtyStyleRecalcRoot) {}

TEST_F(StyleEngineTest, AtCounterStyleUseCounter) {}

TEST_F(StyleEngineTest, AtContainerUseCount) {}

TEST_F(StyleEngineTest, StyleQueryUseCount) {}

TEST_F(StyleEngineTest, NestingUseCount) {}

TEST_F(StyleEngineTest, NestingUseCountUnsupportedDeclaration) {}

TEST_F(StyleEngineTest, NestingUseCountSupportedDeclaration) {}

TEST_F(StyleEngineTest, NestingUseCountDimensionToken) {}

TEST_F(StyleEngineTest, NestingUseCountInvalidSelector) {}

TEST_F(StyleEngineTest, NestingUseCountUnknownAtRule) {}

TEST_F(StyleEngineTest, NestingUseCountAtRule) {}

TEST_F(StyleEngineTest, NestingUseCountNotStartingWithAmpersand) {}

TEST_F(StyleEngineTest, SystemFontsObeyDefaultFontSize) {}

TEST_F(StyleEngineTest, CascadeLayersInOriginsAndTreeScopes) {}

TEST_F(StyleEngineTest, CascadeLayersFromMultipleSheets) {}

TEST_F(StyleEngineTest, CascadeLayersNotExplicitlyDeclared) {}

TEST_F(StyleEngineTest, CascadeLayersSheetsRemoved) {}

TEST_F(StyleEngineTest, NonSlottedStyleDirty) {}

TEST_F(StyleEngineTest, CascadeLayerUseCount) {}

TEST_F(StyleEngineTest, UserKeyframesOverrideWithCascadeLayers) {}

TEST_F(StyleEngineTest, UserCounterStyleOverrideWithCascadeLayers) {}

TEST_F(StyleEngineTest, UserPropertyOverrideWithCascadeLayers) {}

TEST_F(StyleEngineTest, UserAndAuthorPropertyOverrideWithCascadeLayers) {}

TEST_F(StyleEngineSimTest, UserFontFaceOverrideWithCascadeLayers) {}

TEST_F(StyleEngineSimTest, UserAndAuthorFontFaceOverrideWithCascadeLayers) {}

TEST_F(StyleEngineTest, CascadeLayerActiveStyleSheetVectorNullRuleSetCrash) {}

TEST_F(StyleEngineTest, EmptyDetachParent) {}

TEST_F(StyleEngineTest, LegacyListItemRebuildRootCrash) {}

// Regression test for https://crbug.com/1270190
TEST_F(StyleEngineTest, ScrollbarStyleNoExcessiveCaching) {}

TEST_F(StyleEngineTest, HasPseudoClassInvalidationSkipIrrelevantClassChange) {}

TEST_F(StyleEngineTest, HasPseudoClassInvalidationSkipIrrelevantIdChange) {}

TEST_F(StyleEngineTest,
       HasPseudoClassInvalidationSkipIrrelevantAttributeChange) {}

TEST_F(StyleEngineTest,
       HasPseudoClassInvalidationSkipIrrelevantInsertionRemoval) {}

TEST_F(StyleEngineTest, HasPseudoClassInvalidationUniversalInArgument) {}

TEST_F(StyleEngineTest,
       HasPseudoClassInvalidationInsertionRemovalWithPseudoInHas) {}

TEST_F(StyleEngineTest, HasPseudoClassInvalidationLinkInHas) {}

TEST_F(StyleEngineTest, HasPseudoClassInvalidationIgnoreVisitedPseudoInHas) {}

TEST_F(StyleEngineTest, HasPseudoClassInvalidationCheckFiltering) {}

TEST_F(StyleEngineTest, CSSComparisonFunctionsUseCount) {}

TEST_F(StyleEngineTest, MathDepthOverflow) {}

TEST_F(StyleEngineTest, RemovedBodyToHTMLPropagation) {}

TEST_F(StyleEngineTest, RevertWithPresentationalHints) {}

TEST_F(StyleEngineTest, RevertLayerWithPresentationalHints) {}

TEST_F(StyleEngineSimTest, ResizeWithBlockingSheetTransition) {}

TEST_F(StyleEngineSimTest, FocusWithBlockingSheetTransition) {}

TEST_F(StyleEngineSimTest,
       ShouldInvalidateSubjectPseudoHasAfterChildrenParsingFinished) {}

TEST_F(StyleEngineTest, StyleElementTypeAttrChange) {}

TEST_F(StyleEngineTest, SVGURIValueCacheClipPath) {}

TEST_F(StyleEngineTest, SVGURIValueCacheFill) {}

TEST_F(StyleEngineTest, BorderWidthsAreRecalculatedWhenZoomChanges) {}

TEST_F(StyleEngineTest, AnimationShorthandFlags) {}

TEST_F(StyleEngineTest, InitialStyle_Recalc) {}

TEST_F(StyleEngineTest, InitialStyle_FromDisplayNone) {}

TEST_F(StyleEngineTest, InitialStyleCount_EnsureComputedStyle) {}

TEST_F(StyleEngineTest, UseCountCSSAnchorPositioning) {}

TEST_F(StyleEngineTest, EnsureAppRegionTriggersRelayout) {}

TEST_F(StyleEngineTest, ForcedColorsLightDark) {}

}  // namespace blink