1 // Copyright 2015 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 "ash/rotator/screen_rotation_animation.h"
6 #include "ash/test/ash_test_base.h"
7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/aura/window.h"
12 #include "ui/compositor/layer.h"
13 #include "ui/compositor/layer_animation_sequence.h"
14 #include "ui/compositor/layer_animator.h"
15 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
16 #include "ui/gfx/animation/tween.h"
17 #include "ui/gfx/transform.h"
22 class ScreenRotationAnimationTest
: public AshTestBase
{
24 ScreenRotationAnimationTest() {}
25 ~ScreenRotationAnimationTest() override
{}
28 void SetUp() override
;
31 scoped_ptr
<ui::ScopedAnimationDurationScaleMode
> non_zero_duration_mode_
;
33 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimationTest
);
36 void ScreenRotationAnimationTest::SetUp() {
38 non_zero_duration_mode_
.reset(new ui::ScopedAnimationDurationScaleMode(
39 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION
));
42 TEST_F(ScreenRotationAnimationTest
, LayerTransformGetsSetToTargetWhenAborted
) {
43 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithId(9));
44 ui::Layer
* layer
= window
->layer();
46 scoped_ptr
<ScreenRotationAnimation
> screen_rotation(
47 new ScreenRotationAnimation(
48 layer
, 45 /* start_degrees */, 0 /* end_degrees */,
49 0.5f
/* initial_opacity */, 1.0f
/* target_opacity */,
50 gfx::Point(10, 10) /* pivot */,
51 base::TimeDelta::FromSeconds(10) /* duration */, gfx::Tween::LINEAR
));
53 ui::LayerAnimator
* animator
= layer
->GetAnimator();
54 animator
->set_preemption_strategy(
55 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS
);
56 scoped_ptr
<ui::LayerAnimationSequence
> animation_sequence(
57 new ui::LayerAnimationSequence(screen_rotation
.release()));
58 animator
->StartAnimation(animation_sequence
.release());
60 const gfx::Transform identity_transform
;
62 ASSERT_EQ(identity_transform
, layer
->GetTargetTransform());
63 ASSERT_NE(identity_transform
, layer
->transform());
65 layer
->GetAnimator()->AbortAllAnimations();
67 EXPECT_EQ(identity_transform
, layer
->transform());