| 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..6c0c3e576f9f32d818135411300ae38fd040d87f
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/web/tests/SelectionTestBase.cpp
|
| @@ -0,0 +1,61 @@
|
| +// 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,
|
| + bool sendDownEvent, bool sendUpEvent)
|
| +{
|
| + if (sendDownEvent) {
|
| + const auto& downEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, WebMouseEvent::ButtonLeft, downPoint, modifiers);
|
| + m_webView->handleInputEvent(downEvent);
|
| + }
|
| +
|
| + static const int kMoveEventsNumber = 10;
|
| + 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 (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
|
|
|