1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include "../util.h"
#include <QDebug>
#include <QDeclarativeComponent>
#include <QDeclarativeEngine>
#include <QDeclarativeProperty>
#include <QDeclarativeView>
#include <QDir>
#include <QGraphicsWebView>
#include <QTest>
#include <QWebFrame>
QT_BEGIN_NAMESPACE
class tst_QDeclarativeWebView : public QObject {
Q_OBJECT
public:
tst_QDeclarativeWebView();
private slots:
void preferredWidthTest();
void preferredHeightTest();
void preferredWidthDefaultTest();
void preferredHeightDefaultTest();
private:
void checkNoErrors(const QDeclarativeComponent&);
};
tst_QDeclarativeWebView::tst_QDeclarativeWebView()
{
Q_UNUSED(waitForSignal)
}
void tst_QDeclarativeWebView::preferredWidthTest()
{
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewtest.qml"));
checkNoErrors(component);
QObject* wv = component.create();
QVERIFY(wv);
wv->setProperty("testUrl", QUrl("qrc:///resources/sample.html"));
QCOMPARE(wv->property("prefWidth").toInt(), 600);
}
void tst_QDeclarativeWebView::preferredHeightTest()
{
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewtest.qml"));
checkNoErrors(component);
QObject* wv = component.create();
QVERIFY(wv);
wv->setProperty("testUrl", QUrl("qrc:///resources/sample.html"));
QCOMPARE(wv->property("prefHeight").toInt(), 500);
}
void tst_QDeclarativeWebView::preferredWidthDefaultTest()
{
QGraphicsWebView view;
view.load(QUrl("qrc:///resources/sample.html"));
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewtestdefault.qml"));
checkNoErrors(component);
QObject* wv = component.create();
QVERIFY(wv);
wv->setProperty("testUrl", QUrl("qrc:///resources/sample.html"));
QCOMPARE(wv->property("prefWidth").toDouble(), view.preferredWidth());
}
void tst_QDeclarativeWebView::preferredHeightDefaultTest()
{
QGraphicsWebView view;
view.load(QUrl("qrc:///resources/sample.html"));
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewtestdefault.qml"));
checkNoErrors(component);
QObject* wv = component.create();
QVERIFY(wv);
wv->setProperty("testUrl", QUrl("qrc:///resources/sample.html"));
QCOMPARE(wv->property("prefHeight").toDouble(), view.preferredHeight());
}
void tst_QDeclarativeWebView::checkNoErrors(const QDeclarativeComponent& component)
{
// Wait until the component is ready
QTRY_VERIFY(component.isReady() || component.isError());
QVERIFY(!component.isError());
}
QTEST_MAIN(tst_QDeclarativeWebView)
#include "tst_qdeclarativewebview.moc"
QT_END_NAMESPACE
|