summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/qt/tests/qdeclarativewebview
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/qt/tests/qdeclarativewebview')
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.html17
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.pngbin0 -> 3961 bytes
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.qml5
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/elements.html14
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/elements.qml7
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/forward.html12
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/forward.pngbin0 -> 2377 bytes
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/javaScript.html11
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/javaScript.qml12
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/loadError.qml5
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.html16
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.qml34
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/propertychanges.qml34
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/resources/sethtml.qml5
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp415
-rw-r--r--Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc18
16 files changed, 603 insertions, 2 deletions
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.html b/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.html
new file mode 100644
index 0000000..22e3e24
--- /dev/null
+++ b/Source/WebKit/qt/tests/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/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.png b/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.png
new file mode 100644
index 0000000..35717cc
--- /dev/null
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.png
Binary files differ
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.qml
new file mode 100644
index 0000000..b5208d0
--- /dev/null
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/basic.qml
@@ -0,0 +1,5 @@
+import QtWebKit 1.0
+
+WebView {
+ url: "basic.html"
+}
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/elements.html b/Source/WebKit/qt/tests/qdeclarativewebview/resources/elements.html
new file mode 100644
index 0000000..9236867
--- /dev/null
+++ b/Source/WebKit/qt/tests/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/Source/WebKit/qt/tests/qdeclarativewebview/resources/elements.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/elements.qml
new file mode 100644
index 0000000..8fef8c9
--- /dev/null
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/elements.qml
@@ -0,0 +1,7 @@
+import QtWebKit 1.0
+
+WebView {
+ url: "elements.html"
+ width: 310
+ height: 100
+}
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/forward.html b/Source/WebKit/qt/tests/qdeclarativewebview/resources/forward.html
new file mode 100644
index 0000000..62ab62d
--- /dev/null
+++ b/Source/WebKit/qt/tests/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/Source/WebKit/qt/tests/qdeclarativewebview/resources/forward.png b/Source/WebKit/qt/tests/qdeclarativewebview/resources/forward.png
new file mode 100644
index 0000000..a82533e
--- /dev/null
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/forward.png
Binary files differ
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/javaScript.html b/Source/WebKit/qt/tests/qdeclarativewebview/resources/javaScript.html
new file mode 100644
index 0000000..35270bc
--- /dev/null
+++ b/Source/WebKit/qt/tests/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/Source/WebKit/qt/tests/qdeclarativewebview/resources/javaScript.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/javaScript.qml
new file mode 100644
index 0000000..527e3b9
--- /dev/null
+++ b/Source/WebKit/qt/tests/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/Source/WebKit/qt/tests/qdeclarativewebview/resources/loadError.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/loadError.qml
new file mode 100644
index 0000000..26cec8f
--- /dev/null
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/loadError.qml
@@ -0,0 +1,5 @@
+import QtWebKit 1.0
+
+WebView {
+ url: "does-not-exist.html"
+}
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.html b/Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.html
new file mode 100644
index 0000000..dd541f9
--- /dev/null
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.html
@@ -0,0 +1,16 @@
+<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>
+<h1>Multiple windows...</h1>
+
+<a id=thelink target="_blank" href="newwindows.html">Popup!</a>
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.qml
new file mode 100644
index 0000000..e66631d
--- /dev/null
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/newwindows.qml
@@ -0,0 +1,34 @@
+// 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 total: 0
+
+ Component {
+ id: webViewPage
+ Rectangle {
+ width: webView.width
+ height: webView.height
+ border.color: "gray"
+
+ WebView {
+ id: webView
+ width: 150 // force predictable for test
+ newWindowComponent: webViewPage
+ newWindowParent: pages
+ url: "newwindows.html"
+ Timer {
+ interval: 10; running: total<4; repeat: false;
+ onTriggered: { if (webView.status==WebView.Ready) { total++; webView.evaluateJavaScript("clickTheLink()") } }
+ }
+ }
+ }
+ }
+
+ Loader { sourceComponent: webViewPage }
+}
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/propertychanges.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/propertychanges.qml
new file mode 100644
index 0000000..db06887
--- /dev/null
+++ b/Source/WebKit/qt/tests/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/Source/WebKit/qt/tests/qdeclarativewebview/resources/sethtml.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/sethtml.qml
new file mode 100644
index 0000000..5bff442
--- /dev/null
+++ b/Source/WebKit/qt/tests/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/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp
index 8fcab71..23e8bfb 100644
--- a/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp
@@ -1,14 +1,18 @@
#include "../util.h"
+#include <QAction>
#include <QColor>
#include <QDebug>
#include <QDeclarativeComponent>
#include <QDeclarativeEngine>
+#include <QDeclarativeItem>
#include <QDeclarativeProperty>
#include <QDeclarativeView>
#include <QDir>
#include <QGraphicsWebView>
#include <QTest>
+#include <QVariant>
#include <QWebFrame>
+#include "qdeclarativewebview_p.h"
QT_BEGIN_NAMESPACE
@@ -19,16 +23,36 @@ public:
tst_QDeclarativeWebView();
private slots:
+ 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();
#if QT_VERSION >= 0x040703
void backgroundColor();
#endif
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()
@@ -36,6 +60,283 @@ tst_QDeclarativeWebView::tst_QDeclarativeWebView()
Q_UNUSED(waitForSignal)
}
+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::cleanupTestCase()
+{
+ removeRecursive(tmpDir());
+}
+
+void tst_QDeclarativeWebView::basicProperties()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/basic.qml"));
+ checkNoErrors(component);
+ QWebSettings::enablePersistentStorage(tmpDir());
+
+ QObject* wv = component.create();
+ QVERIFY(wv);
+ 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);
+ QEXPECT_FAIL("", "'icon' property isn't working", Continue);
+ QCOMPARE(qvariant_cast<QPixmap>(wv->property("icon")), QPixmap("qrc:///resources/basic.png"));
+ 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.", SkipAll);
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/elements.qml"));
+ checkNoErrors(component);
+ QDeclarativeWebView* wv = qobject_cast<QDeclarativeWebView*>(component.create());
+ QVERIFY(wv);
+ QTRY_COMPARE(wv->property("progress").toDouble(), 1.0);
+
+ // 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);
+ QWebSettings::enablePersistentStorage(tmpDir());
+
+ QObject* wv = component.create();
+ QVERIFY(wv);
+
+ 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);
+ QEXPECT_FAIL("", "'icon' property isn't working", Continue);
+ QCOMPARE(qvariant_cast<QPixmap>(wv->property("icon")), QPixmap("qrc:///data/basic.png"));
+ 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();
+ }
+
+ wv->setProperty("url", QUrl("qrc:///resources/forward.html"));
+ 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);
+ QEXPECT_FAIL("", "'icon' property isn't working", Continue);
+ QCOMPARE(qvariant_cast<QPixmap>(wv->property("icon")), QPixmap("qrc:///resources/forward.png"));
+ 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();
+
+ 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);
+ QWebSettings::enablePersistentStorage(tmpDir());
+
+ 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()
+{
+ QSKIP("Rework this test to not depend on QDeclarativeGrid", SkipAll);
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:///resources/newwindows.qml"));
+ checkNoErrors(component);
+
+// QDeclarativeGrid *grid = qobject_cast<QDeclarativeGrid*>(component.create());
+// QVERIFY(grid != 0);
+// QTRY_COMPARE(grid->children().count(), 2+4); // Component, Loader (with 1 WebView), 4 new-window WebViews
+// QDeclarativeItem* popup = qobject_cast<QDeclarativeItem*>(grid->children().at(2)); // first popup after Component and Loader.
+// QVERIFY(popup != 0);
+// QTRY_COMPARE(popup->x(), 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;
@@ -86,6 +387,110 @@ void tst_QDeclarativeWebView::preferredHeightDefaultTest()
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::fromAscii("autoLoadImages")
+ << QString::fromAscii("developerExtrasEnabled")
+ << QString::fromAscii("javaEnabled")
+ << QString::fromAscii("javascriptCanAccessClipboard")
+ << QString::fromAscii("javascriptCanOpenWindows")
+ << QString::fromAscii("javascriptEnabled")
+ << QString::fromAscii("linksIncludedInFocusChain")
+ << QString::fromAscii("localContentCanAccessRemoteUrls")
+ << QString::fromAscii("localStorageDatabaseEnabled")
+ << QString::fromAscii("offlineStorageDatabaseEnabled")
+ << QString::fromAscii("offlineWebApplicationCacheEnabled")
+ << QString::fromAscii("pluginsEnabled")
+ << QString::fromAscii("printElementBackgrounds")
+ << QString::fromAscii("privateBrowsingEnabled")
+ << QString::fromAscii("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.toAscii().data(), value);
+ for (int i = 0; i < 2; i++) {
+ foreach (const QString& name, settingsList)
+ QCOMPARE(s->property(name.toAscii().data()).toBool(), value);
+ }
+ }
+}
+
#if QT_VERSION >= 0x040703
void tst_QDeclarativeWebView::backgroundColor()
{
@@ -120,6 +525,16 @@ void tst_QDeclarativeWebView::checkNoErrors(const QDeclarativeComponent& compone
{
// 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());
}
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc
index e14c333..fb66ad8 100644
--- a/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc
+++ b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc
@@ -1,8 +1,22 @@
<RCC>
<qresource prefix="/">
- <file>resources/webviewtestdefault.qml</file>
- <file>resources/webviewtest.qml</file>
+ <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>