Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/SelectionTestBase.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/SelectionTestBase.cpp b/third_party/WebKit/Source/web/tests/SelectionTestBase.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c0da97c2bf50f4422ac414b5fb7f6f7c119a3a57 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/web/tests/SelectionTestBase.cpp |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "web/tests/SelectionTestBase.h" |
| + |
| +#include "web/WebLocalFrameImpl.h" |
| + |
| +namespace blink { |
| +namespace { |
| +IntSize scaled(IntSize p, float scale) |
| +{ |
| + p.scale(scale, scale); |
| + return p; |
| +} |
| +} // namespace |
| + |
| +void SelectionTestBase::emulateMouseDrag(const IntPoint& downPoint, const IntPoint& upPoint, int modifiers, DragFlags dragFlags) |
| +{ |
| + if (dragFlags & SendDownEvent) { |
| + const auto& downEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, WebMouseEvent::ButtonLeft, downPoint, modifiers); |
| + m_webView->handleInputEvent(downEvent); |
| + } |
| + |
| + static const int kMoveEventsNumber = 10; |
|
tkent
2016/03/25 03:33:03
"static" for const local variable doesn't make sen
|
| + static const float kMoveIncrementFraction = 1. / kMoveEventsNumber; |
| + const auto& upDownVector = upPoint - downPoint; |
| + for (int i = 0; i < kMoveEventsNumber; ++i) { |
| + const auto& movePoint = downPoint + scaled(upDownVector, i * kMoveIncrementFraction); |
| + const auto& moveEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseMove, WebMouseEvent::ButtonLeft, movePoint, modifiers); |
| + m_webView->handleInputEvent(moveEvent); |
| + } |
| + |
| + if (dragFlags & SendUpEvent) { |
| + const auto& upEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseUp, WebMouseEvent::ButtonLeft, upPoint, modifiers); |
| + m_webView->handleInputEvent(upEvent); |
| + } |
| +} |
| + |
| +void SelectionTestBase::emulateMouseClick(const IntPoint& clickPoint, WebMouseEvent::Button button, int modifiers, int count) |
| +{ |
| + auto event = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, button, clickPoint, modifiers); |
| + event.clickCount = count; |
| + m_webView->handleInputEvent(event); |
| + event.type = WebMouseEvent::MouseUp; |
| + m_webView->handleInputEvent(event); |
| +} |
| + |
| +void SelectionTestBase::emulateMouseDown(const IntPoint& clickPoint, WebMouseEvent::Button button, int modifiers, int count) |
| +{ |
| + auto event = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, button, clickPoint, modifiers); |
| + event.clickCount = count; |
| + m_webView->handleInputEvent(event); |
| +} |
| + |
| +std::string SelectionTestBase::getSelectionText() |
| +{ |
| + return m_mainFrame->selectionAsText().utf8(); |
| +} |
| +} // namespace blink |