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

Side by Side Diff: ui/aura/window_unittest.cc

Issue 10825050: Introduce RootWindowHostDelegate. The RootWindowHost performs most of its communication with RootWi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/event_generator.cc ('k') | ui/views/widget/native_widget_aura_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 EXPECT_EQ(0, delegate.capture_changed_event_count()); 747 EXPECT_EQ(0, delegate.capture_changed_event_count());
748 EventGenerator generator(root_window(), gfx::Point(50, 50)); 748 EventGenerator generator(root_window(), gfx::Point(50, 50));
749 generator.PressLeftButton(); 749 generator.PressLeftButton();
750 EXPECT_EQ(1, delegate.mouse_event_count()); 750 EXPECT_EQ(1, delegate.mouse_event_count());
751 generator.ReleaseLeftButton(); 751 generator.ReleaseLeftButton();
752 752
753 EXPECT_EQ(2, delegate.mouse_event_count()); 753 EXPECT_EQ(2, delegate.mouse_event_count());
754 delegate.ResetCounts(); 754 delegate.ResetCounts();
755 755
756 TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0, getTime()); 756 TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0, getTime());
757 root_window()->DispatchTouchEvent(&touchev); 757 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev);
758 EXPECT_EQ(1, delegate.touch_event_count()); 758 EXPECT_EQ(1, delegate.touch_event_count());
759 delegate.ResetCounts(); 759 delegate.ResetCounts();
760 760
761 window->ReleaseCapture(); 761 window->ReleaseCapture();
762 EXPECT_FALSE(window->HasCapture()); 762 EXPECT_FALSE(window->HasCapture());
763 EXPECT_EQ(1, delegate.capture_lost_count()); 763 EXPECT_EQ(1, delegate.capture_lost_count());
764 EXPECT_EQ(1, delegate.capture_changed_event_count()); 764 EXPECT_EQ(1, delegate.capture_changed_event_count());
765 EXPECT_EQ(1, delegate.mouse_event_count()); 765 EXPECT_EQ(1, delegate.mouse_event_count());
766 EXPECT_EQ(1, delegate.touch_event_count()); 766 EXPECT_EQ(1, delegate.touch_event_count());
767 767
768 generator.PressLeftButton(); 768 generator.PressLeftButton();
769 EXPECT_EQ(1, delegate.mouse_event_count()); 769 EXPECT_EQ(1, delegate.mouse_event_count());
770 770
771 TouchEvent touchev2(ui::ET_TOUCH_PRESSED, gfx::Point(250, 250), 1, getTime()); 771 TouchEvent touchev2(ui::ET_TOUCH_PRESSED, gfx::Point(250, 250), 1, getTime());
772 root_window()->DispatchTouchEvent(&touchev2); 772 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev2);
773 EXPECT_EQ(1, delegate.touch_event_count()); 773 EXPECT_EQ(1, delegate.touch_event_count());
774 774
775 // Removing the capture window from parent should reset the capture window 775 // Removing the capture window from parent should reset the capture window
776 // in the root window. 776 // in the root window.
777 window->SetCapture(); 777 window->SetCapture();
778 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); 778 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window()));
779 window->parent()->RemoveChild(window.get()); 779 window->parent()->RemoveChild(window.get());
780 EXPECT_FALSE(window->HasCapture()); 780 EXPECT_FALSE(window->HasCapture());
781 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); 781 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window()));
782 } 782 }
783 783
784 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) { 784 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) {
785 CaptureWindowDelegateImpl delegate1; 785 CaptureWindowDelegateImpl delegate1;
786 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( 786 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(
787 &delegate1, 0, gfx::Rect(0, 0, 20, 20), NULL)); 787 &delegate1, 0, gfx::Rect(0, 0, 20, 20), NULL));
788 CaptureWindowDelegateImpl delegate2; 788 CaptureWindowDelegateImpl delegate2;
789 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( 789 scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
790 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); 790 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL));
791 791
792 // Press on w1. 792 // Press on w1.
793 TouchEvent press(ui::ET_TOUCH_PRESSED, 793 TouchEvent press(ui::ET_TOUCH_PRESSED,
794 gfx::Point(10, 10), 0, getTime()); 794 gfx::Point(10, 10), 0, getTime());
795 root_window()->DispatchTouchEvent(&press); 795 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
796 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 796 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
797 EXPECT_EQ(2, delegate1.gesture_event_count()); 797 EXPECT_EQ(2, delegate1.gesture_event_count());
798 delegate1.ResetCounts(); 798 delegate1.ResetCounts();
799 w2->SetCapture(); 799 w2->SetCapture();
800 800
801 // The touch was cancelled when the other window 801 // The touch was cancelled when the other window
802 // attained a touch lock. 802 // attained a touch lock.
803 EXPECT_EQ(1, delegate1.touch_event_count()); 803 EXPECT_EQ(1, delegate1.touch_event_count());
804 EXPECT_EQ(0, delegate2.touch_event_count()); 804 EXPECT_EQ(0, delegate2.touch_event_count());
805 805
806 delegate1.ResetCounts(); 806 delegate1.ResetCounts();
807 delegate2.ResetCounts(); 807 delegate2.ResetCounts();
808 808
809 TouchEvent move(ui::ET_TOUCH_MOVED, 809 TouchEvent move(ui::ET_TOUCH_MOVED,
810 gfx::Point(10, 10), 0, getTime()); 810 gfx::Point(10, 10), 0, getTime());
811 root_window()->DispatchTouchEvent(&move); 811 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
812 812
813 // This touch id is now ignored, no scroll fired. 813 // This touch id is now ignored, no scroll fired.
814 EXPECT_EQ(0, delegate1.gesture_event_count()); 814 EXPECT_EQ(0, delegate1.gesture_event_count());
815 EXPECT_EQ(0, delegate2.gesture_event_count()); 815 EXPECT_EQ(0, delegate2.gesture_event_count());
816 816
817 TouchEvent release(ui::ET_TOUCH_RELEASED, 817 TouchEvent release(ui::ET_TOUCH_RELEASED,
818 gfx::Point(10, 10), 0, getTime()); 818 gfx::Point(10, 10), 0, getTime());
819 root_window()->DispatchTouchEvent(&release); 819 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
820 EXPECT_EQ(0, delegate1.gesture_event_count()); 820 EXPECT_EQ(0, delegate1.gesture_event_count());
821 EXPECT_EQ(0, delegate2.gesture_event_count()); 821 EXPECT_EQ(0, delegate2.gesture_event_count());
822 822
823 // A new press is captured by w2. 823 // A new press is captured by w2.
824 824
825 TouchEvent press2(ui::ET_TOUCH_PRESSED, 825 TouchEvent press2(ui::ET_TOUCH_PRESSED,
826 gfx::Point(10, 10), 0, getTime()); 826 gfx::Point(10, 10), 0, getTime());
827 root_window()->DispatchTouchEvent(&press2); 827 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
828 EXPECT_EQ(0, delegate1.gesture_event_count()); 828 EXPECT_EQ(0, delegate1.gesture_event_count());
829 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 829 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
830 EXPECT_EQ(2, delegate2.gesture_event_count()); 830 EXPECT_EQ(2, delegate2.gesture_event_count());
831 } 831 }
832 832
833 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { 833 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) {
834 CaptureWindowDelegateImpl delegate; 834 CaptureWindowDelegateImpl delegate;
835 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 835 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
836 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 836 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
837 837
838 TouchEvent press(ui::ET_TOUCH_PRESSED, 838 TouchEvent press(ui::ET_TOUCH_PRESSED,
839 gfx::Point(10, 10), 0, getTime()); 839 gfx::Point(10, 10), 0, getTime());
840 root_window()->DispatchTouchEvent(&press); 840 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
841 841
842 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 842 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
843 EXPECT_EQ(2, delegate.gesture_event_count()); 843 EXPECT_EQ(2, delegate.gesture_event_count());
844 delegate.ResetCounts(); 844 delegate.ResetCounts();
845 845
846 window->SetCapture(); 846 window->SetCapture();
847 EXPECT_EQ(0, delegate.gesture_event_count()); 847 EXPECT_EQ(0, delegate.gesture_event_count());
848 delegate.ResetCounts(); 848 delegate.ResetCounts();
849 849
850 // The move event should still create a gesture, as this touch was 850 // The move event should still create a gesture, as this touch was
851 // on the window which was captured. 851 // on the window which was captured.
852 TouchEvent release(ui::ET_TOUCH_RELEASED, 852 TouchEvent release(ui::ET_TOUCH_RELEASED,
853 gfx::Point(10, 10), 0, getTime() + 853 gfx::Point(10, 10), 0, getTime() +
854 base::TimeDelta::FromMilliseconds(50)); 854 base::TimeDelta::FromMilliseconds(50));
855 root_window()->DispatchTouchEvent(&release); 855 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
856 EXPECT_EQ(2, delegate.gesture_event_count()); 856 EXPECT_EQ(2, delegate.gesture_event_count());
857 } 857 }
858 858
859 // Assertions around SetCapture() and touch/gestures. 859 // Assertions around SetCapture() and touch/gestures.
860 TEST_F(WindowTest, TransferCaptureTouchEvents) { 860 TEST_F(WindowTest, TransferCaptureTouchEvents) {
861 // Touch on |w1|. 861 // Touch on |w1|.
862 CaptureWindowDelegateImpl d1; 862 CaptureWindowDelegateImpl d1;
863 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( 863 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(
864 &d1, 0, gfx::Rect(0, 0, 20, 20), NULL)); 864 &d1, 0, gfx::Rect(0, 0, 20, 20), NULL));
865 TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); 865 TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
866 root_window()->DispatchTouchEvent(&p1); 866 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p1);
867 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 867 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
868 EXPECT_EQ(2, d1.gesture_event_count()); 868 EXPECT_EQ(2, d1.gesture_event_count());
869 d1.ResetCounts(); 869 d1.ResetCounts();
870 870
871 // Touch on |w2| with a different id. 871 // Touch on |w2| with a different id.
872 CaptureWindowDelegateImpl d2; 872 CaptureWindowDelegateImpl d2;
873 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( 873 scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
874 &d2, 0, gfx::Rect(40, 0, 40, 20), NULL)); 874 &d2, 0, gfx::Rect(40, 0, 40, 20), NULL));
875 TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); 875 TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime());
876 root_window()->DispatchTouchEvent(&p2); 876 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p2);
877 EXPECT_EQ(0, d1.gesture_event_count()); 877 EXPECT_EQ(0, d1.gesture_event_count());
878 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window. 878 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window.
879 EXPECT_EQ(2, d2.gesture_event_count()); 879 EXPECT_EQ(2, d2.gesture_event_count());
880 d1.ResetCounts(); 880 d1.ResetCounts();
881 d2.ResetCounts(); 881 d2.ResetCounts();
882 882
883 // Set capture on |w2|, this should send a cancel to |w1| but not |w2|. 883 // Set capture on |w2|, this should send a cancel to |w1| but not |w2|.
884 w2->SetCapture(); 884 w2->SetCapture();
885 EXPECT_EQ(1, d1.gesture_event_count()); 885 EXPECT_EQ(1, d1.gesture_event_count());
886 EXPECT_EQ(0, d2.gesture_event_count()); 886 EXPECT_EQ(0, d2.gesture_event_count());
887 d1.ResetCounts(); 887 d1.ResetCounts();
888 d2.ResetCounts(); 888 d2.ResetCounts();
889 889
890 CaptureWindowDelegateImpl d3; 890 CaptureWindowDelegateImpl d3;
891 scoped_ptr<Window> w3(CreateTestWindowWithDelegate( 891 scoped_ptr<Window> w3(CreateTestWindowWithDelegate(
892 &d3, 0, gfx::Rect(0, 0, 100, 101), NULL)); 892 &d3, 0, gfx::Rect(0, 0, 100, 101), NULL));
893 // Set capture on w3. No new events should be received. 893 // Set capture on w3. No new events should be received.
894 w3->SetCapture(); 894 w3->SetCapture();
895 EXPECT_EQ(0, d1.gesture_event_count()); 895 EXPECT_EQ(0, d1.gesture_event_count());
896 EXPECT_EQ(0, d2.gesture_event_count()); 896 EXPECT_EQ(0, d2.gesture_event_count());
897 EXPECT_EQ(0, d3.gesture_event_count()); 897 EXPECT_EQ(0, d3.gesture_event_count());
898 898
899 // Move touch id originally associated with |w2|. Since capture was transfered 899 // Move touch id originally associated with |w2|. Since capture was transfered
900 // from 2 to 3 only |w3| should get the event. 900 // from 2 to 3 only |w3| should get the event.
901 TouchEvent m3(ui::ET_TOUCH_MOVED, gfx::Point(110, 105), 1, getTime()); 901 TouchEvent m3(ui::ET_TOUCH_MOVED, gfx::Point(110, 105), 1, getTime());
902 root_window()->DispatchTouchEvent(&m3); 902 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&m3);
903 EXPECT_EQ(0, d1.gesture_event_count()); 903 EXPECT_EQ(0, d1.gesture_event_count());
904 EXPECT_EQ(0, d2.gesture_event_count()); 904 EXPECT_EQ(0, d2.gesture_event_count());
905 // |w3| gets two events, both scroll related. 905 // |w3| gets two events, both scroll related.
906 EXPECT_EQ(2, d3.gesture_event_count()); 906 EXPECT_EQ(2, d3.gesture_event_count());
907 } 907 }
908 908
909 // Changes capture while capture is already ongoing. 909 // Changes capture while capture is already ongoing.
910 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { 910 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
911 CaptureWindowDelegateImpl delegate; 911 CaptureWindowDelegateImpl delegate;
912 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 912 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 gfx::Rect(0, 0, 20, 20), NULL)); 1305 gfx::Rect(0, 0, 20, 20), NULL));
1306 1306
1307 // Rotate the root-window clock-wise 90 degrees. 1307 // Rotate the root-window clock-wise 90 degrees.
1308 ui::Transform transform; 1308 ui::Transform transform;
1309 transform.SetRotate(90.0f); 1309 transform.SetRotate(90.0f);
1310 transform.ConcatTranslate(size.height(), 0); 1310 transform.ConcatTranslate(size.height(), 0);
1311 root_window()->SetTransform(transform); 1311 root_window()->SetTransform(transform);
1312 1312
1313 TouchEvent press(ui::ET_TOUCH_PRESSED, 1313 TouchEvent press(ui::ET_TOUCH_PRESSED,
1314 gfx::Point(size.height() - 10, 10), 0, getTime()); 1314 gfx::Point(size.height() - 10, 10), 0, getTime());
1315 root_window()->DispatchTouchEvent(&press); 1315 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1316 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); 1316 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString());
1317 } 1317 }
1318 1318
1319 // Various assertions for transient children. 1319 // Various assertions for transient children.
1320 TEST_F(WindowTest, TransientChildren) { 1320 TEST_F(WindowTest, TransientChildren) {
1321 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL)); 1321 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL));
1322 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); 1322 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
1323 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get())); 1323 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get()));
1324 Window* w2 = CreateTestWindowWithId(2, parent.get()); 1324 Window* w2 = CreateTestWindowWithId(2, parent.get());
1325 w1->AddTransientChild(w2); // w2 is now owned by w1. 1325 w1->AddTransientChild(w2); // w2 is now owned by w1.
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 2442 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
2443 2443
2444 // No bounds changed notification at the end of animation since layer 2444 // No bounds changed notification at the end of animation since layer
2445 // delegate is NULL. 2445 // delegate is NULL.
2446 EXPECT_FALSE(delegate.bounds_changed()); 2446 EXPECT_FALSE(delegate.bounds_changed());
2447 EXPECT_NE("0,0 100x100", window->bounds().ToString()); 2447 EXPECT_NE("0,0 100x100", window->bounds().ToString());
2448 } 2448 }
2449 2449
2450 } // namespace test 2450 } // namespace test
2451 } // namespace aura 2451 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.cc ('k') | ui/views/widget/native_widget_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698