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

Side by Side Diff: ui/aura/root_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/root_window_host_win.cc ('k') | ui/aura/shared/compound_event_filter_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/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 // How many mouse events have been received? 105 // How many mouse events have been received?
106 int num_mouse_events_; 106 int num_mouse_events_;
107 107
108 DISALLOW_COPY_AND_ASSIGN(EventCountFilter); 108 DISALLOW_COPY_AND_ASSIGN(EventCountFilter);
109 }; 109 };
110 110
111 } // namespace 111 } // namespace
112 112
113 typedef test::AuraTestBase RootWindowTest; 113 typedef test::AuraTestBase RootWindowTest;
114 114
115 TEST_F(RootWindowTest, DispatchMouseEvent) { 115 TEST_F(RootWindowTest, OnHostMouseEvent) {
116 // Create two non-overlapping windows so we don't have to worry about which 116 // Create two non-overlapping windows so we don't have to worry about which
117 // is on top. 117 // is on top.
118 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); 118 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate());
119 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); 119 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate());
120 const int kWindowWidth = 123; 120 const int kWindowWidth = 123;
121 const int kWindowHeight = 45; 121 const int kWindowHeight = 45;
122 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); 122 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight);
123 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); 123 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight);
124 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( 124 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(
125 delegate1.get(), -1234, bounds1, NULL)); 125 delegate1.get(), -1234, bounds1, NULL));
126 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( 126 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate(
127 delegate2.get(), -5678, bounds2, NULL)); 127 delegate2.get(), -5678, bounds2, NULL));
128 128
129 // Send a mouse event to window1. 129 // Send a mouse event to window1.
130 gfx::Point point(101, 201); 130 gfx::Point point(101, 201);
131 MouseEvent event1( 131 MouseEvent event1(
132 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); 132 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON);
133 root_window()->DispatchMouseEvent(&event1); 133 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1);
134 134
135 // Event was tested for non-client area for the target window. 135 // Event was tested for non-client area for the target window.
136 EXPECT_EQ(1, delegate1->non_client_count()); 136 EXPECT_EQ(1, delegate1->non_client_count());
137 EXPECT_EQ(0, delegate2->non_client_count()); 137 EXPECT_EQ(0, delegate2->non_client_count());
138 // The non-client component test was in local coordinates. 138 // The non-client component test was in local coordinates.
139 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); 139 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location());
140 // Mouse event was received by target window. 140 // Mouse event was received by target window.
141 EXPECT_EQ(1, delegate1->mouse_event_count()); 141 EXPECT_EQ(1, delegate1->mouse_event_count());
142 EXPECT_EQ(0, delegate2->mouse_event_count()); 142 EXPECT_EQ(0, delegate2->mouse_event_count());
143 // Event was in local coordinates. 143 // Event was in local coordinates.
144 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); 144 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location());
145 // Non-client flag was set. 145 // Non-client flag was set.
146 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); 146 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT);
147 } 147 }
148 148
149 // Check that we correctly track the state of the mouse buttons in response to 149 // Check that we correctly track the state of the mouse buttons in response to
150 // button press and release events. 150 // button press and release events.
151 TEST_F(RootWindowTest, MouseButtonState) { 151 TEST_F(RootWindowTest, MouseButtonState) {
152 EXPECT_FALSE(Env::GetInstance()->is_mouse_button_down()); 152 EXPECT_FALSE(Env::GetInstance()->is_mouse_button_down());
153 153
154 gfx::Point location; 154 gfx::Point location;
155 scoped_ptr<MouseEvent> event; 155 scoped_ptr<MouseEvent> event;
156 156
157 // Press the left button. 157 // Press the left button.
158 event.reset(new MouseEvent( 158 event.reset(new MouseEvent(
159 ui::ET_MOUSE_PRESSED, 159 ui::ET_MOUSE_PRESSED,
160 location, 160 location,
161 location, 161 location,
162 ui::EF_LEFT_MOUSE_BUTTON)); 162 ui::EF_LEFT_MOUSE_BUTTON));
163 root_window()->DispatchMouseEvent(event.get()); 163 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
164 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); 164 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down());
165 165
166 // Additionally press the right. 166 // Additionally press the right.
167 event.reset(new MouseEvent( 167 event.reset(new MouseEvent(
168 ui::ET_MOUSE_PRESSED, 168 ui::ET_MOUSE_PRESSED,
169 location, 169 location,
170 location, 170 location,
171 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); 171 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON));
172 root_window()->DispatchMouseEvent(event.get()); 172 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
173 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); 173 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down());
174 174
175 // Release the left button. 175 // Release the left button.
176 event.reset(new MouseEvent( 176 event.reset(new MouseEvent(
177 ui::ET_MOUSE_RELEASED, 177 ui::ET_MOUSE_RELEASED,
178 location, 178 location,
179 location, 179 location,
180 ui::EF_RIGHT_MOUSE_BUTTON)); 180 ui::EF_RIGHT_MOUSE_BUTTON));
181 root_window()->DispatchMouseEvent(event.get()); 181 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
182 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); 182 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down());
183 183
184 // Release the right button. We should ignore the Shift-is-down flag. 184 // Release the right button. We should ignore the Shift-is-down flag.
185 event.reset(new MouseEvent( 185 event.reset(new MouseEvent(
186 ui::ET_MOUSE_RELEASED, 186 ui::ET_MOUSE_RELEASED,
187 location, 187 location,
188 location, 188 location,
189 ui::EF_SHIFT_DOWN)); 189 ui::EF_SHIFT_DOWN));
190 root_window()->DispatchMouseEvent(event.get()); 190 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
191 EXPECT_FALSE(Env::GetInstance()->is_mouse_button_down()); 191 EXPECT_FALSE(Env::GetInstance()->is_mouse_button_down());
192 192
193 // Press the middle button. 193 // Press the middle button.
194 event.reset(new MouseEvent( 194 event.reset(new MouseEvent(
195 ui::ET_MOUSE_PRESSED, 195 ui::ET_MOUSE_PRESSED,
196 location, 196 location,
197 location, 197 location,
198 ui::EF_MIDDLE_MOUSE_BUTTON)); 198 ui::EF_MIDDLE_MOUSE_BUTTON));
199 root_window()->DispatchMouseEvent(event.get()); 199 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
200 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); 200 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down());
201 } 201 }
202 202
203 TEST_F(RootWindowTest, TranslatedEvent) { 203 TEST_F(RootWindowTest, TranslatedEvent) {
204 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, 204 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1,
205 gfx::Rect(50, 50, 100, 100), NULL)); 205 gfx::Rect(50, 50, 100, 100), NULL));
206 206
207 gfx::Point origin(100, 100); 207 gfx::Point origin(100, 100);
208 MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); 208 MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0);
209 209
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // Prevent w3 from being deleted by the hierarchy since its delegate is owned 327 // Prevent w3 from being deleted by the hierarchy since its delegate is owned
328 // by this scope. 328 // by this scope.
329 w3->parent()->RemoveChild(w3.get()); 329 w3->parent()->RemoveChild(w3.get());
330 } 330 }
331 331
332 TEST_F(RootWindowTest, IgnoreUnknownKeys) { 332 TEST_F(RootWindowTest, IgnoreUnknownKeys) {
333 EventCountFilter* filter = new EventCountFilter; 333 EventCountFilter* filter = new EventCountFilter;
334 root_window()->SetEventFilter(filter); // passes ownership 334 root_window()->SetEventFilter(filter); // passes ownership
335 335
336 KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0); 336 KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0);
337 EXPECT_FALSE(root_window()->DispatchKeyEvent(&unknown_event)); 337 EXPECT_FALSE(root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent(
338 &unknown_event));
338 EXPECT_EQ(0, filter->num_key_events()); 339 EXPECT_EQ(0, filter->num_key_events());
339 340
340 KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); 341 KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
341 EXPECT_TRUE(root_window()->DispatchKeyEvent(&known_event)); 342 EXPECT_TRUE(root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent(
343 &known_event));
342 EXPECT_EQ(1, filter->num_key_events()); 344 EXPECT_EQ(1, filter->num_key_events());
343 } 345 }
344 346
345 namespace { 347 namespace {
346 348
347 // FilterFilter that tracks the types of events it's seen. 349 // FilterFilter that tracks the types of events it's seen.
348 class EventFilterRecorder : public EventFilter { 350 class EventFilterRecorder : public EventFilter {
349 public: 351 public:
350 typedef std::vector<ui::EventType> Events; 352 typedef std::vector<ui::EventType> Events;
351 353
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 TEST_F(RootWindowTest, HoldMouseMove) { 457 TEST_F(RootWindowTest, HoldMouseMove) {
456 EventFilterRecorder* filter = new EventFilterRecorder; 458 EventFilterRecorder* filter = new EventFilterRecorder;
457 root_window()->SetEventFilter(filter); // passes ownership 459 root_window()->SetEventFilter(filter); // passes ownership
458 460
459 test::TestWindowDelegate delegate; 461 test::TestWindowDelegate delegate;
460 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 462 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
461 &delegate, 1, gfx::Rect(0, 0, 100, 100), NULL)); 463 &delegate, 1, gfx::Rect(0, 0, 100, 100), NULL));
462 464
463 MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), 465 MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
464 gfx::Point(0, 0), 0); 466 gfx::Point(0, 0), 0);
465 root_window()->DispatchMouseEvent(&mouse_move_event); 467 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
468 &mouse_move_event);
466 // Discard MOUSE_ENTER. 469 // Discard MOUSE_ENTER.
467 filter->events().clear(); 470 filter->events().clear();
468 471
469 root_window()->HoldMouseMoves(); 472 root_window()->HoldMouseMoves();
470 473
471 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. 474 // Check that we don't immediately dispatch the MOUSE_DRAGGED event.
472 MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), 475 MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0),
473 gfx::Point(0, 0), 0); 476 gfx::Point(0, 0), 0);
474 root_window()->DispatchMouseEvent(&mouse_dragged_event); 477 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
478 &mouse_dragged_event);
475 EXPECT_TRUE(filter->events().empty()); 479 EXPECT_TRUE(filter->events().empty());
476 480
477 // Check that we do dispatch the held MOUSE_DRAGGED event before another type 481 // Check that we do dispatch the held MOUSE_DRAGGED event before another type
478 // of event. 482 // of event.
479 MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 483 MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
480 gfx::Point(0, 0), 0); 484 gfx::Point(0, 0), 0);
481 root_window()->DispatchMouseEvent(&mouse_pressed_event); 485 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
486 &mouse_pressed_event);
482 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 487 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
483 EventTypesToString(filter->events())); 488 EventTypesToString(filter->events()));
484 filter->events().clear(); 489 filter->events().clear();
485 490
486 // Check that we coalesce held MOUSE_DRAGGED events. 491 // Check that we coalesce held MOUSE_DRAGGED events.
487 MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), 492 MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1),
488 gfx::Point(1, 1), 0); 493 gfx::Point(1, 1), 0);
489 root_window()->DispatchMouseEvent(&mouse_dragged_event); 494 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
490 root_window()->DispatchMouseEvent(&mouse_dragged_event2); 495 &mouse_dragged_event);
496 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
497 &mouse_dragged_event2);
491 EXPECT_TRUE(filter->events().empty()); 498 EXPECT_TRUE(filter->events().empty());
492 root_window()->DispatchMouseEvent(&mouse_pressed_event); 499 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
500 &mouse_pressed_event);
493 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 501 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
494 EventTypesToString(filter->events())); 502 EventTypesToString(filter->events()));
495 filter->events().clear(); 503 filter->events().clear();
496 504
497 // Check that on ReleaseMouseMoves, held events are not dispatched 505 // Check that on ReleaseMouseMoves, held events are not dispatched
498 // immediately, but posted instead. 506 // immediately, but posted instead.
499 root_window()->DispatchMouseEvent(&mouse_dragged_event); 507 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
508 &mouse_dragged_event);
500 root_window()->ReleaseMouseMoves(); 509 root_window()->ReleaseMouseMoves();
501 EXPECT_TRUE(filter->events().empty()); 510 EXPECT_TRUE(filter->events().empty());
502 RunAllPendingInMessageLoop(); 511 RunAllPendingInMessageLoop();
503 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 512 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
504 filter->events().clear(); 513 filter->events().clear();
505 514
506 // However if another message comes in before the dispatch, 515 // However if another message comes in before the dispatch,
507 // the Check that on ReleaseMouseMoves, held events are not dispatched 516 // the Check that on ReleaseMouseMoves, held events are not dispatched
508 // immediately, but posted instead. 517 // immediately, but posted instead.
509 root_window()->HoldMouseMoves(); 518 root_window()->HoldMouseMoves();
510 root_window()->DispatchMouseEvent(&mouse_dragged_event); 519 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
520 &mouse_dragged_event);
511 root_window()->ReleaseMouseMoves(); 521 root_window()->ReleaseMouseMoves();
512 root_window()->DispatchMouseEvent(&mouse_pressed_event); 522 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
523 &mouse_pressed_event);
513 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 524 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
514 EventTypesToString(filter->events())); 525 EventTypesToString(filter->events()));
515 filter->events().clear(); 526 filter->events().clear();
516 RunAllPendingInMessageLoop(); 527 RunAllPendingInMessageLoop();
517 EXPECT_TRUE(filter->events().empty()); 528 EXPECT_TRUE(filter->events().empty());
518 529
519 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce 530 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce
520 // them. 531 // them.
521 root_window()->HoldMouseMoves(); 532 root_window()->HoldMouseMoves();
522 root_window()->DispatchMouseEvent(&mouse_dragged_event); 533 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
534 &mouse_dragged_event);
523 root_window()->ReleaseMouseMoves(); 535 root_window()->ReleaseMouseMoves();
524 root_window()->DispatchMouseEvent(&mouse_dragged_event2); 536 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(
537 &mouse_dragged_event2);
525 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 538 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
526 filter->events().clear(); 539 filter->events().clear();
527 RunAllPendingInMessageLoop(); 540 RunAllPendingInMessageLoop();
528 EXPECT_TRUE(filter->events().empty()); 541 EXPECT_TRUE(filter->events().empty());
529 } 542 }
530 543
531 } // namespace aura 544 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window_host_win.cc ('k') | ui/aura/shared/compound_event_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698