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

Side by Side Diff: content/browser/renderer_host/input/synthetic_pointer_action_unittest.cc

Issue 2633233002: Add the pointer type of pen to the synthetic WebMousEvent (Closed)
Patch Set: Make disallow copy private Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/time/time.h" 6 #include "base/time/time.h"
7 #include "content/browser/renderer_host/input/synthetic_gesture.h" 7 #include "content/browser/renderer_host/input/synthetic_gesture.h"
8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
9 #include "content/browser/renderer_host/input/synthetic_pointer_action.h" 9 #include "content/browser/renderer_host/input/synthetic_pointer_action.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 type_ = mouse_event.type(); 179 type_ = mouse_event.type();
180 position_ = gfx::PointF(mouse_event.x, mouse_event.y); 180 position_ = gfx::PointF(mouse_event.x, mouse_event.y);
181 click_count_ = mouse_event.clickCount; 181 click_count_ = mouse_event.clickCount;
182 modifiers_ = mouse_event.modifiers(); 182 modifiers_ = mouse_event.modifiers();
183 button_ = mouse_event.button; 183 button_ = mouse_event.button;
184 } 184 }
185 185
186 testing::AssertionResult SyntheticMouseActionDispatchedCorrectly( 186 testing::AssertionResult SyntheticMouseActionDispatchedCorrectly(
187 const SyntheticPointerActionParams& param, 187 const SyntheticPointerActionParams& param,
188 int click_count, 188 int click_count,
189 std::vector<SyntheticPointerActionParams::Button> buttons) { 189 std::vector<SyntheticPointerActionParams::Button> buttons,
190 SyntheticGestureParams::GestureSourceType source_type =
191 SyntheticGestureParams::MOUSE_INPUT) {
192 if (GetDefaultSyntheticGestureSourceType() != source_type) {
193 return testing::AssertionFailure()
194 << "Pointer source type was "
195 << static_cast<int>(GetDefaultSyntheticGestureSourceType())
196 << ", expected " << static_cast<int>(source_type) << ".";
197 }
198
190 if (type_ != ToWebMouseEventType(param.pointer_action_type())) { 199 if (type_ != ToWebMouseEventType(param.pointer_action_type())) {
191 return testing::AssertionFailure() 200 return testing::AssertionFailure()
192 << "Pointer type was " << WebInputEvent::GetName(type_) 201 << "Pointer type was " << WebInputEvent::GetName(type_)
193 << ", expected " << WebInputEvent::GetName(ToWebMouseEventType( 202 << ", expected " << WebInputEvent::GetName(ToWebMouseEventType(
194 param.pointer_action_type())) << "."; 203 param.pointer_action_type())) << ".";
195 } 204 }
196 205
197 if (click_count_ != click_count) { 206 if (click_count_ != click_count) {
198 return testing::AssertionFailure() << "Pointer click count was " 207 return testing::AssertionFailure() << "Pointer click count was "
199 << click_count_ << ", expected " 208 << click_count_ << ", expected "
200 << click_count << "."; 209 << click_count << ".";
201 } 210 }
202 211
203 if (click_count_ == 1) { 212 if (click_count_ == 1) {
204 DCHECK_GT(buttons.size(), 0U); 213 DCHECK_GT(buttons.size(), 0U);
205 SyntheticPointerActionParams::Button button = buttons[buttons.size() - 1]; 214 SyntheticPointerActionParams::Button button = buttons[buttons.size() - 1];
206 if (button_ != 215 if (button_ !=
207 SyntheticPointerActionParams::GetWebMouseEventButton(button)) { 216 SyntheticPointerActionParams::GetWebMouseEventButton(button)) {
208 return testing::AssertionFailure() 217 return testing::AssertionFailure()
209 << "Pointer button was " << static_cast<int>(button_) 218 << "Pointer button was " << static_cast<int>(button_)
210 << ", expected " << static_cast<int>(button) << "."; 219 << ", expected " << static_cast<int>(button) << ".";
211 } 220 }
212 } 221 }
213 222
214 if (click_count_ == 0 && button_ != WebMouseEvent::Button::NoButton) { 223 if (click_count_ == 0 && button_ != WebMouseEvent::Button::NoButton) {
215 DCHECK_EQ(buttons.size(), 0U); 224 DCHECK_EQ(buttons.size(), 0U);
216 return testing::AssertionFailure() 225 return testing::AssertionFailure()
217 << "Pointer button was " << static_cast<int>(button_) 226 << "Pointer button was " << static_cast<int>(button_)
218 << ", expected " << (int)WebMouseEvent::Button::NoButton << "."; 227 << ", expected "
228 << static_cast<int>(WebMouseEvent::Button::NoButton) << ".";
219 } 229 }
220 230
221 int modifiers = 0; 231 int modifiers = 0;
222 for (size_t index = 0; index < buttons.size(); ++index) 232 for (size_t index = 0; index < buttons.size(); ++index)
223 modifiers |= SyntheticPointerActionParams::GetWebMouseEventModifier( 233 modifiers |= SyntheticPointerActionParams::GetWebMouseEventModifier(
224 buttons[index]); 234 buttons[index]);
225 if (modifiers_ != modifiers) { 235 if (modifiers_ != modifiers) {
226 return testing::AssertionFailure() << "Pointer modifiers was " 236 return testing::AssertionFailure() << "Pointer modifiers was "
227 << modifiers_ << ", expected " 237 << modifiers_ << ", expected "
228 << modifiers << "."; 238 << modifiers << ".";
(...skipping 16 matching lines...) Expand all
245 return SyntheticGestureParams::MOUSE_INPUT; 255 return SyntheticGestureParams::MOUSE_INPUT;
246 } 256 }
247 257
248 private: 258 private:
249 gfx::PointF position_; 259 gfx::PointF position_;
250 int click_count_; 260 int click_count_;
251 int modifiers_; 261 int modifiers_;
252 WebMouseEvent::Button button_; 262 WebMouseEvent::Button button_;
253 }; 263 };
254 264
265 class MockSyntheticPointerPenActionTarget
266 : public MockSyntheticPointerMouseActionTarget {
267 public:
268 MockSyntheticPointerPenActionTarget() {}
269 ~MockSyntheticPointerPenActionTarget() override {}
270
271 SyntheticGestureParams::GestureSourceType
272 GetDefaultSyntheticGestureSourceType() const override {
273 return SyntheticGestureParams::PEN_INPUT;
274 }
275 };
276
255 class SyntheticPointerActionTest : public testing::Test { 277 class SyntheticPointerActionTest : public testing::Test {
256 public: 278 public:
257 SyntheticPointerActionTest() { 279 SyntheticPointerActionTest() {
258 params_ = SyntheticPointerActionListParams(); 280 params_ = SyntheticPointerActionListParams();
259 num_success_ = 0; 281 num_success_ = 0;
260 num_failure_ = 0; 282 num_failure_ = 0;
261 } 283 }
262 ~SyntheticPointerActionTest() override {} 284 ~SyntheticPointerActionTest() override {}
263 285
264 protected: 286 protected:
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 std::vector<SyntheticPointerActionParams::Button> buttons( 656 std::vector<SyntheticPointerActionParams::Button> buttons(
635 1, SyntheticPointerActionParams::Button::LEFT); 657 1, SyntheticPointerActionParams::Button::LEFT);
636 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly( 658 EXPECT_TRUE(pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(
637 param, 1, buttons)); 659 param, 1, buttons));
638 660
639 ForwardSyntheticPointerAction(); 661 ForwardSyntheticPointerAction();
640 EXPECT_EQ(1, num_success_); 662 EXPECT_EQ(1, num_success_);
641 EXPECT_EQ(2, num_failure_); 663 EXPECT_EQ(2, num_failure_);
642 } 664 }
643 665
666 TEST_F(SyntheticPointerActionTest, PointerPenAction) {
667 CreateSyntheticPointerActionTarget<MockSyntheticPointerPenActionTarget>();
668
669 // Send a pen move.
670 SyntheticPointerActionParams param1 = SyntheticPointerActionParams(
671 SyntheticPointerActionParams::PointerActionType::MOVE);
672 param1.set_position(gfx::PointF(189, 62));
673 params_.PushPointerActionParams(param1);
674
675 // Send a pen down.
676 SyntheticPointerActionParams param2 = SyntheticPointerActionParams(
677 SyntheticPointerActionParams::PointerActionType::PRESS);
678 param2.set_position(gfx::PointF(189, 62));
679 params_.PushPointerActionParams(param2);
680
681 // Send a pen up.
682 SyntheticPointerActionParams param3 = SyntheticPointerActionParams(
683 SyntheticPointerActionParams::PointerActionType::RELEASE);
684 params_.PushPointerActionParams(param3);
685 pointer_action_.reset(new SyntheticPointerAction(params_));
686
687 ForwardSyntheticPointerAction();
688 MockSyntheticPointerPenActionTarget* pointer_pen_target =
689 static_cast<MockSyntheticPointerPenActionTarget*>(target_.get());
690 EXPECT_EQ(1, num_success_);
691 EXPECT_EQ(0, num_failure_);
692 std::vector<SyntheticPointerActionParams::Button> buttons;
693 EXPECT_TRUE(pointer_pen_target->SyntheticMouseActionDispatchedCorrectly(
694 param1, 0, buttons, SyntheticGestureParams::PEN_INPUT));
695
696 ForwardSyntheticPointerAction();
697 EXPECT_EQ(2, num_success_);
698 EXPECT_EQ(0, num_failure_);
699 buttons.push_back(SyntheticPointerActionParams::Button::LEFT);
700 EXPECT_TRUE(pointer_pen_target->SyntheticMouseActionDispatchedCorrectly(
701 param2, 1, buttons, SyntheticGestureParams::PEN_INPUT));
702
703 ForwardSyntheticPointerAction();
704 EXPECT_EQ(3, num_success_);
705 EXPECT_EQ(0, num_failure_);
706 EXPECT_TRUE(pointer_pen_target->SyntheticMouseActionDispatchedCorrectly(
707 param3, 1, buttons, SyntheticGestureParams::PEN_INPUT));
708 }
709
644 } // namespace 710 } // namespace
645 711
646 } // namespace content 712 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698