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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 gfx::Point(55, 10), | 300 gfx::Point(55, 10), |
301 gfx::Point(55, 10), | 301 gfx::Point(55, 10), |
302 0, 0), | 302 0, 0), |
303 new ui::KeyEvent('a', ui::VKEY_A, ui::EF_NONE), | 303 new ui::KeyEvent('a', ui::VKEY_A, ui::EF_NONE), |
304 NULL | 304 NULL |
305 }; | 305 }; |
306 | 306 |
307 new WindowSlider(&slider_delegate, root_window(), window.get()); | 307 new WindowSlider(&slider_delegate, root_window(), window.get()); |
308 for (int i = 0; events[i]; ++i) { | 308 for (int i = 0; events[i]; ++i) { |
309 // Generate a horizontal overscroll. | 309 // Generate a horizontal overscroll. |
310 aura::test::EventGenerator generator(root_window()); | 310 ui::test::EventGenerator generator(root_window()); |
311 generator.GestureScrollSequenceWithCallback( | 311 generator.GestureScrollSequenceWithCallback( |
312 gfx::Point(10, 10), | 312 gfx::Point(10, 10), |
313 gfx::Point(80, 10), | 313 gfx::Point(80, 10), |
314 base::TimeDelta::FromMilliseconds(10), | 314 base::TimeDelta::FromMilliseconds(10), |
315 1, | 315 1, |
316 base::Bind(&DispatchEventDuringScrollCallback, | 316 base::Bind(&DispatchEventDuringScrollCallback, |
317 root_window()->GetHost()->event_processor(), | 317 root_window()->GetHost()->event_processor(), |
318 base::Owned(events[i]))); | 318 base::Owned(events[i]))); |
319 EXPECT_TRUE(slider_delegate.created_back_layer()); | 319 EXPECT_TRUE(slider_delegate.created_back_layer()); |
320 EXPECT_TRUE(slider_delegate.slide_aborted()); | 320 EXPECT_TRUE(slider_delegate.slide_aborted()); |
(...skipping 21 matching lines...) Expand all Loading... |
342 ui::LayerAnimatorTestController test_controller(animator); | 342 ui::LayerAnimatorTestController test_controller(animator); |
343 | 343 |
344 WindowSlider* slider = | 344 WindowSlider* slider = |
345 new WindowSlider(&slider_delegate, root_window(), window.get()); | 345 new WindowSlider(&slider_delegate, root_window(), window.get()); |
346 | 346 |
347 ui::MouseEvent interrupt_event(ui::ET_MOUSE_MOVED, | 347 ui::MouseEvent interrupt_event(ui::ET_MOUSE_MOVED, |
348 gfx::Point(55, 10), | 348 gfx::Point(55, 10), |
349 gfx::Point(55, 10), | 349 gfx::Point(55, 10), |
350 0, 0); | 350 0, 0); |
351 | 351 |
352 aura::test::EventGenerator generator(root_window()); | 352 ui::test::EventGenerator generator(root_window()); |
353 | 353 |
354 // Start the scroll sequence. Scroll forward so that |window|'s layer is the | 354 // Start the scroll sequence. Scroll forward so that |window|'s layer is the |
355 // one animating. | 355 // one animating. |
356 const int kTouchId = 5; | 356 const int kTouchId = 5; |
357 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 357 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
358 gfx::Point(10, 10), | 358 gfx::Point(10, 10), |
359 kTouchId, | 359 kTouchId, |
360 ui::EventTimeForNow()); | 360 ui::EventTimeForNow()); |
361 generator.Dispatch(&press); | 361 generator.Dispatch(&press); |
362 | 362 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 window_delegate.set_window_component(HTNOWHERE); | 442 window_delegate.set_window_component(HTNOWHERE); |
443 scoped_ptr<aura::Window> window(CreateNormalWindow(1, parent.get(), | 443 scoped_ptr<aura::Window> window(CreateNormalWindow(1, parent.get(), |
444 &window_delegate)); | 444 &window_delegate)); |
445 | 445 |
446 WindowSliderDelegateTest slider_delegate; | 446 WindowSliderDelegateTest slider_delegate; |
447 scoped_ptr<WindowSlider> slider( | 447 scoped_ptr<WindowSlider> slider( |
448 new WindowSlider(&slider_delegate, parent.get(), window.get())); | 448 new WindowSlider(&slider_delegate, parent.get(), window.get())); |
449 | 449 |
450 // Generate a horizontal scroll, and change the owner in the middle of the | 450 // Generate a horizontal scroll, and change the owner in the middle of the |
451 // scroll. | 451 // scroll. |
452 aura::test::EventGenerator generator(root_window()); | 452 ui::test::EventGenerator generator(root_window()); |
453 aura::Window* old_window = window.get(); | 453 aura::Window* old_window = window.get(); |
454 generator.GestureScrollSequenceWithCallback( | 454 generator.GestureScrollSequenceWithCallback( |
455 gfx::Point(10, 10), | 455 gfx::Point(10, 10), |
456 gfx::Point(80, 10), | 456 gfx::Point(80, 10), |
457 base::TimeDelta::FromMilliseconds(10), | 457 base::TimeDelta::FromMilliseconds(10), |
458 1, | 458 1, |
459 base::Bind(&ChangeSliderOwnerDuringScrollCallback, | 459 base::Bind(&ChangeSliderOwnerDuringScrollCallback, |
460 base::Unretained(&window), | 460 base::Unretained(&window), |
461 slider.get())); | 461 slider.get())); |
462 aura::Window* new_window = window.get(); | 462 aura::Window* new_window = window.get(); |
(...skipping 11 matching lines...) Expand all Loading... |
474 // shouldn't start the slide or change delegate's state in any way in response | 474 // shouldn't start the slide or change delegate's state in any way in response |
475 // to user input. | 475 // to user input. |
476 TEST_F(WindowSliderTest, NoSlideWhenLayerCantBeCreated) { | 476 TEST_F(WindowSliderTest, NoSlideWhenLayerCantBeCreated) { |
477 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); | 477 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); |
478 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 478 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
479 WindowSliderDelegateTest slider_delegate; | 479 WindowSliderDelegateTest slider_delegate; |
480 slider_delegate.SetCanCreateLayer(false); | 480 slider_delegate.SetCanCreateLayer(false); |
481 WindowSlider* slider = | 481 WindowSlider* slider = |
482 new WindowSlider(&slider_delegate, root_window(), window.get()); | 482 new WindowSlider(&slider_delegate, root_window(), window.get()); |
483 | 483 |
484 aura::test::EventGenerator generator(root_window()); | 484 ui::test::EventGenerator generator(root_window()); |
485 | 485 |
486 // No slide in progress should be reported during scroll since the layer | 486 // No slide in progress should be reported during scroll since the layer |
487 // wasn't created. | 487 // wasn't created. |
488 generator.GestureScrollSequenceWithCallback( | 488 generator.GestureScrollSequenceWithCallback( |
489 gfx::Point(10, 10), | 489 gfx::Point(10, 10), |
490 gfx::Point(180, 10), | 490 gfx::Point(180, 10), |
491 base::TimeDelta::FromMilliseconds(10), | 491 base::TimeDelta::FromMilliseconds(10), |
492 1, | 492 1, |
493 base::Bind(&ConfirmNoSlideDuringScrollCallback, slider)); | 493 base::Bind(&ConfirmNoSlideDuringScrollCallback, slider)); |
494 | 494 |
(...skipping 25 matching lines...) Expand all Loading... |
520 | 520 |
521 // Tests that the owner window can be destroyed from |OnWindowSliderDestroyed()| | 521 // Tests that the owner window can be destroyed from |OnWindowSliderDestroyed()| |
522 // delegate callback without causing a crash. | 522 // delegate callback without causing a crash. |
523 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSliderDestroy) { | 523 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSliderDestroy) { |
524 size_t child_windows = root_window()->children().size(); | 524 size_t child_windows = root_window()->children().size(); |
525 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); | 525 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); |
526 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 526 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
527 EXPECT_EQ(child_windows + 1, root_window()->children().size()); | 527 EXPECT_EQ(child_windows + 1, root_window()->children().size()); |
528 | 528 |
529 WindowSliderDeleteOwnerOnDestroy slider_delegate(window); | 529 WindowSliderDeleteOwnerOnDestroy slider_delegate(window); |
530 aura::test::EventGenerator generator(root_window()); | 530 ui::test::EventGenerator generator(root_window()); |
531 | 531 |
532 // Generate a horizontal overscroll. | 532 // Generate a horizontal overscroll. |
533 scoped_ptr<WindowSlider> slider( | 533 scoped_ptr<WindowSlider> slider( |
534 new WindowSlider(&slider_delegate, root_window(), window)); | 534 new WindowSlider(&slider_delegate, root_window(), window)); |
535 generator.GestureScrollSequence(gfx::Point(10, 10), | 535 generator.GestureScrollSequence(gfx::Point(10, 10), |
536 gfx::Point(180, 10), | 536 gfx::Point(180, 10), |
537 base::TimeDelta::FromMilliseconds(10), | 537 base::TimeDelta::FromMilliseconds(10), |
538 10); | 538 10); |
539 EXPECT_TRUE(slider_delegate.created_back_layer()); | 539 EXPECT_TRUE(slider_delegate.created_back_layer()); |
540 EXPECT_TRUE(slider_delegate.slide_completing()); | 540 EXPECT_TRUE(slider_delegate.slide_completing()); |
(...skipping 10 matching lines...) Expand all Loading... |
551 | 551 |
552 // Tests that the owner window can be destroyed from |OnWindowSlideComplete()| | 552 // Tests that the owner window can be destroyed from |OnWindowSlideComplete()| |
553 // delegate callback without causing a crash. | 553 // delegate callback without causing a crash. |
554 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSlideComplete) { | 554 TEST_F(WindowSliderTest, OwnerIsDestroyedOnSlideComplete) { |
555 size_t child_windows = root_window()->children().size(); | 555 size_t child_windows = root_window()->children().size(); |
556 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); | 556 aura::Window* window = CreateNormalWindow(0, root_window(), NULL); |
557 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 557 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
558 EXPECT_EQ(child_windows + 1, root_window()->children().size()); | 558 EXPECT_EQ(child_windows + 1, root_window()->children().size()); |
559 | 559 |
560 WindowSliderDeleteOwnerOnComplete slider_delegate(window); | 560 WindowSliderDeleteOwnerOnComplete slider_delegate(window); |
561 aura::test::EventGenerator generator(root_window()); | 561 ui::test::EventGenerator generator(root_window()); |
562 | 562 |
563 // Generate a horizontal overscroll. | 563 // Generate a horizontal overscroll. |
564 new WindowSlider(&slider_delegate, root_window(), window); | 564 new WindowSlider(&slider_delegate, root_window(), window); |
565 generator.GestureScrollSequence(gfx::Point(10, 10), | 565 generator.GestureScrollSequence(gfx::Point(10, 10), |
566 gfx::Point(180, 10), | 566 gfx::Point(180, 10), |
567 base::TimeDelta::FromMilliseconds(10), | 567 base::TimeDelta::FromMilliseconds(10), |
568 10); | 568 10); |
569 EXPECT_TRUE(slider_delegate.created_back_layer()); | 569 EXPECT_TRUE(slider_delegate.created_back_layer()); |
570 EXPECT_TRUE(slider_delegate.slide_completing()); | 570 EXPECT_TRUE(slider_delegate.slide_completing()); |
571 EXPECT_TRUE(slider_delegate.slide_completed()); | 571 EXPECT_TRUE(slider_delegate.slide_completed()); |
(...skipping 16 matching lines...) Expand all Loading... |
588 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 588 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
589 WindowSliderDelegateTest slider_delegate; | 589 WindowSliderDelegateTest slider_delegate; |
590 new WindowSlider(&slider_delegate, root_window(), window.get()); | 590 new WindowSlider(&slider_delegate, root_window(), window.get()); |
591 | 591 |
592 ui::ScopedAnimationDurationScaleMode normal_duration_( | 592 ui::ScopedAnimationDurationScaleMode normal_duration_( |
593 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 593 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
594 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 594 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
595 animator->set_disable_timer_for_test(true); | 595 animator->set_disable_timer_for_test(true); |
596 ui::LayerAnimatorTestController test_controller(animator); | 596 ui::LayerAnimatorTestController test_controller(animator); |
597 | 597 |
598 aura::test::EventGenerator generator(root_window()); | 598 ui::test::EventGenerator generator(root_window()); |
599 | 599 |
600 // Swipe forward so that |window|'s layer is the one animating. | 600 // Swipe forward so that |window|'s layer is the one animating. |
601 generator.GestureScrollSequence( | 601 generator.GestureScrollSequence( |
602 gfx::Point(10, 10), | 602 gfx::Point(10, 10), |
603 gfx::Point(180, 10), | 603 gfx::Point(180, 10), |
604 base::TimeDelta::FromMilliseconds(10), | 604 base::TimeDelta::FromMilliseconds(10), |
605 2); | 605 2); |
606 EXPECT_TRUE(slider_delegate.created_back_layer()); | 606 EXPECT_TRUE(slider_delegate.created_back_layer()); |
607 EXPECT_FALSE(slider_delegate.slide_aborted()); | 607 EXPECT_FALSE(slider_delegate.slide_aborted()); |
608 EXPECT_FALSE(slider_delegate.created_front_layer()); | 608 EXPECT_FALSE(slider_delegate.created_front_layer()); |
(...skipping 29 matching lines...) Expand all Loading... |
638 animator->Step(start_time2 + duration); | 638 animator->Step(start_time2 + duration); |
639 // The animation for the second slide should now be completed. | 639 // The animation for the second slide should now be completed. |
640 EXPECT_TRUE(slider_delegate.slide_completed()); | 640 EXPECT_TRUE(slider_delegate.slide_completed()); |
641 slider_delegate.Reset(); | 641 slider_delegate.Reset(); |
642 | 642 |
643 window.reset(); | 643 window.reset(); |
644 EXPECT_TRUE(slider_delegate.slider_destroyed()); | 644 EXPECT_TRUE(slider_delegate.slider_destroyed()); |
645 } | 645 } |
646 | 646 |
647 } // namespace content | 647 } // namespace content |
OLD | NEW |