22
22
23
23
#include < QLineEdit>
24
24
25
+ #ifdef WITH_QTWEBKIT
26
+ #include < QWebFrame>
27
+ #include < QWebView>
28
+ #endif
29
+
30
+ #define SAMPLE_IMAGE QStringLiteral ( " %1/sample_image.png" ).arg( TEST_DATA_DIR )
31
+
25
32
/* *
26
33
* @ingroup UnitTests
27
34
* This is a unit test for the external resource widget wrapper
@@ -37,6 +44,7 @@ class TestQgsExternalResourceWidgetWrapper : public QObject
37
44
void init ();// will be called before each testfunction is executed.
38
45
void cleanup ();// will be called after every testfunction.
39
46
void test_setNullValues ();
47
+ void testBlankAfterValue ();
40
48
41
49
private:
42
50
std::unique_ptr<QgsVectorLayer> vl;
@@ -63,6 +71,14 @@ void TestQgsExternalResourceWidgetWrapper::init()
63
71
vl = qgis::make_unique<QgsVectorLayer>( QStringLiteral ( " NoGeometry?field=link:string" ),
64
72
QStringLiteral ( " myvl" ),
65
73
QLatin1String ( " memory" ) );
74
+
75
+ QgsFeature feat1 ( vl->fields (), 1 );
76
+ feat1.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " type1" ) );
77
+ vl->dataProvider ()->addFeature ( feat1 );
78
+
79
+ QgsFeature feat2 ( vl->fields (), 2 );
80
+ feat2.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " type2" ) );
81
+ vl->dataProvider ()->addFeature ( feat2 );
66
82
}
67
83
68
84
void TestQgsExternalResourceWidgetWrapper::cleanup ()
@@ -99,5 +115,42 @@ void TestQgsExternalResourceWidgetWrapper::test_setNullValues()
99
115
delete widget;
100
116
}
101
117
118
+ void TestQgsExternalResourceWidgetWrapper::testBlankAfterValue ()
119
+ {
120
+ // test that application doesn't crash when we set a blank page in web preview
121
+ // after an item have been set
122
+
123
+ QgsExternalResourceWidgetWrapper ww ( vl.get (), 0 , nullptr , nullptr );
124
+ QWidget *widget = ww.createWidget ( nullptr );
125
+ QVERIFY ( widget );
126
+
127
+ QVariantMap config;
128
+ config.insert ( QStringLiteral ( " DocumentViewer" ), QgsExternalResourceWidget::Web );
129
+ ww.setConfig ( config );
130
+
131
+ QgsFeature feat = vl->getFeature ( 1 );
132
+ QVERIFY ( feat.isValid () );
133
+ ww.setFeature ( feat );
134
+
135
+ ww.initWidget ( widget );
136
+ QVERIFY ( ww.mQgsWidget );
137
+
138
+ widget->show ();
139
+
140
+ QEventLoop loop;
141
+ connect ( ww.mQgsWidget ->mWebView , &QWebView::loadFinished, &loop, &QEventLoop::quit );
142
+
143
+ ww.setValues ( QString ( " file://%1" ).arg ( SAMPLE_IMAGE ), QVariantList () );
144
+
145
+ QVERIFY ( ww.mQgsWidget ->mWebView ->isVisible () );
146
+
147
+ loop.exec ();
148
+
149
+ ww.setValues ( QString (), QVariantList () );
150
+
151
+ QVERIFY ( ww.mQgsWidget ->mWebView ->isVisible () );
152
+ QCOMPARE ( ww.mQgsWidget ->mWebView ->url ().toString (), QStringLiteral ( " about:blank" ) );
153
+ }
154
+
102
155
QGSTEST_MAIN ( TestQgsExternalResourceWidgetWrapper )
103
156
#include " testqgsexternalresourcewidgetwrapper.moc"
0 commit comments