summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-09-26 10:49:56 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-27 15:37:57 +0200
commita8b637e9b70bb420690523cd3f77f139813deec8 (patch)
tree4eba1ed7253baaddf76581312bf0318f5293e055 /tests
parent3ef5a2374862c82076427ca42e334aaaeb21ca45 (diff)
Add QtQuick1 WebKit integration (from QtWebKit module)
This adds the QML1 QDeclarativeWebView integration to the default build (it was added a while ago) as well as the unit tests. Change-Id: I7324f5a3b00716d4b300e8c11d9ea3b8b9577da3 Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/declarative.pro2
-rw-r--r--tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro15
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/basic.html17
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/basic.pngbin0 -> 3961 bytes
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/basic.qml5
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/elements.html14
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/elements.qml7
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/forward.html12
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/forward.pngbin0 -> 2377 bytes
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/javaScript.html11
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/javaScript.qml12
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/loadError.qml5
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/newwindows.html20
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/newwindows.qml51
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/propertychanges.qml34
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/sample.html6
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/sethtml.qml5
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/webviewbackgroundcolor.qml10
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/webviewtest.qml24
-rw-r--r--tests/auto/declarative/qdeclarativewebview/resources/webviewtestdefault.qml22
-rw-r--r--tests/auto/declarative/qdeclarativewebview/test.pngbin0 -> 3836 bytes
-rw-r--r--tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp543
-rw-r--r--tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.qrc22
23 files changed, 837 insertions, 0 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index cebb86bd..eeccd281 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -79,5 +79,7 @@ contains(QT_CONFIG, private_tests) {
contains(QT_CONFIG, opengl): SUBDIRS += qmlshadersplugin
+!isEmpty(QT.webkit.name): SUBDIRS += qdeclarativewebview
+
# Tests which should run in Pulse
PULSE_TESTS = $$SUBDIRS
diff --git a/tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro b/tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro
new file mode 100644
index 00000000..6c447805
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+
+TARGET = tst_qdeclarativewebview
+
+SOURCES += $${TARGET}.cpp
+
+HEADERS += ../shared/debugutil_p.h
+SOURCES += ../shared/debugutil.cpp
+
+INCLUDEPATH += $$PWD/../../../../src/imports/webview
+
+QT += testlib network webkit widgets quick1 quick1-private core-private widgets-private gui-private
+
+exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc
+
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/basic.html b/tests/auto/declarative/qdeclarativewebview/resources/basic.html
new file mode 100644
index 00000000..22e3e243
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/basic.html
@@ -0,0 +1,17 @@
+<html>
+<head><title>Basic</title>
+<link rel="icon" sizes="48x48" href="basic.png">
+<script type="text/javascript">
+<!--
+window.onload = function(){ window.status = "status here"; }
+// -->
+</script>
+</head>
+<body leftmargin="0" marginwidth="0">
+<table width="123">
+<tbody>
+<tr><td>This is a basic test.</td></tr>
+</tbody>
+</table>
+</body>
+</html>
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/basic.png b/tests/auto/declarative/qdeclarativewebview/resources/basic.png
new file mode 100644
index 00000000..35717cca
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/basic.png
Binary files differ
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/basic.qml b/tests/auto/declarative/qdeclarativewebview/resources/basic.qml
new file mode 100644
index 00000000..b5208d03
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/basic.qml
@@ -0,0 +1,5 @@
+import QtWebKit 1.0
+
+WebView {
+ url: "basic.html"
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/elements.html b/tests/auto/declarative/qdeclarativewebview/resources/elements.html
new file mode 100644
index 00000000..92368679
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/elements.html
@@ -0,0 +1,14 @@
+<body leftmargin=0 topmargin=0>
+<table width="300px" border=1 cellpadding=0 cellspacing=0>
+<tr>
+<td align=center width=25%%><p>A</p></td>
+<td width=75% height=50px>
+ <table width=100% border=1 cellpadding=0 cellspacing=0>
+ <tr>
+ <td align=center width=50% height=50px><p>B</p></td>
+ <td align=center width=50% height=50px><p>C</p></td>
+ </tr>
+ </table>
+</td>
+</tr>
+</table>
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/elements.qml b/tests/auto/declarative/qdeclarativewebview/resources/elements.qml
new file mode 100644
index 00000000..8fef8c92
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/elements.qml
@@ -0,0 +1,7 @@
+import QtWebKit 1.0
+
+WebView {
+ url: "elements.html"
+ width: 310
+ height: 100
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/forward.html b/tests/auto/declarative/qdeclarativewebview/resources/forward.html
new file mode 100644
index 00000000..62ab62da
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/forward.html
@@ -0,0 +1,12 @@
+<html>
+<head><title>Forward</title>
+<link rel="icon" sizes="32x32" href="forward.png">
+</head>
+<body leftmargin="0" marginwidth="0">
+<table width="123">
+<tbody>
+<tr><td>This is more.</td></tr>
+</tbody>
+</table>
+</body>
+</html>
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/forward.png b/tests/auto/declarative/qdeclarativewebview/resources/forward.png
new file mode 100644
index 00000000..a82533e3
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/forward.png
Binary files differ
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/javaScript.html b/tests/auto/declarative/qdeclarativewebview/resources/javaScript.html
new file mode 100644
index 00000000..35270bc4
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/javaScript.html
@@ -0,0 +1,11 @@
+<html>
+<head><title>JavaScript</title>
+<link rel="icon" sizes="48x48" href="basic.png">
+<script type="text/javascript">
+<!--
+window.onload = function(){ window.status = "status here"; }
+// -->
+</script>
+</head>
+<body>
+This is a JS test.
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/javaScript.qml b/tests/auto/declarative/qdeclarativewebview/resources/javaScript.qml
new file mode 100644
index 00000000..527e3b98
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/javaScript.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+import QtWebKit 1.0
+
+WebView {
+ url: "javaScript.html"
+ javaScriptWindowObjects: [
+ QtObject {
+ property string qmlprop: "qmlvalue"
+ WebView.windowObjectName: "myjsname"
+ }
+ ]
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/loadError.qml b/tests/auto/declarative/qdeclarativewebview/resources/loadError.qml
new file mode 100644
index 00000000..26cec8f9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/loadError.qml
@@ -0,0 +1,5 @@
+import QtWebKit 1.0
+
+WebView {
+ url: "does-not-exist.html"
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/newwindows.html b/tests/auto/declarative/qdeclarativewebview/resources/newwindows.html
new file mode 100644
index 00000000..4252d9a7
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/newwindows.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script type="text/javascript">
+<!--
+function clickTheLink()
+{
+ var ev = document.createEvent('MouseEvents');
+ ev.initEvent( "click", true, false );
+ document.getElementById('thelink').dispatchEvent(ev);
+}
+// -->
+</script>
+</head>
+<body>
+<h1>Multiple windows...</h1>
+
+<a id=thelink target="_blank" href="newwindows.html">Popup!</a>
+</body>
+</html>
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/newwindows.qml b/tests/auto/declarative/qdeclarativewebview/resources/newwindows.qml
new file mode 100644
index 00000000..166722d5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/newwindows.qml
@@ -0,0 +1,51 @@
+// Demonstrates opening new WebViews from HTML
+
+import QtQuick 1.0
+import QtWebKit 1.0
+
+Grid {
+ columns: 3
+ id: pages
+ height: 300; width: 600
+ property int pagesOpened: 0
+ property Item firstPageOpened: null
+
+ Component {
+ id: webViewPage
+ Rectangle {
+ id: thisPage
+ width: 150
+ height: 150
+ property WebView webView: wv
+
+ WebView {
+ id: wv
+ anchors.fill: parent
+ newWindowComponent: webViewPage
+ newWindowParent: pages
+ url: "newwindows.html"
+ Component.onCompleted: {
+ if (pagesOpened == 1) {
+ pages.firstPageOpened = thisPage;
+ }
+ }
+ }
+ }
+ }
+
+ Loader {
+ id: originalPage
+ sourceComponent: webViewPage
+ property bool ready: status == Loader.Ready && item.webView.status == WebView.Ready
+ }
+
+ Timer {
+ interval: 10
+ running: originalPage.ready && pagesOpened < 4
+ repeat: true
+ onTriggered: {
+ pagesOpened++;
+ originalPage.item.webView.evaluateJavaScript("clickTheLink()");
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/propertychanges.qml b/tests/auto/declarative/qdeclarativewebview/resources/propertychanges.qml
new file mode 100644
index 00000000..8210e85a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/propertychanges.qml
@@ -0,0 +1,34 @@
+import QtQuick 1.0
+import QtWebKit 1.0
+
+Item {
+ width: 240
+ height: 160
+ Grid {
+ anchors.fill: parent
+ objectName: "newWindowParent"
+ id: newWindowParent
+ }
+
+ Row {
+ anchors.fill: parent
+ id: oldWindowParent
+ objectName: "oldWindowParent"
+ }
+
+ Loader {
+ sourceComponent: webViewComponent
+ }
+ Component {
+ id: webViewComponent
+ WebView {
+ id: webView
+ objectName: "webView"
+ newWindowComponent: webViewComponent
+ newWindowParent: oldWindowParent
+ url: "basic.html"
+ renderingEnabled: true
+ pressGrabTime: 200
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/sample.html b/tests/auto/declarative/qdeclarativewebview/resources/sample.html
new file mode 100644
index 00000000..cc9bffaf
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/sample.html
@@ -0,0 +1,6 @@
+<html>
+<head></head>
+<body width=400 height=400>
+Here is a sample text
+</body>
+</html>
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/sethtml.qml b/tests/auto/declarative/qdeclarativewebview/resources/sethtml.qml
new file mode 100644
index 00000000..5bff442b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/sethtml.qml
@@ -0,0 +1,5 @@
+import QtWebKit 1.0
+
+WebView {
+ html: "<p>This is a <b>string</b> set on the WebView"
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/webviewbackgroundcolor.qml b/tests/auto/declarative/qdeclarativewebview/resources/webviewbackgroundcolor.qml
new file mode 100644
index 00000000..fb46d38b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/webviewbackgroundcolor.qml
@@ -0,0 +1,10 @@
+import QtQuick 1.0
+import QtWebKit 1.1
+
+WebView {
+ id: myweb
+ height: 300
+ width: 300
+ focus: true
+ backgroundColor : "red"
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/webviewtest.qml b/tests/auto/declarative/qdeclarativewebview/resources/webviewtest.qml
new file mode 100644
index 00000000..609d9c99
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/webviewtest.qml
@@ -0,0 +1,24 @@
+import QtQuick 1.0
+import QtWebKit 1.0
+
+Flickable {
+ id: flick
+ width: 640
+ height: 400
+ clip: true
+ contentWidth: myweb.width; contentHeight: myweb.height
+ property alias myurl: myweb.url
+ property alias prefHeight: myweb.preferredHeight
+ property alias prefWidth: myweb.preferredWidth
+ property url testUrl;
+ WebView {
+ id: myweb
+ url: testUrl
+ smooth: false
+ scale: 1.0
+ preferredHeight: 500
+ preferredWidth: 600
+ pressGrabTime: 1000
+ focus: true
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/resources/webviewtestdefault.qml b/tests/auto/declarative/qdeclarativewebview/resources/webviewtestdefault.qml
new file mode 100644
index 00000000..b26eea61
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/resources/webviewtestdefault.qml
@@ -0,0 +1,22 @@
+import QtQuick 1.0
+import QtWebKit 1.0
+
+Flickable {
+ id: flick
+ width: 640
+ height: 400
+ clip: true
+ contentWidth: myweb.width; contentHeight: myweb.height
+ property alias myurl: myweb.url
+ property alias prefHeight: myweb.preferredHeight
+ property alias prefWidth: myweb.preferredWidth
+ property url testUrl;
+ WebView {
+ id: myweb
+ url: testUrl;
+ smooth: false
+ scale: 1.0
+ pressGrabTime: 1000
+ focus: true
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativewebview/test.png b/tests/auto/declarative/qdeclarativewebview/test.png
new file mode 100644
index 00000000..2a9ec090
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/test.png
Binary files differ
diff --git a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp
new file mode 100644
index 00000000..51bf3859
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp
@@ -0,0 +1,543 @@
+#include <QAction>
+#include <QColor>
+#include <QDebug>
+#include <QDeclarativeItem>
+#include <QDeclarativeView>
+#include <QDeclarativeComponent>
+#include <QDeclarativeEngine>
+#include <QDeclarativeProperty>
+#include <QDir>
+#include <QGraphicsWebView>
+#include <QTest>
+#include <QVariant>
+#include <QWebFrame>
+#include "../shared/debugutil_p.h"
+#include "qdeclarativewebview_p.h"
+
+class tst_QDeclarativeWebView : public QObject {
+ Q_OBJECT
+
+public:
+ tst_QDeclarativeWebView();
+
+private Q_SLOTS:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void basicProperties();
+ void elementAreaAt();
+ void historyNav();
+ void javaScript();
+ void loadError();
+ void multipleWindows();
+ void newWindowComponent();
+ void newWindowParent();
+ void preferredWidthTest();
+ void preferredHeightTest();
+ void preferredWidthDefaultTest();
+ void preferredHeightDefaultTest();
+ void pressGrabTime();
+ void renderingEnabled();
+ void setHtml();
+ void settings();
+ void backgroundColor();
+
+private:
+ void checkNoErrors(const QDeclarativeComponent&);
+ QString tmpDir() const
+ {
+ static QString tmpd = QDir::tempPath() + "/tst_qdeclarativewebview-"
+ + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss"));
+ return tmpd;
+ }
+};
+
+tst_QDeclarativeWebView::tst_QDeclarativeWebView()
+{
+}
+
+static QString strippedHtml(QString html)
+{
+ html.replace(QRegExp("\\s+"), "");
+ return html;
+}
+
+static QString fileContents(const QString& filename)
+{
+ QFile file(filename);
+ file.open(QIODevice::ReadOnly);
+ return QString::fromUtf8(file.readAll());
+}
+
+static void removeRecursive(const QString& dirname)
+{
+ QDir dir(dirname);
+ QFileInfoList entries(dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot));
+ for (int i = 0; i < entries.count(); ++i)
+ if (entries[i].isDir())
+ removeRecursive(entries[i].filePath());
+ else
+ dir.remove(entries[i].fileName());
+ QDir().rmdir(dirname);
+}
+
+void tst_QDeclarativeWebView::initTestCase()
+{
+ QWebSettings::enablePersistentStorage(tmpDir());
+}
+
+void tst_QDeclarativeWebView::cleanupTestCase()
+{
+ removeRecursive(tmpDir());
+}
+
+void tst_QDeclarativeWebView::basicProperties()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/basic.qml"));
+ checkNoErrors(component);
+
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QDeclarativeDebugTest::waitForSignal(wv, SIGNAL(iconChanged()));
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+ QCOMPARE(wv->property("title").toString(), QLatin1String("Basic"));
+ QTRY_COMPARE(qvariant_cast<QPixmap>(wv->property("icon")).width(), 48);
+ QVERIFY(!qvariant_cast<QPixmap>(wv->property("icon")).isNull());
+ QCOMPARE(wv->property("statusText").toString(), QLatin1String("status here"));
+ QCOMPARE(strippedHtml(fileContents(":/resources/basic.html")), strippedHtml(wv->property("html").toString()));
+ QEXPECT_FAIL("", "TODO: get preferred width from QGraphicsWebView result", Continue);
+ QCOMPARE(wv->property("preferredWidth").toInt(), 0);
+ QEXPECT_FAIL("", "TODO: get preferred height from QGraphicsWebView result", Continue);
+ QCOMPARE(wv->property("preferredHeight").toInt(), 0);
+ QCOMPARE(wv->property("url").toUrl(), QUrl("qrc:///resources/basic.html"));
+ QCOMPARE(wv->property("status").toInt(), int(QDeclarativeWebView::Ready));
+
+ QAction* reloadAction = wv->property("reload").value<QAction*>();
+ QVERIFY(reloadAction);
+ QVERIFY(reloadAction->isEnabled());
+ QAction* backAction = wv->property("back").value<QAction*>();
+ QVERIFY(backAction);
+ QVERIFY(!backAction->isEnabled());
+ QAction* forwardAction = wv->property("forward").value<QAction*>();
+ QVERIFY(forwardAction);
+ QVERIFY(!forwardAction->isEnabled());
+ QAction* stopAction = wv->property("stop").value<QAction*>();
+ QVERIFY(stopAction);
+ QVERIFY(!stopAction->isEnabled());
+
+ wv->setProperty("pixelCacheSize", 0); // mainly testing that it doesn't crash or anything!
+ QCOMPARE(wv->property("pixelCacheSize").toInt(), 0);
+ reloadAction->trigger();
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+}
+
+void tst_QDeclarativeWebView::elementAreaAt()
+{
+ QSKIP("This test should be changed to test 'heuristicZoom' instead.");
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/elements.qml"));
+ checkNoErrors(component);
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+
+ // FIXME: Tests disabled since elementAreaAt isn't exported.
+ // Areas from elements.html.
+// const QRect areaA(1, 1, 75, 54);
+// const QRect areaB(78, 3, 110, 50);
+// const QRect wholeView(0, 0, 310, 100);
+// const QRect areaBC(76, 1, 223, 54);
+
+// QCOMPARE(wv->elementAreaAt(40, 30, 100, 100), areaA);
+// QCOMPARE(wv->elementAreaAt(130, 30, 200, 100), areaB);
+// QCOMPARE(wv->elementAreaAt(40, 30, 400, 400), wholeView);
+// QCOMPARE(wv->elementAreaAt(130, 30, 280, 280), areaBC);
+// QCOMPARE(wv->elementAreaAt(130, 30, 400, 400), wholeView);
+}
+
+void tst_QDeclarativeWebView::historyNav()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/basic.qml"));
+ checkNoErrors(component);
+
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QDeclarativeDebugTest::waitForSignal(wv, SIGNAL(iconChanged()));
+
+ QAction* reloadAction = wv->property("reload").value<QAction*>();
+ QVERIFY(reloadAction);
+ QAction* backAction = wv->property("back").value<QAction*>();
+ QVERIFY(backAction);
+ QAction* forwardAction = wv->property("forward").value<QAction*>();
+ QVERIFY(forwardAction);
+ QAction* stopAction = wv->property("stop").value<QAction*>();
+ QVERIFY(stopAction);
+
+ for (int i = 1; i <= 2; ++i) {
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+ QCOMPARE(wv->property("title").toString(), QLatin1String("Basic"));
+ QTRY_COMPARE(qvariant_cast<QPixmap>(wv->property("icon")).width(), 48);
+ QCOMPARE(wv->property("statusText").toString(), QLatin1String("status here"));
+ QCOMPARE(strippedHtml(fileContents(":/resources/basic.html")), strippedHtml(wv->property("html").toString()));
+ QEXPECT_FAIL("", "TODO: get preferred width from QGraphicsWebView result", Continue);
+ QCOMPARE(wv->property("preferredWidth").toDouble(), 0.0);
+ QCOMPARE(wv->property("url").toUrl(), QUrl("qrc:///resources/basic.html"));
+ QCOMPARE(wv->property("status").toInt(), int(QDeclarativeWebView::Ready));
+ QVERIFY(reloadAction->isEnabled());
+ QVERIFY(!backAction->isEnabled());
+ QVERIFY(!forwardAction->isEnabled());
+ QVERIFY(!stopAction->isEnabled());
+ reloadAction->trigger();
+ QDeclarativeDebugTest::waitForSignal(wv, SIGNAL(iconChanged()));
+ }
+
+ wv->setProperty("url", QUrl("qrc:///resources/forward.html"));
+ QDeclarativeDebugTest::waitForSignal(wv, SIGNAL(iconChanged()));
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+ QCOMPARE(wv->property("title").toString(), QLatin1String("Forward"));
+ QTRY_COMPARE(qvariant_cast<QPixmap>(wv->property("icon")).width(), 32);
+ QCOMPARE(strippedHtml(fileContents(":/resources/forward.html")), strippedHtml(wv->property("html").toString()));
+ QCOMPARE(wv->property("url").toUrl(), QUrl("qrc:///resources/forward.html"));
+ QCOMPARE(wv->property("status").toInt(), int(QDeclarativeWebView::Ready));
+ QCOMPARE(wv->property("statusText").toString(), QString());
+
+ QVERIFY(reloadAction->isEnabled());
+ QVERIFY(backAction->isEnabled());
+ QVERIFY(!forwardAction->isEnabled());
+ QVERIFY(!stopAction->isEnabled());
+
+ backAction->trigger();
+ QDeclarativeDebugTest::waitForSignal(wv, SIGNAL(loadFinished()));
+
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+ QCOMPARE(wv->property("title").toString(), QLatin1String("Basic"));
+ QCOMPARE(strippedHtml(fileContents(":/resources/basic.html")), strippedHtml(wv->property("html").toString()));
+ QCOMPARE(wv->property("url").toUrl(), QUrl("qrc:///resources/basic.html"));
+ QCOMPARE(wv->property("status").toInt(), int(QDeclarativeWebView::Ready));
+
+ QVERIFY(reloadAction->isEnabled());
+ QVERIFY(!backAction->isEnabled());
+ QVERIFY(forwardAction->isEnabled());
+ QVERIFY(!stopAction->isEnabled());
+}
+
+static inline QVariant callEvaluateJavaScript(QObject *object, const QString& snippet)
+{
+ QVariant result;
+ QMetaObject::invokeMethod(object, "evaluateJavaScript", Q_RETURN_ARG(QVariant, result), Q_ARG(QString, snippet));
+ return result;
+}
+
+void tst_QDeclarativeWebView::javaScript()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/javaScript.qml"));
+ checkNoErrors(component);
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+
+ QCOMPARE(callEvaluateJavaScript(wv, "123").toInt(), 123);
+ QCOMPARE(callEvaluateJavaScript(wv, "window.status").toString(), QLatin1String("status here"));
+ QCOMPARE(callEvaluateJavaScript(wv, "window.myjsname.qmlprop").toString(), QLatin1String("qmlvalue"));
+}
+
+void tst_QDeclarativeWebView::loadError()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/loadError.qml"));
+ checkNoErrors(component);
+
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QAction* reloadAction = wv->property("reload").value<QAction*>();
+ QVERIFY(reloadAction);
+
+ for (int i = 1; i <= 2; ++i) {
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+ QCOMPARE(wv->property("title").toString(), QString());
+ QCOMPARE(wv->property("statusText").toString(), QString()); // HTML 'status bar' text, not error message
+ QCOMPARE(wv->property("url").toUrl(), QUrl("qrc:///resources/does-not-exist.html")); // Unlike QWebPage, which loses url
+ QCOMPARE(wv->property("status").toInt(), int(QDeclarativeWebView::Error));
+ reloadAction->trigger();
+ }
+}
+
+void tst_QDeclarativeWebView::multipleWindows()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/newwindows.qml"));
+ checkNoErrors(component);
+
+ QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(rootItem);
+
+ QTRY_COMPARE(rootItem->property("pagesOpened").toInt(), 4);
+
+ QDeclarativeProperty prop(rootItem, "firstPageOpened");
+ QObject* firstPageOpened = qvariant_cast<QObject*>(prop.read());
+ QVERIFY(firstPageOpened);
+
+ QDeclarativeProperty xProp(firstPageOpened, "x");
+ QTRY_COMPARE(xProp.read().toReal(), qreal(150.0));
+}
+
+void tst_QDeclarativeWebView::newWindowComponent()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/propertychanges.qml"));
+ checkNoErrors(component);
+ QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(rootItem);
+ QObject* wv = rootItem->findChild<QObject*>("webView");
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+
+ QDeclarativeComponent substituteComponent(&engine);
+ substituteComponent.setData("import QtQuick 1.0; WebView { objectName: 'newWebView'; url: 'basic.html'; }", QUrl::fromLocalFile(""));
+ QSignalSpy newWindowComponentSpy(wv, SIGNAL(newWindowComponentChanged()));
+
+ wv->setProperty("newWindowComponent", QVariant::fromValue(&substituteComponent));
+ QCOMPARE(wv->property("newWindowComponent"), QVariant::fromValue(&substituteComponent));
+ QCOMPARE(newWindowComponentSpy.count(), 1);
+
+ wv->setProperty("newWindowComponent", QVariant::fromValue(&substituteComponent));
+ QCOMPARE(newWindowComponentSpy.count(), 1);
+
+ wv->setProperty("newWindowComponent", QVariant::fromValue((QDeclarativeComponent*)0));
+ QCOMPARE(newWindowComponentSpy.count(), 2);
+}
+
+void tst_QDeclarativeWebView::newWindowParent()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/propertychanges.qml"));
+ checkNoErrors(component);
+ QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(rootItem);
+ QObject* wv = rootItem->findChild<QObject*>("webView");
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+
+ QDeclarativeItem* oldWindowParent = rootItem->findChild<QDeclarativeItem*>("oldWindowParent");
+ QCOMPARE(qvariant_cast<QDeclarativeItem*>(wv->property("newWindowParent")), oldWindowParent);
+ QSignalSpy newWindowParentSpy(wv, SIGNAL(newWindowParentChanged()));
+
+ QDeclarativeItem* newWindowParent = rootItem->findChild<QDeclarativeItem*>("newWindowParent");
+ wv->setProperty("newWindowParent", QVariant::fromValue(newWindowParent));
+ QVERIFY(newWindowParent);
+ QVERIFY(oldWindowParent);
+ QCOMPARE(oldWindowParent->childItems().count(), 0);
+ QCOMPARE(wv->property("newWindowParent"), QVariant::fromValue(newWindowParent));
+ QCOMPARE(newWindowParentSpy.count(), 1);
+
+ wv->setProperty("newWindowParent", QVariant::fromValue(newWindowParent));
+ QCOMPARE(newWindowParentSpy.count(), 1);
+
+ wv->setProperty("newWindowParent", QVariant::fromValue((QDeclarativeItem*)0));
+ QCOMPARE(newWindowParentSpy.count(), 2);
+}
+
+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::pressGrabTime()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/propertychanges.qml"));
+ checkNoErrors(component);
+ QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(rootItem);
+ QObject* wv = rootItem->findChild<QObject*>("webView");
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+ QCOMPARE(wv->property("pressGrabTime").toInt(), 200);
+ QSignalSpy pressGrabTimeSpy(wv, SIGNAL(pressGrabTimeChanged()));
+
+ wv->setProperty("pressGrabTime", 100);
+ QCOMPARE(wv->property("pressGrabTime").toInt(), 100);
+ QCOMPARE(pressGrabTimeSpy.count(), 1);
+
+ wv->setProperty("pressGrabTime", 100);
+ QCOMPARE(pressGrabTimeSpy.count(), 1);
+
+ wv->setProperty("pressGrabTime", 0);
+ QCOMPARE(pressGrabTimeSpy.count(), 2);
+}
+
+void tst_QDeclarativeWebView::renderingEnabled()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/propertychanges.qml"));
+ checkNoErrors(component);
+ QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(rootItem);
+ QObject* wv = rootItem->findChild<QObject*>("webView");
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+
+ QVERIFY(wv->property("renderingEnabled").toBool());
+ QSignalSpy renderingEnabledSpy(wv, SIGNAL(renderingEnabledChanged()));
+
+ wv->setProperty("renderingEnabled", false);
+ QVERIFY(!wv->property("renderingEnabled").toBool());
+ QCOMPARE(renderingEnabledSpy.count(), 1);
+
+ wv->setProperty("renderingEnabled", false);
+ QCOMPARE(renderingEnabledSpy.count(), 1);
+
+ wv->setProperty("renderingEnabled", true);
+ QCOMPARE(renderingEnabledSpy.count(), 2);
+}
+
+void tst_QDeclarativeWebView::setHtml()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/sethtml.qml"));
+ checkNoErrors(component);
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QCOMPARE(wv->property("html").toString(), QLatin1String("<html><head></head><body><p>This is a <b>string</b> set on the WebView</p></body></html>"));
+
+ QSignalSpy spy(wv, SIGNAL(htmlChanged()));
+ wv->setProperty("html", QLatin1String("<html><head><title>Basic</title></head><body><p>text</p></body></html>"));
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QDeclarativeWebView::settings()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/basic.qml"));
+ checkNoErrors(component);
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+
+ QObject* s = QDeclarativeProperty(wv, "settings").object();
+ QVERIFY(s);
+
+ QStringList settingsList;
+ settingsList << QString::fromLatin1("autoLoadImages")
+ << QString::fromLatin1("developerExtrasEnabled")
+ << QString::fromLatin1("javaEnabled")
+ << QString::fromLatin1("javascriptCanAccessClipboard")
+ << QString::fromLatin1("javascriptCanOpenWindows")
+ << QString::fromLatin1("javascriptEnabled")
+ << QString::fromLatin1("linksIncludedInFocusChain")
+ << QString::fromLatin1("localContentCanAccessRemoteUrls")
+ << QString::fromLatin1("localStorageDatabaseEnabled")
+ << QString::fromLatin1("offlineStorageDatabaseEnabled")
+ << QString::fromLatin1("offlineWebApplicationCacheEnabled")
+ << QString::fromLatin1("pluginsEnabled")
+ << QString::fromLatin1("printElementBackgrounds")
+ << QString::fromLatin1("privateBrowsingEnabled")
+ << QString::fromLatin1("zoomTextOnly");
+
+ // Merely tests that setting gets stored (in QWebSettings), behavioural tests are in WebKit.
+ for (int b = 0; b <= 1; b++) {
+ bool value = !!b;
+ foreach (const QString& name, settingsList)
+ s->setProperty(name.toLatin1().data(), value);
+ for (int i = 0; i < 2; i++) {
+ foreach (const QString& name, settingsList)
+ QCOMPARE(s->property(name.toLatin1().data()).toBool(), value);
+ }
+ }
+}
+
+void tst_QDeclarativeWebView::backgroundColor()
+{
+ // We test here the rendering of the background.
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewbackgroundcolor.qml"));
+ checkNoErrors(component);
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ QCOMPARE(wv->property("backgroundColor").value<QColor>(), QColor(Qt::red));
+ QDeclarativeView view;
+ view.setSource(QUrl("qrc:///resources/webviewbackgroundcolor.qml"));
+ view.show();
+ QTest::qWaitForWindowExposed(&view);
+ QPixmap result(view.width(), view.height());
+ QPainter painter(&result);
+ view.render(&painter);
+ QPixmap reference(view.width(), view.height());
+ reference.fill(Qt::red);
+ QCOMPARE(reference, result);
+
+ // We test the emission of the backgroundColorChanged signal.
+ QSignalSpy spyColorChanged(wv, SIGNAL(backgroundColorChanged()));
+ wv->setProperty("backgroundColor", QColor(Qt::red));
+ QCOMPARE(spyColorChanged.count(), 0);
+ wv->setProperty("backgroundColor", QColor(Qt::green));
+ QCOMPARE(spyColorChanged.count(), 1);
+}
+
+void tst_QDeclarativeWebView::checkNoErrors(const QDeclarativeComponent& component)
+{
+ // Wait until the component is ready
+ QTRY_VERIFY(component.isReady() || component.isError());
+ if (component.isError()) {
+ QList<QDeclarativeError> errors = component.errors();
+ for (int ii = 0; ii < errors.count(); ++ii) {
+ const QDeclarativeError &error = errors.at(ii);
+ QByteArray errorStr = QByteArray::number(error.line()) + ":" +
+ QByteArray::number(error.column()) + ":" +
+ error.description().toUtf8();
+ qWarning() << errorStr;
+ }
+ }
+ QVERIFY(!component.isError());
+}
+
+QTEST_MAIN(tst_QDeclarativeWebView)
+#include "tst_qdeclarativewebview.moc"
diff --git a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.qrc b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.qrc
new file mode 100644
index 00000000..fb66ad88
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.qrc
@@ -0,0 +1,22 @@
+<RCC>
+ <qresource prefix="/">
+ <file>resources/basic.html</file>
+ <file>resources/basic.png</file>
+ <file>resources/basic.qml</file>
+ <file>resources/elements.html</file>
+ <file>resources/elements.qml</file>
+ <file>resources/forward.html</file>
+ <file>resources/forward.png</file>
+ <file>resources/javaScript.html</file>
+ <file>resources/javaScript.qml</file>
+ <file>resources/loadError.qml</file>
+ <file>resources/newwindows.html</file>
+ <file>resources/newwindows.qml</file>
+ <file>resources/propertychanges.qml</file>
+ <file>resources/sample.html</file>
+ <file>resources/sethtml.qml</file>
+ <file>resources/webviewbackgroundcolor.qml</file>
+ <file>resources/webviewtestdefault.qml</file>
+ <file>resources/webviewtest.qml</file>
+ </qresource>
+</RCC>