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

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 472303004: Do not dispatch gesture events to disabled views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2341 EXPECT_EQ(1, v1->GetEventCount(ui::ET_GESTURE_END)); 2341 EXPECT_EQ(1, v1->GetEventCount(ui::ET_GESTURE_END));
2342 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); 2342 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2343 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); 2343 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2344 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END)); 2344 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
2345 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2345 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2346 EXPECT_TRUE(end.handled()); 2346 EXPECT_TRUE(end.handled());
2347 2347
2348 widget->Close(); 2348 widget->Close();
2349 } 2349 }
2350 2350
2351 // Verifies that disabled views are permitted to be set as the default gesture
2352 // handler in RootView. Also verifies that gesture events targeted to a disabled
2353 // view are not actually dispatched to the view, but are still marked as
2354 // handled.
2355 TEST_F(WidgetTest, DisabledGestureEventTarget) {
2356 Widget* widget = CreateTopLevelNativeWidget();
2357 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
2358
2359 // Define a hierarchy of four views (coordinates are in
2360 // their parent coordinate space).
2361 // v1 (0, 0, 300, 300)
2362 // v2 (0, 0, 100, 100)
2363 // v3 (0, 0, 50, 50)
2364 // v4(0, 0, 10, 10)
2365 EventCountView* v1 = new EventCountView();
2366 v1->SetBounds(0, 0, 300, 300);
2367 EventCountView* v2 = new EventCountView();
2368 v2->SetBounds(0, 0, 100, 100);
2369 EventCountView* v3 = new EventCountView();
2370 v3->SetBounds(0, 0, 50, 50);
2371 EventCountView* v4 = new EventCountView();
2372 v4->SetBounds(0, 0, 10, 10);
2373 internal::RootView* root_view =
2374 static_cast<internal::RootView*>(widget->GetRootView());
2375 root_view->AddChildView(v1);
2376 v1->AddChildView(v2);
2377 v2->AddChildView(v3);
2378 v3->AddChildView(v4);
2379
2380 widget->Show();
2381
2382 // |v1|, |v2|, and |v3| all handle gesture events but |v3| is marked as
2383 // disabled.
2384 v1->set_handle_mode(EventCountView::CONSUME_EVENTS);
2385 v2->set_handle_mode(EventCountView::CONSUME_EVENTS);
2386 v3->set_handle_mode(EventCountView::CONSUME_EVENTS);
2387 v3->SetEnabled(false);
2388
2389 // No gesture handler is set in the root view, so it should remain unset
2390 // after a GESTURE_END. The event is first dispatched to |v4| (which does
2391 // not want to handle the event) and is then targeted at |v3|. Since |v3|
2392 // is disabled, the event is not dispatched but is still marked as handled.
2393 GestureEventForTest end(ui::ET_GESTURE_END, 5, 5);
2394 widget->OnGestureEvent(&end);
2395 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
2396 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2397 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2398 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_END));
2399 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2400 EXPECT_TRUE(end.handled());
2401 v1->ResetCounts();
2402 v2->ResetCounts();
2403 v3->ResetCounts();
2404 v4->ResetCounts();
2405
2406 // No gesture handler is set in the root view. In this case the tap event
2407 // should be dispatched only to |v4|, the gesture handler should be set to
2408 // |v3|, and the event should be marked as handled.
2409 GestureEventForTest tap(ui::ET_GESTURE_TAP, 5, 5);
2410 widget->OnGestureEvent(&tap);
2411 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP));
2412 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP));
2413 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_TAP));
2414 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_TAP));
2415 EXPECT_EQ(v3, GetGestureHandler(root_view));
2416 EXPECT_TRUE(tap.handled());
2417 v1->ResetCounts();
2418 v2->ResetCounts();
2419 v3->ResetCounts();
2420 v4->ResetCounts();
2421
2422 // A subsequent gesture event should be marked as handled but not dispatched.
2423 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 5, 5);
2424 widget->OnGestureEvent(&tap);
2425 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP));
2426 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP));
2427 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_TAP));
2428 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP));
2429 EXPECT_EQ(v3, GetGestureHandler(root_view));
2430 EXPECT_TRUE(tap.handled());
2431 v1->ResetCounts();
2432 v2->ResetCounts();
2433 v3->ResetCounts();
2434 v4->ResetCounts();
2435
2436 // A GESTURE_END should reset the default gesture handler to NULL. It should
2437 // also not be dispatched to |v3| but still marked as handled.
2438 end = GestureEventForTest(ui::ET_GESTURE_END, 5, 5);
2439 widget->OnGestureEvent(&end);
2440 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
2441 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2442 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2443 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
2444 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2445 EXPECT_TRUE(end.handled());
2446 v1->ResetCounts();
2447 v2->ResetCounts();
2448 v3->ResetCounts();
2449 v4->ResetCounts();
2450
2451 // Change the handle mode of |v3| to indicate that it would no longer like
2452 // to handle events which are dispatched to it.
2453 v3->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
2454
2455 // No gesture handler is set in the root view. In this case the tap event
2456 // should be dispatched only to |v4| and the event should be marked as
2457 // handled. Furthermore, the gesture handler should be set to
2458 // |v3|; even though |v3| does not explicitly handle events, it is a
2459 // valid target for the tap event because it is disabled.
2460 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 5, 5);
2461 widget->OnGestureEvent(&tap);
2462 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP));
2463 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP));
2464 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_TAP));
2465 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_TAP));
2466 EXPECT_EQ(v3, GetGestureHandler(root_view));
2467 EXPECT_TRUE(tap.handled());
2468 v1->ResetCounts();
2469 v2->ResetCounts();
2470 v3->ResetCounts();
2471 v4->ResetCounts();
2472
2473 // A GESTURE_END should reset the default gesture handler to NULL. It should
2474 // also not be dispatched to |v3| but still marked as handled.
2475 end = GestureEventForTest(ui::ET_GESTURE_END, 5, 5);
2476 widget->OnGestureEvent(&end);
2477 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
2478 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2479 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2480 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
2481 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2482 EXPECT_TRUE(end.handled());
2483
2484 widget->Close();
2485 }
2486
2351 // Test the result of Widget::GetAllChildWidgets(). 2487 // Test the result of Widget::GetAllChildWidgets().
2352 TEST_F(WidgetTest, GetAllChildWidgets) { 2488 TEST_F(WidgetTest, GetAllChildWidgets) {
2353 // Create the following widget hierarchy: 2489 // Create the following widget hierarchy:
2354 // 2490 //
2355 // toplevel 2491 // toplevel
2356 // +-- w1 2492 // +-- w1
2357 // +-- w11 2493 // +-- w11
2358 // +-- w2 2494 // +-- w2
2359 // +-- w21 2495 // +-- w21
2360 // +-- w22 2496 // +-- w22
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
2952 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); 3088 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED));
2953 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); 3089 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED));
2954 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); 3090 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED));
2955 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); 3091 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags());
2956 3092
2957 widget->CloseNow(); 3093 widget->CloseNow();
2958 } 3094 }
2959 3095
2960 } // namespace test 3096 } // namespace test
2961 } // namespace views 3097 } // namespace views
OLDNEW
« ui/views/widget/root_view.cc ('K') | « ui/views/widget/root_view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698