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

Side by Side Diff: ui/views/view_unittest.cc

Issue 406943002: Add test WidgetTest.GestureEventDispatch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/views/widget/widget_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 <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/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 widget->CloseNow(); 478 widget->CloseNow();
479 } 479 }
480 480
481 //////////////////////////////////////////////////////////////////////////////// 481 ////////////////////////////////////////////////////////////////////////////////
482 // GestureEvent 482 // GestureEvent
483 //////////////////////////////////////////////////////////////////////////////// 483 ////////////////////////////////////////////////////////////////////////////////
484 484
485 void TestView::OnGestureEvent(ui::GestureEvent* event) { 485 void TestView::OnGestureEvent(ui::GestureEvent* event) {
486 } 486 }
487 487
488 TEST_F(ViewTest, GestureEvent) {
489 // Views hierarchy for non delivery of GestureEvent.
490 TestView* v1 = new TestViewConsumeGesture();
491 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
492
493 TestView* v2 = new TestViewConsumeGesture();
494 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
495
496 TestView* v3 = new TestViewIgnoreGesture();
497 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100));
498
499 scoped_ptr<Widget> widget(new Widget());
500 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
501 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
502 params.bounds = gfx::Rect(50, 50, 650, 650);
503 widget->Init(params);
504 internal::RootView* root =
505 static_cast<internal::RootView*>(widget->GetRootView());
506 ui::EventDispatchDetails details;
507
508 root->AddChildView(v1);
509 v1->AddChildView(v2);
510 v2->AddChildView(v3);
511
512 // |v3| completely obscures |v2|, but all the gesture events on |v3| should
513 // reach |v2| because |v3| doesn't process any gesture events. However, since
514 // |v2| does process gesture events, gesture events on |v3| or |v2| should not
515 // reach |v1|.
516
517 v1->Reset();
518 v2->Reset();
519 v3->Reset();
520
521 // Gesture on |v3|
522 GestureEventForTest g1(ui::ET_GESTURE_TAP, 110, 110, 0);
523 details = root->OnEventFromSource(&g1);
524 EXPECT_FALSE(details.dispatcher_destroyed);
525 EXPECT_FALSE(details.target_destroyed);
526
527 EXPECT_EQ(ui::ET_GESTURE_TAP, v2->last_gesture_event_type_);
528 EXPECT_EQ(gfx::Point(10, 10), v2->location_);
529 EXPECT_EQ(ui::ET_UNKNOWN, v1->last_gesture_event_type_);
530
531 // Simulate an up so that RootView is no longer targetting |v3|.
532 GestureEventForTest g1_up(ui::ET_GESTURE_END, 110, 110, 0);
533 details = root->OnEventFromSource(&g1_up);
534 EXPECT_FALSE(details.dispatcher_destroyed);
535 EXPECT_FALSE(details.target_destroyed);
536
537 v1->Reset();
538 v2->Reset();
539 v3->Reset();
540
541 // Gesture on |v1|
542 GestureEventForTest g2(ui::ET_GESTURE_TAP, 80, 80, 0);
543 details = root->OnEventFromSource(&g2);
544 EXPECT_FALSE(details.dispatcher_destroyed);
545 EXPECT_FALSE(details.target_destroyed);
546
547 EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_);
548 EXPECT_EQ(gfx::Point(80, 80), v1->location_);
549 EXPECT_EQ(ui::ET_UNKNOWN, v2->last_gesture_event_type_);
550
551 // Send event |g1| again. Even though the coordinates target |v3| it should go
552 // to |v1| as that is the view the touch was initially down on.
553 v1->last_gesture_event_type_ = ui::ET_UNKNOWN;
554 v3->last_gesture_event_type_ = ui::ET_UNKNOWN;
555 details = root->OnEventFromSource(&g1);
556 EXPECT_FALSE(details.dispatcher_destroyed);
557 EXPECT_FALSE(details.target_destroyed);
558
559 EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_);
560 EXPECT_EQ(ui::ET_UNKNOWN, v3->last_gesture_event_type_);
561 EXPECT_EQ("110,110", v1->location_.ToString());
562
563 widget->CloseNow();
564 }
565
566 TEST_F(ViewTest, ScrollGestureEvent) { 488 TEST_F(ViewTest, ScrollGestureEvent) {
567 // Views hierarchy for non delivery of GestureEvent. 489 // Views hierarchy for non delivery of GestureEvent.
568 TestView* v1 = new TestViewConsumeGesture(); 490 TestView* v1 = new TestViewConsumeGesture();
569 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); 491 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
570 492
571 TestView* v2 = new TestViewIgnoreScrollGestures(); 493 TestView* v2 = new TestViewIgnoreScrollGestures();
572 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); 494 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
573 495
574 TestView* v3 = new TestViewIgnoreGesture(); 496 TestView* v3 = new TestViewIgnoreGesture();
575 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 497 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100));
(...skipping 3327 matching lines...) Expand 10 before | Expand all | Expand 10 after
3903 // notification. 3825 // notification.
3904 TestView* test_view_child_2 = new TestView(); 3826 TestView* test_view_child_2 = new TestView();
3905 test_view->AddChildView(test_view_child_2); 3827 test_view->AddChildView(test_view_child_2);
3906 EXPECT_TRUE(test_view_child_2->native_theme_); 3828 EXPECT_TRUE(test_view_child_2->native_theme_);
3907 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); 3829 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_);
3908 3830
3909 widget->CloseNow(); 3831 widget->CloseNow();
3910 } 3832 }
3911 3833
3912 } // namespace views 3834 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698