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

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

Issue 101573006: Changes MouseEvent constructor to take changed_button_flags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows side Created 7 years 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
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/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/client/event_client.h" 10 #include "ui/aura/client/event_client.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); 105 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight);
106 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); 106 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight);
107 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( 107 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(
108 delegate1.get(), -1234, bounds1, root_window())); 108 delegate1.get(), -1234, bounds1, root_window()));
109 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( 109 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate(
110 delegate2.get(), -5678, bounds2, root_window())); 110 delegate2.get(), -5678, bounds2, root_window()));
111 111
112 // Send a mouse event to window1. 112 // Send a mouse event to window1.
113 gfx::Point point(101, 201); 113 gfx::Point point(101, 201);
114 ui::MouseEvent event1( 114 ui::MouseEvent event1(
115 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); 115 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON,
116 ui::EF_LEFT_MOUSE_BUTTON);
116 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); 117 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1);
117 118
118 // Event was tested for non-client area for the target window. 119 // Event was tested for non-client area for the target window.
119 EXPECT_EQ(1, delegate1->non_client_count()); 120 EXPECT_EQ(1, delegate1->non_client_count());
120 EXPECT_EQ(0, delegate2->non_client_count()); 121 EXPECT_EQ(0, delegate2->non_client_count());
121 // The non-client component test was in local coordinates. 122 // The non-client component test was in local coordinates.
122 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); 123 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location());
123 // Mouse event was received by target window. 124 // Mouse event was received by target window.
124 EXPECT_EQ(1, delegate1->mouse_event_count()); 125 EXPECT_EQ(1, delegate1->mouse_event_count());
125 EXPECT_EQ(0, delegate2->mouse_event_count()); 126 EXPECT_EQ(0, delegate2->mouse_event_count());
126 // Event was in local coordinates. 127 // Event was in local coordinates.
127 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); 128 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location());
128 // Non-client flag was set. 129 // Non-client flag was set.
129 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); 130 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT);
130 } 131 }
131 132
132 TEST_F(RootWindowTest, RepostEvent) { 133 TEST_F(RootWindowTest, RepostEvent) {
133 // Test RepostEvent in RootWindow. It only works for Mouse Press. 134 // Test RepostEvent in RootWindow. It only works for Mouse Press.
134 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 135 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
135 gfx::Point point(10, 10); 136 gfx::Point point(10, 10);
136 ui::MouseEvent event( 137 ui::MouseEvent event(
137 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); 138 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON,
139 ui::EF_LEFT_MOUSE_BUTTON);
138 dispatcher()->RepostEvent(event); 140 dispatcher()->RepostEvent(event);
139 RunAllPendingInMessageLoop(); 141 RunAllPendingInMessageLoop();
140 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 142 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
141 } 143 }
142 144
143 // Check that we correctly track the state of the mouse buttons in response to 145 // Check that we correctly track the state of the mouse buttons in response to
144 // button press and release events. 146 // button press and release events.
145 TEST_F(RootWindowTest, MouseButtonState) { 147 TEST_F(RootWindowTest, MouseButtonState) {
146 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 148 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
147 149
148 gfx::Point location; 150 gfx::Point location;
149 scoped_ptr<ui::MouseEvent> event; 151 scoped_ptr<ui::MouseEvent> event;
150 152
151 // Press the left button. 153 // Press the left button.
152 event.reset(new ui::MouseEvent( 154 event.reset(new ui::MouseEvent(
153 ui::ET_MOUSE_PRESSED, 155 ui::ET_MOUSE_PRESSED,
154 location, 156 location,
155 location, 157 location,
158 ui::EF_LEFT_MOUSE_BUTTON,
156 ui::EF_LEFT_MOUSE_BUTTON)); 159 ui::EF_LEFT_MOUSE_BUTTON));
157 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); 160 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
158 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 161 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
159 162
160 // Additionally press the right. 163 // Additionally press the right.
161 event.reset(new ui::MouseEvent( 164 event.reset(new ui::MouseEvent(
162 ui::ET_MOUSE_PRESSED, 165 ui::ET_MOUSE_PRESSED,
163 location, 166 location,
164 location, 167 location,
165 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); 168 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
169 ui::EF_RIGHT_MOUSE_BUTTON));
166 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); 170 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
167 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 171 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
168 172
169 // Release the left button. 173 // Release the left button.
170 event.reset(new ui::MouseEvent( 174 event.reset(new ui::MouseEvent(
171 ui::ET_MOUSE_RELEASED, 175 ui::ET_MOUSE_RELEASED,
172 location, 176 location,
173 location, 177 location,
174 ui::EF_RIGHT_MOUSE_BUTTON)); 178 ui::EF_RIGHT_MOUSE_BUTTON,
179 ui::EF_LEFT_MOUSE_BUTTON));
175 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); 180 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
176 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 181 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
177 182
178 // Release the right button. We should ignore the Shift-is-down flag. 183 // Release the right button. We should ignore the Shift-is-down flag.
179 event.reset(new ui::MouseEvent( 184 event.reset(new ui::MouseEvent(
180 ui::ET_MOUSE_RELEASED, 185 ui::ET_MOUSE_RELEASED,
181 location, 186 location,
182 location, 187 location,
183 ui::EF_SHIFT_DOWN)); 188 ui::EF_SHIFT_DOWN,
189 ui::EF_RIGHT_MOUSE_BUTTON));
184 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); 190 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
185 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 191 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
186 192
187 // Press the middle button. 193 // Press the middle button.
188 event.reset(new ui::MouseEvent( 194 event.reset(new ui::MouseEvent(
189 ui::ET_MOUSE_PRESSED, 195 ui::ET_MOUSE_PRESSED,
190 location, 196 location,
191 location, 197 location,
198 ui::EF_MIDDLE_MOUSE_BUTTON,
192 ui::EF_MIDDLE_MOUSE_BUTTON)); 199 ui::EF_MIDDLE_MOUSE_BUTTON));
193 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); 200 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
194 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 201 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
195 } 202 }
196 203
197 TEST_F(RootWindowTest, TranslatedEvent) { 204 TEST_F(RootWindowTest, TranslatedEvent) {
198 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, 205 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1,
199 gfx::Rect(50, 50, 100, 100), root_window())); 206 gfx::Rect(50, 50, 100, 100), root_window()));
200 207
201 gfx::Point origin(100, 100); 208 gfx::Point origin(100, 100);
202 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); 209 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0, 0);
203 210
204 EXPECT_EQ("100,100", root.location().ToString()); 211 EXPECT_EQ("100,100", root.location().ToString());
205 EXPECT_EQ("100,100", root.root_location().ToString()); 212 EXPECT_EQ("100,100", root.root_location().ToString());
206 213
207 ui::MouseEvent translated_event( 214 ui::MouseEvent translated_event(
208 root, static_cast<Window*>(root_window()), w1.get(), 215 root, static_cast<Window*>(root_window()), w1.get(),
209 ui::ET_MOUSE_ENTERED, root.flags()); 216 ui::ET_MOUSE_ENTERED, root.flags());
210 EXPECT_EQ("50,50", translated_event.location().ToString()); 217 EXPECT_EQ("50,50", translated_event.location().ToString());
211 EXPECT_EQ("100,100", translated_event.root_location().ToString()); 218 EXPECT_EQ("100,100", translated_event.root_location().ToString());
212 } 219 }
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 // over |window| and verify |window| gets it (|window| gets it because it has 565 // over |window| and verify |window| gets it (|window| gets it because it has
559 // capture). 566 // capture).
560 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 567 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
561 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); 568 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL));
562 window->SetBounds(gfx::Rect(20, 20, 40, 30)); 569 window->SetBounds(gfx::Rect(20, 20, 40, 30));
563 EventFilterRecorder* recorder = new EventFilterRecorder; 570 EventFilterRecorder* recorder = new EventFilterRecorder;
564 window->SetEventFilter(recorder); // Takes ownership. 571 window->SetEventFilter(recorder); // Takes ownership.
565 window->SetCapture(); 572 window->SetCapture();
566 const ui::MouseEvent press_event( 573 const ui::MouseEvent press_event(
567 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 574 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
568 ui::EF_LEFT_MOUSE_BUTTON); 575 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
569 dispatcher()->RepostEvent(press_event); 576 dispatcher()->RepostEvent(press_event);
570 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). 577 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent().
571 // Mouse moves/enters may be generated. We only care about a pressed. 578 // Mouse moves/enters may be generated. We only care about a pressed.
572 EXPECT_TRUE(EventTypesToString(recorder->events()).find("MOUSE_PRESSED") != 579 EXPECT_TRUE(EventTypesToString(recorder->events()).find("MOUSE_PRESSED") !=
573 std::string::npos) << EventTypesToString(recorder->events()); 580 std::string::npos) << EventTypesToString(recorder->events());
574 } 581 }
575 582
576 TEST_F(RootWindowTest, MouseMovesHeld) { 583 TEST_F(RootWindowTest, MouseMovesHeld) {
577 EventFilterRecorder* filter = new EventFilterRecorder; 584 EventFilterRecorder* filter = new EventFilterRecorder;
578 root_window()->SetEventFilter(filter); // passes ownership 585 root_window()->SetEventFilter(filter); // passes ownership
579 586
580 test::TestWindowDelegate delegate; 587 test::TestWindowDelegate delegate;
581 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 588 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
582 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 589 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
583 590
584 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), 591 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
585 gfx::Point(0, 0), 0); 592 gfx::Point(0, 0), 0, 0);
586 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( 593 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
587 &mouse_move_event); 594 &mouse_move_event);
588 // Discard MOUSE_ENTER. 595 // Discard MOUSE_ENTER.
589 filter->events().clear(); 596 filter->events().clear();
590 597
591 dispatcher()->HoldPointerMoves(); 598 dispatcher()->HoldPointerMoves();
592 599
593 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. 600 // Check that we don't immediately dispatch the MOUSE_DRAGGED event.
594 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), 601 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0),
595 gfx::Point(0, 0), 0); 602 gfx::Point(0, 0), 0, 0);
596 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( 603 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
597 &mouse_dragged_event); 604 &mouse_dragged_event);
598 EXPECT_TRUE(filter->events().empty()); 605 EXPECT_TRUE(filter->events().empty());
599 606
600 // Check that we do dispatch the held MOUSE_DRAGGED event before another type 607 // Check that we do dispatch the held MOUSE_DRAGGED event before another type
601 // of event. 608 // of event.
602 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 609 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
603 gfx::Point(0, 0), 0); 610 gfx::Point(0, 0), 0, 0);
604 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( 611 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
605 &mouse_pressed_event); 612 &mouse_pressed_event);
606 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 613 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
607 EventTypesToString(filter->events())); 614 EventTypesToString(filter->events()));
608 filter->events().clear(); 615 filter->events().clear();
609 616
610 // Check that we coalesce held MOUSE_DRAGGED events. 617 // Check that we coalesce held MOUSE_DRAGGED events.
611 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), 618 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1),
612 gfx::Point(1, 1), 0); 619 gfx::Point(1, 1), 0, 0);
613 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( 620 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
614 &mouse_dragged_event); 621 &mouse_dragged_event);
615 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( 622 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
616 &mouse_dragged_event2); 623 &mouse_dragged_event2);
617 EXPECT_TRUE(filter->events().empty()); 624 EXPECT_TRUE(filter->events().empty());
618 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( 625 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
619 &mouse_pressed_event); 626 &mouse_pressed_event);
620 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 627 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
621 EventTypesToString(filter->events())); 628 EventTypesToString(filter->events()));
622 filter->events().clear(); 629 filter->events().clear();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 test::TestWindowDelegate delegate; 730 test::TestWindowDelegate delegate;
724 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 731 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
725 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); 732 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window()));
726 window->Show(); 733 window->Show();
727 window->SetCapture(); 734 window->SetCapture();
728 735
729 test::TestCursorClient cursor_client(root_window()); 736 test::TestCursorClient cursor_client(root_window());
730 737
731 // Dispatch a non-synthetic mouse event when mouse events are enabled. 738 // Dispatch a non-synthetic mouse event when mouse events are enabled.
732 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 739 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
733 gfx::Point(10, 10), 0); 740 gfx::Point(10, 10), 0, 0);
734 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); 741 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1);
735 EXPECT_FALSE(filter->events().empty()); 742 EXPECT_FALSE(filter->events().empty());
736 filter->events().clear(); 743 filter->events().clear();
737 744
738 // Dispatch a synthetic mouse event when mouse events are enabled. 745 // Dispatch a synthetic mouse event when mouse events are enabled.
739 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 746 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
740 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED); 747 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0);
741 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); 748 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2);
742 EXPECT_FALSE(filter->events().empty()); 749 EXPECT_FALSE(filter->events().empty());
743 filter->events().clear(); 750 filter->events().clear();
744 751
745 // Dispatch a synthetic mouse event when mouse events are disabled. 752 // Dispatch a synthetic mouse event when mouse events are disabled.
746 cursor_client.DisableMouseEvents(); 753 cursor_client.DisableMouseEvents();
747 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); 754 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2);
748 EXPECT_TRUE(filter->events().empty()); 755 EXPECT_TRUE(filter->events().empty());
749 } 756 }
750 757
751 // Tests that a mouse exit is dispatched to the last known cursor location 758 // Tests that a mouse exit is dispatched to the last known cursor location
752 // when the cursor becomes invisible. 759 // when the cursor becomes invisible.
753 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { 760 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) {
754 EventFilterRecorder* filter = new EventFilterRecorder; 761 EventFilterRecorder* filter = new EventFilterRecorder;
755 root_window()->SetEventFilter(filter); // passes ownership 762 root_window()->SetEventFilter(filter); // passes ownership
756 763
757 test::TestWindowDelegate delegate; 764 test::TestWindowDelegate delegate;
758 gfx::Point window_origin(7, 18); 765 gfx::Point window_origin(7, 18);
759 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 766 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
760 &delegate, 1234, gfx::Rect(window_origin, 767 &delegate, 1234, gfx::Rect(window_origin,
761 gfx::Size(100, 100)), root_window())); 768 gfx::Size(100, 100)), root_window()));
762 window->Show(); 769 window->Show();
763 770
764 // Dispatch a mouse move event into the window. 771 // Dispatch a mouse move event into the window.
765 gfx::Point mouse_location(gfx::Point(15, 25)); 772 gfx::Point mouse_location(gfx::Point(15, 25));
766 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, 773 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location,
767 mouse_location, 0); 774 mouse_location, 0, 0);
768 EXPECT_TRUE(filter->events().empty()); 775 EXPECT_TRUE(filter->events().empty());
769 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); 776 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1);
770 EXPECT_FALSE(filter->events().empty()); 777 EXPECT_FALSE(filter->events().empty());
771 filter->events().clear(); 778 filter->events().clear();
772 779
773 // Hide the cursor and verify a mouse exit was dispatched. 780 // Hide the cursor and verify a mouse exit was dispatched.
774 dispatcher()->OnCursorVisibilityChanged(false); 781 dispatcher()->OnCursorVisibilityChanged(false);
775 EXPECT_FALSE(filter->events().empty()); 782 EXPECT_FALSE(filter->events().empty());
776 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); 783 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events()));
777 784
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 virtual ~DontResetHeldEventWindowDelegate() {} 1259 virtual ~DontResetHeldEventWindowDelegate() {}
1253 1260
1254 int mouse_event_count() const { return mouse_event_count_; } 1261 int mouse_event_count() const { return mouse_event_count_; }
1255 1262
1256 // TestWindowDelegate: 1263 // TestWindowDelegate:
1257 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 1264 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
1258 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && 1265 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 &&
1259 mouse_event_count_++ == 0) { 1266 mouse_event_count_++ == 0) {
1260 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, 1267 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED,
1261 gfx::Point(10, 10), gfx::Point(10, 10), 1268 gfx::Point(10, 10), gfx::Point(10, 10),
1262 ui::EF_SHIFT_DOWN); 1269 ui::EF_SHIFT_DOWN, 0);
1263 root_->GetDispatcher()->RepostEvent(mouse_event); 1270 root_->GetDispatcher()->RepostEvent(mouse_event);
1264 } 1271 }
1265 } 1272 }
1266 1273
1267 private: 1274 private:
1268 Window* root_; 1275 Window* root_;
1269 int mouse_event_count_; 1276 int mouse_event_count_;
1270 1277
1271 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); 1278 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate);
1272 }; 1279 };
1273 1280
1274 } // namespace 1281 } // namespace
1275 1282
1276 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after 1283 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after
1277 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which 1284 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which
1278 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events 1285 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events
1279 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to 1286 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to
1280 // schedule another reposted event. 1287 // schedule another reposted event.
1281 TEST_F(RootWindowTest, DontResetHeldEvent) { 1288 TEST_F(RootWindowTest, DontResetHeldEvent) {
1282 DontResetHeldEventWindowDelegate delegate(root_window()); 1289 DontResetHeldEventWindowDelegate delegate(root_window());
1283 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); 1290 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate));
1284 RootWindowHostDelegate* root_window_delegate = 1291 RootWindowHostDelegate* root_window_delegate =
1285 static_cast<RootWindowHostDelegate*>(root_window()->GetDispatcher()); 1292 static_cast<RootWindowHostDelegate*>(root_window()->GetDispatcher());
1286 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); 1293 w1->SetBounds(gfx::Rect(0, 0, 40, 40));
1287 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, 1294 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED,
1288 gfx::Point(10, 10), gfx::Point(10, 10), 1295 gfx::Point(10, 10), gfx::Point(10, 10),
1289 ui::EF_SHIFT_DOWN); 1296 ui::EF_SHIFT_DOWN, 0);
1290 root_window()->GetDispatcher()->RepostEvent(pressed); 1297 root_window()->GetDispatcher()->RepostEvent(pressed);
1291 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, 1298 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED,
1292 gfx::Point(10, 10), gfx::Point(10, 10), 0); 1299 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0);
1293 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent(). 1300 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent().
1294 root_window_delegate->OnHostMouseEvent(&pressed2); 1301 root_window_delegate->OnHostMouseEvent(&pressed2);
1295 // Delegate should have seen reposted event (identified by way of 1302 // Delegate should have seen reposted event (identified by way of
1296 // EF_SHIFT_DOWN). Invoke OnHostMouseEvent() to flush the second 1303 // EF_SHIFT_DOWN). Invoke OnHostMouseEvent() to flush the second
1297 // RepostedEvent(). 1304 // RepostedEvent().
1298 EXPECT_EQ(1, delegate.mouse_event_count()); 1305 EXPECT_EQ(1, delegate.mouse_event_count());
1299 root_window_delegate->OnHostMouseEvent(&pressed2); 1306 root_window_delegate->OnHostMouseEvent(&pressed2);
1300 EXPECT_EQ(2, delegate.mouse_event_count()); 1307 EXPECT_EQ(2, delegate.mouse_event_count());
1301 } 1308 }
1302 1309
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 // Should be deleted by |delegate|. 1356 // Should be deleted by |delegate|.
1350 RootWindow* r2 = 1357 RootWindow* r2 =
1351 new RootWindow(RootWindow::CreateParams(gfx::Rect(0, 0, 100, 100))); 1358 new RootWindow(RootWindow::CreateParams(gfx::Rect(0, 0, 100, 100)));
1352 r2->Init(); 1359 r2->Init();
1353 DeleteRootFromHeldMouseEventDelegate delegate(r2); 1360 DeleteRootFromHeldMouseEventDelegate delegate(r2);
1354 // Owned by |r2|. 1361 // Owned by |r2|.
1355 Window* w1 = CreateNormalWindow(1, r2->window(), &delegate); 1362 Window* w1 = CreateNormalWindow(1, r2->window(), &delegate);
1356 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); 1363 w1->SetBounds(gfx::Rect(0, 0, 40, 40));
1357 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, 1364 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED,
1358 gfx::Point(10, 10), gfx::Point(10, 10), 1365 gfx::Point(10, 10), gfx::Point(10, 10),
1359 ui::EF_SHIFT_DOWN); 1366 ui::EF_SHIFT_DOWN, 0);
1360 r2->RepostEvent(pressed); 1367 r2->RepostEvent(pressed);
1361 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. 1368 // RunAllPendingInMessageLoop() to make sure the |pressed| is run.
1362 RunAllPendingInMessageLoop(); 1369 RunAllPendingInMessageLoop();
1363 EXPECT_TRUE(delegate.got_mouse_event()); 1370 EXPECT_TRUE(delegate.got_mouse_event());
1364 EXPECT_TRUE(delegate.got_destroy()); 1371 EXPECT_TRUE(delegate.got_destroy());
1365 } 1372 }
1366 1373
1367 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) { 1374 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) {
1368 EventFilterRecorder* filter = new EventFilterRecorder; 1375 EventFilterRecorder* filter = new EventFilterRecorder;
1369 root_window()->SetEventFilter(filter); // passes ownership 1376 root_window()->SetEventFilter(filter); // passes ownership
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 1450
1444 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " 1451 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED "
1445 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " 1452 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE "
1446 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END", 1453 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END",
1447 EventTypesToString(filter1->events())); 1454 EventTypesToString(filter1->events()));
1448 1455
1449 EXPECT_TRUE(filter2->events().empty()); 1456 EXPECT_TRUE(filter2->events().empty());
1450 } 1457 }
1451 1458
1452 } // namespace aura 1459 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.cc ('k') | ui/aura/test/event_generator.cc » ('j') | ui/events/event.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698