chromium/ui/compositor/callback_layer_animation_observer_unittest.cc

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

#include "ui/compositor/callback_layer_animation_observer.h"

#include <memory>

#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/test/layer_animation_observer_test_api.h"

namespace ui {
namespace test {

// Simple class that tracks whether callbacks were invoked and when.
class TestCallbacks {};

TestCallbacks::TestCallbacks() {}

TestCallbacks::~TestCallbacks() {}

void TestCallbacks::ResetCallbackObservations() {}

void TestCallbacks::AnimationsStarted(const CallbackLayerAnimationObserver&) {}

bool TestCallbacks::AnimationsEnded(const CallbackLayerAnimationObserver&) {}

testing::AssertionResult TestCallbacks::StartedEpochIsBeforeEndedEpoch() {}

// A child of TestCallbacks that can explicitly delete a
// CallbackLayerAnimationObserver in the AnimationsStarted() or
// AnimationsEnded() callback.
class TestCallbacksThatExplicitlyDeletesObserver : public TestCallbacks {};

TestCallbacksThatExplicitlyDeletesObserver::
    TestCallbacksThatExplicitlyDeletesObserver() {}

void TestCallbacksThatExplicitlyDeletesObserver::AnimationsStarted(
    const CallbackLayerAnimationObserver& observer) {}

bool TestCallbacksThatExplicitlyDeletesObserver::AnimationsEnded(
    const CallbackLayerAnimationObserver& observer) {}

// A test specific CallbackLayerAnimationObserver that will set a bool when
// destroyed.
class TestCallbackLayerAnimationObserver
    : public CallbackLayerAnimationObserver {};

TestCallbackLayerAnimationObserver::TestCallbackLayerAnimationObserver(
    AnimationStartedCallback animation_started_callback,
    AnimationEndedCallback animation_ended_callback,
    bool* destroyed)
    :{}

TestCallbackLayerAnimationObserver::TestCallbackLayerAnimationObserver(
    AnimationStartedCallback animation_started_callback,
    bool should_delete_observer,
    bool* destroyed)
    :{}

TestCallbackLayerAnimationObserver::TestCallbackLayerAnimationObserver(
    AnimationEndedCallback animation_ended_callback,
    bool* destroyed)
    :{}

TestCallbackLayerAnimationObserver::~TestCallbackLayerAnimationObserver() {}

class CallbackLayerAnimationObserverTest : public testing::Test {};

CallbackLayerAnimationObserverTest::CallbackLayerAnimationObserverTest()
    :{}

CallbackLayerAnimationObserverTest::~CallbackLayerAnimationObserverTest() {}

LayerAnimationSequence*
CallbackLayerAnimationObserverTest::CreateLayerAnimationSequence() {}

class CallbackLayerAnimationObserverTestOverwrite
    : public CallbackLayerAnimationObserverTest {};

CallbackLayerAnimationObserverTestOverwrite::
    CallbackLayerAnimationObserverTestOverwrite() {}

void CallbackLayerAnimationObserverTestOverwrite::AnimationStarted(
    const CallbackLayerAnimationObserver& observer) {}

std::unique_ptr<CallbackLayerAnimationObserver>
CallbackLayerAnimationObserverTestOverwrite::CreateAnimationObserver() {}

TEST(CallbackLayerAnimationObserverDestructionTest, VerifyFalseAutoDelete) {}

TEST(CallbackLayerAnimationObserverDestructionTest, VerifyTrueAutoDelete) {}

TEST(CallbackLayerAnimationObserverDestructionTest,
     AnimationEndedReturnsFalse) {}

TEST(CallbackLayerAnimationObserverDestructionTest, AnimationEndedReturnsTrue) {}

// Verifies that there are not heap-use-after-free errors when an observer has
// its animation aborted and it gets destroyed due to a
// unique_ptr<CallbackLayerAnimationObserver> being assigned a new value.
TEST_F(CallbackLayerAnimationObserverTestOverwrite,
       VerifyOverwriteOnAnimationStart) {}

TEST_F(CallbackLayerAnimationObserverTest, VerifyInitialState) {}

// Verifies that the CallbackLayerAnimationObserver is robust to explicit
// deletes caused as a side effect of calling the AnimationsStartedCallback()
// when there are no animation sequences attached. This test also guards against
// heap-use-after-free errors.
TEST_F(
    CallbackLayerAnimationObserverTest,
    ExplicitlyDeleteObserverInAnimationStartedCallbackWithNoSequencesAttached) {}

// Verifies that the CallbackLayerAnimationObserver is robust to explicit
// deletes caused as a side effect of calling the AnimationsStartedCallback()
// when all attached animation sequences detach. This test also guards against
// heap-use-after-free errors.
TEST_F(CallbackLayerAnimationObserverTest,
       ExplicitlyDeleteObserverInAnimationStartedCallbackSequencesDetached) {}

// Verifies that the CallbackLayerAnimationObserver is robust to explicit
// deletes caused as a side effect of calling the AnimationsStartedCallback()
// when there are some animation sequences attached. This test also guards
// against heap-use-after-free errors.
TEST_F(
    CallbackLayerAnimationObserverTest,
    ExplicitlyDeleteObserverInAnimationStartedCallbackWithSomeSequencesAttached) {}

// Verifies that a 'true' return value for AnimationEndedCallback is ignored if
// the CallbackLayerAnimationObserver is explicitly deleted as a side effect of
// calling the AnimationEndedCallback. This test also guards against
// heap-use-after-free errors.
TEST_F(CallbackLayerAnimationObserverTest,
       IgnoreTrueReturnValueForAnimationEndedCallbackIfExplicitlyDeleted) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveWhenNoSequencesWereAttached) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveWhenAllSequencesAreAttachedButNoneWereStarted) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveWhenAllSequencesAreAttachedAndOnlySomeWereStarted) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveWhenAllSequencesAreAttachedAndOnlySomeWereCompleted) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveAfterAllSequencesWereStartedButNoneWereCompleted) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveWhenAllSequencesAreStartedAndOnlySomeWereCompleted) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveWhenAllSequencesWereCompleted) {}

TEST_F(CallbackLayerAnimationObserverTest,
       SetActiveAgainAfterAllSequencesWereCompleted) {}

TEST_F(CallbackLayerAnimationObserverTest, DetachBeforeActive) {}

TEST_F(CallbackLayerAnimationObserverTest, DetachAfterActive) {}

}  // namespace test
}  // namespace ui