1 // Copyright (c) 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 "content/browser/web_contents/aura/window_slider.h"
8 #include "base/time/time.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/test/aura_test_base.h"
11 #include "ui/aura/test/event_generator.h"
12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/window.h"
14 #include "ui/base/hit_test.h"
15 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
16 #include "ui/compositor/scoped_layer_animation_settings.h"
17 #include "ui/compositor/test/layer_animator_test_controller.h"
18 #include "ui/events/event_processor.h"
19 #include "ui/events/event_utils.h"
20 #include "ui/gfx/frame_time.h"
24 void DispatchEventDuringScrollCallback(ui::EventProcessor
* dispatcher
,
27 const gfx::Vector2dF
& delta
) {
28 if (type
!= ui::ET_GESTURE_SCROLL_UPDATE
)
30 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(event
);
31 CHECK(!details
.dispatcher_destroyed
);
34 void ChangeSliderOwnerDuringScrollCallback(scoped_ptr
<aura::Window
>* window
,
37 const gfx::Vector2dF
& delta
) {
38 if (type
!= ui::ET_GESTURE_SCROLL_UPDATE
)
40 aura::Window
* new_window
= new aura::Window(NULL
);
41 new_window
->Init(aura::WINDOW_LAYER_TEXTURED
);
43 slider
->ChangeOwner(new_window
);
44 (*window
)->parent()->AddChild(new_window
);
45 window
->reset(new_window
);
48 void ConfirmSlideDuringScrollCallback(WindowSlider
* slider
,
50 const gfx::Vector2dF
& delta
) {
51 static float total_delta_x
= 0;
52 if (type
== ui::ET_GESTURE_SCROLL_BEGIN
)
55 if (type
== ui::ET_GESTURE_SCROLL_UPDATE
) {
56 total_delta_x
+= delta
.x();
57 if (total_delta_x
>= 70)
58 EXPECT_TRUE(slider
->IsSlideInProgress());
60 EXPECT_FALSE(slider
->IsSlideInProgress());
64 void ConfirmNoSlideDuringScrollCallback(WindowSlider
* slider
,
66 const gfx::Vector2dF
& delta
) {
67 EXPECT_FALSE(slider
->IsSlideInProgress());
70 // The window delegate does not receive any events.
71 class NoEventWindowDelegate
: public aura::test::TestWindowDelegate
{
73 NoEventWindowDelegate() {
75 virtual ~NoEventWindowDelegate() {}
78 // Overridden from aura::WindowDelegate:
79 virtual bool HasHitTestMask() const OVERRIDE
{ return true; }
81 DISALLOW_COPY_AND_ASSIGN(NoEventWindowDelegate
);
84 class WindowSliderDelegateTest
: public WindowSlider::Delegate
{
86 WindowSliderDelegateTest()
87 : can_create_layer_(true),
88 created_back_layer_(false),
89 created_front_layer_(false),
90 slide_completing_(false),
91 slide_completed_(false),
92 slide_aborted_(false),
93 slider_destroyed_(false) {
95 virtual ~WindowSliderDelegateTest() {
96 // Make sure slide_completed() gets called if slide_completing() was called.
97 CHECK(!slide_completing_
|| slide_completed_
);
101 can_create_layer_
= true;
102 created_back_layer_
= false;
103 created_front_layer_
= false;
104 slide_completing_
= false;
105 slide_completed_
= false;
106 slide_aborted_
= false;
107 slider_destroyed_
= false;
110 void SetCanCreateLayer(bool can_create_layer
) {
111 can_create_layer_
= can_create_layer
;
114 bool created_back_layer() const { return created_back_layer_
; }
115 bool created_front_layer() const { return created_front_layer_
; }
116 bool slide_completing() const { return slide_completing_
; }
117 bool slide_completed() const { return slide_completed_
; }
118 bool slide_aborted() const { return slide_aborted_
; }
119 bool slider_destroyed() const { return slider_destroyed_
; }
122 ui::Layer
* CreateLayerForTest() {
123 CHECK(can_create_layer_
);
124 ui::Layer
* layer
= new ui::Layer(ui::LAYER_SOLID_COLOR
);
125 layer
->SetColor(SK_ColorRED
);
129 // Overridden from WindowSlider::Delegate:
130 virtual ui::Layer
* CreateBackLayer() OVERRIDE
{
131 if (!can_create_layer_
)
133 created_back_layer_
= true;
134 return CreateLayerForTest();
137 virtual ui::Layer
* CreateFrontLayer() OVERRIDE
{
138 if (!can_create_layer_
)
140 created_front_layer_
= true;
141 return CreateLayerForTest();
144 virtual void OnWindowSlideCompleted() OVERRIDE
{
145 slide_completed_
= true;
148 virtual void OnWindowSlideCompleting() OVERRIDE
{
149 slide_completing_
= true;
152 virtual void OnWindowSlideAborted() OVERRIDE
{
153 slide_aborted_
= true;
156 virtual void OnWindowSliderDestroyed() OVERRIDE
{
157 slider_destroyed_
= true;
161 bool can_create_layer_
;
162 bool created_back_layer_
;
163 bool created_front_layer_
;
164 bool slide_completing_
;
165 bool slide_completed_
;
167 bool slider_destroyed_
;
169 DISALLOW_COPY_AND_ASSIGN(WindowSliderDelegateTest
);
172 // This delegate destroys the owner window when the slider is destroyed.
173 class WindowSliderDeleteOwnerOnDestroy
: public WindowSliderDelegateTest
{
175 explicit WindowSliderDeleteOwnerOnDestroy(aura::Window
* owner
)
178 virtual ~WindowSliderDeleteOwnerOnDestroy() {}
181 // Overridden from WindowSlider::Delegate:
182 virtual void OnWindowSliderDestroyed() OVERRIDE
{
183 WindowSliderDelegateTest::OnWindowSliderDestroyed();
187 aura::Window
* owner_
;
188 DISALLOW_COPY_AND_ASSIGN(WindowSliderDeleteOwnerOnDestroy
);
191 // This delegate destroyes the owner window when a slide is completed.
192 class WindowSliderDeleteOwnerOnComplete
: public WindowSliderDelegateTest
{
194 explicit WindowSliderDeleteOwnerOnComplete(aura::Window
* owner
)
197 virtual ~WindowSliderDeleteOwnerOnComplete() {}
200 // Overridden from WindowSlider::Delegate:
201 virtual void OnWindowSlideCompleted() OVERRIDE
{
202 WindowSliderDelegateTest::OnWindowSlideCompleted();
206 aura::Window
* owner_
;
207 DISALLOW_COPY_AND_ASSIGN(WindowSliderDeleteOwnerOnComplete
);
210 typedef aura::test::AuraTestBase WindowSliderTest
;
212 TEST_F(WindowSliderTest
, WindowSlideUsingGesture
) {
213 scoped_ptr
<aura::Window
> window(CreateNormalWindow(0, root_window(), NULL
));
214 window
->SetBounds(gfx::Rect(0, 0, 400, 400));
215 WindowSliderDelegateTest slider_delegate
;
217 aura::test::EventGenerator
generator(root_window());
219 // Generate a horizontal overscroll.
220 WindowSlider
* slider
=
221 new WindowSlider(&slider_delegate
, root_window(), window
.get());
222 generator
.GestureScrollSequenceWithCallback(
225 base::TimeDelta::FromMilliseconds(10),
227 base::Bind(&ConfirmSlideDuringScrollCallback
, slider
));
228 EXPECT_TRUE(slider_delegate
.created_back_layer());
229 EXPECT_TRUE(slider_delegate
.slide_completing());
230 EXPECT_TRUE(slider_delegate
.slide_completed());
231 EXPECT_FALSE(slider_delegate
.created_front_layer());
232 EXPECT_FALSE(slider_delegate
.slide_aborted());
233 EXPECT_FALSE(slider_delegate
.slider_destroyed());
234 EXPECT_FALSE(slider
->IsSlideInProgress());
235 slider_delegate
.Reset();
236 window
->SetTransform(gfx::Transform());
238 // Generate a horizontal overscroll in the reverse direction.
239 generator
.GestureScrollSequenceWithCallback(
242 base::TimeDelta::FromMilliseconds(10),
244 base::Bind(&ConfirmSlideDuringScrollCallback
, slider
));
245 EXPECT_TRUE(slider_delegate
.created_front_layer());
246 EXPECT_TRUE(slider_delegate
.slide_completing());
247 EXPECT_TRUE(slider_delegate
.slide_completed());
248 EXPECT_FALSE(slider_delegate
.created_back_layer());
249 EXPECT_FALSE(slider_delegate
.slide_aborted());
250 EXPECT_FALSE(slider_delegate
.slider_destroyed());
251 EXPECT_FALSE(slider
->IsSlideInProgress());
252 slider_delegate
.Reset();
254 // Generate a vertical overscroll.
255 generator
.GestureScrollSequenceWithCallback(
258 base::TimeDelta::FromMilliseconds(10),
260 base::Bind(&ConfirmNoSlideDuringScrollCallback
, slider
));
261 EXPECT_FALSE(slider_delegate
.created_back_layer());
262 EXPECT_FALSE(slider_delegate
.slide_completing());
263 EXPECT_FALSE(slider_delegate
.slide_completed());
264 EXPECT_FALSE(slider_delegate
.created_front_layer());
265 EXPECT_FALSE(slider_delegate
.slide_aborted());
266 EXPECT_FALSE(slider
->IsSlideInProgress());
267 slider_delegate
.Reset();
269 // Generate a horizontal scroll that starts overscroll, but doesn't scroll
270 // enough to complete it.
271 generator
.GestureScrollSequenceWithCallback(
274 base::TimeDelta::FromMilliseconds(10),
276 base::Bind(&ConfirmSlideDuringScrollCallback
, slider
));
277 EXPECT_TRUE(slider_delegate
.created_back_layer());
278 EXPECT_TRUE(slider_delegate
.slide_aborted());
279 EXPECT_FALSE(slider_delegate
.created_front_layer());
280 EXPECT_FALSE(slider_delegate
.slide_completing());
281 EXPECT_FALSE(slider_delegate
.slide_completed());
282 EXPECT_FALSE(slider_delegate
.slider_destroyed());
283 EXPECT_FALSE(slider
->IsSlideInProgress());
284 slider_delegate
.Reset();
286 // Destroy the window. This should destroy the slider.
288 EXPECT_TRUE(slider_delegate
.slider_destroyed());
291 // Tests that the window slide is interrupted when a different type of event
293 TEST_F(WindowSliderTest
, WindowSlideIsCancelledOnEvent
) {
294 scoped_ptr
<aura::Window
> window(CreateNormalWindow(0, root_window(), NULL
));
295 window
->SetBounds(gfx::Rect(0, 0, 400, 400));
296 WindowSliderDelegateTest slider_delegate
;
298 ui::Event
* events
[] = {
299 new ui::MouseEvent(ui::ET_MOUSE_MOVED
,
303 new ui::KeyEvent(ui::ET_KEY_PRESSED
,
310 new WindowSlider(&slider_delegate
, root_window(), window
.get());
311 for (int i
= 0; events
[i
]; ++i
) {
312 // Generate a horizontal overscroll.
313 aura::test::EventGenerator
generator(root_window());
314 generator
.GestureScrollSequenceWithCallback(
317 base::TimeDelta::FromMilliseconds(10),
319 base::Bind(&DispatchEventDuringScrollCallback
,
320 root_window()->GetHost()->event_processor(),
321 base::Owned(events
[i
])));
322 EXPECT_TRUE(slider_delegate
.created_back_layer());
323 EXPECT_TRUE(slider_delegate
.slide_aborted());
324 EXPECT_FALSE(slider_delegate
.created_front_layer());
325 EXPECT_FALSE(slider_delegate
.slide_completing());
326 EXPECT_FALSE(slider_delegate
.slide_completed());
327 EXPECT_FALSE(slider_delegate
.slider_destroyed());
328 slider_delegate
.Reset();
331 EXPECT_TRUE(slider_delegate
.slider_destroyed());
334 // Tests that the window slide can continue after it is interrupted by another
335 // event if the user continues scrolling.
336 TEST_F(WindowSliderTest
, WindowSlideInterruptedThenContinues
) {
337 scoped_ptr
<aura::Window
> window(CreateNormalWindow(0, root_window(), NULL
));
338 window
->SetBounds(gfx::Rect(0, 0, 400, 400));
339 WindowSliderDelegateTest slider_delegate
;
341 ui::ScopedAnimationDurationScaleMode
normal_duration_(
342 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
);
343 ui::LayerAnimator
* animator
= window
->layer()->GetAnimator();
344 gfx::AnimationContainerElement
* element
= animator
;
345 animator
->set_disable_timer_for_test(true);
346 ui::LayerAnimatorTestController
test_controller(animator
);
348 WindowSlider
* slider
=
349 new WindowSlider(&slider_delegate
, root_window(), window
.get());
351 ui::MouseEvent
interrupt_event(ui::ET_MOUSE_MOVED
,
356 aura::test::EventGenerator
generator(root_window());
358 // Start the scroll sequence. Scroll forward so that |window|'s layer is the
360 const int kTouchId
= 5;
361 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
364 ui::EventTimeForNow());
365 generator
.Dispatch(&press
);
367 // First scroll event of the sequence.
368 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
,
371 ui::EventTimeForNow());
372 generator
.Dispatch(&move1
);
373 EXPECT_TRUE(slider
->IsSlideInProgress());
374 EXPECT_FALSE(animator
->is_animating());
375 // Dispatch the event after the first scroll and confirm it interrupts the
376 // scroll and starts the "reset slide" animation.
377 generator
.Dispatch(&interrupt_event
);
378 EXPECT_TRUE(slider
->IsSlideInProgress());
379 EXPECT_TRUE(animator
->is_animating());
380 EXPECT_TRUE(slider_delegate
.created_back_layer());
381 // slide_aborted() should be false because the 'reset slide' animation
382 // hasn't completed yet.
383 EXPECT_FALSE(slider_delegate
.slide_aborted());
384 EXPECT_FALSE(slider_delegate
.created_front_layer());
385 EXPECT_FALSE(slider_delegate
.slide_completing());
386 EXPECT_FALSE(slider_delegate
.slide_completed());
387 EXPECT_FALSE(slider_delegate
.slider_destroyed());
388 slider_delegate
.Reset();
390 // Second scroll event of the sequence.
391 ui::TouchEvent
move2(ui::ET_TOUCH_MOVED
,
394 ui::EventTimeForNow());
395 generator
.Dispatch(&move2
);
396 // The second scroll should instantly cause the animation to complete.
397 EXPECT_FALSE(animator
->is_animating());
398 EXPECT_FALSE(slider_delegate
.created_back_layer());
399 // The ResetScroll() animation was completed, so now slide_aborted()
401 EXPECT_TRUE(slider_delegate
.slide_aborted());
403 // Third scroll event of the sequence.
404 ui::TouchEvent
move3(ui::ET_TOUCH_MOVED
,
407 ui::EventTimeForNow());
408 generator
.Dispatch(&move3
);
409 // The third scroll should re-start the sliding.
410 EXPECT_TRUE(slider
->IsSlideInProgress());
411 EXPECT_TRUE(slider_delegate
.created_back_layer());
413 // Generate the release event, finishing the scroll sequence.
414 ui::TouchEvent
release(ui::ET_TOUCH_RELEASED
,
417 ui::EventTimeForNow());
418 generator
.Dispatch(&release
);
419 // When the scroll gesture ends, the slide animation should start.
420 EXPECT_TRUE(slider
->IsSlideInProgress());
421 EXPECT_TRUE(animator
->is_animating());
422 EXPECT_TRUE(slider_delegate
.slide_completing());
423 EXPECT_FALSE(slider_delegate
.created_front_layer());
424 EXPECT_FALSE(slider_delegate
.slide_completed());
425 EXPECT_FALSE(slider_delegate
.slider_destroyed());
427 // Progress the animator to complete the slide animation.
428 ui::ScopedLayerAnimationSettings
settings(animator
);
429 base::TimeDelta duration
= settings
.GetTransitionDuration();
430 test_controller
.StartThreadedAnimationsIfNeeded();
431 element
->Step(gfx::FrameTime::Now() + duration
);
433 EXPECT_TRUE(slider_delegate
.slide_completed());
434 EXPECT_FALSE(slider_delegate
.slider_destroyed());
437 EXPECT_TRUE(slider_delegate
.slider_destroyed());
440 // Tests that the slide works correctly when the owner of the window changes
441 // during the duration of the slide.
442 TEST_F(WindowSliderTest
, OwnerWindowChangesDuringWindowSlide
) {
443 scoped_ptr
<aura::Window
> parent(CreateNormalWindow(0, root_window(), NULL
));
445 NoEventWindowDelegate window_delegate
;
446 window_delegate
.set_window_component(HTNOWHERE
);
447 scoped_ptr
<aura::Window
> window(CreateNormalWindow(1, parent
.get(),
450 WindowSliderDelegateTest slider_delegate
;
451 scoped_ptr
<WindowSlider
> slider(
452 new WindowSlider(&slider_delegate
, parent
.get(), window
.get()));
454 // Generate a horizontal scroll, and change the owner in the middle of the
456 aura::test::EventGenerator
generator(root_window());
457 aura::Window
* old_window
= window
.get();
458 generator
.GestureScrollSequenceWithCallback(
461 base::TimeDelta::FromMilliseconds(10),
463 base::Bind(&ChangeSliderOwnerDuringScrollCallback
,
464 base::Unretained(&window
),
466 aura::Window
* new_window
= window
.get();
467 EXPECT_NE(old_window
, new_window
);
469 EXPECT_TRUE(slider_delegate
.created_back_layer());
470 EXPECT_TRUE(slider_delegate
.slide_completing());
471 EXPECT_TRUE(slider_delegate
.slide_completed());
472 EXPECT_FALSE(slider_delegate
.created_front_layer());
473 EXPECT_FALSE(slider_delegate
.slide_aborted());
474 EXPECT_FALSE(slider_delegate
.slider_destroyed());
477 // If the delegate doesn't create the layer to show while sliding, WindowSlider
478 // shouldn't start the slide or change delegate's state in any way in response
480 TEST_F(WindowSliderTest
, NoSlideWhenLayerCantBeCreated
) {
481 scoped_ptr
<aura::Window
> window(CreateNormalWindow(0, root_window(), NULL
));
482 window
->SetBounds(gfx::Rect(0, 0, 400, 400));
483 WindowSliderDelegateTest slider_delegate
;
484 slider_delegate
.SetCanCreateLayer(false);
485 WindowSlider
* slider
=
486 new WindowSlider(&slider_delegate
, root_window(), window
.get());
488 aura::test::EventGenerator
generator(root_window());
490 // No slide in progress should be reported during scroll since the layer
492 generator
.GestureScrollSequenceWithCallback(
495 base::TimeDelta::FromMilliseconds(10),
497 base::Bind(&ConfirmNoSlideDuringScrollCallback
, slider
));
499 EXPECT_FALSE(slider_delegate
.created_back_layer());
500 EXPECT_FALSE(slider_delegate
.slide_completing());
501 EXPECT_FALSE(slider_delegate
.slide_completed());
502 EXPECT_FALSE(slider_delegate
.created_front_layer());
503 EXPECT_FALSE(slider_delegate
.slide_aborted());
504 EXPECT_FALSE(slider_delegate
.slider_destroyed());
505 window
->SetTransform(gfx::Transform());
507 slider_delegate
.SetCanCreateLayer(true);
508 generator
.GestureScrollSequenceWithCallback(
511 base::TimeDelta::FromMilliseconds(10),
513 base::Bind(&ConfirmSlideDuringScrollCallback
, slider
));
514 EXPECT_TRUE(slider_delegate
.created_back_layer());
515 EXPECT_TRUE(slider_delegate
.slide_completing());
516 EXPECT_TRUE(slider_delegate
.slide_completed());
517 EXPECT_FALSE(slider_delegate
.created_front_layer());
518 EXPECT_FALSE(slider_delegate
.slide_aborted());
519 EXPECT_FALSE(slider_delegate
.slider_destroyed());
522 EXPECT_TRUE(slider_delegate
.slider_destroyed());
525 // Tests that the owner window can be destroyed from |OnWindowSliderDestroyed()|
526 // delegate callback without causing a crash.
527 TEST_F(WindowSliderTest
, OwnerIsDestroyedOnSliderDestroy
) {
528 size_t child_windows
= root_window()->children().size();
529 aura::Window
* window
= CreateNormalWindow(0, root_window(), NULL
);
530 window
->SetBounds(gfx::Rect(0, 0, 400, 400));
531 EXPECT_EQ(child_windows
+ 1, root_window()->children().size());
533 WindowSliderDeleteOwnerOnDestroy
slider_delegate(window
);
534 aura::test::EventGenerator
generator(root_window());
536 // Generate a horizontal overscroll.
537 scoped_ptr
<WindowSlider
> slider(
538 new WindowSlider(&slider_delegate
, root_window(), window
));
539 generator
.GestureScrollSequence(gfx::Point(10, 10),
541 base::TimeDelta::FromMilliseconds(10),
543 EXPECT_TRUE(slider_delegate
.created_back_layer());
544 EXPECT_TRUE(slider_delegate
.slide_completing());
545 EXPECT_TRUE(slider_delegate
.slide_completed());
546 EXPECT_FALSE(slider_delegate
.created_front_layer());
547 EXPECT_FALSE(slider_delegate
.slide_aborted());
548 EXPECT_FALSE(slider_delegate
.slider_destroyed());
551 // Destroying the slider would have destroyed |window| too. So |window| should
552 // not need to be destroyed here.
553 EXPECT_EQ(child_windows
, root_window()->children().size());
556 // Tests that the owner window can be destroyed from |OnWindowSlideComplete()|
557 // delegate callback without causing a crash.
558 TEST_F(WindowSliderTest
, OwnerIsDestroyedOnSlideComplete
) {
559 size_t child_windows
= root_window()->children().size();
560 aura::Window
* window
= CreateNormalWindow(0, root_window(), NULL
);
561 window
->SetBounds(gfx::Rect(0, 0, 400, 400));
562 EXPECT_EQ(child_windows
+ 1, root_window()->children().size());
564 WindowSliderDeleteOwnerOnComplete
slider_delegate(window
);
565 aura::test::EventGenerator
generator(root_window());
567 // Generate a horizontal overscroll.
568 new WindowSlider(&slider_delegate
, root_window(), window
);
569 generator
.GestureScrollSequence(gfx::Point(10, 10),
571 base::TimeDelta::FromMilliseconds(10),
573 EXPECT_TRUE(slider_delegate
.created_back_layer());
574 EXPECT_TRUE(slider_delegate
.slide_completing());
575 EXPECT_TRUE(slider_delegate
.slide_completed());
576 EXPECT_FALSE(slider_delegate
.created_front_layer());
577 EXPECT_FALSE(slider_delegate
.slide_aborted());
578 EXPECT_TRUE(slider_delegate
.slider_destroyed());
580 // Destroying the slider would have destroyed |window| too. So |window| should
581 // not need to be destroyed here.
582 EXPECT_EQ(child_windows
, root_window()->children().size());
585 // Test the scenario when two swipe gesture occur quickly one after another so
586 // that the second swipe occurs while the transition animation triggered by the
587 // first swipe is in progress.
588 // The second swipe is supposed to instantly complete the animation caused by
589 // the first swipe, ask the delegate to create a new layer, and animate it.
590 TEST_F(WindowSliderTest
, SwipeDuringSwipeAnimation
) {
591 scoped_ptr
<aura::Window
> window(CreateNormalWindow(0, root_window(), NULL
));
592 window
->SetBounds(gfx::Rect(0, 0, 400, 400));
593 WindowSliderDelegateTest slider_delegate
;
594 new WindowSlider(&slider_delegate
, root_window(), window
.get());
596 ui::ScopedAnimationDurationScaleMode
normal_duration_(
597 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
);
598 ui::LayerAnimator
* animator
= window
->layer()->GetAnimator();
599 gfx::AnimationContainerElement
* element
= animator
;
600 animator
->set_disable_timer_for_test(true);
601 ui::LayerAnimatorTestController
test_controller(animator
);
603 aura::test::EventGenerator
generator(root_window());
605 // Swipe forward so that |window|'s layer is the one animating.
606 generator
.GestureScrollSequence(
609 base::TimeDelta::FromMilliseconds(10),
611 EXPECT_TRUE(slider_delegate
.created_back_layer());
612 EXPECT_FALSE(slider_delegate
.slide_aborted());
613 EXPECT_FALSE(slider_delegate
.created_front_layer());
614 EXPECT_TRUE(slider_delegate
.slide_completing());
615 EXPECT_FALSE(slider_delegate
.slide_completed());
616 EXPECT_FALSE(slider_delegate
.slider_destroyed());
617 ui::ScopedLayerAnimationSettings
settings(animator
);
618 base::TimeDelta duration
= settings
.GetTransitionDuration();
619 test_controller
.StartThreadedAnimationsIfNeeded();
620 base::TimeTicks start_time1
= gfx::FrameTime::Now();
622 element
->Step(start_time1
+ duration
/2);
623 EXPECT_FALSE(slider_delegate
.slide_completed());
624 slider_delegate
.Reset();
625 // Generate another horizontal swipe while the animation from the previous
626 // swipe is in progress.
627 generator
.GestureScrollSequence(
630 base::TimeDelta::FromMilliseconds(10),
632 // Performing the second swipe should instantly complete the slide started
633 // by the first swipe and create a new layer.
634 EXPECT_TRUE(slider_delegate
.created_back_layer());
635 EXPECT_FALSE(slider_delegate
.slide_aborted());
636 EXPECT_FALSE(slider_delegate
.created_front_layer());
637 EXPECT_TRUE(slider_delegate
.slide_completing());
638 EXPECT_TRUE(slider_delegate
.slide_completed());
639 EXPECT_FALSE(slider_delegate
.slider_destroyed());
640 test_controller
.StartThreadedAnimationsIfNeeded();
641 base::TimeTicks start_time2
= gfx::FrameTime::Now();
642 slider_delegate
.Reset();
643 element
->Step(start_time2
+ duration
);
644 // The animation for the second slide should now be completed.
645 EXPECT_TRUE(slider_delegate
.slide_completed());
646 slider_delegate
.Reset();
649 EXPECT_TRUE(slider_delegate
.slider_destroyed());
652 } // namespace content