summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-09-25 18:55:42 +0200
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-09-25 18:55:42 +0200
commitfb639faa8898ce6b8fbcc8870ec316114a79f975 (patch)
tree49bf84b2528b53ee07db29e076bf08b2709f1671
parentabb6af14fb632d32d8cce83b4042acd6f9a4767e (diff)
parent7f56ce273a90aaa2273d9438f16678716275d803 (diff)
Merge 5.9 into 5.9.2
-rw-r--r--mkspecs/features/gn_generator.prf3
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp20
-rw-r--r--tests/auto/quick/shared/util.h121
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp8
4 files changed, 47 insertions, 105 deletions
diff --git a/mkspecs/features/gn_generator.prf b/mkspecs/features/gn_generator.prf
index b2b749154..072b0444e 100644
--- a/mkspecs/features/gn_generator.prf
+++ b/mkspecs/features/gn_generator.prf
@@ -175,7 +175,8 @@ GN_CONTENTS += " if (!defined(include_dirs)) {"\
" }"
GN_CONTENTS += " include_dirs += ["
for (path, INCLUDEPATH): GN_CONTENTS += " \"$$path\","
-GN_CONTENTS += " rebase_path(\"$target_gen_dir/.moc/\")"
+GN_CONTENTS += " rebase_path(\"$target_gen_dir/.moc/\"),"
+GN_CONTENTS += " \"$$QMAKESPEC\""
GN_CONTENTS += " ]"
GN_CONTENTS += " if (!defined(ldflags)) {"\
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index 4bc136539..c5718dc1f 100644
--- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
+++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
@@ -507,7 +507,7 @@ void tst_QQuickWebEngineView::interruptImeTextComposition()
QVERIFY(waitForLoadSucceeded(view));
runJavaScript("document.getElementById('input1').focus();");
- QTRY_COMPARE(activeElementId(view), QStringLiteral("input1"));
+ QTRY_COMPARE(evaluateJavaScriptSync(view, "document.activeElement.id").toString(), QStringLiteral("input1"));
TestInputContext testContext;
@@ -516,7 +516,7 @@ void tst_QQuickWebEngineView::interruptImeTextComposition()
QInputMethodEvent event("x", attributes);
input = qobject_cast<QQuickItem *>(qApp->focusObject());
QGuiApplication::sendEvent(input, &event);
- QTRY_COMPARE(elementValue(view, "input1"), QStringLiteral("x"));
+ QTRY_COMPARE(evaluateJavaScriptSync(view, "document.getElementById('input1').value").toString(), QStringLiteral("x"));
// Focus 'input2' input field by an input event
QFETCH(QString, eventType);
@@ -529,7 +529,7 @@ void tst_QQuickWebEngineView::interruptImeTextComposition()
QTest::touchEvent(view->window(), touchDevice).press(0, textInputCenter, view->window());
QTest::touchEvent(view->window(), touchDevice).release(0, textInputCenter, view->window());
}
- QTRY_COMPARE(activeElementId(view), QStringLiteral("input2"));
+ QTRY_COMPARE(evaluateJavaScriptSync(view, "document.activeElement.id").toString(), QStringLiteral("input2"));
#ifndef Q_OS_WIN
QTRY_COMPARE(testContext.commitCallCount, 1);
#else
@@ -538,7 +538,7 @@ void tst_QQuickWebEngineView::interruptImeTextComposition()
// Check the composition text has been committed
runJavaScript("document.getElementById('input1').focus();");
- QTRY_COMPARE(activeElementId(view), QStringLiteral("input1"));
+ QTRY_COMPARE(evaluateJavaScriptSync(view, "document.activeElement.id").toString(), QStringLiteral("input1"));
input = qobject_cast<QQuickItem *>(qApp->focusObject());
QTRY_COMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("x"));
}
@@ -786,8 +786,8 @@ void tst_QQuickWebEngineView::changeLocale()
viewDE->setUrl(url);
QVERIFY(waitForLoadFailed(viewDE.data()));
- QTRY_VERIFY(!bodyInnerText(viewDE.data()).isEmpty());
- errorLines = bodyInnerText(viewDE.data()).split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
+ QTRY_VERIFY(!evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").isNull());
+ errorLines = evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").toString().split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("Diese Website ist nicht erreichbar"));
QLocale::setDefault(QLocale("en"));
@@ -795,8 +795,8 @@ void tst_QQuickWebEngineView::changeLocale()
viewEN->setUrl(url);
QVERIFY(waitForLoadFailed(viewEN.data()));
- QTRY_VERIFY(!bodyInnerText(viewEN.data()).isEmpty());
- errorLines = bodyInnerText(viewEN.data()).split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
+ QTRY_VERIFY(!evaluateJavaScriptSync(viewEN.data(), "document.body.innerText").isNull());
+ errorLines = evaluateJavaScriptSync(viewEN.data(), "document.body.innerText").toString().split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("This site can\xE2\x80\x99t be reached"));
// Reset error page
@@ -807,8 +807,8 @@ void tst_QQuickWebEngineView::changeLocale()
viewDE->setUrl(url);
QVERIFY(waitForLoadFailed(viewDE.data()));
- QTRY_VERIFY(!bodyInnerText(viewDE.data()).isEmpty());
- errorLines = bodyInnerText(viewDE.data()).split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
+ QTRY_VERIFY(!evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").isNull());
+ errorLines = evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").toString().split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("Diese Website ist nicht erreichbar"));
}
diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h
index 8e7169be7..619a02d67 100644
--- a/tests/auto/quick/shared/util.h
+++ b/tests/auto/quick/shared/util.h
@@ -30,6 +30,7 @@
#define UTIL_H
#include <QEventLoop>
+#include <QQmlEngine>
#include <QSignalSpy>
#include <QTimer>
#include <QtTest/QtTest>
@@ -120,103 +121,43 @@ inline bool waitForViewportReady(QQuickWebEngineView *webEngineView, int timeout
#endif
}
-inline QString bodyInnerText(QQuickWebEngineView *webEngineView)
+inline QVariant evaluateJavaScriptSync(QQuickWebEngineView *view, const QString &script)
{
- qRegisterMetaType<QQuickWebEngineView::JavaScriptConsoleMessageLevel>("JavaScriptConsoleMessageLevel");
- QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage);
-
- webEngineView->runJavaScript(
- "if (document.body == null)"
- " console.log('');"
- "else"
- " console.log(document.body.innerText);"
- );
-
- if (!consoleMessageSpy.wait())
- return QString();
-
- QList<QVariant> arguments = consoleMessageSpy.takeFirst();
- if (static_cast<QQuickWebEngineView::JavaScriptConsoleMessageLevel>(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel)
- return QString();
-
- return arguments.at(1).toString();
-}
-
-inline QString activeElementId(QQuickWebEngineView *webEngineView)
-{
- qRegisterMetaType<QQuickWebEngineView::JavaScriptConsoleMessageLevel>("JavaScriptConsoleMessageLevel");
- QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage);
-
- webEngineView->runJavaScript(
- "if (document.activeElement == null)"
- " console.log('');"
- "else"
- " console.log(document.activeElement.id);"
- );
-
- if (!consoleMessageSpy.wait())
- return QString();
-
- QList<QVariant> arguments = consoleMessageSpy.takeFirst();
- if (static_cast<QQuickWebEngineView::JavaScriptConsoleMessageLevel>(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel)
- return QString();
-
- return arguments.at(1).toString();
-}
-
-inline QString elementValue(QQuickWebEngineView *webEngineView, const QString &id)
-{
- qRegisterMetaType<QQuickWebEngineView::JavaScriptConsoleMessageLevel>("JavaScriptConsoleMessageLevel");
- QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage);
-
- webEngineView->runJavaScript(QString(
- "var element = document.getElementById('" + id + "');"
- "if (element == null)"
- " console.log('');"
- "else"
- " console.log(element.value);")
- );
-
- if (!consoleMessageSpy.wait())
- return QString();
-
- QList<QVariant> arguments = consoleMessageSpy.takeFirst();
- if (static_cast<QQuickWebEngineView::JavaScriptConsoleMessageLevel>(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel)
- return QString();
+ QQmlEngine *engine = qmlEngine(view);
+ engine->globalObject().setProperty("called", false);
+ engine->globalObject().setProperty("result", QJSValue());
+ QJSValue callback = engine->evaluate(
+ "(function callback(r) {"
+ " called = true;"
+ " result = r;"
+ "})"
+ );
+ view->runJavaScript(script, callback);
+ QTRY_LOOP_IMPL(engine->globalObject().property("called").toBool(), 5000, 50);
+ if (!engine->globalObject().property("called").toBool()) {
+ qWarning("JavaScript wasn't evaluated");
+ return QVariant();
+ }
- return arguments.at(1).toString();
+ return engine->globalObject().property("result").toVariant();
}
-inline QPoint elementCenter(QQuickWebEngineView *webEngineView, const QString &id)
+inline QPoint elementCenter(QQuickWebEngineView *view, const QString &id)
{
- qRegisterMetaType<QQuickWebEngineView::JavaScriptConsoleMessageLevel>("JavaScriptConsoleMessageLevel");
- QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage);
-
- webEngineView->runJavaScript(QString(
- "var element = document.getElementById('" + id + "');"
- "var rect = element.getBoundingClientRect();"
- "console.log((rect.left + rect.right) / 2);"
- "console.log((rect.top + rect.bottom) / 2);")
- );
-
- QTRY_LOOP_IMPL(consoleMessageSpy.count() == 2, 5000, 50);
- if (consoleMessageSpy.count() != 2)
+ const QString jsCode(
+ "(function(){"
+ " var elem = document.getElementById('" + id + "');"
+ " var rect = elem.getBoundingClientRect();"
+ " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];"
+ "})()");
+ QVariantList rectList = evaluateJavaScriptSync(view, jsCode).toList();
+
+ if (rectList.count() != 2) {
+ qWarning("elementCenter failed.");
return QPoint();
+ }
- QList<QVariant> arguments;
- double x, y;
-
- arguments = consoleMessageSpy.takeFirst();
- if (static_cast<QQuickWebEngineView::JavaScriptConsoleMessageLevel>(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel)
- return QPoint();
- x = arguments.at(1).toDouble();
-
- arguments = consoleMessageSpy.takeLast();
- if (static_cast<QQuickWebEngineView::JavaScriptConsoleMessageLevel>(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel)
- return QPoint();
- y = arguments.at(1).toDouble();
-
- return QPoint(x, y);
+ return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt());
}
#endif /* UTIL_H */
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index c9d5cda90..7f9e1cff5 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -1814,8 +1814,8 @@ void tst_QWebEngineView::emptyInputMethodEvent()
QApplication::sendEvent(view.focusProxy(), &emptyEvent);
QString inputValue = evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString();
- QCOMPARE(inputValue, QStringLiteral("QtWebEngine"));
- QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("QtWebEngine"));
+ QTRY_COMPARE(inputValue, QStringLiteral("QtWebEngine"));
+ QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("QtWebEngine"));
// Reset: clear input field
evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1').value = ''");
@@ -1828,12 +1828,12 @@ void tst_QWebEngineView::emptyInputMethodEvent()
QInputMethodEvent eventComposition("a", attributes);
QApplication::sendEvent(view.focusProxy(), &eventComposition);
QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QStringLiteral("a"));
- QVERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty());
+ QTRY_VERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty());
// Cancel IME composition
QApplication::sendEvent(view.focusProxy(), &emptyEvent);
QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty());
- QVERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty());
+ QTRY_VERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty());
// Try key press after cancelled IME composition
QTest::keyClick(view.focusProxy(), Qt::Key_B);