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

Side by Side Diff: ash/extended_desktop_unittest.cc

Issue 380343002: aura: Make sure redirected events have the correct location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix-clang-build Created 6 years, 5 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 | ui/aura/window_event_dispatcher_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 "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/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 location_.SetPoint(-999, -999); 110 location_.SetPoint(-999, -999);
111 root_location_.SetPoint(-999, -999); 111 root_location_.SetPoint(-999, -999);
112 } 112 }
113 113
114 gfx::Point root_location_; 114 gfx::Point root_location_;
115 gfx::Point location_; 115 gfx::Point location_;
116 116
117 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler); 117 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
118 }; 118 };
119 119
120 class EventLocationHandler : public ui::EventHandler {
121 public:
122 EventLocationHandler() {}
123 virtual ~EventLocationHandler() {}
124
125 const gfx::Point& press_location() const { return press_location_; }
126 const gfx::Point& release_location() const { return release_location_; }
127
128 private:
129 // ui::EventHandler:
130 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
131 if (event->type() == ui::ET_MOUSE_PRESSED)
132 press_location_ = event->location();
133 else if (event->type() == ui::ET_MOUSE_RELEASED)
134 release_location_ = event->location();
135 }
136
137 gfx::Point press_location_;
138 gfx::Point release_location_;
139
140 DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
141 };
142
120 } // namespace 143 } // namespace
121 144
122 class ExtendedDesktopTest : public test::AshTestBase { 145 class ExtendedDesktopTest : public test::AshTestBase {
123 public: 146 public:
124 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { 147 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
125 return CreateTestWidgetWithParentAndContext( 148 return CreateTestWidgetWithParentAndContext(
126 NULL, CurrentContext(), bounds, false); 149 NULL, CurrentContext(), bounds, false);
127 } 150 }
128 151
129 views::Widget* CreateTestWidgetWithParent(views::Widget* parent, 152 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 431
409 generator.MoveMouseToCenterOf(r2_w1.get()); 432 generator.MoveMouseToCenterOf(r2_w1.get());
410 generator.ClickLeftButton(); 433 generator.ClickLeftButton();
411 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); 434 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
412 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); 435 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
413 // Make sure the mouse_moved_handler_ is properly reset. 436 // Make sure the mouse_moved_handler_ is properly reset.
414 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); 437 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
415 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); 438 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
416 } 439 }
417 440
441 TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
442 if (!SupportsMultipleDisplays())
443 return;
444
445 UpdateDisplay("1000x600,600x400");
446 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
447
448 aura::test::EventCountDelegate r1_d1;
449 aura::test::EventCountDelegate r1_d2;
450 aura::test::EventCountDelegate r2_d1;
451
452 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
453 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
454 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
455 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
456 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
457 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
458
459 r1_w1->SetCapture();
460
461 aura::test::EventGenerator& generator = GetEventGenerator();
462 generator.MoveMouseToCenterOf(r2_w1.get());
463 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
464 generator.current_location().ToString());
465
466 EventLocationHandler location_handler;
467 r1_w1->AddPreTargetHandler(&location_handler);
468 generator.ClickLeftButton();
469 r1_w1->RemovePreTargetHandler(&location_handler);
470 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
471 location_handler.press_location().ToString());
472 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
473 location_handler.release_location().ToString());
474 }
475
476 TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
477 if (!SupportsMultipleDisplays())
478 return;
479
480 UpdateDisplay("1000x600*2,600x400");
481 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
482
483 aura::test::EventCountDelegate r1_d1;
484 aura::test::EventCountDelegate r1_d2;
485 aura::test::EventCountDelegate r2_d1;
486
487 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
488 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
489 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
490 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
491 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
492 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
493
494 r1_w1->SetCapture();
495
496 aura::test::EventGenerator& generator = GetEventGenerator();
497 generator.MoveMouseToCenterOf(r2_w1.get());
498 EXPECT_EQ(gfx::Point(560, 60).ToString(),
499 generator.current_location().ToString());
500
501 EventLocationHandler location_handler;
502 r1_w1->AddPreTargetHandler(&location_handler);
503 generator.ClickLeftButton();
504 r1_w1->RemovePreTargetHandler(&location_handler);
505 EXPECT_EQ(gfx::Point(550, 50).ToString(),
506 location_handler.press_location().ToString());
507 EXPECT_EQ(gfx::Point(550, 50).ToString(),
508 location_handler.release_location().ToString());
509 }
510
511 TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
512 if (!SupportsMultipleDisplays())
513 return;
514
515 UpdateDisplay("1000x600,600x400*2");
516 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
517
518 aura::test::EventCountDelegate r1_d1;
519 aura::test::EventCountDelegate r1_d2;
520 aura::test::EventCountDelegate r2_d1;
521
522 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
523 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
524 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
525 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
526 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
527 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
528
529 r1_w1->SetCapture();
530
531 aura::test::EventGenerator& generator = GetEventGenerator();
532 generator.MoveMouseToCenterOf(r2_w1.get());
533 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
534 generator.current_location().ToString());
535
536 EventLocationHandler location_handler;
537 r1_w1->AddPreTargetHandler(&location_handler);
538 generator.ClickLeftButton();
539 r1_w1->RemovePreTargetHandler(&location_handler);
540 // Event-generator dispatches the event in the primary root-window's coord
541 // space. Since the location is (1060, 60), it goes to the secondary
542 // root-window as (30, 30) since the secondary root-window has a device scale
543 // factor of 2.
544 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
545 location_handler.press_location().ToString());
546 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
547 location_handler.release_location().ToString());
548 }
549
418 TEST_F(ExtendedDesktopTest, MoveWindow) { 550 TEST_F(ExtendedDesktopTest, MoveWindow) {
419 if (!SupportsMultipleDisplays()) 551 if (!SupportsMultipleDisplays())
420 return; 552 return;
421 553
422 UpdateDisplay("1000x600,600x400"); 554 UpdateDisplay("1000x600,600x400");
423 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 555 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
424 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); 556 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
425 557
426 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); 558 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
427 559
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 generator.ReleaseLeftButton(); 929 generator.ReleaseLeftButton();
798 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset()); 930 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
799 931
800 generator.MoveMouseTo(400, 150); 932 generator.MoveMouseTo(400, 150);
801 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset()); 933 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
802 934
803 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 935 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
804 } 936 }
805 937
806 } // namespace ash 938 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/aura/window_event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698