Consolidates app id comparison
[chromium-blink-merge.git] / ppapi / tests / test_mouse_lock.cc
blob0c4efd4896c30abc69bf3dcb55c5a99dcf42875c
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)
14 : TestCase(instance),
15 MouseLock(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());
47 UnlockMouse();
48 // Wait for the MouseLockLost() call.
49 nested_event_.Wait();
51 PASS();
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());
62 PASS();
65 void TestMouseLock::SimulateUserGesture() {
66 pp::Point mouse_movement;
67 pp::MouseInputEvent input_event(
68 instance_,
69 PP_INPUTEVENT_TYPE_MOUSEDOWN,
70 0, // time_stamp
71 0, // modifiers
72 PP_INPUTEVENT_MOUSEBUTTON_LEFT,
73 position_.CenterPoint(),
74 1, // click_count
75 mouse_movement);
77 testing_interface_->SimulateInputEvent(instance_->pp_instance(),
78 input_event.pp_resource());