summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
}