| OLD | NEW |
| 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/aura/window.h" | 5 #include "ui/aura/window.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( | 619 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 620 &delegate1, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 620 &delegate1, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
| 621 CaptureWindowDelegateImpl delegate2; | 621 CaptureWindowDelegateImpl delegate2; |
| 622 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 622 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 623 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); | 623 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); |
| 624 | 624 |
| 625 // Press on w1. | 625 // Press on w1. |
| 626 TouchEvent press(ui::ET_TOUCH_PRESSED, | 626 TouchEvent press(ui::ET_TOUCH_PRESSED, |
| 627 gfx::Point(10, 10), 0, getTime()); | 627 gfx::Point(10, 10), 0, getTime()); |
| 628 root_window()->DispatchTouchEvent(&press); | 628 root_window()->DispatchTouchEvent(&press); |
| 629 EXPECT_EQ(1, delegate1.gesture_event_count()); | 629 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 630 EXPECT_EQ(2, delegate1.gesture_event_count()); |
| 630 delegate1.ResetCounts(); | 631 delegate1.ResetCounts(); |
| 631 w2->SetCapture(); | 632 w2->SetCapture(); |
| 632 | 633 |
| 633 // The touch was cancelled when the other window | 634 // The touch was cancelled when the other window |
| 634 // attained a touch lock. | 635 // attained a touch lock. |
| 635 EXPECT_EQ(1, delegate1.touch_event_count()); | 636 EXPECT_EQ(1, delegate1.touch_event_count()); |
| 636 EXPECT_EQ(0, delegate2.touch_event_count()); | 637 EXPECT_EQ(0, delegate2.touch_event_count()); |
| 637 | 638 |
| 638 delegate1.ResetCounts(); | 639 delegate1.ResetCounts(); |
| 639 delegate2.ResetCounts(); | 640 delegate2.ResetCounts(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 651 root_window()->DispatchTouchEvent(&release); | 652 root_window()->DispatchTouchEvent(&release); |
| 652 EXPECT_EQ(0, delegate1.gesture_event_count()); | 653 EXPECT_EQ(0, delegate1.gesture_event_count()); |
| 653 EXPECT_EQ(0, delegate2.gesture_event_count()); | 654 EXPECT_EQ(0, delegate2.gesture_event_count()); |
| 654 | 655 |
| 655 // A new press is captured by w2. | 656 // A new press is captured by w2. |
| 656 | 657 |
| 657 TouchEvent press2(ui::ET_TOUCH_PRESSED, | 658 TouchEvent press2(ui::ET_TOUCH_PRESSED, |
| 658 gfx::Point(10, 10), 0, getTime()); | 659 gfx::Point(10, 10), 0, getTime()); |
| 659 root_window()->DispatchTouchEvent(&press2); | 660 root_window()->DispatchTouchEvent(&press2); |
| 660 EXPECT_EQ(0, delegate1.gesture_event_count()); | 661 EXPECT_EQ(0, delegate1.gesture_event_count()); |
| 661 EXPECT_EQ(1, delegate2.gesture_event_count()); | 662 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 663 EXPECT_EQ(2, delegate2.gesture_event_count()); |
| 662 } | 664 } |
| 663 | 665 |
| 664 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { | 666 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { |
| 665 CaptureWindowDelegateImpl delegate; | 667 CaptureWindowDelegateImpl delegate; |
| 666 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 668 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
| 667 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 669 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
| 668 | 670 |
| 669 TouchEvent press(ui::ET_TOUCH_PRESSED, | 671 TouchEvent press(ui::ET_TOUCH_PRESSED, |
| 670 gfx::Point(10, 10), 0, getTime()); | 672 gfx::Point(10, 10), 0, getTime()); |
| 671 root_window()->DispatchTouchEvent(&press); | 673 root_window()->DispatchTouchEvent(&press); |
| 672 | 674 |
| 673 EXPECT_EQ(1, delegate.gesture_event_count()); | 675 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 676 EXPECT_EQ(2, delegate.gesture_event_count()); |
| 674 delegate.ResetCounts(); | 677 delegate.ResetCounts(); |
| 675 | 678 |
| 676 window->SetCapture(); | 679 window->SetCapture(); |
| 677 EXPECT_EQ(0, delegate.gesture_event_count()); | 680 EXPECT_EQ(0, delegate.gesture_event_count()); |
| 678 delegate.ResetCounts(); | 681 delegate.ResetCounts(); |
| 679 | 682 |
| 680 // The move event should still create a gesture, as this touch was | 683 // The move event should still create a gesture, as this touch was |
| 681 // on the window which was captured. | 684 // on the window which was captured. |
| 682 TouchEvent release(ui::ET_TOUCH_RELEASED, | 685 TouchEvent release(ui::ET_TOUCH_RELEASED, |
| 683 gfx::Point(10, 10), 0, getTime() + | 686 gfx::Point(10, 10), 0, getTime() + |
| 684 base::TimeDelta::FromMilliseconds(50)); | 687 base::TimeDelta::FromMilliseconds(50)); |
| 685 root_window()->DispatchTouchEvent(&release); | 688 root_window()->DispatchTouchEvent(&release); |
| 686 EXPECT_EQ(2, delegate.gesture_event_count()); | 689 EXPECT_EQ(2, delegate.gesture_event_count()); |
| 687 } | 690 } |
| 688 | 691 |
| 689 // Assertions around SetCapture() and touch/gestures. | 692 // Assertions around SetCapture() and touch/gestures. |
| 690 TEST_F(WindowTest, TransferCaptureTouchEvents) { | 693 TEST_F(WindowTest, TransferCaptureTouchEvents) { |
| 691 // Touch on |w1|. | 694 // Touch on |w1|. |
| 692 CaptureWindowDelegateImpl d1; | 695 CaptureWindowDelegateImpl d1; |
| 693 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( | 696 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 694 &d1, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 697 &d1, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
| 695 TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 698 TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
| 696 root_window()->DispatchTouchEvent(&p1); | 699 root_window()->DispatchTouchEvent(&p1); |
| 697 EXPECT_EQ(1, d1.gesture_event_count()); | 700 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 701 EXPECT_EQ(2, d1.gesture_event_count()); |
| 698 d1.ResetCounts(); | 702 d1.ResetCounts(); |
| 699 | 703 |
| 700 // Touch on |w2| with a different id. | 704 // Touch on |w2| with a different id. |
| 701 CaptureWindowDelegateImpl d2; | 705 CaptureWindowDelegateImpl d2; |
| 702 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 706 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 703 &d2, 0, gfx::Rect(40, 0, 40, 20), NULL)); | 707 &d2, 0, gfx::Rect(40, 0, 40, 20), NULL)); |
| 704 TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); | 708 TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); |
| 705 root_window()->DispatchTouchEvent(&p2); | 709 root_window()->DispatchTouchEvent(&p2); |
| 706 EXPECT_EQ(0, d1.gesture_event_count()); | 710 EXPECT_EQ(0, d1.gesture_event_count()); |
| 707 EXPECT_EQ(1, d2.gesture_event_count()); | 711 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window. |
| 712 EXPECT_EQ(2, d2.gesture_event_count()); |
| 708 d1.ResetCounts(); | 713 d1.ResetCounts(); |
| 709 d2.ResetCounts(); | 714 d2.ResetCounts(); |
| 710 | 715 |
| 711 // Set capture on |w2|, this should send a cancel to |w1| but not |w2|. | 716 // Set capture on |w2|, this should send a cancel to |w1| but not |w2|. |
| 712 w2->SetCapture(); | 717 w2->SetCapture(); |
| 713 EXPECT_EQ(1, d1.gesture_event_count()); | 718 EXPECT_EQ(1, d1.gesture_event_count()); |
| 714 EXPECT_EQ(0, d2.gesture_event_count()); | 719 EXPECT_EQ(0, d2.gesture_event_count()); |
| 715 d1.ResetCounts(); | 720 d1.ResetCounts(); |
| 716 d2.ResetCounts(); | 721 d2.ResetCounts(); |
| 717 | 722 |
| (...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2168 base::TimeTicks start_time = | 2173 base::TimeTicks start_time = |
| 2169 window->layer()->GetAnimator()->last_step_time(); | 2174 window->layer()->GetAnimator()->last_step_time(); |
| 2170 ui::AnimationContainerElement* element = window->layer()->GetAnimator(); | 2175 ui::AnimationContainerElement* element = window->layer()->GetAnimator(); |
| 2171 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 2176 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 2172 EXPECT_TRUE(delegate.bounds_changed()); | 2177 EXPECT_TRUE(delegate.bounds_changed()); |
| 2173 EXPECT_NE("0,0 100x100", window->bounds().ToString()); | 2178 EXPECT_NE("0,0 100x100", window->bounds().ToString()); |
| 2174 } | 2179 } |
| 2175 | 2180 |
| 2176 } // namespace test | 2181 } // namespace test |
| 2177 } // namespace aura | 2182 } // namespace aura |
| OLD | NEW |