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

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

Issue 147203004: aura: Remove event-dispatch methods from WindowTreeHostDelegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 10 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 | « ui/views/widget/widget_interactive_uitest.cc ('k') | no next file » | 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 <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 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 1316
1317 DISALLOW_COPY_AND_ASSIGN(CloseWidgetView); 1317 DISALLOW_COPY_AND_ASSIGN(CloseWidgetView);
1318 }; 1318 };
1319 1319
1320 // Generates two moves (first generates enter, second real move), a press, drag 1320 // Generates two moves (first generates enter, second real move), a press, drag
1321 // and release stopping at |last_event_type|. 1321 // and release stopping at |last_event_type|.
1322 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { 1322 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) {
1323 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); 1323 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen());
1324 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), 1324 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(),
1325 screen_bounds.CenterPoint(), 0, 0); 1325 screen_bounds.CenterPoint(), 0, 0);
1326 aura::WindowTreeHostDelegate* rwhd = 1326 aura::WindowEventDispatcher* dispatcher =
1327 widget->GetNativeWindow()->GetDispatcher()->AsWindowTreeHostDelegate(); 1327 widget->GetNativeWindow()->GetDispatcher();
1328 rwhd->OnHostMouseEvent(&move_event); 1328 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event);
1329 if (last_event_type == ui::ET_MOUSE_ENTERED) 1329 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed)
1330 return; 1330 return;
1331 rwhd->OnHostMouseEvent(&move_event); 1331 details = dispatcher->OnEventFromSource(&move_event);
1332 if (last_event_type == ui::ET_MOUSE_MOVED) 1332 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed)
1333 return; 1333 return;
1334 1334
1335 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), 1335 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(),
1336 screen_bounds.CenterPoint(), 0, 0); 1336 screen_bounds.CenterPoint(), 0, 0);
1337 rwhd->OnHostMouseEvent(&press_event); 1337 details = dispatcher->OnEventFromSource(&press_event);
1338 if (last_event_type == ui::ET_MOUSE_PRESSED) 1338 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed)
1339 return; 1339 return;
1340 1340
1341 gfx::Point end_point(screen_bounds.CenterPoint()); 1341 gfx::Point end_point(screen_bounds.CenterPoint());
1342 end_point.Offset(1, 1); 1342 end_point.Offset(1, 1);
1343 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, 0, 0); 1343 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, 0, 0);
1344 rwhd->OnHostMouseEvent(&drag_event); 1344 details = dispatcher->OnEventFromSource(&drag_event);
1345 if (last_event_type == ui::ET_MOUSE_DRAGGED) 1345 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed)
1346 return; 1346 return;
1347 1347
1348 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, 0, 1348 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, 0,
1349 0); 1349 0);
1350 rwhd->OnHostMouseEvent(&release_event); 1350 details = dispatcher->OnEventFromSource(&release_event);
1351 if (details.dispatcher_destroyed)
1352 return;
1351 } 1353 }
1352 1354
1353 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. 1355 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|.
1354 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, 1356 void RunCloseWidgetDuringDispatchTest(WidgetTest* test,
1355 ui::EventType last_event_type) { 1357 ui::EventType last_event_type) {
1356 // |widget| is deleted by CloseWidgetView. 1358 // |widget| is deleted by CloseWidgetView.
1357 Widget* widget = new Widget; 1359 Widget* widget = new Widget;
1358 Widget::InitParams params = 1360 Widget::InitParams params =
1359 test->CreateParams(Widget::InitParams::TYPE_POPUP); 1361 test->CreateParams(Widget::InitParams::TYPE_POPUP);
1360 params.native_widget = new DesktopNativeWidgetAura(widget); 1362 params.native_widget = new DesktopNativeWidgetAura(widget);
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 EventCountView* widget_view = new EventCountView(); 2081 EventCountView* widget_view = new EventCountView();
2080 widget_view->SetBounds(0, 0, 10, 10); 2082 widget_view->SetBounds(0, 0, 10, 10);
2081 top_level_widget.GetRootView()->AddChildView(widget_view); 2083 top_level_widget.GetRootView()->AddChildView(widget_view);
2082 2084
2083 gfx::Point cursor_location_main(5, 5); 2085 gfx::Point cursor_location_main(5, 5);
2084 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, 2086 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED,
2085 cursor_location_main, 2087 cursor_location_main,
2086 cursor_location_main, 2088 cursor_location_main,
2087 ui::EF_NONE, 2089 ui::EF_NONE,
2088 ui::EF_NONE); 2090 ui::EF_NONE);
2089 top_level_widget.GetNativeView()->GetDispatcher()-> 2091 ui::EventDispatchDetails details = top_level_widget.GetNativeView()->
2090 AsWindowTreeHostDelegate()->OnHostMouseEvent(&move_main); 2092 GetDispatcher()->OnEventFromSource(&move_main);
2093 ASSERT_FALSE(details.dispatcher_destroyed);
2091 2094
2092 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); 2095 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED));
2093 widget_view->ResetCounts(); 2096 widget_view->ResetCounts();
2094 2097
2095 // Create a modal dialog and validate that a mouse down message makes it to 2098 // Create a modal dialog and validate that a mouse down message makes it to
2096 // the main view within the dialog. 2099 // the main view within the dialog.
2097 2100
2098 // This instance will be destroyed when the dialog is destroyed. 2101 // This instance will be destroyed when the dialog is destroyed.
2099 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; 2102 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate;
2100 2103
2101 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( 2104 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
2102 dialog_delegate, NULL, top_level_widget.GetNativeWindow()); 2105 dialog_delegate, NULL, top_level_widget.GetNativeWindow());
2103 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); 2106 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
2104 EventCountView* dialog_widget_view = new EventCountView(); 2107 EventCountView* dialog_widget_view = new EventCountView();
2105 dialog_widget_view->SetBounds(0, 0, 50, 50); 2108 dialog_widget_view->SetBounds(0, 0, 50, 50);
2106 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); 2109 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view);
2107 modal_dialog_widget->Show(); 2110 modal_dialog_widget->Show();
2108 EXPECT_TRUE(modal_dialog_widget->IsVisible()); 2111 EXPECT_TRUE(modal_dialog_widget->IsVisible());
2109 2112
2110 gfx::Point cursor_location_dialog(100, 100); 2113 gfx::Point cursor_location_dialog(100, 100);
2111 ui::MouseEvent mouse_down_dialog(ui::ET_MOUSE_PRESSED, 2114 ui::MouseEvent mouse_down_dialog(ui::ET_MOUSE_PRESSED,
2112 cursor_location_dialog, 2115 cursor_location_dialog,
2113 cursor_location_dialog, 2116 cursor_location_dialog,
2114 ui::EF_NONE, 2117 ui::EF_NONE,
2115 ui::EF_NONE); 2118 ui::EF_NONE);
2116 top_level_widget.GetNativeView()->GetDispatcher()-> 2119 details = top_level_widget.GetNativeView()->GetDispatcher()->
2117 AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_down_dialog); 2120 OnEventFromSource(&mouse_down_dialog);
2121 ASSERT_FALSE(details.dispatcher_destroyed);
2118 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); 2122 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED));
2119 2123
2120 // Send a mouse move message to the main window. It should not be received by 2124 // Send a mouse move message to the main window. It should not be received by
2121 // the main window as the modal dialog is still active. 2125 // the main window as the modal dialog is still active.
2122 gfx::Point cursor_location_main2(6, 6); 2126 gfx::Point cursor_location_main2(6, 6);
2123 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, 2127 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED,
2124 cursor_location_main2, 2128 cursor_location_main2,
2125 cursor_location_main2, 2129 cursor_location_main2,
2126 ui::EF_NONE, 2130 ui::EF_NONE,
2127 ui::EF_NONE); 2131 ui::EF_NONE);
2128 top_level_widget.GetNativeView()->GetDispatcher()-> 2132 details = top_level_widget.GetNativeView()->GetDispatcher()->
2129 AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_down_main); 2133 OnEventFromSource(&mouse_down_main);
2134 ASSERT_FALSE(details.dispatcher_destroyed);
2130 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); 2135 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED));
2131 2136
2132 modal_dialog_widget->CloseNow(); 2137 modal_dialog_widget->CloseNow();
2133 top_level_widget.CloseNow(); 2138 top_level_widget.CloseNow();
2134 } 2139 }
2135 2140
2136 #if defined(USE_AURA) 2141 #if defined(USE_AURA)
2137 // Verifies nativeview visbility matches that of Widget visibility when 2142 // Verifies nativeview visbility matches that of Widget visibility when
2138 // SetFullscreen is invoked. 2143 // SetFullscreen is invoked.
2139 TEST_F(WidgetTest, FullscreenStatePropagated) { 2144 TEST_F(WidgetTest, FullscreenStatePropagated) {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 widget->SetFullscreen(true); 2381 widget->SetFullscreen(true);
2377 widget->Show(); 2382 widget->Show();
2378 RunPendingMessages(); 2383 RunPendingMessages();
2379 EXPECT_TRUE(frame->fullscreen_layout_called()); 2384 EXPECT_TRUE(frame->fullscreen_layout_called());
2380 2385
2381 widget->CloseNow(); 2386 widget->CloseNow();
2382 } 2387 }
2383 2388
2384 } // namespace test 2389 } // namespace test
2385 } // namespace views 2390 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget_interactive_uitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698