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
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_mouse_lock.h"
7 #include "ppapi/cpp/input_event.h"
8 #include "ppapi/cpp/view.h"
9 #include "ppapi/tests/testing_instance.h"
11 REGISTER_TEST_CASE(MouseLock
);
13 TestMouseLock::TestMouseLock(TestingInstance
* instance
)
16 nested_event_(instance
->pp_instance()) {
19 TestMouseLock::~TestMouseLock() {
22 bool TestMouseLock::Init() {
23 return CheckTestingInterface();
26 void TestMouseLock::RunTests(const std::string
& filter
) {
27 RUN_TEST(SucceedWhenAllowed
, filter
);
28 RUN_TEST(FailWhenBlocked
, filter
);
31 void TestMouseLock::DidChangeView(const pp::View
& view
) {
32 position_
= view
.GetRect();
35 void TestMouseLock::MouseLockLost() {
36 nested_event_
.Signal();
39 std::string
TestMouseLock::TestSucceedWhenAllowed() {
40 // Content settings are configured to allow mouse lock for any site.
41 // Please see chrome/test/ppapi/ppapi_interactive_browsertest.cc.
42 TestCompletionCallback
callback(instance_
->pp_instance(), callback_type());
43 SimulateUserGesture();
44 callback
.WaitForResult(LockMouse(callback
.GetCallback()));
45 ASSERT_EQ(PP_OK
, callback
.result());
48 // Wait for the MouseLockLost() call.
54 std::string
TestMouseLock::TestFailWhenBlocked() {
55 // Content settings are configured to block mouse lock for any site.
56 // Please see chrome/test/ppapi/ppapi_interactive_browsertest.cc.
57 TestCompletionCallback
callback(instance_
->pp_instance(), callback_type());
58 SimulateUserGesture();
59 callback
.WaitForResult(LockMouse(callback
.GetCallback()));
60 ASSERT_NE(PP_OK
, callback
.result());
65 void TestMouseLock::SimulateUserGesture() {
66 pp::Point mouse_movement
;
67 pp::MouseInputEvent
input_event(
69 PP_INPUTEVENT_TYPE_MOUSEDOWN
,
72 PP_INPUTEVENT_MOUSEBUTTON_LEFT
,
73 position_
.CenterPoint(),
77 testing_interface_
->SimulateInputEvent(instance_
->pp_instance(),
78 input_event
.pp_resource());