summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-10-29 14:49:14 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2014-10-29 15:15:19 +0100
commitb00a436a78e624e2d22877c30e889428f98eaac0 (patch)
treec1084722120053d0edfa0be8ba1db700ff8ba047 /tests
parent06a94e282cd8ae90e92777dca065a6110872fb5d (diff)
Add runJavaScript test
Adds a test to check the return types of runJavaScript. Change-Id: Ifd0cb4adf57c972e8a8ad240d51f11f0cc17aa3d Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index b6d3f14c..5de0f799 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -193,6 +193,8 @@ private Q_SLOTS:
void macCopyUnicodeToClipboard();
#endif
+ void runJavaScript();
+
private:
QWebEngineView* m_view;
QWebEnginePage* m_page;
@@ -3736,5 +3738,71 @@ void tst_QWebEnginePage::cssMediaTypePageSetting()
#endif
}
+class JavaScriptCallback
+{
+public:
+ JavaScriptCallback() { }
+ JavaScriptCallback(const QVariant& _expected) : expected(_expected) { }
+ virtual void operator() (const QVariant& result) {
+ QVERIFY(result.isValid());
+ QCOMPARE(result, expected);
+ }
+private:
+ QVariant expected;
+};
+
+class JavaScriptCallbackNull
+{
+public:
+ virtual void operator() (const QVariant& result) {
+ QVERIFY(result.isNull());
+// FIXME: Returned null values are currently invalid QVariants.
+// QVERIFY(result.isValid());
+ }
+};
+
+class JavaScriptCallbackUndefined
+{
+public:
+ virtual void operator() (const QVariant& result) {
+ QVERIFY(result.isNull());
+ QVERIFY(!result.isValid());
+ }
+};
+
+void tst_QWebEnginePage::runJavaScript()
+{
+ TestPage page;
+
+ JavaScriptCallback callbackBool(QVariant(false));
+ page.runJavaScript("false", QWebEngineCallback<const QVariant&>(callbackBool));
+
+ JavaScriptCallback callbackInt(QVariant(2));
+ page.runJavaScript("2", QWebEngineCallback<const QVariant&>(callbackInt));
+
+ JavaScriptCallback callbackDouble(QVariant(2.5));
+ page.runJavaScript("2.5", QWebEngineCallback<const QVariant&>(callbackDouble));
+
+ JavaScriptCallback callbackString(QVariant(QStringLiteral("Test")));
+ page.runJavaScript("\"Test\"", QWebEngineCallback<const QVariant&>(callbackString));
+
+ QVariantList list;
+ JavaScriptCallback callbackList(list);
+ page.runJavaScript("[]", QWebEngineCallback<const QVariant&>(callbackList));
+
+ QVariantMap map;
+ map.insert(QStringLiteral("test"), QVariant(2));
+ JavaScriptCallback callbackMap(map);
+ page.runJavaScript("var el = {\"test\": 2}; el", QWebEngineCallback<const QVariant&>(callbackMap));
+
+ JavaScriptCallbackNull callbackNull;
+ page.runJavaScript("null", QWebEngineCallback<const QVariant&>(callbackNull));
+
+ JavaScriptCallbackNull callbackUndefined;
+ page.runJavaScript("undefined", QWebEngineCallback<const QVariant&>(callbackUndefined));
+
+ QTest::qWait(100);
+}
+
QTEST_MAIN(tst_QWebEnginePage)
#include "tst_qwebenginepage.moc"