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

Side by Side Diff: ash/extended_desktop_unittest.cc

Issue 11825015: [Cleanup] consolidate DISABLED macros in mouse_cursor_event_filter_unittests.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | « no previous file | ash/test/ash_test_base.h » ('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 "ash/display/display_controller.h" 5 #include "ash/display/display_controller.h"
6 #include "ash/display/display_manager.h" 6 #include "ash/display/display_manager.h"
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/system/tray/system_tray.h" 10 #include "ash/system/tray/system_tray.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 private: 57 private:
58 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); 58 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
59 }; 59 };
60 60
61 internal::DisplayManager* GetDisplayManager() { 61 internal::DisplayManager* GetDisplayManager() {
62 return Shell::GetInstance()->display_manager(); 62 return Shell::GetInstance()->display_manager();
63 } 63 }
64 64
65 // An event filter which moves the target window to the secondary root window 65 // An event handler which moves the target window to the secondary root window
66 // at pre-handle phase of a mouse release event. 66 // at pre-handle phase of a mouse release event.
67 class MoveWindowByClickEventFilter : public ui::EventHandler { 67 class MoveWindowByClickEventHandler : public ui::EventHandler {
68 public: 68 public:
69 explicit MoveWindowByClickEventFilter(aura::Window* target) 69 explicit MoveWindowByClickEventHandler(aura::Window* target)
70 : target_(target) {} 70 : target_(target) {}
71 virtual ~MoveWindowByClickEventFilter() {} 71 virtual ~MoveWindowByClickEventHandler() {}
72 72
73 private: 73 private:
74 // ui::EventHandler overrides: 74 // ui::EventHandler overrides:
75 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 75 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
76 if (event->type() == ui::ET_MOUSE_RELEASED) { 76 if (event->type() == ui::ET_MOUSE_RELEASED) {
77 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 77 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
78 DCHECK_LT(1u, root_windows.size()); 78 DCHECK_LT(1u, root_windows.size());
79 root_windows[1]->AddChild(target_); 79 root_windows[1]->AddChild(target_);
80 } 80 }
81 } 81 }
82 82
83 aura::Window* target_; 83 aura::Window* target_;
84 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventFilter); 84 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
85 };
86
87 // An event handler which records the event's locations.
88 class EventLocationRecordingEventHandler : public ui::EventHandler {
89 public:
90 EventLocationRecordingEventHandler() {
91 Reset();
92 }
93 virtual ~EventLocationRecordingEventHandler() {}
94
95 std::string GetLocationsAndReset() {
96 std::string result =
97 location_.ToString() + " " + root_location_.ToString();
98 Reset();
99 return result;
100 }
101
102 private:
103 // ui::EventHandler overrides:
104 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
105 if (event->type() == ui::ET_MOUSE_MOVED ||
106 event->type() == ui::ET_MOUSE_DRAGGED) {
107 location_ = event->location();
108 root_location_ = event->root_location();
109 }
110 }
111
112 void Reset() {
113 location_.SetPoint(-999, -999);
114 root_location_.SetPoint(-999, -999);
115 }
116
117 gfx::Point root_location_;
118 gfx::Point location_;
119
120 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
85 }; 121 };
86 122
87 } // namespace 123 } // namespace
88 124
89 class ExtendedDesktopTest : public test::AshTestBase { 125 class ExtendedDesktopTest : public test::AshTestBase {
90 public: 126 public:
91 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { 127 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
92 return CreateTestWidgetWithParentAndContext( 128 return CreateTestWidgetWithParentAndContext(
93 NULL, CurrentContext(), bounds, false); 129 NULL, CurrentContext(), bounds, false);
94 } 130 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); 181 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
146 views::Widget* widget_on_2nd = 182 views::Widget* widget_on_2nd =
147 CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); 183 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
148 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); 184 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
149 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); 185 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
150 186
151 EXPECT_EQ(widget_on_2nd->GetNativeView(), 187 EXPECT_EQ(widget_on_2nd->GetNativeView(),
152 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); 188 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
153 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); 189 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
154 190
155 aura::test::EventGenerator generator_1st(root_windows[0]); 191 aura::test::EventGenerator& event_generator = GetEventGenerator();
156 aura::test::EventGenerator generator_2nd(root_windows[1]);
157
158 // Clicking a window changes the active window and active root window. 192 // Clicking a window changes the active window and active root window.
159 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); 193 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
160 generator_1st.ClickLeftButton(); 194 event_generator.ClickLeftButton();
161 195
162 EXPECT_EQ(widget_on_1st->GetNativeView(), 196 EXPECT_EQ(widget_on_1st->GetNativeView(),
163 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); 197 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
164 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); 198 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
165 199
166 generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); 200 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
167 generator_2nd.ClickLeftButton(); 201 event_generator.ClickLeftButton();
168 202
169 EXPECT_EQ(widget_on_2nd->GetNativeView(), 203 EXPECT_EQ(widget_on_2nd->GetNativeView(),
170 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); 204 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
171 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); 205 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
172 } 206 }
173 207
174 TEST_F(ExtendedDesktopTest, SystemModal) { 208 TEST_F(ExtendedDesktopTest, SystemModal) {
175 UpdateDisplay("1000x600,600x400"); 209 UpdateDisplay("1000x600,600x400");
176 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 210 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
177 211
178 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); 212 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
179 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); 213 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
180 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); 214 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
181 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); 215 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
182 216
183 // Open system modal. Make sure it's on 2nd root window and active. 217 // Open system modal. Make sure it's on 2nd root window and active.
184 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds( 218 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
185 new ModalWidgetDelegate(), 219 new ModalWidgetDelegate(),
186 CurrentContext(), 220 CurrentContext(),
187 gfx::Rect(1200, 100, 100, 100)); 221 gfx::Rect(1200, 100, 100, 100));
188 modal_widget->Show(); 222 modal_widget->Show();
189 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); 223 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
190 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); 224 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
191 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); 225 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
192 226
227 aura::test::EventGenerator& event_generator = GetEventGenerator();
228
193 // Clicking a widget on widget_on_1st display should not change activation. 229 // Clicking a widget on widget_on_1st display should not change activation.
194 aura::test::EventGenerator generator_1st(root_windows[0]); 230 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
195 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); 231 event_generator.ClickLeftButton();
196 generator_1st.ClickLeftButton();
197 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); 232 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
198 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); 233 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
199 234
200 // Close system modal and so clicking a widget should work now. 235 // Close system modal and so clicking a widget should work now.
201 modal_widget->Close(); 236 modal_widget->Close();
202 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); 237 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
203 generator_1st.ClickLeftButton(); 238 event_generator.ClickLeftButton();
204 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); 239 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
205 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); 240 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
206 } 241 }
207 242
208 TEST_F(ExtendedDesktopTest, TestCursor) { 243 TEST_F(ExtendedDesktopTest, TestCursor) {
209 UpdateDisplay("1000x600,600x400"); 244 UpdateDisplay("1000x600,600x400");
210 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 245 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
211 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type()); 246 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
212 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type()); 247 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
213 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy); 248 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); 385 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
351 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( 386 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
352 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); 387 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
353 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( 388 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
354 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); 389 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
355 390
356 r1_w1->SetCapture(); 391 r1_w1->SetCapture();
357 392
358 EXPECT_EQ(r1_w1.get(), 393 EXPECT_EQ(r1_w1.get(),
359 aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); 394 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
395
360 aura::test::EventGenerator generator2(root_windows[1]); 396 aura::test::EventGenerator generator2(root_windows[1]);
361 generator2.MoveMouseToCenterOf(r2_w1.get()); 397 generator2.MoveMouseToCenterOf(r2_w1.get());
362 generator2.ClickLeftButton(); 398 generator2.ClickLeftButton();
363 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); 399 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
364 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); 400 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
365 // The mouse is outside. On chromeos, the mouse is warped to the 401 // The mouse is outside. On chromeos, the mouse is warped to the
366 // dest root window, but it's not implemented on Win yet, so 402 // dest root window, but it's not implemented on Win yet, so
367 // no mouse move event on Win. 403 // no mouse move event on Win.
368 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset()); 404 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
369 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset()); 405 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
370 // (15,15) on 1st display is (-985,15) on 2nd display. 406 // Emulate passive grab. (15,15) on 1st display is (-985,15) on 2nd
407 // display.
371 generator2.MoveMouseTo(-985, 15); 408 generator2.MoveMouseTo(-985, 15);
372 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset()); 409 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
373 410
374 r1_w2->SetCapture(); 411 r1_w2->SetCapture();
375 EXPECT_EQ(r1_w2.get(), 412 EXPECT_EQ(r1_w2.get(),
376 aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); 413 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
377 generator2.MoveMouseBy(10, 10); 414 generator2.MoveMouseBy(10, 10);
378 generator2.ClickLeftButton(); 415 generator2.ClickLeftButton();
379 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); 416 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
380 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); 417 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
381 // mouse is already entered. 418 // mouse is already entered.
382 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset()); 419 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
383 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset()); 420 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
384
385 r1_w2->ReleaseCapture(); 421 r1_w2->ReleaseCapture();
386 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); 422 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
387 generator2.MoveMouseTo(15, 15); 423 generator2.MoveMouseTo(15, 15);
388 generator2.ClickLeftButton(); 424 generator2.ClickLeftButton();
389 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); 425 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
390 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); 426 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
391 // Make sure the mouse_moved_handler_ is properly reset. 427 // Make sure the mouse_moved_handler_ is properly reset.
392 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); 428 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
393 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); 429 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
394 } 430 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 463
428 // Verifies if the mouse event arrives to the window even when the window 464 // Verifies if the mouse event arrives to the window even when the window
429 // moves to another root in a pre-target handler. See: crbug.com/157583 465 // moves to another root in a pre-target handler. See: crbug.com/157583
430 TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) { 466 TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
431 UpdateDisplay("1000x600,600x400"); 467 UpdateDisplay("1000x600,600x400");
432 468
433 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 469 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
434 aura::test::EventCountDelegate delegate; 470 aura::test::EventCountDelegate delegate;
435 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( 471 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
436 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); 472 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
437 MoveWindowByClickEventFilter event_filter(window.get()); 473 MoveWindowByClickEventHandler event_handler(window.get());
438 window->AddPreTargetHandler(&event_filter); 474 window->AddPreTargetHandler(&event_handler);
439 aura::test::EventGenerator generator(root_windows[0], window.get()); 475
440 generator.ClickLeftButton(); 476 aura::test::EventGenerator& event_generator = GetEventGenerator();
477
478 event_generator.MoveMouseToCenterOf(window.get());
479 event_generator.ClickLeftButton();
441 // Both mouse pressed and released arrive at the window and its delegate. 480 // Both mouse pressed and released arrive at the window and its delegate.
442 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); 481 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
443 // Also event_filter moves the window to another root at mouse release. 482 // Also event_handler moves the window to another root at mouse release.
444 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 483 EXPECT_EQ(root_windows[1], window->GetRootWindow());
445 } 484 }
446 485
447 TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) { 486 TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
448 UpdateDisplay("1000x1000,1000x1000"); 487 UpdateDisplay("1000x1000,1000x1000");
449 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 488 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
450 489
451 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching( 490 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching(
452 root_windows[0]->GetBoundsInScreen()); 491 root_windows[0]->GetBoundsInScreen());
453 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching( 492 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching(
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 p.SetPoint(0, 0); 624 p.SetPoint(0, 0);
586 aura::Window::ConvertPointToTarget(d1, d2, &p); 625 aura::Window::ConvertPointToTarget(d1, d2, &p);
587 EXPECT_EQ("-10,-610", p.ToString()); 626 EXPECT_EQ("-10,-610", p.ToString());
588 } 627 }
589 628
590 TEST_F(ExtendedDesktopTest, OpenSystemTray) { 629 TEST_F(ExtendedDesktopTest, OpenSystemTray) {
591 UpdateDisplay("500x600,600x400"); 630 UpdateDisplay("500x600,600x400");
592 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); 631 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
593 ASSERT_FALSE(tray->HasSystemBubble()); 632 ASSERT_FALSE(tray->HasSystemBubble());
594 633
634 aura::test::EventGenerator& event_generator = GetEventGenerator();
635
595 // Opens the tray by a dummy click event and makes sure that adding/removing 636 // Opens the tray by a dummy click event and makes sure that adding/removing
596 // displays doesn't break anything. 637 // displays doesn't break anything.
597 aura::test::EventGenerator event_generator( 638 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
598 ash::Shell::GetInstance()->GetPrimaryRootWindow(),
599 tray->GetWidget()->GetNativeWindow());
600 event_generator.ClickLeftButton(); 639 event_generator.ClickLeftButton();
601 EXPECT_TRUE(tray->HasSystemBubble()); 640 EXPECT_TRUE(tray->HasSystemBubble());
602 641
603 UpdateDisplay("500x600"); 642 UpdateDisplay("500x600");
604 EXPECT_TRUE(tray->HasSystemBubble()); 643 EXPECT_TRUE(tray->HasSystemBubble());
605 UpdateDisplay("500x600,600x400"); 644 UpdateDisplay("500x600,600x400");
606 EXPECT_TRUE(tray->HasSystemBubble()); 645 EXPECT_TRUE(tray->HasSystemBubble());
607 646
608 // Closes the tray and again makes sure that adding/removing displays doesn't 647 // Closes the tray and again makes sure that adding/removing displays doesn't
609 // break anything. 648 // break anything.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 ash::internal::kShellWindowId_LockScreenContainer)-> 702 ash::internal::kShellWindowId_LockScreenContainer)->
664 AddChild(lock_widget->GetNativeView()); 703 AddChild(lock_widget->GetNativeView());
665 lock_widget->Show(); 704 lock_widget->Show();
666 textfield->RequestFocus(); 705 textfield->RequestFocus();
667 706
668 aura::client::FocusClient* focus_client = 707 aura::client::FocusClient* focus_client =
669 aura::client::GetFocusClient(root_windows[0]); 708 aura::client::GetFocusClient(root_windows[0]);
670 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); 709 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
671 710
672 // The lock window should get events on both root windows. 711 // The lock window should get events on both root windows.
673 aura::test::EventGenerator generator1(root_windows[0]); 712 aura::test::EventGenerator& event_generator = GetEventGenerator();
674 generator1.PressKey(ui::VKEY_A, 0); 713
675 generator1.ReleaseKey(ui::VKEY_A, 0); 714 event_generator.set_current_root_window(root_windows[0]);
715 event_generator.PressKey(ui::VKEY_A, 0);
716 event_generator.ReleaseKey(ui::VKEY_A, 0);
676 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); 717 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
677 EXPECT_EQ("a", UTF16ToASCII(textfield->text())); 718 EXPECT_EQ("a", UTF16ToASCII(textfield->text()));
678 719
679 aura::test::EventGenerator generator2(root_windows[1]); 720 event_generator.set_current_root_window(root_windows[1]);
680 generator2.PressKey(ui::VKEY_B, 0); 721 event_generator.PressKey(ui::VKEY_B, 0);
681 generator2.ReleaseKey(ui::VKEY_B, 0); 722 event_generator.ReleaseKey(ui::VKEY_B, 0);
682 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); 723 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
683 EXPECT_EQ("ab", UTF16ToASCII(textfield->text())); 724 EXPECT_EQ("ab", UTF16ToASCII(textfield->text()));
684 725
685 // Deleting 2nd display. The lock window still should get the events. 726 // Deleting 2nd display. The lock window still should get the events.
686 UpdateDisplay("100x100"); 727 UpdateDisplay("100x100");
687 generator2.PressKey(ui::VKEY_C, 0); 728 event_generator.PressKey(ui::VKEY_C, 0);
688 generator2.ReleaseKey(ui::VKEY_C, 0); 729 event_generator.ReleaseKey(ui::VKEY_C, 0);
689 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); 730 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
690 EXPECT_EQ("abc", UTF16ToASCII(textfield->text())); 731 EXPECT_EQ("abc", UTF16ToASCII(textfield->text()));
691 732
692 // Creating 2nd display again, and lock window still should get events 733 // Creating 2nd display again, and lock window still should get events
693 // on both root windows. 734 // on both root windows.
694 UpdateDisplay("100x100,200x200"); 735 UpdateDisplay("100x100,200x200");
695 root_windows = Shell::GetAllRootWindows(); 736 root_windows = Shell::GetAllRootWindows();
696 generator1.PressKey(ui::VKEY_D, 0); 737 event_generator.set_current_root_window(root_windows[0]);
697 generator1.ReleaseKey(ui::VKEY_D, 0); 738 event_generator.PressKey(ui::VKEY_D, 0);
739 event_generator.ReleaseKey(ui::VKEY_D, 0);
698 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); 740 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
699 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text())); 741 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text()));
700 742
701 aura::test::EventGenerator generator22(root_windows[1]); 743 event_generator.set_current_root_window(root_windows[1]);
702 generator22.PressKey(ui::VKEY_E, 0); 744 event_generator.PressKey(ui::VKEY_E, 0);
703 generator22.ReleaseKey(ui::VKEY_E, 0); 745 event_generator.ReleaseKey(ui::VKEY_E, 0);
704 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); 746 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
705 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); 747 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text()));
706 } 748 }
707 749
750 TEST_F(ExtendedDesktopTest, PassiveGrab) {
751 EventLocationRecordingEventHandler event_handler;
752 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
753
754 UpdateDisplay("300x300,200x200");
755
756 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
757 widget->Show();
758 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
759
760 aura::test::EventGenerator& generator = GetEventGenerator();
761 generator.MoveMouseTo(150, 150);
762 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
763
764 generator.PressLeftButton();
765 generator.MoveMouseTo(400, 150);
766
767 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
768
769 generator.ReleaseLeftButton();
770 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
771
772 generator.MoveMouseTo(400, 150);
773 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
774
775 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
776 }
777
708 } // namespace internal 778 } // namespace internal
709 } // namespace ash 779 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/test/ash_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698