chromium/ui/compositor/layer_animation_sequence_unittest.cc

// Copyright 2012 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/layer_animation_sequence.h"

#include <memory>

#include "base/compiler_specific.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/layer_animation_delegate.h"
#include "ui/compositor/layer_animation_element.h"
#include "ui/compositor/test/test_layer_animation_delegate.h"
#include "ui/compositor/test/test_layer_animation_observer.h"
#include "ui/compositor/test/test_utils.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/transform.h"

namespace ui {

namespace {

// Check that the sequence behaves sanely when it contains no elements.
TEST(LayerAnimationSequenceTest, NoElement) {}

// Check that the sequences progresses the delegate as expected when it contains
// a single non-threaded element.
TEST(LayerAnimationSequenceTest, SingleElement) {}

// Check that the sequences progresses the delegate as expected when it contains
// a single threaded element.
TEST(LayerAnimationSequenceTest, SingleThreadedElement) {}

// Check that the sequences progresses the delegate as expected when it contains
// multiple elements. Note, see the layer animator tests for repeating
// sequences.
TEST(LayerAnimationSequenceTest, MultipleElement) {}

// Check that a sequence can still be aborted if it has repeated many times.
TEST(LayerAnimationSequenceTest, AbortingRepeatingSequence) {}

// Check that a sequence can be 'fast-forwarded' to the end and the target set.
// Also check that this has no effect if the sequence is repeating.
TEST(LayerAnimationSequenceTest, SetTarget) {}

TEST(LayerAnimationSequenceTest, AddObserver) {}

TEST(LayerAnimationSequenceTest, ToString) {}

// TODO(b/352744702): Remove this test or convert to DEATH test after
// https://crrev.com/c/5713998 has rolled out and any cases like this have been
// removed.
#if !DCHECK_IS_ON()
// Check that the sequence doesn't get stuck in an infinite loop when it's
// repeating and has a total duration of zero.
TEST(LayerAnimationSequenceTest, RepeatingWithZeroDuration) {
  const float final_brightness = 1.f;
  const int num_steps_to_test = 3;
  const base::TimeDelta animation_step_size = base::Seconds(1);

  LayerAnimationSequence sequence;
  sequence.set_is_repeating(true);
  sequence.AddElement(
      LayerAnimationElement::CreateBrightnessElement(0.5f, base::TimeDelta()));
  sequence.AddElement(LayerAnimationElement::CreateBrightnessElement(
      final_brightness, base::TimeDelta()));
  TestLayerAnimationDelegate delegate;
  delegate.SetBrightnessFromAnimation(0.f,
                                      PropertyChangeReason::NOT_FROM_ANIMATION);

  base::TimeTicks now = base::TimeTicks::Now();
  sequence.set_start_time(now);
  sequence.Start(&delegate);
  for (int i = 0; i < num_steps_to_test; ++i, now += animation_step_size) {
    sequence.Progress(now, &delegate);
    EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), final_brightness);
  }
}
#endif

} // namespace

} // namespace ui