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

Side by Side Diff: content/renderer/mouse_lock_dispatcher_browsertest.cc

Issue 63253002: Rename WebKit namespace to blink (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | « content/renderer/mouse_lock_dispatcher.cc ('k') | content/renderer/notification_provider.h » ('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 <string> 5 #include <string>
6 6
7 #include "content/common/view_messages.h" 7 #include "content/common/view_messages.h"
8 #include "content/public/test/render_view_test.h" 8 #include "content/public/test/render_view_test.h"
9 #include "content/renderer/mouse_lock_dispatcher.h" 9 #include "content/renderer/mouse_lock_dispatcher.h"
10 #include "content/renderer/render_view_impl.h" 10 #include "content/renderer/render_view_impl.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using ::testing::_; 14 using ::testing::_;
15 15
16 namespace content { 16 namespace content {
17 namespace { 17 namespace {
18 18
19 class MockLockTarget : public MouseLockDispatcher::LockTarget { 19 class MockLockTarget : public MouseLockDispatcher::LockTarget {
20 public: 20 public:
21 MOCK_METHOD1(OnLockMouseACK, void(bool)); 21 MOCK_METHOD1(OnLockMouseACK, void(bool));
22 MOCK_METHOD0(OnMouseLockLost, void()); 22 MOCK_METHOD0(OnMouseLockLost, void());
23 MOCK_METHOD1(HandleMouseLockedInputEvent, 23 MOCK_METHOD1(HandleMouseLockedInputEvent,
24 bool(const WebKit::WebMouseEvent&)); 24 bool(const blink::WebMouseEvent&));
25 }; 25 };
26 26
27 // MouseLockDispatcher is a RenderViewObserver, and we test it by creating a 27 // MouseLockDispatcher is a RenderViewObserver, and we test it by creating a
28 // fixture containing a RenderViewImpl view() and interacting to that interface. 28 // fixture containing a RenderViewImpl view() and interacting to that interface.
29 class MouseLockDispatcherTest : public RenderViewTest { 29 class MouseLockDispatcherTest : public RenderViewTest {
30 public: 30 public:
31 virtual void SetUp() { 31 virtual void SetUp() {
32 RenderViewTest::SetUp(); 32 RenderViewTest::SetUp();
33 route_id_ = view()->GetRoutingID(); 33 route_id_ = view()->GetRoutingID();
34 target_ = new MockLockTarget(); 34 target_ = new MockLockTarget();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Start unlocked. 83 // Start unlocked.
84 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(NULL)); 84 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(NULL));
85 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_)); 85 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_));
86 86
87 // Lock. 87 // Lock.
88 EXPECT_TRUE(dispatcher()->LockMouse(target_)); 88 EXPECT_TRUE(dispatcher()->LockMouse(target_));
89 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true)); 89 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true));
90 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_)); 90 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_));
91 91
92 // Receive mouse event. 92 // Receive mouse event.
93 dispatcher()->WillHandleMouseEvent(WebKit::WebMouseEvent()); 93 dispatcher()->WillHandleMouseEvent(blink::WebMouseEvent());
94 94
95 // Unlock. 95 // Unlock.
96 dispatcher()->UnlockMouse(target_); 96 dispatcher()->UnlockMouse(target_);
97 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_)); 97 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_));
98 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_)); 98 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_));
99 99
100 // Attempt a lock, and have it fail. 100 // Attempt a lock, and have it fail.
101 EXPECT_TRUE(dispatcher()->LockMouse(target_)); 101 EXPECT_TRUE(dispatcher()->LockMouse(target_));
102 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, false)); 102 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, false));
103 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_)); 103 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_));
104 } 104 }
105 105
106 // Test deleting a target while it is in use by MouseLockDispatcher. 106 // Test deleting a target while it is in use by MouseLockDispatcher.
107 TEST_F(MouseLockDispatcherTest, DeleteAndUnlock) { 107 TEST_F(MouseLockDispatcherTest, DeleteAndUnlock) {
108 ::testing::InSequence expect_calls_in_sequence; 108 ::testing::InSequence expect_calls_in_sequence;
109 EXPECT_CALL(*target_, OnLockMouseACK(true)); 109 EXPECT_CALL(*target_, OnLockMouseACK(true));
110 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)).Times(0); 110 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)).Times(0);
111 EXPECT_CALL(*target_, OnMouseLockLost()).Times(0); 111 EXPECT_CALL(*target_, OnMouseLockLost()).Times(0);
112 112
113 // Lock. 113 // Lock.
114 EXPECT_TRUE(dispatcher()->LockMouse(target_)); 114 EXPECT_TRUE(dispatcher()->LockMouse(target_));
115 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true)); 115 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true));
116 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_)); 116 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_));
117 117
118 // Unlock, with a deleted target. 118 // Unlock, with a deleted target.
119 // Don't receive mouse events or lock lost. 119 // Don't receive mouse events or lock lost.
120 dispatcher()->OnLockTargetDestroyed(target_); 120 dispatcher()->OnLockTargetDestroyed(target_);
121 delete target_; 121 delete target_;
122 target_ = NULL; 122 target_ = NULL;
123 dispatcher()->WillHandleMouseEvent(WebKit::WebMouseEvent()); 123 dispatcher()->WillHandleMouseEvent(blink::WebMouseEvent());
124 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_)); 124 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_));
125 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_)); 125 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_));
126 } 126 }
127 127
128 // Test deleting a target that is pending a lock request response. 128 // Test deleting a target that is pending a lock request response.
129 TEST_F(MouseLockDispatcherTest, DeleteWithPendingLockSuccess) { 129 TEST_F(MouseLockDispatcherTest, DeleteWithPendingLockSuccess) {
130 ::testing::InSequence expect_calls_in_sequence; 130 ::testing::InSequence expect_calls_in_sequence;
131 EXPECT_CALL(*target_, OnLockMouseACK(true)).Times(0); 131 EXPECT_CALL(*target_, OnLockMouseACK(true)).Times(0);
132 EXPECT_CALL(*target_, OnMouseLockLost()).Times(0); 132 EXPECT_CALL(*target_, OnMouseLockLost()).Times(0);
133 133
(...skipping 30 matching lines...) Expand all
164 // Test not receiving mouse events when a target is not locked. 164 // Test not receiving mouse events when a target is not locked.
165 TEST_F(MouseLockDispatcherTest, MouseEventsNotReceived) { 165 TEST_F(MouseLockDispatcherTest, MouseEventsNotReceived) {
166 ::testing::InSequence expect_calls_in_sequence; 166 ::testing::InSequence expect_calls_in_sequence;
167 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)).Times(0); 167 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)).Times(0);
168 EXPECT_CALL(*target_, OnLockMouseACK(true)); 168 EXPECT_CALL(*target_, OnLockMouseACK(true));
169 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)); 169 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_));
170 EXPECT_CALL(*target_, OnMouseLockLost()); 170 EXPECT_CALL(*target_, OnMouseLockLost());
171 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)).Times(0); 171 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)).Times(0);
172 172
173 // (Don't) receive mouse event. 173 // (Don't) receive mouse event.
174 dispatcher()->WillHandleMouseEvent(WebKit::WebMouseEvent()); 174 dispatcher()->WillHandleMouseEvent(blink::WebMouseEvent());
175 175
176 // Lock. 176 // Lock.
177 EXPECT_TRUE(dispatcher()->LockMouse(target_)); 177 EXPECT_TRUE(dispatcher()->LockMouse(target_));
178 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true)); 178 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true));
179 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_)); 179 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_));
180 180
181 // Receive mouse event. 181 // Receive mouse event.
182 dispatcher()->WillHandleMouseEvent(WebKit::WebMouseEvent()); 182 dispatcher()->WillHandleMouseEvent(blink::WebMouseEvent());
183 183
184 // Unlock. 184 // Unlock.
185 dispatcher()->UnlockMouse(target_); 185 dispatcher()->UnlockMouse(target_);
186 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_)); 186 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_));
187 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_)); 187 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_));
188 188
189 // (Don't) receive mouse event. 189 // (Don't) receive mouse event.
190 dispatcher()->WillHandleMouseEvent(WebKit::WebMouseEvent()); 190 dispatcher()->WillHandleMouseEvent(blink::WebMouseEvent());
191 } 191 }
192 192
193 // Test multiple targets 193 // Test multiple targets
194 TEST_F(MouseLockDispatcherTest, MultipleTargets) { 194 TEST_F(MouseLockDispatcherTest, MultipleTargets) {
195 ::testing::InSequence expect_calls_in_sequence; 195 ::testing::InSequence expect_calls_in_sequence;
196 EXPECT_CALL(*target_, OnLockMouseACK(true)); 196 EXPECT_CALL(*target_, OnLockMouseACK(true));
197 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_)); 197 EXPECT_CALL(*target_, HandleMouseLockedInputEvent(_));
198 EXPECT_CALL(*alternate_target_, HandleMouseLockedInputEvent(_)).Times(0); 198 EXPECT_CALL(*alternate_target_, HandleMouseLockedInputEvent(_)).Times(0);
199 EXPECT_CALL(*target_, OnMouseLockLost()).Times(0); 199 EXPECT_CALL(*target_, OnMouseLockLost()).Times(0);
200 EXPECT_CALL(*alternate_target_, OnMouseLockLost()).Times(0); 200 EXPECT_CALL(*alternate_target_, OnMouseLockLost()).Times(0);
201 EXPECT_CALL(*target_, OnMouseLockLost()); 201 EXPECT_CALL(*target_, OnMouseLockLost());
202 202
203 // Lock request for target. 203 // Lock request for target.
204 EXPECT_TRUE(dispatcher()->LockMouse(target_)); 204 EXPECT_TRUE(dispatcher()->LockMouse(target_));
205 205
206 // Fail attempt to lock alternate. 206 // Fail attempt to lock alternate.
207 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(alternate_target_)); 207 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(alternate_target_));
208 EXPECT_FALSE(dispatcher()->LockMouse(alternate_target_)); 208 EXPECT_FALSE(dispatcher()->LockMouse(alternate_target_));
209 209
210 // Lock completion for target. 210 // Lock completion for target.
211 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true)); 211 view()->OnMessageReceived(ViewMsg_LockMouse_ACK(route_id_, true));
212 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_)); 212 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_));
213 213
214 // Fail attempt to lock alternate. 214 // Fail attempt to lock alternate.
215 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(alternate_target_)); 215 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(alternate_target_));
216 EXPECT_FALSE(dispatcher()->LockMouse(alternate_target_)); 216 EXPECT_FALSE(dispatcher()->LockMouse(alternate_target_));
217 217
218 // Receive mouse event to only one target. 218 // Receive mouse event to only one target.
219 dispatcher()->WillHandleMouseEvent(WebKit::WebMouseEvent()); 219 dispatcher()->WillHandleMouseEvent(blink::WebMouseEvent());
220 220
221 // Unlock alternate target has no effect. 221 // Unlock alternate target has no effect.
222 dispatcher()->UnlockMouse(alternate_target_); 222 dispatcher()->UnlockMouse(alternate_target_);
223 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_)); 223 EXPECT_TRUE(dispatcher()->IsMouseLockedTo(target_));
224 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(alternate_target_)); 224 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(alternate_target_));
225 225
226 // Though the call to UnlockMouse should not unlock any target, we will 226 // Though the call to UnlockMouse should not unlock any target, we will
227 // cause an unlock (as if e.g. user escaped mouse lock) and verify the 227 // cause an unlock (as if e.g. user escaped mouse lock) and verify the
228 // correct target is unlocked. 228 // correct target is unlocked.
229 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_)); 229 view()->OnMessageReceived(ViewMsg_MouseLockLost(route_id_));
230 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_)); 230 EXPECT_FALSE(dispatcher()->IsMouseLockedTo(target_));
231 } 231 }
232 232
233 } // namespace content 233 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/mouse_lock_dispatcher.cc ('k') | content/renderer/notification_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698