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

Side by Side Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 1898683002: CC Animation: Erase LayerAnimationEventObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eventobserver
Patch Set: Created 4 years, 8 months 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/animation/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "cc/animation/animation.h" 10 #include "cc/animation/animation.h"
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 controller_impl->UpdateState(true, &events); 1201 controller_impl->UpdateState(true, &events);
1202 1202
1203 // Synchronize the start times. 1203 // Synchronize the start times.
1204 EXPECT_EQ(1u, events.events_.size()); 1204 EXPECT_EQ(1u, events.events_.size());
1205 controller->NotifyAnimationStarted(events.events_[0]); 1205 controller->NotifyAnimationStarted(events.events_[0]);
1206 1206
1207 // Validate start time on the main thread delegate. 1207 // Validate start time on the main thread delegate.
1208 EXPECT_EQ(start_time, delegate.start_time()); 1208 EXPECT_EQ(start_time, delegate.start_time());
1209 } 1209 }
1210 1210
1211 class FakeLayerAnimationEventObserver : public LayerAnimationEventObserver {
1212 public:
1213 FakeLayerAnimationEventObserver() : start_time_(base::TimeTicks()) {}
1214
1215 void OnAnimationStarted(const AnimationEvent& event) override {
1216 start_time_ = event.monotonic_time;
1217 }
1218
1219 TimeTicks start_time() { return start_time_; }
1220
1221 private:
1222 TimeTicks start_time_;
1223 };
1224
1225 // Tests that specified start times are sent to the event observers
1226 TEST(LayerAnimationControllerTest, SpecifiedStartTimesAreSentToEventObservers) {
1227 FakeLayerAnimationValueObserver dummy_impl;
1228 scoped_refptr<LayerAnimationController> controller_impl(
1229 LayerAnimationController::Create(0));
1230 controller_impl->set_value_observer(&dummy_impl);
1231 controller_impl->set_needs_active_value_observations(true);
1232
1233 FakeLayerAnimationValueObserver dummy;
1234 scoped_refptr<LayerAnimationController> controller(
1235 LayerAnimationController::Create(0));
1236 controller->set_value_observer(&dummy);
1237 controller->set_needs_active_value_observations(true);
1238
1239 FakeLayerAnimationEventObserver observer;
1240 controller->SetEventObserver(&observer);
1241
1242 int animation_id =
1243 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
1244
1245 const TimeTicks start_time = TicksFromSecondsF(123);
1246 controller->GetAnimation(TargetProperty::OPACITY)->set_start_time(start_time);
1247
1248 controller->PushAnimationUpdatesTo(controller_impl.get());
1249 controller_impl->ActivateAnimations();
1250
1251 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1252 EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
1253 controller_impl->GetAnimationById(animation_id)->run_state());
1254
1255 AnimationEvents events;
1256 controller_impl->Animate(kInitialTickTime);
1257 controller_impl->UpdateState(true, &events);
1258
1259 // Synchronize the start times.
1260 EXPECT_EQ(1u, events.events_.size());
1261 controller->NotifyAnimationStarted(events.events_[0]);
1262
1263 // Validate start time on the event observer.
1264 EXPECT_EQ(start_time, observer.start_time());
1265
1266 controller->SetEventObserver(nullptr);
1267 }
1268
1269 // Tests animations that are waiting for a synchronized start time do not 1211 // Tests animations that are waiting for a synchronized start time do not
1270 // finish. 1212 // finish.
1271 TEST(LayerAnimationControllerTest, 1213 TEST(LayerAnimationControllerTest,
1272 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) { 1214 AnimationsWaitingForStartTimeDoNotFinishIfTheyOutwaitTheirFinish) {
1273 std::unique_ptr<AnimationEvents> events( 1215 std::unique_ptr<AnimationEvents> events(
1274 base::WrapUnique(new AnimationEvents)); 1216 base::WrapUnique(new AnimationEvents));
1275 FakeLayerAnimationValueObserver dummy; 1217 FakeLayerAnimationValueObserver dummy;
1276 scoped_refptr<LayerAnimationController> controller( 1218 scoped_refptr<LayerAnimationController> controller(
1277 LayerAnimationController::Create(0)); 1219 LayerAnimationController::Create(0));
1278 controller->set_value_observer(&dummy); 1220 controller->set_value_observer(&dummy);
(...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); 3154 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
3213 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( 3155 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
3214 TargetProperty::OPACITY, 3156 TargetProperty::OPACITY,
3215 LayerAnimationController::ObserverType::PENDING)); 3157 LayerAnimationController::ObserverType::PENDING));
3216 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( 3158 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
3217 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); 3159 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
3218 } 3160 }
3219 3161
3220 } // namespace 3162 } // namespace
3221 } // namespace cc 3163 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/animation/layer_animation_event_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698