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

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

Issue 10824309: Adding unit test to check for incorrect mouse enter/exit event handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed names as requested Created 8 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
« no previous file with comments | « no previous file | 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/native_widget_types.h" 9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/gfx/point.h" 10 #include "ui/gfx/point.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // relevant platforms. 64 // relevant platforms.
65 #if defined(USE_AURA) 65 #if defined(USE_AURA)
66 typedef NativeWidgetCapture NativeWidgetPlatformForTest; 66 typedef NativeWidgetCapture NativeWidgetPlatformForTest;
67 #elif defined(OS_WIN) 67 #elif defined(OS_WIN)
68 typedef NativeWidgetWin NativeWidgetPlatformForTest; 68 typedef NativeWidgetWin NativeWidgetPlatformForTest;
69 #endif 69 #endif
70 70
71 // A view that always processes all mouse events. 71 // A view that always processes all mouse events.
72 class MouseView : public View { 72 class MouseView : public View {
73 public: 73 public:
74 MouseView() : View() { 74 MouseView()
75 : View(),
76 entered_(0),
77 exited_(0) {
75 } 78 }
76 virtual ~MouseView() {} 79 virtual ~MouseView() {}
77 80
78 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { 81 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
79 return true; 82 return true;
80 } 83 }
84
85 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
86 entered_++;
87 }
88
89 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
90 exited_++;
91 }
92
93 // Return the number of OnMouseEntered calls and reset the counter.
94 int EnteredCalls() {
95 int i = entered_;
96 entered_ = 0;
97 return i;
98 }
99
100 // Return the number of OnMouseExited calls and reset the counter.
101 int ExitedCalls() {
102 int i = exited_;
103 exited_ = 0;
104 return i;
105 }
106
107 private:
108 int entered_;
109 int exited_;
110
111 DISALLOW_COPY_AND_ASSIGN(MouseView);
81 }; 112 };
82 113
83 typedef ViewsTestBase WidgetTest; 114 typedef ViewsTestBase WidgetTest;
84 115
85 NativeWidget* CreatePlatformNativeWidget( 116 NativeWidget* CreatePlatformNativeWidget(
86 internal::NativeWidgetDelegate* delegate) { 117 internal::NativeWidgetDelegate* delegate) {
87 return new NativeWidgetPlatformForTest(delegate); 118 return new NativeWidgetPlatformForTest(delegate);
88 } 119 }
89 120
90 Widget* CreateTopLevelPlatformWidget() { 121 Widget* CreateTopLevelPlatformWidget() {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2, 275 ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2,
245 ui::EF_LEFT_MOUSE_BUTTON); 276 ui::EF_LEFT_MOUSE_BUTTON);
246 toplevel->OnMouseEvent(released2); 277 toplevel->OnMouseEvent(released2);
247 EXPECT_FALSE(WidgetHasMouseCapture(toplevel)); 278 EXPECT_FALSE(WidgetHasMouseCapture(toplevel));
248 EXPECT_FALSE(WidgetHasMouseCapture(child1)); 279 EXPECT_FALSE(WidgetHasMouseCapture(child1));
249 EXPECT_FALSE(WidgetHasMouseCapture(child2)); 280 EXPECT_FALSE(WidgetHasMouseCapture(child2));
250 281
251 toplevel->CloseNow(); 282 toplevel->CloseNow();
252 } 283 }
253 284
285 // Tests mouse move outside of the window into the "resize controller" and back
286 // will still generate an OnMouseEntered and OnMouseExited event..
287 TEST_F(WidgetTest, CheckResizeControllerEvents) {
288 Widget* toplevel = CreateTopLevelPlatformWidget();
289
290 toplevel->SetBounds(gfx::Rect(0, 0, 100, 100));
291
292 MouseView* view = new MouseView();
293 view->SetBounds(90, 90, 10, 10);
294 toplevel->GetRootView()->AddChildView(view);
295
296 toplevel->Show();
297 RunPendingMessages();
298
299 // Move to an outside position.
300 gfx::Point p1(200, 200);
301 ui::MouseEvent moved_out(ui::ET_MOUSE_MOVED, p1, p1, ui::EF_NONE);
302 toplevel->OnMouseEvent(moved_out);
303 EXPECT_EQ(0, view->EnteredCalls());
304 EXPECT_EQ(0, view->ExitedCalls());
305
306 // Move onto the active view.
307 gfx::Point p2(95, 95);
308 ui::MouseEvent moved_over(ui::ET_MOUSE_MOVED, p2, p2, ui::EF_NONE);
309 toplevel->OnMouseEvent(moved_over);
310 EXPECT_EQ(1, view->EnteredCalls());
311 EXPECT_EQ(0, view->ExitedCalls());
312
313 // Move onto the outer resizing border.
314 gfx::Point p3(102, 95);
315 ui::MouseEvent moved_resizer(ui::ET_MOUSE_MOVED, p3, p3, ui::EF_NONE);
316 toplevel->OnMouseEvent(moved_resizer);
317 EXPECT_EQ(0, view->EnteredCalls());
318 EXPECT_EQ(1, view->ExitedCalls());
319
320 // Move onto the view again.
321 toplevel->OnMouseEvent(moved_over);
322 EXPECT_EQ(1, view->EnteredCalls());
323 EXPECT_EQ(0, view->ExitedCalls());
324
325 RunPendingMessages();
326
327 toplevel->CloseNow();
328 }
329
254 // Test if a focus manager and an inputmethod work without CHECK failure 330 // Test if a focus manager and an inputmethod work without CHECK failure
255 // when window activation changes. 331 // when window activation changes.
256 TEST_F(WidgetTest, ChangeActivation) { 332 TEST_F(WidgetTest, ChangeActivation) {
257 Widget* top1 = CreateTopLevelPlatformWidget(); 333 Widget* top1 = CreateTopLevelPlatformWidget();
258 // CreateInputMethod before activated 334 // CreateInputMethod before activated
259 top1->GetInputMethod(); 335 top1->GetInputMethod();
260 top1->Show(); 336 top1->Show();
261 RunPendingMessages(); 337 RunPendingMessages();
262 338
263 Widget* top2 = CreateTopLevelPlatformWidget(); 339 Widget* top2 = CreateTopLevelPlatformWidget();
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 // And it stays maximized after getting out of full screen. 897 // And it stays maximized after getting out of full screen.
822 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel)); 898 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel));
823 899
824 // Clean up. 900 // Clean up.
825 toplevel->Close(); 901 toplevel->Close();
826 RunPendingMessages(); 902 RunPendingMessages();
827 } 903 }
828 904
829 } // namespace 905 } // namespace
830 } // namespace views 906 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698