From 9f7fe69dfd11380d71c6f8ef176218d4e905caff Mon Sep 17 00:00:00 2001 From: hekra Date: Wed, 18 Jan 2017 09:53:00 -0800 Subject: [PATCH 1/4] replace QQuickView by QQuickWindow --- inc/extension_qt/quick2_view_executor.h | 7 +- src/Test/Headers.h | 2 +- src/webdriver/extension_qt/qml_view_util.cc | 64 +++++++- src/webdriver/extension_qt/qml_view_util.h | 7 +- .../extension_qt/quick2_view_enumerator.cc | 13 +- .../extension_qt/quick2_view_executor.cc | 140 ++++++++---------- 6 files changed, 147 insertions(+), 86 deletions(-) diff --git a/inc/extension_qt/quick2_view_executor.h b/inc/extension_qt/quick2_view_executor.h index e3f08a83..1f02afaf 100644 --- a/inc/extension_qt/quick2_view_executor.h +++ b/inc/extension_qt/quick2_view_executor.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace webdriver { @@ -137,15 +138,15 @@ class Quick2ViewCmdExecutor : public QWindowViewCmdExecutor { virtual void IsOnline(bool*, Error** error) NOT_SUPPORTED_IMPL; protected: - QQuickView* getView(const ViewId& viewId, Error** error); + QQuickWindow* getView(const ViewId& viewId, Error** error); typedef QHash XMLElementMap; QQuickItem* getElement(const ElementId &element, Error** error); - QQuickItem* getFocusItem(QQuickView* view); + QQuickItem* getFocusItem(QQuickWindow* view); bool FilterElement(const QQuickItem* item, const std::string& locator, const std::string& query); void FindElementsByXpath(QQuickItem* parent, const std::string &query, std::vector* elements, Error **error); void FindElements(QQuickItem* parent, const std::string& locator, const std::string& query, std::vector* elements, Error** error); - void moveMouseInternal(QQuickView* view, QPointF& point); + void moveMouseInternal(QQuickWindow* view, QPointF& point); private: DISALLOW_COPY_AND_ASSIGN(Quick2ViewCmdExecutor); diff --git a/src/Test/Headers.h b/src/Test/Headers.h index 60b260b4..2526acf9 100644 --- a/src/Test/Headers.h +++ b/src/Test/Headers.h @@ -164,7 +164,7 @@ int wd_setup(int argc, char *argv[]) #elif defined(OS_POSIX) cmd_line.InitFromArgv(argc, argv); #endif - +cmd_line.AppendSwitch("verbose"); #ifndef QT_NO_SAMPLES /* optional samples setup */ wd_samples_setup(widgetCreator, webCreator, qmlCreator, cmd_line); diff --git a/src/webdriver/extension_qt/qml_view_util.cc b/src/webdriver/extension_qt/qml_view_util.cc index 51854eac..d0578889 100644 --- a/src/webdriver/extension_qt/qml_view_util.cc +++ b/src/webdriver/extension_qt/qml_view_util.cc @@ -94,7 +94,7 @@ QWindow* QQmlViewUtil::getQWindowView(Session* session, const ViewId& viewId) { return qobject_cast(qViewHandle->get()); } -QQuickView* QQmlViewUtil::getQMLView(Session* session, const ViewId& viewId) { +QQuickWindow* QQmlViewUtil::getQMLView(Session* session, const ViewId& viewId) { ViewHandle* viewHandle = session->GetViewHandle(viewId); if (NULL == viewHandle) return NULL; @@ -103,8 +103,68 @@ QQuickView* QQmlViewUtil::getQMLView(Session* session, const ViewId& viewId) { if (NULL == qViewHandle) return NULL; - return qobject_cast(qViewHandle->get()); + return qobject_cast(qViewHandle->get()); } + +QQmlEngine* QQmlViewUtil::getQMLEngine(QQuickWindow* qquickWindow) { + QQuickView* pView = qobject_cast(qquickWindow); + + if (pView != NULL) + return pView->engine(); + + QQuickWindow* pWin = qobject_cast(qquickWindow); + + if (pView != NULL) { + QQuickItem* item = pWin->contentItem(); + return QQmlEngine::contextForObject(item)->engine(); + } + + return NULL; +} + +void QQmlViewUtil::setSource(const QUrl &url, bool sync, QQuickWindow* qquickWindow) { + QQuickView* pView = qobject_cast(qquickWindow); + + if (pView != NULL) { + if (sync) { + QEventLoop loop; + QObject::connect(pView, SIGNAL(statusChanged(QQuickView::Status)),&loop,SLOT(quit())); + pView->setSource(url); + + if (QQuickView::Loading == pView->status()) { + loop.exec(); + } + } else { + pView->setSource(url); + } + } + else { + // TODO async / sync mode + QQmlEngine* engine = QQmlViewUtil::getQMLEngine(qquickWindow); + QQmlApplicationEngine* appEngine = qobject_cast(engine); + + if (appEngine != NULL) { + appEngine->load(url); + } + } +} + +const QUrl QQmlViewUtil::getSource(QQuickWindow* qquickWindow) { + QQuickView* pView = qobject_cast(qquickWindow); + + if (pView != NULL) { + return pView->source(); + } + + QQmlEngine* engine = QQmlViewUtil::getQMLEngine(qquickWindow); + QQmlApplicationEngine* appEngine = qobject_cast(engine); + + if (appEngine != NULL) { + return appEngine->baseUrl(); + } + return QUrl(); +} + #else void QQmlViewUtil::removeInternalSuffixes(QString& str) { str.remove(QRegExp(QLatin1String("_QMLTYPE_\\d+"))); diff --git a/src/webdriver/extension_qt/qml_view_util.h b/src/webdriver/extension_qt/qml_view_util.h index cb12b97a..79e4ceec 100644 --- a/src/webdriver/extension_qt/qml_view_util.h +++ b/src/webdriver/extension_qt/qml_view_util.h @@ -30,6 +30,8 @@ class QWindow; class QQuickView; #include +#include +#include #else class QDeclarativeView; #include @@ -49,7 +51,10 @@ class QQmlViewUtil { #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) static QWindow* getQWindowView(Session* session, const ViewId& viewId); - static QQuickView* getQMLView(Session* session, const ViewId& viewId); + static QQuickWindow* getQMLView(Session* session, const ViewId& viewId); + static QQmlEngine* getQMLEngine(QQuickWindow* qquickWindow); + static void setSource(const QUrl &url, bool sync, QQuickWindow* qquickWindow); + static const QUrl getSource(QQuickWindow* qquickWindow); #else static QDeclarativeView* getQMLView(Session* session, const ViewId& viewId); #endif diff --git a/src/webdriver/extension_qt/quick2_view_enumerator.cc b/src/webdriver/extension_qt/quick2_view_enumerator.cc index 54306c78..ac532205 100644 --- a/src/webdriver/extension_qt/quick2_view_enumerator.cc +++ b/src/webdriver/extension_qt/quick2_view_enumerator.cc @@ -29,6 +29,7 @@ #include #include #include +#include namespace webdriver { @@ -37,13 +38,23 @@ void Quick2ViewEnumeratorImpl::EnumerateViews(Session* session, std::set foreach(QWindow* pWindow, QGuiApplication::allWindows()) { + session->logger().Log(kInfoLogLevel, + "Quick2ViewEnumerator found new view "); if (!pWindow->isVisible()) continue; + session->logger().Log(kInfoLogLevel, + "Quick2ViewEnumerator found new view visible "); - QQuickView* pView = qobject_cast(pWindow); + QQuickWindow* pView = qobject_cast(pWindow); if (pView != NULL) { + session->logger().Log(kInfoLogLevel, + "Quick2ViewEnumerator found new view QQuickWindow "); + ViewHandlePtr handle(new QWindowViewHandle(pView)); ViewId viewId = session->GetViewForHandle(handle); if (!viewId.is_valid()) { + session->logger().Log(kInfoLogLevel, + "Quick2ViewEnumerator found new view is_valid"); + if (session->AddNewView(handle, &viewId)) { session->logger().Log(kInfoLogLevel, "Quick2ViewEnumerator found new view("+viewId.id()+")"); diff --git a/src/webdriver/extension_qt/quick2_view_executor.cc b/src/webdriver/extension_qt/quick2_view_executor.cc index 98b42bde..044f62ab 100644 --- a/src/webdriver/extension_qt/quick2_view_executor.cc +++ b/src/webdriver/extension_qt/quick2_view_executor.cc @@ -57,7 +57,7 @@ Quick2ViewCmdExecutorCreator::Quick2ViewCmdExecutorCreator() : ViewCmdExecutorCreator() { } ViewCmdExecutor* Quick2ViewCmdExecutorCreator::CreateExecutor(Session* session, ViewId viewId) const { - QQuickView* pView = QQmlViewUtil::getQMLView(session, viewId); + QQuickWindow* pView = QQmlViewUtil::getQMLView(session, viewId); if (NULL != pView) { session->logger().Log(kFineLogLevel, "Quick2 executor for view("+viewId.id()+")"); @@ -68,7 +68,7 @@ ViewCmdExecutor* Quick2ViewCmdExecutorCreator::CreateExecutor(Session* session, } bool Quick2ViewCmdExecutorCreator::CanHandleView(Session* session, ViewId viewId, ViewType* viewType) const { - QQuickView* pView = QQmlViewUtil::getQMLView(session, viewId); + QQuickWindow* pView = QQmlViewUtil::getQMLView(session, viewId); if (NULL != pView) { if (NULL != viewType) *viewType = QML_VIEW_TYPE; @@ -88,8 +88,8 @@ Quick2ViewCmdExecutor::Quick2ViewCmdExecutor(Session* session, ViewId viewId) Quick2ViewCmdExecutor::~Quick2ViewCmdExecutor() {} -QQuickView* Quick2ViewCmdExecutor::getView(const ViewId& viewId, Error** error) { - QQuickView* pView = QQmlViewUtil::getQMLView(session_, viewId); +QQuickWindow* Quick2ViewCmdExecutor::getView(const ViewId& viewId, Error** error) { + QQuickWindow* pView = QQmlViewUtil::getQMLView(session_, viewId); if (NULL == pView) { session_->logger().Log(kWarningLogLevel, "checkView - no such qml view("+viewId.id()+")"); @@ -127,7 +127,7 @@ void Quick2ViewCmdExecutor::CanHandleUrl(const std::string& url, bool* can, Erro } void Quick2ViewCmdExecutor::GetSource(std::string* source, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -148,7 +148,7 @@ void Quick2ViewCmdExecutor::GetSource(std::string* source, Error** error) { } void Quick2ViewCmdExecutor::SendKeys(const ElementId& element, const string16& keys, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -189,7 +189,7 @@ void Quick2ViewCmdExecutor::SendKeys(const ElementId& element, const string16& k } void Quick2ViewCmdExecutor::SendKeys(const string16& keys, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -229,7 +229,7 @@ void Quick2ViewCmdExecutor::SendKeys(const string16& keys, Error** error) { } void Quick2ViewCmdExecutor::MouseDoubleClick(Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -261,7 +261,7 @@ void Quick2ViewCmdExecutor::MouseDoubleClick(Error** error) { } void Quick2ViewCmdExecutor::MouseButtonUp(Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -285,7 +285,7 @@ void Quick2ViewCmdExecutor::MouseButtonUp(Error** error) { } void Quick2ViewCmdExecutor::MouseButtonDown(Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -309,7 +309,7 @@ void Quick2ViewCmdExecutor::MouseButtonDown(Error** error) { } void Quick2ViewCmdExecutor::MouseClick(MouseButton button, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -343,7 +343,7 @@ void Quick2ViewCmdExecutor::MouseClick(MouseButton button, Error** error) { } void Quick2ViewCmdExecutor::MouseWheel(const int delta, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -372,7 +372,7 @@ void Quick2ViewCmdExecutor::MouseWheel(const int delta, Error **error) { } void Quick2ViewCmdExecutor::MouseMove(const int x_offset, const int y_offset, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -394,7 +394,7 @@ void Quick2ViewCmdExecutor::MouseMove(const int x_offset, const int y_offset, Er } void Quick2ViewCmdExecutor::MouseMove(const ElementId& element, int x_offset, const int y_offset, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -416,7 +416,7 @@ void Quick2ViewCmdExecutor::MouseMove(const ElementId& element, int x_offset, co } void Quick2ViewCmdExecutor::MouseMove(const ElementId& element, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -437,7 +437,7 @@ void Quick2ViewCmdExecutor::MouseMove(const ElementId& element, Error** error) { session_->set_mouse_position(Point(scenePoint.x(), scenePoint.y())); } -void Quick2ViewCmdExecutor::moveMouseInternal(QQuickView* view, QPointF& point) { +void Quick2ViewCmdExecutor::moveMouseInternal(QQuickWindow* view, QPointF& point) { QPoint startViewPos = QCommonUtil::ConvertPointToQPoint(session_->get_mouse_position()); QPointF targetScreenPos(view->x() + point.x(), view->y() + point.y()); @@ -467,7 +467,7 @@ void Quick2ViewCmdExecutor::moveMouseInternal(QQuickView* view, QPointF& point) } void Quick2ViewCmdExecutor::ClickElement(const ElementId& element, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -509,7 +509,7 @@ void Quick2ViewCmdExecutor::ClickElement(const ElementId& element, Error** error } void Quick2ViewCmdExecutor::GetAttribute(const ElementId& element, const std::string& key, base::Value** value, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -547,7 +547,7 @@ void Quick2ViewCmdExecutor::GetAttribute(const ElementId& element, const std::st } void Quick2ViewCmdExecutor::ClearElement(const ElementId& element, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -578,7 +578,7 @@ void Quick2ViewCmdExecutor::ClearElement(const ElementId& element, Error** error } void Quick2ViewCmdExecutor::IsElementDisplayed(const ElementId& element, bool ignore_opacity, bool* is_displayed, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -590,7 +590,7 @@ void Quick2ViewCmdExecutor::IsElementDisplayed(const ElementId& element, bool ig } void Quick2ViewCmdExecutor::IsElementEnabled(const ElementId& element, bool* is_enabled, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -602,7 +602,7 @@ void Quick2ViewCmdExecutor::IsElementEnabled(const ElementId& element, bool* is_ } void Quick2ViewCmdExecutor::ElementEquals(const ElementId& element1, const ElementId& element2, bool* is_equal, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -618,7 +618,7 @@ void Quick2ViewCmdExecutor::ElementEquals(const ElementId& element1, const Eleme } void Quick2ViewCmdExecutor::GetElementLocation(const ElementId& element, Point* location, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -632,7 +632,7 @@ void Quick2ViewCmdExecutor::GetElementLocation(const ElementId& element, Point* } void Quick2ViewCmdExecutor::GetElementLocationInView(const ElementId& element, Point* location, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -647,7 +647,7 @@ void Quick2ViewCmdExecutor::GetElementLocationInView(const ElementId& element, P } void Quick2ViewCmdExecutor::GetElementTagName(const ElementId& element, std::string* tag_name, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -662,7 +662,7 @@ void Quick2ViewCmdExecutor::GetElementTagName(const ElementId& element, std::str } void Quick2ViewCmdExecutor::GetElementSize(const ElementId& element, Size* size, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -674,7 +674,7 @@ void Quick2ViewCmdExecutor::GetElementSize(const ElementId& element, Size* size, } void Quick2ViewCmdExecutor::GetElementText(const ElementId& element, std::string* element_text, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -696,7 +696,7 @@ void Quick2ViewCmdExecutor::GetElementText(const ElementId& element, std::string } void Quick2ViewCmdExecutor::FindElements(const ElementId& root_element, const std::string& locator, const std::string& query, std::vector* elements, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -740,7 +740,7 @@ void Quick2ViewCmdExecutor::FindElements(QQuickItem* parent, const std::string& } void Quick2ViewCmdExecutor::ActiveElement(ElementId* element, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -758,7 +758,7 @@ void Quick2ViewCmdExecutor::ActiveElement(ElementId* element, Error** error) { } void Quick2ViewCmdExecutor::NavigateToURL(const std::string& url, bool sync, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -766,46 +766,29 @@ void Quick2ViewCmdExecutor::NavigateToURL(const std::string& url, bool sync, Err QUrl address(QString(url.c_str())); - view->engine()->clearComponentCache(); + QQmlEngine* engine = QQmlViewUtil::getQMLEngine(view); + engine->clearComponentCache(); - QQmlContext *rootContext = view->rootContext(); + QQmlContext *rootContext = engine->rootContext(); QVariant pWin = rootContext->contextProperty("QmlWindow"); if (pWin.isNull()) { rootContext->setContextProperty("QmlWindow", view); } - if (sync) { - QEventLoop loop; - QObject::connect(view, SIGNAL(statusChanged(QQuickView::Status)),&loop,SLOT(quit())); - view->setSource(address); - - if (QQuickView::Loading == view->status()) { - loop.exec(); - } - - if (QQuickView::Ready != view->status()) { - session_->logger().Log(kWarningLogLevel, "QML sync load, smth wrong. View is not in READY state."); - } - - session_->logger().Log(kFineLogLevel, "QML sync load - " + url); - } else { - view->setSource(address); - - session_->logger().Log(kFineLogLevel, "QML async load - " + url); - } + QQmlViewUtil::setSource(address, sync, view); } void Quick2ViewCmdExecutor::GetURL(std::string* url, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; - *url = view->source().toString().toStdString(); + *url = QQmlViewUtil::getSource(view).toString().toStdString(); } void Quick2ViewCmdExecutor::GetScreenShot(std::string* png, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -835,7 +818,7 @@ void Quick2ViewCmdExecutor::GetScreenShot(std::string* png, Error** error) { } void Quick2ViewCmdExecutor::GetElementScreenShot(const ElementId& element, std::string* png, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -874,7 +857,7 @@ void Quick2ViewCmdExecutor::GetElementScreenShot(const ElementId& element, std:: } void Quick2ViewCmdExecutor::ExecuteScript(const std::string& script, const base::ListValue* const args, base::Value** value, Error** error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -886,7 +869,8 @@ void Quick2ViewCmdExecutor::ExecuteScript(const std::string& script, const base: script.c_str(), args_as_json.c_str()); - QQmlContext *rootContext = view->rootContext(); + QQmlEngine* engine = QQmlViewUtil::getQMLEngine(view); + QQmlContext *rootContext = engine->rootContext(); QVariant p = rootContext->contextProperty("ObjectNameUtils"); if (p.isNull()) { @@ -940,7 +924,7 @@ void Quick2ViewCmdExecutor::ExecuteScript(const std::string& script, const base: void Quick2ViewCmdExecutor::GetPlayerState(const ElementId &element, PlayerState *state, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -986,7 +970,7 @@ void Quick2ViewCmdExecutor::GetPlayerState(const ElementId &element, PlayerState void Quick2ViewCmdExecutor::SetPlayerState(const ElementId &element, PlayerState state, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1019,7 +1003,7 @@ void Quick2ViewCmdExecutor::SetPlayerState(const ElementId &element, PlayerState void Quick2ViewCmdExecutor::GetPlayerVolume(const ElementId &element, double *volume, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1049,7 +1033,7 @@ void Quick2ViewCmdExecutor::GetPlayerVolume(const ElementId &element, double *vo void Quick2ViewCmdExecutor::SetPlayerVolume(const ElementId &element, double volume, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1078,7 +1062,7 @@ void Quick2ViewCmdExecutor::SetPlayerVolume(const ElementId &element, double vol void Quick2ViewCmdExecutor::GetPlayingPosition(const ElementId &element, double *position, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1111,7 +1095,7 @@ void Quick2ViewCmdExecutor::GetPlayingPosition(const ElementId &element, double void Quick2ViewCmdExecutor::SetPlayingPosition(const ElementId &element, double position, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1141,7 +1125,7 @@ void Quick2ViewCmdExecutor::SetPlayingPosition(const ElementId &element, double void Quick2ViewCmdExecutor::SetMute(const ElementId &element, bool mute, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1170,7 +1154,7 @@ void Quick2ViewCmdExecutor::SetMute(const ElementId &element, bool mute, Error * void Quick2ViewCmdExecutor::GetMute(const ElementId &element, bool *mute, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1198,7 +1182,7 @@ void Quick2ViewCmdExecutor::GetMute(const ElementId &element, bool *mute, Error void Quick2ViewCmdExecutor::SetPlaybackSpeed(const ElementId &element, double speed, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1227,7 +1211,7 @@ void Quick2ViewCmdExecutor::SetPlaybackSpeed(const ElementId &element, double sp void Quick2ViewCmdExecutor::GetPlaybackSpeed(const ElementId &element, double *speed, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1257,7 +1241,7 @@ void Quick2ViewCmdExecutor::GetPlaybackSpeed(const ElementId &element, double *s void Quick2ViewCmdExecutor::TouchClick(const ElementId& element, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1291,7 +1275,7 @@ void Quick2ViewCmdExecutor::TouchClick(const ElementId& element, Error **error) void Quick2ViewCmdExecutor::TouchDoubleClick(const ElementId& element, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1329,7 +1313,7 @@ void Quick2ViewCmdExecutor::TouchDoubleClick(const ElementId& element, Error **e void Quick2ViewCmdExecutor::TouchDown(const int &x, const int &y, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1344,7 +1328,7 @@ void Quick2ViewCmdExecutor::TouchDown(const int &x, const int &y, Error **error) void Quick2ViewCmdExecutor::TouchUp(const int &x, const int &y, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1359,7 +1343,7 @@ void Quick2ViewCmdExecutor::TouchUp(const int &x, const int &y, Error **error) void Quick2ViewCmdExecutor::TouchMove(const int &x, const int &y, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1374,7 +1358,7 @@ void Quick2ViewCmdExecutor::TouchMove(const int &x, const int &y, Error **error) void Quick2ViewCmdExecutor::TouchLongClick(const ElementId& element, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1413,7 +1397,7 @@ void Quick2ViewCmdExecutor::TouchLongClick(const ElementId& element, Error **err void Quick2ViewCmdExecutor::TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1463,7 +1447,7 @@ void Quick2ViewCmdExecutor::TouchScroll(const ElementId &element, const int &xof void Quick2ViewCmdExecutor::TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1521,7 +1505,7 @@ void Quick2ViewCmdExecutor::TouchFlick(const ElementId &element, const int &xoff void Quick2ViewCmdExecutor::TouchPinchRotate(const ElementId &element, const int &angle, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1577,7 +1561,7 @@ void Quick2ViewCmdExecutor::TouchPinchRotate(const ElementId &element, const int void Quick2ViewCmdExecutor::TouchPinchZoom(const ElementId &element, const double &scale, Error **error) { - QQuickView* view = getView(view_id_, error); + QQuickWindow* view = getView(view_id_, error); if (NULL == view) return; @@ -1643,7 +1627,7 @@ void Quick2ViewCmdExecutor::TouchPinchZoom(const ElementId &element, const doubl QGuiApplication::processEvents(); } -QQuickItem* Quick2ViewCmdExecutor::getFocusItem(QQuickView* view) { +QQuickItem* Quick2ViewCmdExecutor::getFocusItem(QQuickWindow* view) { QQuickItem* pFocusItem = view->activeFocusItem(); if (NULL != pFocusItem) return pFocusItem; From 62a78e752972af8bd06e96d5f307015b5578e062 Mon Sep 17 00:00:00 2001 From: hekra Date: Fri, 20 Jan 2017 09:03:13 -0800 Subject: [PATCH 2/4] add log --- src/webdriver/extension_qt/qml_view_util.cc | 8 +++++++- src/webdriver/extension_qt/qml_view_util.h | 3 ++- src/webdriver/extension_qt/quick2_view_enumerator.cc | 10 ---------- src/webdriver/extension_qt/quick2_view_executor.cc | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/webdriver/extension_qt/qml_view_util.cc b/src/webdriver/extension_qt/qml_view_util.cc index d0578889..eefb808c 100644 --- a/src/webdriver/extension_qt/qml_view_util.cc +++ b/src/webdriver/extension_qt/qml_view_util.cc @@ -122,7 +122,7 @@ QQmlEngine* QQmlViewUtil::getQMLEngine(QQuickWindow* qquickWindow) { return NULL; } -void QQmlViewUtil::setSource(const QUrl &url, bool sync, QQuickWindow* qquickWindow) { +void QQmlViewUtil::setSource(const Logger& logger, const QUrl &url, bool sync, QQuickWindow* qquickWindow) { QQuickView* pView = qobject_cast(qquickWindow); if (pView != NULL) { @@ -134,8 +134,14 @@ void QQmlViewUtil::setSource(const QUrl &url, bool sync, QQuickWindow* qquickWin if (QQuickView::Loading == pView->status()) { loop.exec(); } + + if (QQuickView::Ready != pView->status()) { + logger.Log(kWarningLogLevel, "QML sync load, smth wrong. View is not in READY state."); + } + } else { pView->setSource(url); + logger.Log(kFineLogLevel, "QML async load - "); } } else { diff --git a/src/webdriver/extension_qt/qml_view_util.h b/src/webdriver/extension_qt/qml_view_util.h index 79e4ceec..de132a29 100644 --- a/src/webdriver/extension_qt/qml_view_util.h +++ b/src/webdriver/extension_qt/qml_view_util.h @@ -25,6 +25,7 @@ #include #include "common_util.h" +#include "webdriver_logging.h" #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) class QWindow; @@ -53,7 +54,7 @@ class QQmlViewUtil { static QWindow* getQWindowView(Session* session, const ViewId& viewId); static QQuickWindow* getQMLView(Session* session, const ViewId& viewId); static QQmlEngine* getQMLEngine(QQuickWindow* qquickWindow); - static void setSource(const QUrl &url, bool sync, QQuickWindow* qquickWindow); + static void setSource(const Logger& logger, const QUrl &url, bool sync, QQuickWindow* qquickWindow); static const QUrl getSource(QQuickWindow* qquickWindow); #else static QDeclarativeView* getQMLView(Session* session, const ViewId& viewId); diff --git a/src/webdriver/extension_qt/quick2_view_enumerator.cc b/src/webdriver/extension_qt/quick2_view_enumerator.cc index ac532205..6ea97cbc 100644 --- a/src/webdriver/extension_qt/quick2_view_enumerator.cc +++ b/src/webdriver/extension_qt/quick2_view_enumerator.cc @@ -38,23 +38,13 @@ void Quick2ViewEnumeratorImpl::EnumerateViews(Session* session, std::set foreach(QWindow* pWindow, QGuiApplication::allWindows()) { - session->logger().Log(kInfoLogLevel, - "Quick2ViewEnumerator found new view "); if (!pWindow->isVisible()) continue; - session->logger().Log(kInfoLogLevel, - "Quick2ViewEnumerator found new view visible "); QQuickWindow* pView = qobject_cast(pWindow); if (pView != NULL) { - session->logger().Log(kInfoLogLevel, - "Quick2ViewEnumerator found new view QQuickWindow "); - ViewHandlePtr handle(new QWindowViewHandle(pView)); ViewId viewId = session->GetViewForHandle(handle); if (!viewId.is_valid()) { - session->logger().Log(kInfoLogLevel, - "Quick2ViewEnumerator found new view is_valid"); - if (session->AddNewView(handle, &viewId)) { session->logger().Log(kInfoLogLevel, "Quick2ViewEnumerator found new view("+viewId.id()+")"); diff --git a/src/webdriver/extension_qt/quick2_view_executor.cc b/src/webdriver/extension_qt/quick2_view_executor.cc index 044f62ab..15142f82 100644 --- a/src/webdriver/extension_qt/quick2_view_executor.cc +++ b/src/webdriver/extension_qt/quick2_view_executor.cc @@ -776,7 +776,7 @@ void Quick2ViewCmdExecutor::NavigateToURL(const std::string& url, bool sync, Err rootContext->setContextProperty("QmlWindow", view); } - QQmlViewUtil::setSource(address, sync, view); + QQmlViewUtil::setSource(session_->logger(), address, sync, view); } void Quick2ViewCmdExecutor::GetURL(std::string* url, Error** error) { From eb799e6023da74e233d8ed5ba6b5a4cbc2567c07 Mon Sep 17 00:00:00 2001 From: hekra01 Date: Fri, 20 Jan 2017 21:18:50 +0100 Subject: [PATCH 3/4] Update Headers.h --- src/Test/Headers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Test/Headers.h b/src/Test/Headers.h index 2526acf9..60b260b4 100644 --- a/src/Test/Headers.h +++ b/src/Test/Headers.h @@ -164,7 +164,7 @@ int wd_setup(int argc, char *argv[]) #elif defined(OS_POSIX) cmd_line.InitFromArgv(argc, argv); #endif -cmd_line.AppendSwitch("verbose"); + #ifndef QT_NO_SAMPLES /* optional samples setup */ wd_samples_setup(widgetCreator, webCreator, qmlCreator, cmd_line); From d5a4766a5c0db074e1c93f8832550f6a86159b6b Mon Sep 17 00:00:00 2001 From: hekra Date: Fri, 20 Jan 2017 14:36:22 -0800 Subject: [PATCH 4/4] cleanup code --- src/webdriver/extension_qt/qml_view_util.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/webdriver/extension_qt/qml_view_util.cc b/src/webdriver/extension_qt/qml_view_util.cc index eefb808c..e168bebd 100644 --- a/src/webdriver/extension_qt/qml_view_util.cc +++ b/src/webdriver/extension_qt/qml_view_util.cc @@ -112,14 +112,9 @@ QQmlEngine* QQmlViewUtil::getQMLEngine(QQuickWindow* qquickWindow) { if (pView != NULL) return pView->engine(); - QQuickWindow* pWin = qobject_cast(qquickWindow); - - if (pView != NULL) { - QQuickItem* item = pWin->contentItem(); - return QQmlEngine::contextForObject(item)->engine(); - } + QQmlContext *rootContext = QQmlEngine::contextForObject(qquickWindow->contentItem()); - return NULL; + return rootContext->engine(); } void QQmlViewUtil::setSource(const Logger& logger, const QUrl &url, bool sync, QQuickWindow* qquickWindow) {