summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/util.h
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-01-15 19:01:18 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-22 08:46:17 +0100
commit6f07e22acf15651f91d326529519119af7e807a9 (patch)
tree2db55f3ea7ebe6c74905ed87dce5b6140bf5222e /tests/auto/widgets/util.h
parent2830bc6e16e553a52ba465bb4199ab7c18ee4dbc (diff)
Unskip and ajust tests using setHtml, setContent, toHtml and toPlainText
Replace direct calls of toHtml and toPlainText to use a blocking helper function that spins a QEventLoop to wait for the async result. This should work fine for tests where the event loop is less polluted by other events that could cause code reentrancy through stacked stacks. Change-Id: Ic46a06a9abad782a39a620ceecdc51c3bbb6b5a1 Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'tests/auto/widgets/util.h')
-rw-r--r--tests/auto/widgets/util.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h
index 4925aa4c7..e5e991f89 100644
--- a/tests/auto/widgets/util.h
+++ b/tests/auto/widgets/util.h
@@ -25,6 +25,15 @@
#include <QEventLoop>
#include <QSignalSpy>
#include <QTimer>
+#include <qwebenginepage.h>
+
+#if __cplusplus >= 201103L
+#include <functional>
+using std::ref;
+#else
+#include <tr1/functional>
+using std::tr1::ref;
+#endif
#if !defined(TESTS_SOURCE_DIR)
#define TESTS_SOURCE_DIR ""
@@ -78,4 +87,47 @@ public:
}
};
+template<typename T>
+class CallbackSpy {
+public:
+ // Tells tr1::ref the result of void operator()(const T &result) when decltype isn't available.
+ typedef void result_type;
+
+ CallbackSpy() {
+ timeoutTimer.setSingleShot(true);
+ QObject::connect(&timeoutTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
+ }
+
+ T waitForResult() {
+ timeoutTimer.start(10000);
+ eventLoop.exec();
+ return result;
+ }
+
+ void operator()(const T &result) {
+ this->result = result;
+ eventLoop.quit();
+ }
+
+private:
+ Q_DISABLE_COPY(CallbackSpy)
+ QTimer timeoutTimer;
+ QEventLoop eventLoop;
+ T result;
+};
+
+static inline QString toPlainText(QWebEnginePage *page)
+{
+ CallbackSpy<QString> spy;
+ page->toPlainText(ref(spy));
+ return spy.waitForResult();
+}
+
+static inline QString toHtml(QWebEnginePage *page)
+{
+ CallbackSpy<QString> spy;
+ page->toHtml(ref(spy));
+ return spy.waitForResult();
+}
+
#define W_QSKIP(a, b) QSKIP(a)