OLD | NEW |
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 { | 17 namespace { |
17 | 18 |
18 class MockLockTarget : public MouseLockDispatcher::LockTarget { | 19 class MockLockTarget : public MouseLockDispatcher::LockTarget { |
19 public: | 20 public: |
20 MOCK_METHOD1(OnLockMouseACK, void(bool)); | 21 MOCK_METHOD1(OnLockMouseACK, void(bool)); |
21 MOCK_METHOD0(OnMouseLockLost, void()); | 22 MOCK_METHOD0(OnMouseLockLost, void()); |
22 MOCK_METHOD1(HandleMouseLockedInputEvent, | 23 MOCK_METHOD1(HandleMouseLockedInputEvent, |
23 bool(const WebKit::WebMouseEvent&)); | 24 bool(const WebKit::WebMouseEvent&)); |
24 }; | 25 }; |
25 | 26 |
26 // MouseLockDispatcher is a RenderViewObserver, and we test it by creating a | 27 // MouseLockDispatcher is a RenderViewObserver, and we test it by creating a |
27 // fixture containing a RenderViewImpl view() and interacting to that interface. | 28 // fixture containing a RenderViewImpl view() and interacting to that interface. |
28 class MouseLockDispatcherTest | 29 class MouseLockDispatcherTest : public RenderViewTest { |
29 : public content::RenderViewTest { | |
30 public: | 30 public: |
31 virtual void SetUp() { | 31 virtual void SetUp() { |
32 content::RenderViewTest::SetUp(); | 32 RenderViewTest::SetUp(); |
33 route_id_ = view()->GetRoutingID(); | 33 route_id_ = view()->GetRoutingID(); |
34 target_ = new MockLockTarget(); | 34 target_ = new MockLockTarget(); |
35 alternate_target_ = new MockLockTarget(); | 35 alternate_target_ = new MockLockTarget(); |
36 } | 36 } |
37 | 37 |
38 virtual void TearDown() { | 38 virtual void TearDown() { |
39 content::RenderViewTest::TearDown(); | 39 RenderViewTest::TearDown(); |
40 delete target_; | 40 delete target_; |
41 delete alternate_target_; | 41 delete alternate_target_; |
42 } | 42 } |
43 | 43 |
44 protected: | 44 protected: |
45 RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); } | 45 RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); } |
46 MouseLockDispatcher* dispatcher() { return view()->mouse_lock_dispatcher(); } | 46 MouseLockDispatcher* dispatcher() { return view()->mouse_lock_dispatcher(); } |
47 int route_id_; | 47 int route_id_; |
48 MockLockTarget* target_; | 48 MockLockTarget* target_; |
49 MockLockTarget* alternate_target_; | 49 MockLockTarget* alternate_target_; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |