Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 // A view subclass that ignores all touch events for testing purposes. | 267 // A view subclass that ignores all touch events for testing purposes. |
| 268 class TestViewIgnoreTouch : public TestView { | 268 class TestViewIgnoreTouch : public TestView { |
| 269 public: | 269 public: |
| 270 TestViewIgnoreTouch() : TestView() {} | 270 TestViewIgnoreTouch() : TestView() {} |
| 271 virtual ~TestViewIgnoreTouch() {} | 271 virtual ~TestViewIgnoreTouch() {} |
| 272 | 272 |
| 273 private: | 273 private: |
| 274 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | 274 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; |
| 275 }; | 275 }; |
| 276 | 276 |
| 277 #if defined(TOUCH_UI) | |
|
rjkroege
2011/11/10 16:34:40
add a TOOO about making this test work on non-X pl
Gajen
2011/11/11 13:39:07
Done.
| |
| 278 // Test GestureManager for touch to mouse conversion. | |
| 279 class TestGestureManager : public GestureManager { | |
| 280 public: | |
| 281 // Reset all test state. | |
| 282 void Reset() { | |
| 283 last_touch_event_ = 0; | |
| 284 last_view_ = NULL; | |
| 285 previously_handled_flag_ = false; | |
| 286 dispatched_synthetic_event_ = false; | |
| 287 } | |
| 288 | |
| 289 bool ProcessTouchEventForGesture(const TouchEvent& event, | |
| 290 View* source, | |
| 291 ui::TouchStatus status); | |
| 292 TestGestureManager(); | |
| 293 | |
| 294 bool previously_handled_flag_; | |
| 295 int last_touch_event_; | |
| 296 View *last_view_; | |
| 297 bool dispatched_synthetic_event_; | |
| 298 | |
| 299 DISALLOW_COPY_AND_ASSIGN(TestGestureManager); | |
| 300 }; | |
| 301 | |
| 302 // A TouchEvent with filled in native event part to ease touch to | |
| 303 // mouse conversion. | |
| 304 class MockTouchEvent : public TouchEvent { | |
| 305 public: | |
| 306 // Create a new touch event. | |
| 307 MockTouchEvent(ui::EventType type, | |
| 308 int x, | |
| 309 int y, | |
| 310 int flags, | |
| 311 int touch_id, | |
| 312 float radius_x, | |
| 313 float radius_y, | |
| 314 float angle, | |
| 315 float force); | |
| 316 }; | |
| 317 #endif | |
| 318 | |
| 277 //////////////////////////////////////////////////////////////////////////////// | 319 //////////////////////////////////////////////////////////////////////////////// |
| 278 // OnBoundsChanged | 320 // OnBoundsChanged |
| 279 //////////////////////////////////////////////////////////////////////////////// | 321 //////////////////////////////////////////////////////////////////////////////// |
| 280 | 322 |
| 281 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 323 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 282 did_change_bounds_ = true; | 324 did_change_bounds_ = true; |
| 283 new_bounds_ = bounds(); | 325 new_bounds_ = bounds(); |
| 284 } | 326 } |
| 285 | 327 |
| 286 TEST_F(ViewTest, OnBoundsChanged) { | 328 TEST_F(ViewTest, OnBoundsChanged) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 EXPECT_EQ(v2->location_.y(), -100); | 416 EXPECT_EQ(v2->location_.y(), -100); |
| 375 // Make sure v1 did not receive the event | 417 // Make sure v1 did not receive the event |
| 376 EXPECT_EQ(v1->last_mouse_event_type_, 0); | 418 EXPECT_EQ(v1->last_mouse_event_type_, 0); |
| 377 | 419 |
| 378 widget->CloseNow(); | 420 widget->CloseNow(); |
| 379 } | 421 } |
| 380 | 422 |
| 381 //////////////////////////////////////////////////////////////////////////////// | 423 //////////////////////////////////////////////////////////////////////////////// |
| 382 // TouchEvent | 424 // TouchEvent |
| 383 //////////////////////////////////////////////////////////////////////////////// | 425 //////////////////////////////////////////////////////////////////////////////// |
| 426 | |
|
rjkroege
2011/11/10 16:34:40
remove
Gajen
2011/11/11 13:39:07
Done.
| |
| 384 bool MockGestureManager::ProcessTouchEventForGesture( | 427 bool MockGestureManager::ProcessTouchEventForGesture( |
| 385 const TouchEvent& event, | 428 const TouchEvent& event, |
| 386 View* source, | 429 View* source, |
| 387 ui::TouchStatus status) { | 430 ui::TouchStatus status) { |
| 388 if (status != ui::TOUCH_STATUS_UNKNOWN) { | 431 if (status != ui::TOUCH_STATUS_UNKNOWN) { |
| 389 dispatched_synthetic_event_ = false; | 432 dispatched_synthetic_event_ = false; |
| 390 return false; | 433 return false; |
| 391 } | 434 } |
| 392 last_touch_event_ = event.type(); | 435 last_touch_event_ = event.type(); |
| 393 last_view_ = source; | 436 last_view_ = source; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 // Make sure v1 did not receive the event | 573 // Make sure v1 did not receive the event |
| 531 EXPECT_EQ(v1->last_touch_event_type_, 0); | 574 EXPECT_EQ(v1->last_touch_event_type_, 0); |
| 532 | 575 |
| 533 EXPECT_EQ(gm.last_touch_event_, 0); | 576 EXPECT_EQ(gm.last_touch_event_, 0); |
| 534 EXPECT_EQ(NULL, gm.last_view_); | 577 EXPECT_EQ(NULL, gm.last_view_); |
| 535 EXPECT_EQ(gm.previously_handled_flag_, false); | 578 EXPECT_EQ(gm.previously_handled_flag_, false); |
| 536 | 579 |
| 537 widget->CloseNow(); | 580 widget->CloseNow(); |
| 538 } | 581 } |
| 539 | 582 |
| 583 #if defined(TOUCH_UI) | |
|
rjkroege
2011/11/10 16:34:40
there is lot of code in this file that assumes tou
Gajen
2011/11/11 13:39:07
Now placed, X11 based code and actual test "TouchT
| |
| 584 bool TestGestureManager::ProcessTouchEventForGesture( | |
| 585 const TouchEvent& event, | |
| 586 View* source, | |
| 587 ui::TouchStatus status) { | |
| 588 if (status != ui::TOUCH_STATUS_UNKNOWN) { | |
| 589 dispatched_synthetic_event_ = false; | |
| 590 return false; | |
| 591 } | |
| 592 last_touch_event_ = event.type(); | |
| 593 last_view_ = source; | |
| 594 previously_handled_flag_ = status != ui::TOUCH_STATUS_UNKNOWN; | |
| 595 return dispatched_synthetic_event_ = | |
| 596 GestureManager::ProcessTouchEventForGesture(event, source, status); | |
| 597 } | |
| 598 | |
| 599 TestGestureManager::TestGestureManager() { | |
| 600 } | |
| 601 | |
| 602 MockTouchEvent::MockTouchEvent(ui::EventType type, | |
| 603 int x, | |
| 604 int y, | |
| 605 int flags, | |
| 606 int touch_id, | |
| 607 float radius_x, | |
| 608 float radius_y, | |
| 609 float angle, | |
| 610 float force) | |
| 611 : TouchEvent(type, x, y, flags, touch_id, radius_x, radius_y, | |
| 612 angle, force) { | |
| 613 // Set XEvent and its internal fields. | |
|
rjkroege
2011/11/10 16:34:40
this code could be completely portable with differ
Gajen
2011/11/11 13:39:07
Added new files test_event_utils/_x/.h/.cc under v
| |
| 614 base::NativeEvent native_event = ui::GetNativeEventForTesting(); | |
| 615 ui::SetNativeEventLocationForTesting(native_event, x, y); | |
| 616 set_native_event(native_event); | |
| 617 } | |
| 618 | |
| 619 // Tests Real GestureManager instead of the mock one and validates Touch event | |
| 620 // to Mouse conversion when view hierarchy doesn't handle touch events. | |
| 621 TEST_F(ViewTest, TouchToMouse) { | |
| 622 TestGestureManager gm; | |
| 623 | |
| 624 TestView* v1 = new TestViewIgnoreTouch(); | |
| 625 v1->SetBounds(0, 0, 300, 300); | |
| 626 | |
| 627 TestView* v2 = new TestViewIgnoreTouch(); | |
| 628 v2->SetBounds(100, 100, 100, 100); | |
| 629 | |
| 630 scoped_ptr<Widget> widget(new Widget()); | |
| 631 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | |
| 632 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 633 params.bounds = gfx::Rect(50, 50, 650, 650); | |
| 634 widget->Init(params); | |
| 635 View* root = widget->GetRootView(); | |
| 636 root->AddChildView(v1); | |
| 637 static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm); | |
| 638 v1->AddChildView(v2); | |
| 639 | |
| 640 // Test press. | |
| 641 v1->Reset(); | |
| 642 v2->Reset(); | |
| 643 gm.Reset(); | |
| 644 | |
| 645 MockTouchEvent pressed(ui::ET_TOUCH_PRESSED, | |
| 646 110, | |
| 647 120, | |
| 648 0, /* no flags */ | |
| 649 0, /* first finger touch */ | |
| 650 1.0, 0.0, 1.0, 0.0); | |
| 651 root->OnTouchEvent(pressed); | |
| 652 | |
| 653 EXPECT_EQ(v2->last_touch_event_type_, 0); | |
| 654 EXPECT_EQ(v2->location_.x(), 10); | |
| 655 EXPECT_EQ(v2->location_.y(), 20); | |
| 656 // Make sure v1 did not receive the event | |
| 657 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 658 | |
| 659 // Since v1 and v2 didn't handled the touch-event, the gesture manager should | |
| 660 // handle it. | |
| 661 EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_PRESSED); | |
| 662 EXPECT_EQ(root, gm.last_view_); | |
| 663 EXPECT_EQ(gm.previously_handled_flag_, false); | |
| 664 EXPECT_EQ(gm.dispatched_synthetic_event_, true); | |
| 665 | |
| 666 // Check GestureManager converted Touch event to Mouse and propogates to v2 | |
| 667 // but v1. | |
| 668 EXPECT_EQ(v2->last_mouse_event_type_, ui::ET_MOUSE_PRESSED); | |
| 669 EXPECT_EQ(v2->location_.x(), 10); | |
| 670 EXPECT_EQ(v2->location_.y(), 20); | |
| 671 EXPECT_EQ(v1->last_mouse_event_type_, 0); | |
| 672 EXPECT_EQ(v1->location_.x(), 0); | |
| 673 EXPECT_EQ(v1->location_.y(), 0); | |
| 674 widget->CloseNow(); | |
| 675 } | |
| 676 #endif | |
| 677 | |
| 540 //////////////////////////////////////////////////////////////////////////////// | 678 //////////////////////////////////////////////////////////////////////////////// |
| 541 // Painting | 679 // Painting |
| 542 //////////////////////////////////////////////////////////////////////////////// | 680 //////////////////////////////////////////////////////////////////////////////// |
| 543 | 681 |
| 544 void TestView::Paint(gfx::Canvas* canvas) { | 682 void TestView::Paint(gfx::Canvas* canvas) { |
| 545 canvas->GetSkCanvas()->getClipBounds(&last_clip_); | 683 canvas->GetSkCanvas()->getClipBounds(&last_clip_); |
| 546 } | 684 } |
| 547 | 685 |
| 548 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { | 686 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { |
| 549 scheduled_paint_rects_.push_back(rect); | 687 scheduled_paint_rects_.push_back(rect); |
| (...skipping 2546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3096 ScrambleTree(content); | 3234 ScrambleTree(content); |
| 3097 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3235 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3098 | 3236 |
| 3099 ScrambleTree(content); | 3237 ScrambleTree(content); |
| 3100 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3238 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3101 } | 3239 } |
| 3102 | 3240 |
| 3103 #endif // VIEWS_COMPOSITOR | 3241 #endif // VIEWS_COMPOSITOR |
| 3104 | 3242 |
| 3105 } // namespace views | 3243 } // namespace views |
| OLD | NEW |