1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/compositor/transform_animation_curve_adapter.h"
9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/compositor/test/test_utils.h"
17 // Check that the inverse transform curve gives the gives a transform that when
18 // applied on top of the parent transform gives the original transform
19 TEST(InverseTransformCurveAdapterTest
, InversesTransform
) {
20 gfx::Transform parent_start
, parent_target
;
21 parent_start
.Scale(0.5, 3.0);
22 parent_start
.Translate(-20.0, 30.0);
23 parent_target
.Translate(0, 100);
25 gfx::Transform child_transform
;
26 child_transform
.Rotate(-30.0);
28 base::TimeDelta duration
= base::TimeDelta::FromSeconds(1);
30 const gfx::Transform effective_child_transform
=
31 parent_start
* child_transform
;
33 TransformAnimationCurveAdapter
parent_curve(gfx::Tween::LINEAR
,
38 InverseTransformCurveAdapter
child_curve(parent_curve
,
41 static const int kSteps
= 1000;
42 double step
= 1.0 / kSteps
;
43 for (int i
= 0; i
<= kSteps
; ++i
) {
44 std::ostringstream message
;
45 message
<< "Step " << i
<< " of " << kSteps
;
46 SCOPED_TRACE(message
.str());
47 gfx::Transform progress_parent_transform
=
48 parent_curve
.GetValue(i
*step
);
49 gfx::Transform progress_child_transform
=
50 child_curve
.GetValue(i
*step
);
51 CheckApproximatelyEqual(effective_child_transform
,
52 progress_parent_transform
*
53 progress_child_transform
);