summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2017-08-23 12:32:18 +0200
committerViktor Engelmann <viktor.engelmann@qt.io>2017-08-28 08:29:27 +0000
commitab97078faffa2d3321e721a887bb5fa3049dd513 (patch)
treea70aa224ad405fd546e2dcfc49d84ffd45af1318
parent647307f534d45758832f23912ed281af819f0174 (diff)
Make deletion of CallbackSpy safe
The deletion of CallBackSpy before web engine page destruction could end up in segmentation fault. Make CallbackSpy safe to be deleted before web engine page. Change-Id: I71a184091c0251c61e3383010e3badfef5cb6124 Reviewed-by: Viktor Engelmann <viktor.engelmann@qt.io>
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp17
-rw-r--r--tests/auto/widgets/util.h14
2 files changed, 24 insertions, 7 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 4cb8e23e5..bea44f73c 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -105,6 +105,7 @@ private Q_SLOTS:
void updatePositionDependentActionsCrash();
void createPluginWithPluginsEnabled();
void createPluginWithPluginsDisabled();
+ void callbackSpyDeleted();
void destroyPlugin_data();
void destroyPlugin();
void createViewlessPlugin_data();
@@ -441,6 +442,22 @@ static QImage imageWithoutAlpha(const QImage &image)
return result;
}
+void tst_QWebEnginePage::callbackSpyDeleted()
+{
+ QWebEnginePage *page = m_view->page();
+ CallbackSpy<QVariant> spy;
+ QString poorManSleep("function wait(ms){"
+ " var start = new Date().getTime();"
+ " var end = start;"
+ " while (start + ms > end) {"
+ "end = new Date().getTime();"
+ " }"
+ "}"
+ "wait(1000);");
+ page->runJavaScript(poorManSleep, spy.ref());
+ //spy deleted before callback
+}
+
void tst_QWebEnginePage::pasteImage()
{
// Pixels with an alpha value of 0 will have different RGB values after the
diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h
index 356cf6ebb..ab3b9e6b9 100644
--- a/tests/auto/widgets/util.h
+++ b/tests/auto/widgets/util.h
@@ -67,15 +67,16 @@ public:
};
template<typename T, typename R>
-struct RefWrapper {
- R &ref;
+struct CallbackWrapper {
+ QPointer<R> p;
void operator()(const T& result) {
- ref(result);
+ if (p)
+ (*p)(result);
}
};
template<typename T>
-class CallbackSpy {
+class CallbackSpy: public QObject {
public:
CallbackSpy() : called(false) {
timeoutTimer.setSingleShot(true);
@@ -100,10 +101,9 @@ public:
eventLoop.quit();
}
- // Cheap rip-off of boost/std::ref
- RefWrapper<T, CallbackSpy<T> > ref()
+ CallbackWrapper<T, CallbackSpy<T> > ref()
{
- RefWrapper<T, CallbackSpy<T> > wrapper = {*this};
+ CallbackWrapper<T, CallbackSpy<T> > wrapper = {this};
return wrapper;
}