Skip to content

Commit 18d4c46

Browse files
committed
Merge branch 'WD_1.X_dev' of https://portal-ua.globallogic.com/git/wd into WD_1.X_dev
2 parents 0ba6c26 + 0788613 commit 18d4c46

File tree

8 files changed

+338
-19
lines changed

8 files changed

+338
-19
lines changed

inc/extension_qt/quick2_view_executor.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ class Quick2ViewCmdExecutor : public QWindowViewCmdExecutor {
8585
virtual void GetAlertMessage(std::string* text, Error** error) NOT_SUPPORTED_IMPL;
8686
virtual void SetAlertPromptText(const std::string& alert_prompt_text, Error** error) NOT_SUPPORTED_IMPL;
8787
virtual void AcceptOrDismissAlert(bool accept, Error** error) NOT_SUPPORTED_IMPL;
88-
virtual void TouchClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
89-
virtual void TouchDoubleClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
90-
virtual void TouchDown(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
91-
virtual void TouchUp(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
92-
virtual void TouchMove(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
93-
virtual void TouchLongClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
88+
virtual void TouchClick(const ElementId& element, Error **error);
89+
virtual void TouchDoubleClick(const ElementId& element, Error **error);
90+
virtual void TouchDown(const int &x, const int &y, Error **error);
91+
virtual void TouchUp(const int &x, const int &y, Error **error);
92+
virtual void TouchMove(const int &x, const int &y, Error **error);
93+
virtual void TouchLongClick(const ElementId& element, Error **error);
9494
virtual void TouchScroll(const int &xoffset, const int &yoffset, Error **error) NOT_SUPPORTED_IMPL;
95-
virtual void TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error) NOT_SUPPORTED_IMPL;
95+
virtual void TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error);
9696
virtual void TouchFlick(const int &xSpeed, const int &ySpeed, Error **error) NOT_SUPPORTED_IMPL;
97-
virtual void TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error) NOT_SUPPORTED_IMPL;
97+
virtual void TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error);
9898
virtual void GetPlayerState(const ElementId& element, PlayerState*, Error** error);
9999
virtual void SetPlayerState(const ElementId& element, PlayerState, Error** error);
100100
virtual void GetPlayerVolume(const ElementId& element, double*, Error** error);

inc/extension_qt/qwindow_view_executor.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include "webdriver_error.h"
1111

1212
#include <QtCore/QDebug>
13-
#include <QtGui/QTouchDevice>
13+
#include <QtGui/QTouchEvent>
14+
#include <QtGui/QTouchDevice>
1415
#include <QtGui/QWindow>
1516

1617
namespace webdriver {
@@ -43,10 +44,12 @@ class QWindowViewCmdExecutor : public ViewCmdExecutor {
4344
QRect ConvertRectToQRect(const Rect &rect);
4445
QPoint ConvertPointToQPoint(const Point &p);
4546
Qt::MouseButton ConvertMouseButtonToQtMouseButton(MouseButton button);
46-
47-
QTouchDevice touchDevice;
47+
QTouchEvent::TouchPoint createTouchPoint(Qt::TouchPointState state, QPointF &point, QVector2D velocity = QVector2D());
48+
QTouchEvent* createSimpleTouchEvent(QEvent::Type eventType, Qt::TouchPointStates touchPointStates, QPointF &point, QVector2D velocity = QVector2D());
49+
QTouchEvent* createTouchEvent(QEvent::Type eventType, Qt::TouchPointStates touchPointStates, const QList<QTouchEvent::TouchPoint> &touchPoints);
4850

4951
private:
52+
QTouchDevice touchDevice;
5053
DISALLOW_COPY_AND_ASSIGN(QWindowViewCmdExecutor);
5154
};
5255

src/Test/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ int main(int argc, char *argv[])
253253

254254
int startError = wd_server->Start();
255255
if (startError){
256-
std::cout << "Error while starting server, errorCode " << startError << endl;
256+
std::cout << "Error while starting server, errorCode " << startError << std::endl;
257257
return startError;
258258
}
259259

src/webdriver/commands/cisco_player_commands.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void CISCO_PlaybackSpeedCommand::ExecuteGet(Response * const response)
303303
return;
304304
}
305305

306-
Value* value = Value::CreateBooleanValue(speed);
306+
Value* value = Value::CreateDoubleValue(speed);
307307
response->SetValue(value);
308308
}
309309

src/webdriver/extension_qt/quick2_view_executor.cc

Lines changed: 280 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
#include <QtCore/QBuffer>
2121
#include <QtCore/QDebug>
22+
#include <QtCore/QTimer>
2223
#include <QtGui/QGuiApplication>
2324
#include <QtQml/QQmlExpression>
2425
#include <QtQml/QQmlEngine>
26+
#include <QtGui/QStyleHints>
2527

2628
#include "third_party/pugixml/pugixml.hpp"
2729

@@ -826,11 +828,23 @@ void Quick2ViewCmdExecutor::GetPlayerState(const ElementId &element, PlayerState
826828
if (NULL == pItem)
827829
return;
828830

829-
830831
base::Value* playbackState = NULL;
831-
GetAttribute(element, "playbackState", &playbackState, error);
832+
QVariant propertyValue = pItem->property("playbackState");
832833

833-
if( error != NULL && *error != NULL && (*error)->code() != kSuccess){
834+
if (propertyValue.isValid()) {
835+
// convert QVariant to base::Value
836+
switch (propertyValue.type()) {
837+
case QVariant::Int:
838+
playbackState = Value::CreateIntegerValue(propertyValue.toInt());
839+
break;
840+
default:
841+
session_->logger().Log(kWarningLogLevel, "wrong property type");
842+
*error = new Error(kInvalidElementState);
843+
return;
844+
}
845+
} else {
846+
session_->logger().Log(kWarningLogLevel, "property not found.");
847+
*error = new Error(kInvalidElementState);
834848
return;
835849
}
836850

@@ -1027,6 +1041,269 @@ void Quick2ViewCmdExecutor::GetPlaybackSpeed(const ElementId &element, double *s
10271041
positionValue->GetAsDouble(speed);
10281042
}
10291043

1044+
void Quick2ViewCmdExecutor::TouchClick(const ElementId& element, Error **error)
1045+
{
1046+
QQuickView* view = getView(view_id_, error);
1047+
if (NULL == view)
1048+
return;
1049+
1050+
Point location(0,0);
1051+
1052+
// calculate the half of the element size and translate by it.
1053+
Size size;
1054+
GetElementSize(element, &size, error);
1055+
if (*error)
1056+
return;
1057+
1058+
location.Offset(size.width() / 2, size.height() / 2);
1059+
1060+
QPointF point = ConvertPointToQPoint(location);
1061+
1062+
QQuickItem* pItem = getElement(element, error);
1063+
if (*error)
1064+
return;
1065+
1066+
point = pItem->mapToScene(point);
1067+
1068+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1069+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1070+
1071+
QGuiApplication::postEvent(view, touchBeginEvent);
1072+
QGuiApplication::postEvent(view, touchEndEvent);
1073+
1074+
QGuiApplication::processEvents();
1075+
}
1076+
1077+
void Quick2ViewCmdExecutor::TouchDoubleClick(const ElementId& element, Error **error)
1078+
{
1079+
QQuickView* view = getView(view_id_, error);
1080+
if (NULL == view)
1081+
return;
1082+
1083+
Point location(0,0);
1084+
1085+
// calculate the half of the element size and translate by it.
1086+
Size size;
1087+
GetElementSize(element, &size, error);
1088+
if (*error)
1089+
return;
1090+
1091+
location.Offset(size.width() / 2, size.height() / 2);
1092+
1093+
QPointF point = ConvertPointToQPoint(location);
1094+
1095+
QQuickItem* pItem = getElement(element, error);
1096+
if (*error)
1097+
return;
1098+
1099+
point = pItem->mapToScene(point);
1100+
1101+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1102+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1103+
QTouchEvent *touchBeginEvent2 = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1104+
QTouchEvent *touchEndEvent2 = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1105+
1106+
QGuiApplication::postEvent(view, touchBeginEvent);
1107+
QGuiApplication::postEvent(view, touchEndEvent);
1108+
QGuiApplication::postEvent(view, touchBeginEvent2);
1109+
QGuiApplication::postEvent(view, touchEndEvent2);
1110+
1111+
1112+
QGuiApplication::processEvents();
1113+
}
1114+
1115+
void Quick2ViewCmdExecutor::TouchDown(const int &x, const int &y, Error **error)
1116+
{
1117+
QQuickView* view = getView(view_id_, error);
1118+
if (NULL == view)
1119+
return;
1120+
1121+
QPointF point = ConvertPointToQPoint(Point(x, y));
1122+
1123+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1124+
1125+
QGuiApplication::postEvent(view, touchBeginEvent);
1126+
1127+
QGuiApplication::processEvents();
1128+
}
1129+
1130+
void Quick2ViewCmdExecutor::TouchUp(const int &x, const int &y, Error **error)
1131+
{
1132+
QQuickView* view = getView(view_id_, error);
1133+
if (NULL == view)
1134+
return;
1135+
1136+
QPointF point = ConvertPointToQPoint(Point(x, y));
1137+
1138+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1139+
1140+
QGuiApplication::postEvent(view, touchEndEvent);
1141+
1142+
QGuiApplication::processEvents();
1143+
}
1144+
1145+
void Quick2ViewCmdExecutor::TouchMove(const int &x, const int &y, Error **error)
1146+
{
1147+
QQuickView* view = getView(view_id_, error);
1148+
if (NULL == view)
1149+
return;
1150+
1151+
QPointF point = ConvertPointToQPoint(Point(x, y));
1152+
1153+
QTouchEvent *touchMoveEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, point);
1154+
1155+
QGuiApplication::postEvent(view, touchMoveEvent);
1156+
1157+
QGuiApplication::processEvents();
1158+
}
1159+
1160+
void Quick2ViewCmdExecutor::TouchLongClick(const ElementId& element, Error **error)
1161+
{
1162+
QQuickView* view = getView(view_id_, error);
1163+
if (NULL == view)
1164+
return;
1165+
1166+
Point location(0,0);
1167+
1168+
// calculate the half of the element size and translate by it.
1169+
Size size;
1170+
GetElementSize(element, &size, error);
1171+
if (*error)
1172+
return;
1173+
1174+
location.Offset(size.width() / 2, size.height() / 2);
1175+
1176+
QPointF point = ConvertPointToQPoint(location);
1177+
1178+
QEventLoop loop;
1179+
QTimer::singleShot(1000, &loop, SLOT(quit()));
1180+
1181+
QQuickItem* pItem = getElement(element, error);
1182+
if (*error)
1183+
return;
1184+
1185+
point = pItem->mapToScene(point);
1186+
1187+
QTouchEvent *touchBeginEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, point);
1188+
QGuiApplication::postEvent(view, touchBeginEvent);
1189+
1190+
loop.exec();
1191+
1192+
QTouchEvent *touchEndEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, point);
1193+
QGuiApplication::postEvent(view, touchEndEvent);
1194+
1195+
QGuiApplication::processEvents();
1196+
1197+
}
1198+
1199+
void Quick2ViewCmdExecutor::TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error)
1200+
{
1201+
QQuickView* view = getView(view_id_, error);
1202+
if (NULL == view)
1203+
return;
1204+
1205+
Point location(0,0);
1206+
1207+
// calculate the half of the element size and translate by it.
1208+
Size sizel;
1209+
GetElementSize(element, &sizel, error);
1210+
if (*error)
1211+
return;
1212+
1213+
location.Offset(sizel.width() / 2, sizel.height() / 2);
1214+
1215+
QPointF startPoint = ConvertPointToQPoint(location);
1216+
1217+
QQuickItem* pItem = getElement(element, error);
1218+
if (*error)
1219+
return;
1220+
1221+
startPoint = pItem->mapToScene(startPoint);
1222+
1223+
Point offset(xoffset, yoffset);
1224+
QPointF offsetPoint = ConvertPointToQPoint(offset);
1225+
int stepCount = 20;
1226+
int timeBetweenEvent = 30;
1227+
QEventLoop loop;
1228+
1229+
for (int i = 0; i <= stepCount; ++i)
1230+
{
1231+
QPointF touchPoint(startPoint.x()+offsetPoint.x()*i/stepCount, startPoint.y()+offsetPoint.y()*i/stepCount);
1232+
1233+
QTouchEvent *touchEvent;
1234+
if (i == 0)
1235+
touchEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, touchPoint);
1236+
else if (i == stepCount)
1237+
touchEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, touchPoint);
1238+
else
1239+
touchEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, touchPoint);
1240+
1241+
1242+
QGuiApplication::postEvent(view, touchEvent);
1243+
QTimer::singleShot(timeBetweenEvent, &loop, SLOT(quit()));
1244+
loop.exec();
1245+
}
1246+
QGuiApplication::processEvents();
1247+
}
1248+
1249+
void Quick2ViewCmdExecutor::TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error)
1250+
{
1251+
QQuickView* view = getView(view_id_, error);
1252+
if (NULL == view)
1253+
return;
1254+
1255+
Point location(0,0);
1256+
1257+
// calculate the half of the element size and translate by it.
1258+
Size size;
1259+
GetElementSize(element, &size, error);
1260+
if (*error)
1261+
return;
1262+
1263+
location.Offset(size.width() / 2, size.height() / 2);
1264+
QPointF startPoint = ConvertPointToQPoint(location);
1265+
1266+
QQuickItem* pItem = getElement(element, error);
1267+
if (*error)
1268+
return;
1269+
1270+
startPoint = pItem->mapToScene(startPoint);
1271+
1272+
QPointF offsetPoint = ConvertPointToQPoint(Point(xoffset, yoffset));
1273+
1274+
QEventLoop loop;
1275+
1276+
//some magic numbers
1277+
int stepCount = 20;
1278+
int timeBetweenEvent = 30/(speed+1);
1279+
1280+
QVector2D velocity(xoffset*1000/(stepCount*timeBetweenEvent), yoffset*1000/(stepCount*timeBetweenEvent));
1281+
1282+
for (int i = 0; i <= stepCount; ++i)
1283+
{
1284+
QPointF touchPoint(startPoint.x()+offsetPoint.x()*i/stepCount, startPoint.y()+offsetPoint.y()*i/stepCount);
1285+
1286+
QTouchEvent *touchEvent;
1287+
if (i == 0)
1288+
touchEvent = createSimpleTouchEvent(QEvent::TouchBegin, Qt::TouchPointPressed, touchPoint, velocity);
1289+
else if (i == stepCount)
1290+
touchEvent = createSimpleTouchEvent(QEvent::TouchEnd, Qt::TouchPointReleased, touchPoint, velocity);
1291+
else
1292+
touchEvent = createSimpleTouchEvent(QEvent::TouchUpdate, Qt::TouchPointMoved, touchPoint, velocity);
1293+
1294+
QGuiApplication::postEvent(view, touchEvent);
1295+
QTimer::singleShot(timeBetweenEvent, &loop, SLOT(quit()));
1296+
loop.exec();
1297+
if (i == stepCount)
1298+
{
1299+
QPointF touchPoint(startPoint);
1300+
touchEvent = createSimpleTouchEvent(QEvent::TouchCancel, Qt::TouchPointPressed, touchPoint);
1301+
QGuiApplication::postEvent(view, touchEvent);
1302+
}
1303+
}
1304+
QGuiApplication::processEvents();
1305+
}
1306+
10301307
QQuickItem* Quick2ViewCmdExecutor::getFocusItem(QQuickView* view) {
10311308
QQuickItem* pFocusItem = view->activeFocusItem();
10321309
if (NULL != pFocusItem) return pFocusItem;

src/webdriver/extension_qt/qwebkit_proxy.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,8 @@ Error* QWebkitProxy::SetPlayingPosition(const ElementId& element, const double r
10121012

10131013
Error* error = ExecuteScriptAndParse(
10141014
GetFrame(page_, session_->current_frame()),
1015-
"function(elem, time) { elem.currentTime = time; }",
1016-
"setVolume",
1015+
"function(elem, time) { elem. = false; elem.currentTime = time; }",
1016+
"setPosition",
10171017
CreateListValueFrom(element, reletivePos),
10181018
CreateDirectValueParser(&value));
10191019
scoped_ptr<Value> scoped_value(value);
@@ -1024,7 +1024,7 @@ Error* QWebkitProxy::SetPlayingPosition(const ElementId& element, const double r
10241024
Error *QWebkitProxy::GetPlaybackSpeed(const ElementId &element, double *speed)
10251025
{
10261026
base::Value* speedValue = NULL;
1027-
Error* error = GetAttribute(element, std::string("currentTime"), &speedValue);
1027+
Error* error = GetAttribute(element, std::string("playbackRate"), &speedValue);
10281028
scoped_ptr<base::Value> scoped_position_value(speedValue);
10291029
if(error)
10301030
return error;

0 commit comments

Comments
 (0)