test_mouse_lock.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.
  4. #include "ppapi/tests/test_mouse_lock.h"
  5. #include "ppapi/cpp/input_event.h"
  6. #include "ppapi/cpp/view.h"
  7. #include "ppapi/tests/testing_instance.h"
  8. REGISTER_TEST_CASE(MouseLock);
  9. TestMouseLock::TestMouseLock(TestingInstance* instance)
  10. : TestCase(instance),
  11. MouseLock(instance),
  12. nested_event_(instance->pp_instance()) {
  13. }
  14. TestMouseLock::~TestMouseLock() {
  15. }
  16. bool TestMouseLock::Init() {
  17. return CheckTestingInterface();
  18. }
  19. void TestMouseLock::RunTests(const std::string& filter) {
  20. RUN_TEST(SucceedWhenAllowed, filter);
  21. }
  22. void TestMouseLock::DidChangeView(const pp::View& view) {
  23. position_ = view.GetRect();
  24. }
  25. void TestMouseLock::MouseLockLost() {
  26. nested_event_.Signal();
  27. }
  28. std::string TestMouseLock::TestSucceedWhenAllowed() {
  29. // Content settings are configured to allow mouse lock for any site.
  30. // Please see chrome/test/ppapi/ppapi_interactive_browsertest.cc.
  31. TestCompletionCallback callback(instance_->pp_instance(), callback_type());
  32. SimulateUserGesture();
  33. callback.WaitForResult(LockMouse(callback.GetCallback()));
  34. ASSERT_EQ(PP_OK, callback.result());
  35. UnlockMouse();
  36. // Wait for the MouseLockLost() call.
  37. nested_event_.Wait();
  38. PASS();
  39. }
  40. void TestMouseLock::SimulateUserGesture() {
  41. pp::Point mouse_movement;
  42. pp::MouseInputEvent input_event(
  43. instance_,
  44. PP_INPUTEVENT_TYPE_MOUSEDOWN,
  45. 0, // time_stamp
  46. 0, // modifiers
  47. PP_INPUTEVENT_MOUSEBUTTON_LEFT,
  48. position_.CenterPoint(),
  49. 1, // click_count
  50. mouse_movement);
  51. testing_interface_->SimulateInputEvent(instance_->pp_instance(),
  52. input_event.pp_resource());
  53. }