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

Side by Side Diff: ui/aura/desktop_unittest.cc

Issue 8526020: aura: Track mouse button state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 1 month 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/aura/desktop.cc ('k') | ui/aura/window_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) 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 "ui/aura/desktop.h" 5 #include "ui/aura/desktop.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/aura/event.h" 8 #include "ui/aura/event.h"
9 #include "ui/aura/test/aura_test_base.h" 9 #include "ui/aura/test/aura_test_base.h"
10 #include "ui/aura/test/test_window_delegate.h" 10 #include "ui/aura/test/test_window_delegate.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 private: 50 private:
51 int non_client_count_; 51 int non_client_count_;
52 gfx::Point non_client_location_; 52 gfx::Point non_client_location_;
53 int mouse_event_count_; 53 int mouse_event_count_;
54 gfx::Point mouse_event_location_; 54 gfx::Point mouse_event_location_;
55 int mouse_event_flags_; 55 int mouse_event_flags_;
56 }; 56 };
57 57
58 } // namespace 58 } // namespace
59 59
60 class DesktopTest : public AuraTestBase { 60 typedef AuraTestBase DesktopTest;
61 };
62 61
63 TEST_F(DesktopTest, DispatchMouseEvent) { 62 TEST_F(DesktopTest, DispatchMouseEvent) {
64 // Create two non-overlapping windows so we don't have to worry about which 63 // Create two non-overlapping windows so we don't have to worry about which
65 // is on top. 64 // is on top.
66 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); 65 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate());
67 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); 66 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate());
68 const int kWindowWidth = 123; 67 const int kWindowWidth = 123;
69 const int kWindowHeight = 45; 68 const int kWindowHeight = 45;
70 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); 69 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight);
71 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); 70 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight);
(...skipping 14 matching lines...) Expand all
86 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); 85 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location());
87 // Mouse event was received by target window. 86 // Mouse event was received by target window.
88 EXPECT_EQ(1, delegate1->mouse_event_count()); 87 EXPECT_EQ(1, delegate1->mouse_event_count());
89 EXPECT_EQ(0, delegate2->mouse_event_count()); 88 EXPECT_EQ(0, delegate2->mouse_event_count());
90 // Event was in local coordinates. 89 // Event was in local coordinates.
91 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); 90 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location());
92 // Non-client flag was set. 91 // Non-client flag was set.
93 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); 92 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT);
94 } 93 }
95 94
95 // Check that we correctly track the state of the mouse buttons in response to
96 // button press and release events.
97 TEST_F(DesktopTest, MouseButtonState) {
98 Desktop* desktop = Desktop::GetInstance();
99 EXPECT_FALSE(desktop->IsMouseButtonDown());
100
101 gfx::Point location;
102 scoped_ptr<MouseEvent> event;
103
104 // Press the left button.
105 event.reset(new MouseEvent(
106 ui::ET_MOUSE_PRESSED,
107 location,
108 ui::EF_LEFT_BUTTON_DOWN));
109 desktop->DispatchMouseEvent(event.get());
110 EXPECT_TRUE(desktop->IsMouseButtonDown());
111
112 // Additionally press the right.
113 event.reset(new MouseEvent(
114 ui::ET_MOUSE_PRESSED,
115 location,
116 ui::EF_LEFT_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN));
117 desktop->DispatchMouseEvent(event.get());
118 EXPECT_TRUE(desktop->IsMouseButtonDown());
119
120 // Release the left button.
121 event.reset(new MouseEvent(
122 ui::ET_MOUSE_RELEASED,
123 location,
124 ui::EF_RIGHT_BUTTON_DOWN));
125 desktop->DispatchMouseEvent(event.get());
126 EXPECT_TRUE(desktop->IsMouseButtonDown());
127
128 // Release the right button. We should ignore the Shift-is-down flag.
129 event.reset(new MouseEvent(
130 ui::ET_MOUSE_RELEASED,
131 location,
132 ui::EF_SHIFT_DOWN));
133 desktop->DispatchMouseEvent(event.get());
134 EXPECT_FALSE(desktop->IsMouseButtonDown());
135
136 // Press the middle button.
137 event.reset(new MouseEvent(
138 ui::ET_MOUSE_PRESSED,
139 location,
140 ui::EF_MIDDLE_BUTTON_DOWN));
141 desktop->DispatchMouseEvent(event.get());
142 EXPECT_TRUE(desktop->IsMouseButtonDown());
143 }
144
96 } // namespace test 145 } // namespace test
97 } // namespace aura 146 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/desktop.cc ('k') | ui/aura/window_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698