Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: ui/compositor/layer_animator_unittest.cc

Issue 2550933002: Make all LayerAnimationElement::Create*Element return unique_ptr (Closed)
Patch Set: More change and typo fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/layer_animator.h" 5 #include "ui/compositor/layer_animator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 26 matching lines...) Expand all
37 // space and the order if A R G B. 37 // space and the order if A R G B.
38 std::string ColorToString(SkColor color) { 38 std::string ColorToString(SkColor color) {
39 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), 39 return base::StringPrintf("%d %d %d %d", SkColorGetA(color),
40 SkColorGetR(color), SkColorGetG(color), 40 SkColorGetR(color), SkColorGetG(color),
41 SkColorGetB(color)); 41 SkColorGetB(color));
42 } 42 }
43 43
44 // Creates vector with two LayerAnimationSequences, based on |first| and 44 // Creates vector with two LayerAnimationSequences, based on |first| and
45 // |second| layer animation elements. 45 // |second| layer animation elements.
46 std::vector<LayerAnimationSequence*> CreateMultiSequence( 46 std::vector<LayerAnimationSequence*> CreateMultiSequence(
47 LayerAnimationElement* first, 47 std::unique_ptr<LayerAnimationElement> first,
48 LayerAnimationElement* second) { 48 std::unique_ptr<LayerAnimationElement> second) {
49 LayerAnimationSequence* first_sequence = new LayerAnimationSequence(); 49 LayerAnimationSequence* first_sequence = new LayerAnimationSequence();
50 first_sequence->AddElement(first); 50 first_sequence->AddElement(std::move(first));
51 LayerAnimationSequence* second_sequence = new LayerAnimationSequence(); 51 LayerAnimationSequence* second_sequence = new LayerAnimationSequence();
52 second_sequence->AddElement(second); 52 second_sequence->AddElement(std::move(second));
53 53
54 std::vector<ui::LayerAnimationSequence*> animations; 54 std::vector<ui::LayerAnimationSequence*> animations;
55 animations.push_back(first_sequence); 55 animations.push_back(first_sequence);
56 animations.push_back(second_sequence); 56 animations.push_back(second_sequence);
57 return animations; 57 return animations;
58 } 58 }
59 59
60 // Creates a default animator with timers disabled for test. |delegate| and 60 // Creates a default animator with timers disabled for test. |delegate| and
61 // |observer| are attached if non-null. 61 // |observer| are attached if non-null.
62 LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate, 62 LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 private: 235 private:
236 LayerAnimatorDestructionObserver* destruction_observer_; 236 LayerAnimatorDestructionObserver* destruction_observer_;
237 237
238 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); 238 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator);
239 }; 239 };
240 240
241 // The test layer animation sequence updates a live instances count when it is 241 // The test layer animation sequence updates a live instances count when it is
242 // created and destroyed. 242 // created and destroyed.
243 class TestLayerAnimationSequence : public LayerAnimationSequence { 243 class TestLayerAnimationSequence : public LayerAnimationSequence {
244 public: 244 public:
245 TestLayerAnimationSequence(LayerAnimationElement* element, 245 TestLayerAnimationSequence(std::unique_ptr<LayerAnimationElement> element,
246 int* num_live_instances) 246 int* num_live_instances)
247 : LayerAnimationSequence(element), 247 : LayerAnimationSequence(std::move(element)),
248 num_live_instances_(num_live_instances) { 248 num_live_instances_(num_live_instances) {
249 (*num_live_instances_)++; 249 (*num_live_instances_)++;
250 } 250 }
251 251
252 ~TestLayerAnimationSequence() override { (*num_live_instances_)--; } 252 ~TestLayerAnimationSequence() override { (*num_live_instances_)--; }
253 253
254 private: 254 private:
255 int* num_live_instances_; 255 int* num_live_instances_;
256 256
257 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); 257 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence);
(...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 TestLayerAnimationDelegate delegate; 2099 TestLayerAnimationDelegate delegate;
2100 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate)); 2100 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2101 2101
2102 double start_opacity(0.0); 2102 double start_opacity(0.0);
2103 double target_opacity(1.0); 2103 double target_opacity(1.0);
2104 2104
2105 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 2105 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
2106 2106
2107 delegate.SetOpacityFromAnimation(start_opacity); 2107 delegate.SetOpacityFromAnimation(start_opacity);
2108 2108
2109 std::unique_ptr<LayerAnimationSequence> sequence(new LayerAnimationSequence( 2109 std::unique_ptr<LayerAnimationSequence> sequence =
2110 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 2110 base::MakeUnique<LayerAnimationSequence>(
2111 LayerAnimationElement::CreateOpacityElement(target_opacity, delta));
2111 2112
2112 animator->StartAnimation(sequence.release()); 2113 animator->StartAnimation(sequence.release());
2113 2114
2114 animator->SetOpacity(0.5); 2115 animator->SetOpacity(0.5);
2115 2116
2116 EXPECT_FALSE(animator->is_animating()); 2117 EXPECT_FALSE(animator->is_animating());
2117 EXPECT_EQ(0.5, animator->GetTargetOpacity()); 2118 EXPECT_EQ(0.5, animator->GetTargetOpacity());
2118 } 2119 }
2119 2120
2120 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the 2121 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the
(...skipping 12 matching lines...) Expand all
2133 { 2134 {
2134 // start an implicit bounds animation. 2135 // start an implicit bounds animation.
2135 ScopedLayerAnimationSettings settings(animator.get()); 2136 ScopedLayerAnimationSettings settings(animator.get());
2136 animator->SetBounds(middle_bounds); 2137 animator->SetBounds(middle_bounds);
2137 } 2138 }
2138 2139
2139 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 2140 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2140 2141
2141 int num_live_instances = 0; 2142 int num_live_instances = 0;
2142 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 2143 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
2143 std::unique_ptr<TestLayerAnimationSequence> sequence( 2144 std::unique_ptr<TestLayerAnimationSequence> sequence =
2144 new TestLayerAnimationSequence( 2145 base::MakeUnique<TestLayerAnimationSequence>(
2145 LayerAnimationElement::CreateBoundsElement(target_bounds, delta), 2146 LayerAnimationElement::CreateBoundsElement(target_bounds, delta),
2146 &num_live_instances)); 2147 &num_live_instances);
2147 2148
2148 EXPECT_EQ(1, num_live_instances); 2149 EXPECT_EQ(1, num_live_instances);
2149 2150
2150 // This should interrupt the running sequence causing us to immediately set 2151 // This should interrupt the running sequence causing us to immediately set
2151 // the target value. The sequence should alse be destructed. 2152 // the target value. The sequence should alse be destructed.
2152 animator->StartAnimation(sequence.release()); 2153 animator->StartAnimation(sequence.release());
2153 2154
2154 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 2155 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2155 EXPECT_EQ(0, num_live_instances); 2156 EXPECT_EQ(0, num_live_instances);
2156 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 2157 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
2945 EXPECT_EQ(observer.last_ended_sequence(), nullptr); 2946 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2946 EXPECT_EQ(observer.last_detached_sequence(), first_sequence); 2947 EXPECT_EQ(observer.last_detached_sequence(), first_sequence);
2947 2948
2948 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch()); 2949 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch());
2949 EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch()); 2950 EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch());
2950 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch()); 2951 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
2951 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch()); 2952 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
2952 } 2953 }
2953 2954
2954 } // namespace ui 2955 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698