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

Side by Side Diff: ppapi/tests/test_mouse_lock.cc

Issue 10699045: Fix PPB_MouseLock.LockMouse crash and add tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes in response to Vincent's suggestions & fix compilation failure. Created 8 years, 5 months 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
OLDNEW
(Empty)
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
5 #include "ppapi/tests/test_mouse_lock.h"
6
7 #include "ppapi/cpp/input_event.h"
8 #include "ppapi/cpp/view.h"
9 #include "ppapi/tests/testing_instance.h"
10
11 REGISTER_TEST_CASE(MouseLock);
12
13 TestMouseLock::TestMouseLock(TestingInstance* instance)
14 : TestCase(instance),
15 MouseLock(instance),
16 nested_event_(instance->pp_instance()) {
17 }
18
19 TestMouseLock::~TestMouseLock() {
20 }
21
22 bool TestMouseLock::Init() {
23 return CheckTestingInterface();
24 }
25
26 void TestMouseLock::RunTests(const std::string& filter) {
27 RUN_TEST(SucceedWhenAllowed, filter);
28 RUN_TEST(FailWhenBlocked, filter);
29 }
30
31 void TestMouseLock::DidChangeView(const pp::View& view) {
32 position_ = view.GetRect();
33 }
34
35 void TestMouseLock::MouseLockLost() {
36 nested_event_.Signal();
37 }
38
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());
dmichael (off chromium) 2012/07/02 17:34:16 Optional suggestion: If you also provide the callb
yzshen1 2012/07/02 19:20:20 Done.
43 SimulateUserGesture();
44 int32_t rv = LockMouse(callback);
dmichael (off chromium) 2012/07/02 17:34:16 nit: You could do: callback.WaitForResult(LockMous
45 if (rv == PP_OK_COMPLETIONPENDING)
46 rv = callback.WaitForResult();
47 if (rv != PP_OK)
48 return ReportError("MouseLock::LockMouse", rv);
49
50 UnlockMouse();
51 // Wait for the MouseLockLost() call.
52 nested_event_.Wait();
53
54 PASS();
55 }
56
57 std::string TestMouseLock::TestFailWhenBlocked() {
58 // Content settings are configured to block mouse lock for any site.
59 // Please see chrome/test/ppapi/ppapi_interactive_browsertest.cc.
60 TestCompletionCallback callback(instance_->pp_instance());
61 SimulateUserGesture();
62 int32_t rv = LockMouse(callback);
63 if (rv == PP_OK_COMPLETIONPENDING)
64 rv = callback.WaitForResult();
65 ASSERT_NE(PP_OK, rv);
66
67 PASS();
68 }
69
70 void TestMouseLock::SimulateUserGesture() {
71 pp::Point mouse_movement;
72 pp::MouseInputEvent input_event(
73 instance_,
74 PP_INPUTEVENT_TYPE_MOUSEDOWN,
75 0, // time_stamp
76 0, // modifiers
77 PP_INPUTEVENT_MOUSEBUTTON_LEFT,
78 position_.CenterPoint(),
79 1, // click_count
80 mouse_movement);
81
82 testing_interface_->SimulateInputEvent(instance_->pp_instance(),
83 input_event.pp_resource());
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698