chromium/third_party/blink/renderer/core/animation/animation_test.cc

/*
 * Copyright (c) 2013, Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "third_party/blink/renderer/core/animation/animation.h"

#include <bit>
#include <memory>
#include <tuple>

#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "cc/trees/target_property.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_optional_effect_timing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_scroll_timeline_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_cssnumericvalue_double.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_cssnumericvalue_string_unrestricteddouble.h"
#include "third_party/blink/renderer/core/animation/animation_clock.h"
#include "third_party/blink/renderer/core/animation/css/compositor_keyframe_double.h"
#include "third_party/blink/renderer/core/animation/css_number_interpolation_type.h"
#include "third_party/blink/renderer/core/animation/document_timeline.h"
#include "third_party/blink/renderer/core/animation/element_animations.h"
#include "third_party/blink/renderer/core/animation/keyframe_effect.h"
#include "third_party/blink/renderer/core/animation/keyframe_effect_model.h"
#include "third_party/blink/renderer/core/animation/pending_animations.h"
#include "third_party/blink/renderer/core/animation/scroll_timeline.h"
#include "third_party/blink/renderer/core/animation/timing.h"
#include "third_party/blink/renderer/core/css/cssom/css_unit_values.h"
#include "third_party/blink/renderer/core/css/properties/longhands.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/events/native_event_listener.h"
#include "third_party/blink/renderer/core/dom/qualified_name.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/execution_context/security_context.h"
#include "third_party/blink/renderer/core/page/page_animator.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h"
#include "third_party/blink/renderer/platform/graphics/compositing/paint_artifact_compositor.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/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/testing/paint_test_configurations.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"

namespace blink {

void ExpectRelativeErrorWithinEpsilon(double expected, double observed) {}

class AnimationAnimationTestNoCompositing : public PaintTestConfigurations,
                                            public RenderingTest {};

class AnimationAnimationTestCompositing
    : public AnimationAnimationTestNoCompositing {};

INSTANTIATE_PAINT_TEST_SUITE_P();
INSTANTIATE_PAINT_TEST_SUITE_P();

TEST_P(AnimationAnimationTestNoCompositing, InitialState) {}

TEST_P(AnimationAnimationTestNoCompositing, CurrentTimeDoesNotSetOutdated) {}

TEST_P(AnimationAnimationTestNoCompositing, SetCurrentTime) {}

TEST_P(AnimationAnimationTestNoCompositing, SetCurrentTimeNegative) {}

TEST_P(AnimationAnimationTestNoCompositing,
       SetCurrentTimeNegativeWithoutSimultaneousPlaybackRateChange) {}

TEST_P(AnimationAnimationTestNoCompositing, SetCurrentTimePastContentEnd) {}

TEST_P(AnimationAnimationTestCompositing, SetCurrentTimeMax) {}

TEST_P(AnimationAnimationTestCompositing, SetCurrentTimeAboveMaxTimeDelta) {}

TEST_P(AnimationAnimationTestNoCompositing, SetCurrentTimeSetsStartTime) {}

TEST_P(AnimationAnimationTestNoCompositing, SetStartTime) {}

TEST_P(AnimationAnimationTestNoCompositing, SetStartTimeLimitsAnimation) {}

TEST_P(AnimationAnimationTestNoCompositing, SetStartTimeOnLimitedAnimation) {}

TEST_P(AnimationAnimationTestNoCompositing, StartTimePauseFinish) {}

TEST_P(AnimationAnimationTestNoCompositing, FinishWhenPaused) {}

TEST_P(AnimationAnimationTestNoCompositing, StartTimeFinishPause) {}

TEST_P(AnimationAnimationTestNoCompositing, StartTimeWithZeroPlaybackRate) {}

TEST_P(AnimationAnimationTestNoCompositing, PausePlay) {}

TEST_P(AnimationAnimationTestNoCompositing, PlayRewindsToStart) {}

TEST_P(AnimationAnimationTestNoCompositing, PlayRewindsToEnd) {}

TEST_P(AnimationAnimationTestNoCompositing,
       PlayWithPlaybackRateZeroDoesNotSeek) {}

TEST_P(AnimationAnimationTestNoCompositing,
       PlayAfterPauseWithPlaybackRateZeroUpdatesPlayState) {}

TEST_P(AnimationAnimationTestNoCompositing, Reverse) {}

TEST_P(AnimationAnimationTestNoCompositing,
       ReverseHoldsCurrentTimeWithPlaybackRateZero) {}

TEST_P(AnimationAnimationTestNoCompositing, ReverseSeeksToStart) {}

TEST_P(AnimationAnimationTestNoCompositing, ReverseSeeksToEnd) {}

TEST_P(AnimationAnimationTestNoCompositing, ReverseBeyondLimit) {}

TEST_P(AnimationAnimationTestNoCompositing, Finish) {}

TEST_P(AnimationAnimationTestNoCompositing, FinishAfterEffectEnd) {}

TEST_P(AnimationAnimationTestNoCompositing, FinishBeforeStart) {}

TEST_P(AnimationAnimationTestNoCompositing,
       FinishDoesNothingWithPlaybackRateZero) {}

TEST_P(AnimationAnimationTestNoCompositing, FinishRaisesException) {}

TEST_P(AnimationAnimationTestNoCompositing, LimitingAtEffectEnd) {}

TEST_P(AnimationAnimationTestNoCompositing, LimitingAtStart) {}

TEST_P(AnimationAnimationTestNoCompositing, LimitingWithNoEffect) {}

TEST_P(AnimationAnimationTestNoCompositing, SetPlaybackRate) {}

TEST_P(AnimationAnimationTestNoCompositing, SetPlaybackRateWhilePaused) {}

TEST_P(AnimationAnimationTestNoCompositing, SetPlaybackRateWhileLimited) {}

TEST_P(AnimationAnimationTestNoCompositing, SetPlaybackRateZero) {}

TEST_P(AnimationAnimationTestNoCompositing, SetPlaybackRateMax) {}

TEST_P(AnimationAnimationTestNoCompositing, UpdatePlaybackRate) {}

TEST_P(AnimationAnimationTestNoCompositing, UpdatePlaybackRateWhilePaused) {}

TEST_P(AnimationAnimationTestNoCompositing, UpdatePlaybackRateWhileLimited) {}

TEST_P(AnimationAnimationTestNoCompositing, UpdatePlaybackRateWhileRunning) {}

TEST_P(AnimationAnimationTestNoCompositing, SetEffect) {}

TEST_P(AnimationAnimationTestNoCompositing, SetEffectLimitsAnimation) {}

TEST_P(AnimationAnimationTestNoCompositing, SetEffectUnlimitsAnimation) {}

TEST_P(AnimationAnimationTestNoCompositing, EmptyAnimationsDontUpdateEffects) {}

TEST_P(AnimationAnimationTestNoCompositing, AnimationsDisassociateFromEffect) {}

#define EXPECT_TIMEDELTA(expected, observed)

TEST_P(AnimationAnimationTestNoCompositing, AnimationsReturnTimeToNextEffect) {}

TEST_P(AnimationAnimationTestNoCompositing, TimeToNextEffectWhenPaused) {}

TEST_P(AnimationAnimationTestNoCompositing,
       TimeToNextEffectWhenCancelledBeforeStart) {}

TEST_P(AnimationAnimationTestNoCompositing,
       TimeToNextEffectWhenCancelledBeforeStartReverse) {}

TEST_P(AnimationAnimationTestNoCompositing,
       TimeToNextEffectSimpleCancelledBeforeStart) {}

TEST_P(AnimationAnimationTestNoCompositing, AttachedAnimations) {}

TEST_P(AnimationAnimationTestNoCompositing, HasLowerCompositeOrdering) {}

TEST_P(AnimationAnimationTestNoCompositing, PlayAfterCancel) {}

TEST_P(AnimationAnimationTestNoCompositing, PlayBackwardsAfterCancel) {}

TEST_P(AnimationAnimationTestNoCompositing, ReverseAfterCancel) {}

TEST_P(AnimationAnimationTestNoCompositing, FinishAfterCancel) {}

TEST_P(AnimationAnimationTestNoCompositing, PauseAfterCancel) {}

// crbug.com/1052217
TEST_P(AnimationAnimationTestNoCompositing, SetPlaybackRateAfterFinish) {}

TEST_P(AnimationAnimationTestNoCompositing, UpdatePlaybackRateAfterFinish) {}

TEST_P(AnimationAnimationTestCompositing,
       NoCompositeWithoutCompositedElementId) {}

// Regression test for http://crbug.com/819591 . If a compositable animation is
// played and then paused before any start time is set (either blink or
// compositor side), the pausing must still set compositor pending or the pause
// won't be synced.
TEST_P(AnimationAnimationTestCompositing,
       SetCompositorPendingWithUnresolvedStartTimes) {}

TEST_P(AnimationAnimationTestCompositing, PreCommitWithUnresolvedStartTimes) {}

// Cancel is synchronous on the main thread, but asynchronously deferred on the
// compositor to reduce thread contention.
TEST_P(AnimationAnimationTestCompositing, AsynchronousCancel) {}

namespace {
int GenerateHistogramValue(CompositorAnimations::FailureReason reason) {}
}  // namespace

TEST_P(AnimationAnimationTestCompositing, PreCommitRecordsHistograms) {}

// crbug.com/990000.
TEST_P(AnimationAnimationTestCompositing, ReplaceCompositedAnimation) {}

TEST_P(AnimationAnimationTestCompositing, SetKeyframesCausesCompositorPending) {}

// crbug.com/1057076
// Infinite duration animations should not run on the compositor.
TEST_P(AnimationAnimationTestCompositing, InfiniteDurationAnimation) {}

TEST_P(AnimationAnimationTestCompositing, ZeroPlaybackSpeed) {}

// crbug.com/1149012
// Regression test to ensure proper restart logic for composited animations on
// relative transforms after a size change. In this test, the transform depends
// on the width and height of the box and a change to either triggers a restart
// of the animation if running.
TEST_P(AnimationAnimationTestCompositing,
       RestartCompositedAnimationOnSizeChange) {}

// crbug.com/1149012
// Regression test to ensure proper restart logic for composited animations on
// relative transforms after a size change. In this test, the transform only
// depends on width and a change to the height does not trigger a restart.
TEST_P(AnimationAnimationTestCompositing,
       RestartCompositedAnimationOnWidthChange) {}

// crbug.com/1149012
// Regression test to ensure proper restart logic for composited animations on
// relative transforms after a size change.  In this test, the transition only
// affects height and a change to the width does not trigger a restart.
TEST_P(AnimationAnimationTestCompositing,
       RestartCompositedAnimationOnHeightChange) {}

TEST_P(AnimationAnimationTestCompositing,
       ScrollLinkedAnimationCanBeComposited) {}

TEST_P(AnimationAnimationTestCompositing,
       StartScrollLinkedAnimationWithStartTimeIfApplicable) {}

// Verifies correctness of scroll linked animation current and start times in
// various animation states.
TEST_P(AnimationAnimationTestNoCompositing, ScrollLinkedAnimationCreation) {}

// Verifies that finished composited scroll-linked animations restart on
// compositor upon reverse scrolling.
TEST_P(AnimationAnimationTestCompositing,
       FinishedScrollLinkedAnimationRestartsOnReverseScrolling) {}

TEST_P(AnimationAnimationTestNoCompositing,
       RemoveCanceledAnimationFromActiveSet) {}

TEST_P(AnimationAnimationTestNoCompositing,
       RemoveFinishedAnimationFromActiveSet) {}

TEST_P(AnimationAnimationTestNoCompositing,
       PendingActivityWithFinishedPromise) {}

class MockEventListener final : public NativeEventListener {};

TEST_P(AnimationAnimationTestNoCompositing,
       PendingActivityWithFinishedEventListener) {}

TEST_P(AnimationAnimationTestCompositing, InvalidExecutionContext) {}

class AnimationPendingAnimationsTest : public PaintTestConfigurations,
                                       public RenderingTest {};

INSTANTIATE_PAINT_TEST_SUITE_P();

TEST_P(AnimationPendingAnimationsTest, PendingAnimationStartSynchronization) {}

TEST_P(AnimationPendingAnimationsTest,
       PendingAnimationCancelUnblocksSynchronizedStart) {}

TEST_P(AnimationPendingAnimationsTest,
       PendingAnimationOnlySynchronizeStartsOfNewlyPendingAnimations) {}

TEST_P(AnimationAnimationTestCompositing,
       ScrollLinkedAnimationCompositedEvenIfSourceIsNotComposited) {}

#if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
// https://crbug.com/1222646
#define MAYBE_ContentVisibleDisplayLockTest
#else
#define MAYBE_ContentVisibleDisplayLockTest
#endif
TEST_P(AnimationAnimationTestCompositing, MAYBE_ContentVisibleDisplayLockTest) {}

TEST_P(AnimationAnimationTestCompositing, HiddenAnimationsDoNotTick) {}

TEST_P(AnimationAnimationTestCompositing, HiddenAnimationsTickWhenVisible) {}

TEST_P(AnimationAnimationTestNoCompositing,
       GetEffectTimingDelayZeroUseCounter) {}

}  // namespace blink