OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/web_contents/aura/window_slider.h" | 5 #include "content/browser/web_contents/aura/window_slider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/test/aura_test_base.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" | 11 #include "ui/aura/test/test_window_delegate.h" |
13 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
14 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
16 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
17 #include "ui/compositor/test/layer_animator_test_controller.h" | 16 #include "ui/compositor/test/layer_animator_test_controller.h" |
18 #include "ui/events/event_processor.h" | 17 #include "ui/events/event_processor.h" |
19 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
| 19 #include "ui/events/test/event_generator.h" |
20 #include "ui/gfx/frame_time.h" | 20 #include "ui/gfx/frame_time.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 void DispatchEventDuringScrollCallback(ui::EventProcessor* dispatcher, | 24 void DispatchEventDuringScrollCallback(ui::EventProcessor* dispatcher, |
25 ui::Event* event, | 25 ui::Event* event, |
26 ui::EventType type, | 26 ui::EventType type, |
27 const gfx::Vector2dF& delta) { | 27 const gfx::Vector2dF& delta) { |
28 if (type != ui::ET_GESTURE_SCROLL_UPDATE) | 28 if (type != ui::ET_GESTURE_SCROLL_UPDATE) |
29 return; | 29 return; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 DISALLOW_COPY_AND_ASSIGN(WindowSliderDeleteOwnerOnComplete); | 207 DISALLOW_COPY_AND_ASSIGN(WindowSliderDeleteOwnerOnComplete); |
208 }; | 208 }; |
209 | 209 |
210 typedef aura::test::AuraTestBase WindowSliderTest; | 210 typedef aura::test::AuraTestBase WindowSliderTest; |
211 | 211 |
212 TEST_F(WindowSliderTest, WindowSlideUsingGesture) { | 212 TEST_F(WindowSliderTest, WindowSlideUsingGesture) { |
213 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); | 213 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); |
214 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 214 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
215 WindowSliderDelegateTest slider_delegate; | 215 WindowSliderDelegateTest slider_delegate; |
216 | 216 |
217 aura::test::EventGenerator generator(root_window()); | 217 ui::test::EventGenerator generator(root_window()); |
218 | 218 |
219 // Generate a horizontal overscroll. | 219 // Generate a horizontal overscroll. |
220 WindowSlider* slider = | 220 WindowSlider* slider = |
221 new WindowSlider(&slider_delegate, root_window(), window.get()); | 221 new WindowSlider(&slider_delegate, root_window(), window.get()); |
222 generator.GestureScrollSequenceWithCallback( | 222 generator.GestureScrollSequenceWithCallback( |
223 gfx::Point(10, 10), | 223 gfx::Point(10, 10), |
224 gfx::Point(180, 10), | 224 gfx::Point(180, 10), |
225 base::TimeDelta::FromMilliseconds(10), | 225 base::TimeDelta::FromMilliseconds(10), |
226 10, | 226 10, |
227 base::Bind(&ConfirmSlideDuringScrollCallback, slider)); | 227 base::Bind(&ConfirmSlideDuringScrollCallback, slider)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 new ui::KeyEvent(ui::ET_KEY_PRESSED, | 303 new ui::KeyEvent(ui::ET_KEY_PRESSED, |
304 ui::VKEY_A, | 304 ui::VKEY_A, |
305 0, | 305 0, |
306 true), | 306 true), |
307 NULL | 307 NULL |
308 }; | 308 }; |
309 | 309 |
310 new WindowSlider(&slider_delegate, root_window(), window.get()); | 310 new WindowSlider(&slider_delegate, root_window(), window.get()); |
311 for (int i = 0; events[i]; ++i) { | 311 for (int i = 0; events[i]; ++i) { |
312 // Generate a horizontal overscroll. | 312 // Generate a horizontal overscroll. |
313 aura::test::EventGenerator generator(root_window()); | 313 ui::test::EventGenerator generator(root_window()); |
314 generator.GestureScrollSequenceWithCallback( | 314 generator.GestureScrollSequenceWithCallback( |
315 gfx::Point(10, 10), | 315 gfx::Point(10, 10), |
316 gfx::Point(80, 10), | 316 gfx::Point(80, 10), |
317 base::TimeDelta::FromMilliseconds(10), | 317 base::TimeDelta::FromMilliseconds(10), |
318 1, | 318 1, |
319 base::Bind(&DispatchEventDuringScrollCallback, | 319 base::Bind(&DispatchEventDuringScrollCallback, |
320 root_window()->GetHost()->event_processor(), | 320 root_window()->GetHost()->event_processor(), |
321 base::Owned(events[i]))); | 321 base::Owned(events[i]))); |
322 EXPECT_TRUE(slider_delegate.created_back_layer()); | 322 EXPECT_TRUE(slider_delegate.created_back_layer()); |
323 EXPECT_TRUE(slider_delegate.slide_aborted()); | 323 EXPECT_TRUE(slider_delegate.slide_aborted()); |
(...skipping 21 matching lines...) Expand all Loading... |
345 ui::LayerAnimatorTestController test_controller(animator); | 345 ui::LayerAnimatorTestController test_controller(animator); |
346 | 346 |
347 WindowSlider* slider = | 347 WindowSlider* slider = |
348 new WindowSlider(&slider_delegate, root_window(), window.get()); | 348 new WindowSlider(&slider_delegate, root_window(), window.get()); |
349 | 349 |
350 ui::MouseEvent interrupt_event(ui::ET_MOUSE_MOVED, | 350 ui::MouseEvent interrupt_event(ui::ET_MOUSE_MOVED, |
351 gfx::Point(55, 10), | 351 gfx::Point(55, 10), |
352 gfx::Point(55, 10), | 352 gfx::Point(55, 10), |
353 0, 0); | 353 0, 0); |
354 | 354 |
355 aura::test::EventGenerator generator(root_window()); | 355 ui::test::EventGenerator generator(root_window()); |
356 | 356 |
357 // Start the scroll sequence. Scroll forward so that |window|'s layer is the | 357 // Start the scroll sequence. Scroll forward so that |window|'s layer is the |
358 // one animating. | 358 // one animating. |
359 const int kTouchId = 5; | 359 const int kTouchId = 5; |
360 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 360 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
361 gfx::Point(10, 10), | 361 gfx::Point(10, 10), |
362 kTouchId, | 362 kTouchId, |
363 ui::EventTimeForNow()); | 363 ui::EventTimeForNow()); |
364 generator.Dispatch(&press); | 364 generator.Dispatch(&press); |
365 | 365 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 window_delegate.set_window_component(HTNOWHERE); | 445 window_delegate.set_window_component(HTNOWHERE); |
446 scoped_ptr<aura::Window> window(CreateNormalWindow(1, parent.get(), | 446 scoped_ptr<aura::Window> window(CreateNormalWindow(1, parent.get(), |
447 &window_delegate)); | 447 &window_delegate)); |
448 | 448 |
449 WindowSliderDelegateTest slider_delegate; | 449 WindowSliderDelegateTest slider_delegate; |
450 scoped_ptr<WindowSlider> slider( | 450 scoped_ptr<WindowSlider> slider( |
451 new WindowSlider(&slider_delegate, parent.get(), window.get())); | 451 new WindowSlider(&slider_delegate, parent.get(), window.get())); |
452 | 452 |
453 // Generate a horizontal scroll, and change the owner in the middle of the | 453 // Generate a horizontal scroll, and change the owner in the middle of the |
454 // scroll. | 454 // scroll. |
455 aura::test::EventGenerator generator(root_window()); | 455 ui::test::EventGenerator generator(root_window()); |
456 aura::Window* old_window = window.get(); | 456 aura::Window* old_window = window.get(); |
457 generator.GestureScrollSequenceWithCallback( | 457 generator.GestureScrollSequenceWithCallback( |
458 gfx::Point(10, 10), | 458 gfx::Point(10, 10), |
459 gfx::Point(80, 10), | 459 gfx::Point(80, 10), |
460 base::TimeDelta::FromMilliseconds(10), | 460 base::TimeDelta::FromMilliseconds(10), |
461 1, | 461 1, |
462 base::Bind(&ChangeSliderOwnerDuringScrollCallback, | 462 base::Bind(&ChangeSliderOwnerDuringScrollCallback, |
463 base::Unretained(&window), | 463 base::Unretained(&window), |
464 slider.get())); | 464 slider.get())); |
465 aura::Window* new_window = window.get(); | 465 aura::Window* new_window = window.get(); |
(...skipping 11 matching lines...) Expand all Loading... |
477 // shouldn't start the slide or change delegate's state in any way in response | 477 // shouldn't start the slide or change delegate's state in any way in response |
478 // to user input. | 478 // to user input. |
479 TEST_F(WindowSliderTest, NoSlideWhenLayerCantBeCreated) { | 479 TEST_F(WindowSliderTest, NoSlideWhenLayerCantBeCreated) { |
480 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); | 480 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); |
481 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 481 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
482 WindowSliderDelegateTest slider_delegate; | 482 WindowSliderDelegateTest slider_delegate; |
483 slider_delegate.SetCanCreateLayer(false); | 483 slider_delegate.SetCanCreateLayer(false); |
484 WindowSlider* slider = | 484 WindowSlider* slider = |
485 new WindowSlider(&slider_delegate, root_window(), window.get()); | 485 new WindowSlider(&slider_delegate, root_window(), window.get()); |
486 | 486 |
487 aura::test::EventGenerator generator(root_window()); | 487 ui::test::EventGenerator generator(root_window()); |
488 | 488 |
489 // No slide in progress should be reported during scroll since the layer | 489 // No slide in progress should be reported during scroll since the layer |
490 // wasn't created. | 490 // wasn't created. |
491 generator.GestureScrollSequenceWithCallback( | 491 generator.GestureScrollSequenceWithCallback( |
492 gfx::Point(10, 10), | 492 gfx::Point(10, 10), |
493 gfx::Point(180, 10), | 493 gfx::Point(180, 10), |
494 base::TimeDelta::FromMilliseconds(10), | 494 base::TimeDelta::FromMilliseconds(10), |
495 1, | 495 1, |
496 base::Bind(&ConfirmNoSlideDuringScrollCallback, slider)); | 496 base::Bind(&ConfirmNoSlideDuringScrollCallback, slider)); |
497 | 497 |
(...skipping 25 matching lines...) Expand all Loading... |
523 | 523 |
524 // Tests that the owner window can be destroyed from |OnWindowSliderDestroyed()| | 524 // Tests that the owner window can be destroyed from |OnWindowSliderDestroyed()| |
525 // delegate callback without causing a crash. | 525 // delegate callback without causing a crash. |
526 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSliderDestroy) { | 526 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSliderDestroy) { |
527 size_t child_windows = root_window()->children().size(); | 527 size_t child_windows = root_window()->children().size(); |
528 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); | 528 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); |
529 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 529 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
530 EXPECT_EQ(child_windows + 1, root_window()->children().size()); | 530 EXPECT_EQ(child_windows + 1, root_window()->children().size()); |
531 | 531 |
532 WindowSliderDeleteOwnerOnDestroy slider_delegate(window); | 532 WindowSliderDeleteOwnerOnDestroy slider_delegate(window); |
533 aura::test::EventGenerator generator(root_window()); | 533 ui::test::EventGenerator generator(root_window()); |
534 | 534 |
535 // Generate a horizontal overscroll. | 535 // Generate a horizontal overscroll. |
536 scoped_ptr<WindowSlider> slider( | 536 scoped_ptr<WindowSlider> slider( |
537 new WindowSlider(&slider_delegate, root_window(), window)); | 537 new WindowSlider(&slider_delegate, root_window(), window)); |
538 generator.GestureScrollSequence(gfx::Point(10, 10), | 538 generator.GestureScrollSequence(gfx::Point(10, 10), |
539 gfx::Point(180, 10), | 539 gfx::Point(180, 10), |
540 base::TimeDelta::FromMilliseconds(10), | 540 base::TimeDelta::FromMilliseconds(10), |
541 10); | 541 10); |
542 EXPECT_TRUE(slider_delegate.created_back_layer()); | 542 EXPECT_TRUE(slider_delegate.created_back_layer()); |
543 EXPECT_TRUE(slider_delegate.slide_completing()); | 543 EXPECT_TRUE(slider_delegate.slide_completing()); |
(...skipping 10 matching lines...) Expand all Loading... |
554 | 554 |
555 // Tests that the owner window can be destroyed from |OnWindowSlideComplete()| | 555 // Tests that the owner window can be destroyed from |OnWindowSlideComplete()| |
556 // delegate callback without causing a crash. | 556 // delegate callback without causing a crash. |
557 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSlideComplete) { | 557 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSlideComplete) { |
558 size_t child_windows = root_window()->children().size(); | 558 size_t child_windows = root_window()->children().size(); |
559 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); | 559 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); |
560 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 560 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
561 EXPECT_EQ(child_windows + 1, root_window()->children().size()); | 561 EXPECT_EQ(child_windows + 1, root_window()->children().size()); |
562 | 562 |
563 WindowSliderDeleteOwnerOnComplete slider_delegate(window); | 563 WindowSliderDeleteOwnerOnComplete slider_delegate(window); |
564 aura::test::EventGenerator generator(root_window()); | 564 ui::test::EventGenerator generator(root_window()); |
565 | 565 |
566 // Generate a horizontal overscroll. | 566 // Generate a horizontal overscroll. |
567 new WindowSlider(&slider_delegate, root_window(), window); | 567 new WindowSlider(&slider_delegate, root_window(), window); |
568 generator.GestureScrollSequence(gfx::Point(10, 10), | 568 generator.GestureScrollSequence(gfx::Point(10, 10), |
569 gfx::Point(180, 10), | 569 gfx::Point(180, 10), |
570 base::TimeDelta::FromMilliseconds(10), | 570 base::TimeDelta::FromMilliseconds(10), |
571 10); | 571 10); |
572 EXPECT_TRUE(slider_delegate.created_back_layer()); | 572 EXPECT_TRUE(slider_delegate.created_back_layer()); |
573 EXPECT_TRUE(slider_delegate.slide_completing()); | 573 EXPECT_TRUE(slider_delegate.slide_completing()); |
574 EXPECT_TRUE(slider_delegate.slide_completed()); | 574 EXPECT_TRUE(slider_delegate.slide_completed()); |
(...skipping 16 matching lines...) Expand all Loading... |
591 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 591 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
592 WindowSliderDelegateTest slider_delegate; | 592 WindowSliderDelegateTest slider_delegate; |
593 new WindowSlider(&slider_delegate, root_window(), window.get()); | 593 new WindowSlider(&slider_delegate, root_window(), window.get()); |
594 | 594 |
595 ui::ScopedAnimationDurationScaleMode normal_duration_( | 595 ui::ScopedAnimationDurationScaleMode normal_duration_( |
596 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 596 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
597 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 597 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
598 animator->set_disable_timer_for_test(true); | 598 animator->set_disable_timer_for_test(true); |
599 ui::LayerAnimatorTestController test_controller(animator); | 599 ui::LayerAnimatorTestController test_controller(animator); |
600 | 600 |
601 aura::test::EventGenerator generator(root_window()); | 601 ui::test::EventGenerator generator(root_window()); |
602 | 602 |
603 // Swipe forward so that |window|'s layer is the one animating. | 603 // Swipe forward so that |window|'s layer is the one animating. |
604 generator.GestureScrollSequence( | 604 generator.GestureScrollSequence( |
605 gfx::Point(10, 10), | 605 gfx::Point(10, 10), |
606 gfx::Point(180, 10), | 606 gfx::Point(180, 10), |
607 base::TimeDelta::FromMilliseconds(10), | 607 base::TimeDelta::FromMilliseconds(10), |
608 2); | 608 2); |
609 EXPECT_TRUE(slider_delegate.created_back_layer()); | 609 EXPECT_TRUE(slider_delegate.created_back_layer()); |
610 EXPECT_FALSE(slider_delegate.slide_aborted()); | 610 EXPECT_FALSE(slider_delegate.slide_aborted()); |
611 EXPECT_FALSE(slider_delegate.created_front_layer()); | 611 EXPECT_FALSE(slider_delegate.created_front_layer()); |
(...skipping 29 matching lines...) Expand all Loading... |
641 animator->Step(start_time2 + duration); | 641 animator->Step(start_time2 + duration); |
642 // The animation for the second slide should now be completed. | 642 // The animation for the second slide should now be completed. |
643 EXPECT_TRUE(slider_delegate.slide_completed()); | 643 EXPECT_TRUE(slider_delegate.slide_completed()); |
644 slider_delegate.Reset(); | 644 slider_delegate.Reset(); |
645 | 645 |
646 window.reset(); | 646 window.reset(); |
647 EXPECT_TRUE(slider_delegate.slider_destroyed()); | 647 EXPECT_TRUE(slider_delegate.slider_destroyed()); |
648 } | 648 } |
649 | 649 |
650 } // namespace content | 650 } // namespace content |
OLD | NEW |