158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// found in the LICENSE file.
458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/compositor/transform_animation_curve_adapter.h"
658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include <sstream>
858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/time/time.h"
1058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
1158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/compositor/test/test_utils.h"
1258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)namespace ui {
1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)namespace {
1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Check that the inverse transform curve gives the gives a transform that when
1858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// applied on top of the parent transform gives the original transform
1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST(InverseTransformCurveAdapterTest, InversesTransform) {
2058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform parent_start, parent_target;
2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  parent_start.Scale(0.5, 3.0);
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  parent_start.Translate(-20.0, 30.0);
2358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  parent_target.Translate(0, 100);
2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform child_transform;
2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  child_transform.Rotate(-30.0);
2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  base::TimeDelta duration = base::TimeDelta::FromSeconds(1);
2958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const gfx::Transform effective_child_transform =
3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      parent_start * child_transform;
3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
33d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  TransformAnimationCurveAdapter parent_curve(gfx::Tween::LINEAR,
3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                              parent_start,
3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                              parent_target,
3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                              duration);
3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  InverseTransformCurveAdapter child_curve(parent_curve,
3958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                           child_transform,
4058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                           duration);
4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static const int kSteps = 1000;
4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  double step = 1.0 / kSteps;
4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  for (int i = 0; i <= kSteps ; ++i) {
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    std::ostringstream message;
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    message << "Step " << i << " of " << kSteps;
4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    SCOPED_TRACE(message.str());
4758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    gfx::Transform progress_parent_transform =
4858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            parent_curve.GetValue(i*step);
4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    gfx::Transform progress_child_transform =
5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            child_curve.GetValue(i*step);
5158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    CheckApproximatelyEqual(effective_child_transform,
5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                            progress_parent_transform *
5358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                            progress_child_transform);
5458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
5558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
5658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
5758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} // namespace
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} // namespace ui
60