summaryrefslogtreecommitdiffstats
path: root/WebKit/qt/tests
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2009-12-15 10:12:09 +0000
committerSteve Block <steveblock@google.com>2009-12-17 17:41:10 +0000
commit643ca7872b450ea4efacab6188849e5aac2ba161 (patch)
tree6982576c228bcd1a7efe98afed544d840751094c /WebKit/qt/tests
parentd026980fde6eb3b01c1fe49441174e89cd1be298 (diff)
downloadexternal_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.zip
external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.gz
external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.bz2
Merge webkit.org at r51976 : Initial merge by git.
Change-Id: Ib0e7e2f0fb4bee5a186610272edf3186f0986b43
Diffstat (limited to 'WebKit/qt/tests')
-rw-r--r--WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp35
-rw-r--r--WebKit/qt/tests/qwebelement/tst_qwebelement.cpp62
-rw-r--r--WebKit/qt/tests/qwebframe/qwebframe.pro2
-rw-r--r--WebKit/qt/tests/qwebframe/tst_qwebframe.cpp105
-rw-r--r--WebKit/qt/tests/qwebinspector/qwebinspector.pro6
-rw-r--r--WebKit/qt/tests/qwebinspector/tst_qwebinspector.cpp68
-rw-r--r--WebKit/qt/tests/qwebpage/qwebpage.pro2
-rw-r--r--WebKit/qt/tests/qwebpage/tst_qwebpage.cpp299
-rw-r--r--WebKit/qt/tests/qwebview/data/frame_a.html2
-rw-r--r--WebKit/qt/tests/qwebview/data/index.html4
-rw-r--r--WebKit/qt/tests/qwebview/qwebview.pro1
-rw-r--r--WebKit/qt/tests/qwebview/tst_qwebview.cpp113
-rw-r--r--WebKit/qt/tests/qwebview/tst_qwebview.qrc7
-rw-r--r--WebKit/qt/tests/tests.pro2
-rw-r--r--WebKit/qt/tests/util.h28
15 files changed, 539 insertions, 197 deletions
diff --git a/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp b/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp
index 4bdb7f5..657e09f 100644
--- a/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp
+++ b/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp
@@ -17,36 +17,13 @@
Boston, MA 02110-1301, USA.
*/
+#include "../util.h"
#include <QtTest/QtTest>
-
#include <QGraphicsView>
#include <qgraphicswebview.h>
#include <qwebpage.h>
#include <qwebframe.h>
-/**
- * Starts an event loop that runs until the given signal is received.
- * Optionally the event loop
- * can return earlier on a timeout.
- *
- * \return \p true if the requested signal was received
- * \p false on timeout
- */
-static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000)
-{
- QEventLoop loop;
- QObject::connect(obj, signal, &loop, SLOT(quit()));
- QTimer timer;
- QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
- if (timeout > 0) {
- QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
- timer.setSingleShot(true);
- timer.start(timeout);
- }
- loop.exec();
- return timeoutSpy.isEmpty();
-}
-
class tst_QGraphicsWebView : public QObject
{
Q_OBJECT
@@ -63,21 +40,17 @@ void tst_QGraphicsWebView::qgraphicswebview()
item.title();
item.icon();
item.zoomFactor();
- item.isInteractive();
- item.progress();
- item.toHtml();
item.history();
item.settings();
- item.status();
item.page();
item.setPage(0);
item.page();
item.setUrl(QUrl());
item.setZoomFactor(0);
- item.setInteractive(true);
item.load(QUrl());
item.setHtml(QString());
item.setContent(QByteArray());
+ item.isModified();
}
class WebPage : public QWebPage
@@ -117,7 +90,7 @@ void tst_QGraphicsWebView::crashOnViewlessWebPages()
view.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
view.resize(600, 480);
webView->resize(view.geometry().size());
- QTest::qWait(200);
+ QCoreApplication::processEvents();
view.show();
page->mainFrame()->setHtml(QString("data:text/html,"
@@ -126,7 +99,7 @@ void tst_QGraphicsWebView::crashOnViewlessWebPages()
"<frame src=\"data:text/html,bar\">"
"</frameset>"));
- QVERIFY(::waitForSignal(page, SIGNAL(loadFinished(bool))));
+ QVERIFY(waitForSignal(page, SIGNAL(loadFinished(bool))));
}
QTEST_MAIN(tst_QGraphicsWebView)
diff --git a/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp b/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
index cf83fe8..e9dae18 100644
--- a/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
+++ b/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
@@ -68,9 +68,12 @@ private slots:
void simpleCollection();
void attributes();
void attributesNS();
+ void listAttributes();
void classes();
void namespaceURI();
void iteration();
+ void nonConstIterator();
+ void constIterator();
void foreachManipulation();
void emptyCollection();
void appendCollection();
@@ -185,6 +188,29 @@ void tst_QWebElement::attributesNS()
QCOMPARE(svg.attributeNS("http://www.w3.org/2000/svg", "foobar", "defaultblah"), QString("true"));
}
+void tst_QWebElement::listAttributes()
+{
+ QString content = "<html xmlns=\"http://www.w3.org/1999/xhtml\" "
+ "xmlns:svg=\"http://www.w3.org/2000/svg\">"
+ "<body><svg:svg foo=\"\" svg:bar=\"\">"
+ "</svg:svg></body></html>";
+
+ m_mainFrame->setContent(content.toUtf8(), "application/xhtml+xml");
+
+ QWebElement svg = m_mainFrame->findFirstElement("svg");
+ QVERIFY(!svg.isNull());
+
+ QVERIFY(svg.attributeNames().contains("foo"));
+ QVERIFY(svg.attributeNames("http://www.w3.org/2000/svg").contains("bar"));
+
+ svg.setAttributeNS("http://www.w3.org/2000/svg", "svg:foobar", "true");
+ QVERIFY(svg.attributeNames().contains("foo"));
+ QStringList attributes = svg.attributeNames("http://www.w3.org/2000/svg");
+ QCOMPARE(attributes.size(), 2);
+ QVERIFY(attributes.contains("bar"));
+ QVERIFY(attributes.contains("foobar"));
+}
+
void tst_QWebElement::classes()
{
m_mainFrame->setHtml("<body><p class=\"a b c d a c\">Test");
@@ -305,6 +331,37 @@ void tst_QWebElement::iteration()
QCOMPARE(paras.at(1), paras.last());
}
+void tst_QWebElement::nonConstIterator()
+{
+ QString html = "<body><p>first para</p><p>second para</p></body>";
+ m_mainFrame->setHtml(html);
+ QWebElement body = m_mainFrame->documentElement();
+ QWebElementCollection paras = body.findAll("p");
+
+ QWebElementCollection::iterator it = paras.begin();
+ QCOMPARE(*it, paras.at(0));
+ ++it;
+ (*it).encloseWith("<div>");
+ QCOMPARE(*it, paras.at(1));
+ ++it;
+ QCOMPARE(it, paras.end());
+}
+
+void tst_QWebElement::constIterator()
+{
+ QString html = "<body><p>first para</p><p>second para</p></body>";
+ m_mainFrame->setHtml(html);
+ QWebElement body = m_mainFrame->documentElement();
+ const QWebElementCollection paras = body.findAll("p");
+
+ QWebElementCollection::const_iterator it = paras.begin();
+ QCOMPARE(*it, paras.at(0));
+ ++it;
+ QCOMPARE(*it, paras.at(1));
+ ++it;
+ QCOMPARE(it, paras.end());
+}
+
void tst_QWebElement::foreachManipulation()
{
QString html = "<body><p>first para</p><p>second para</p></body>";
@@ -938,7 +995,10 @@ void tst_QWebElement::render()
QImage testImage(resource.width(), resource.height(), QImage::Format_ARGB32);
QPainter painter0(&testImage);
painter0.fillRect(imageRect, Qt::white);
- painter0.drawImage(0, 0, resource);
+ // render() uses pixmaps internally, and pixmaps might have bit depths
+ // other than 32, giving different pixel values due to rounding.
+ QPixmap pix = QPixmap::fromImage(resource);
+ painter0.drawPixmap(0, 0, pix);
painter0.end();
QImage image1(resource.width(), resource.height(), QImage::Format_ARGB32);
diff --git a/WebKit/qt/tests/qwebframe/qwebframe.pro b/WebKit/qt/tests/qwebframe/qwebframe.pro
index 0e540e5..b8734cd 100644
--- a/WebKit/qt/tests/qwebframe/qwebframe.pro
+++ b/WebKit/qt/tests/qwebframe/qwebframe.pro
@@ -5,7 +5,7 @@ SOURCES += tst_qwebframe.cpp
RESOURCES += qwebframe.qrc
QT += testlib network
QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
-DEFINES += SRCDIR=\\\"$$PWD/resources\\\"
+!symbian:DEFINES += SRCDIR=\\\"$$PWD/resources\\\"
symbian {
TARGET.UID3 = 0xA000E53D
diff --git a/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp b/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
index 7cc62b0..7c13fd0 100644
--- a/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
+++ b/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
@@ -38,35 +38,9 @@
#endif
#include "../util.h"
-//TESTED_CLASS=
-//TESTED_FILES=
-
-// Task 160192
-/**
- * Starts an event loop that runs until the given signal is received.
- Optionally the event loop
- * can return earlier on a timeout.
- *
- * \return \p true if the requested signal was received
- * \p false on timeout
- */
-static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0)
-{
- QEventLoop loop;
- QObject::connect(obj, signal, &loop, SLOT(quit()));
- QTimer timer;
- QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
- if (timeout > 0) {
- QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
- timer.setSingleShot(true);
- timer.start(timeout);
- }
- loop.exec();
- return timeoutSpy.isEmpty();
-}
-
-/* Mostly a test for the JavaScript related parts of QWebFrame */
-
+#if defined(Q_OS_SYMBIAN)
+# define SRCDIR ""
+#endif
struct CustomType {
QString string;
@@ -600,6 +574,7 @@ private slots:
void render();
void scrollPosition();
void evaluateWillCauseRepaint();
+ void qObjectWrapperWithSameIdentity();
private:
QString evalJS(const QString&s) {
@@ -2238,7 +2213,7 @@ protected:
virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest& request, QIODevice* outgoingData)
{
QString url = request.url().toString();
- if (op == QNetworkAccessManager::GetOperation)
+ if (op == QNetworkAccessManager::GetOperation) {
if (url == "qrc:/test1.html" || url == "http://abcdef.abcdef/")
return new FakeReply(request, this);
#ifndef QT_NO_OPENSSL
@@ -2249,6 +2224,7 @@ protected:
return reply;
}
#endif
+ }
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
@@ -2265,19 +2241,19 @@ void tst_QWebFrame::requestedUrl()
page.setNetworkAccessManager(networkManager);
frame->setUrl(QUrl("qrc:/test1.html"));
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(spy.count(), 1);
QCOMPARE(frame->requestedUrl(), QUrl("qrc:/test1.html"));
QCOMPARE(frame->url(), QUrl("qrc:/test2.html"));
frame->setUrl(QUrl("qrc:/non-existent.html"));
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(spy.count(), 2);
QCOMPARE(frame->requestedUrl(), QUrl("qrc:/non-existent.html"));
QCOMPARE(frame->url(), QUrl("qrc:/non-existent.html"));
frame->setUrl(QUrl("http://abcdef.abcdef"));
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(spy.count(), 3);
QCOMPARE(frame->requestedUrl(), QUrl("http://abcdef.abcdef/"));
QCOMPARE(frame->url(), QUrl("http://abcdef.abcdef/"));
@@ -2286,9 +2262,9 @@ void tst_QWebFrame::requestedUrl()
qRegisterMetaType<QList<QSslError> >("QList<QSslError>");
qRegisterMetaType<QNetworkReply* >("QNetworkReply*");
- QSignalSpy spy2(page.networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)));
+ QSignalSpy spy2(page.networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)));
frame->setUrl(QUrl("qrc:/fake-ssl-error.html"));
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(spy2.count(), 1);
QCOMPARE(frame->requestedUrl(), QUrl("qrc:/fake-ssl-error.html"));
QCOMPARE(frame->url(), QUrl("qrc:/fake-ssl-error.html"));
@@ -2346,7 +2322,7 @@ void tst_QWebFrame::setHtmlWithResource()
// in few seconds, the image should be completey loaded
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
frame->setHtml(html);
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(spy.count(), 1);
QCOMPARE(frame->evaluateJavaScript("document.images.length").toInt(), 1);
@@ -2365,7 +2341,7 @@ void tst_QWebFrame::setHtmlWithResource()
// in few seconds, the CSS should be completey loaded
frame->setHtml(html2);
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(spy.size(), 2);
QWebElement p = frame->documentElement().findAll("p").at(0);
@@ -2383,7 +2359,7 @@ void tst_QWebFrame::setHtmlWithBaseURL()
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
frame->setHtml(html, QUrl::fromLocalFile(QDir::currentPath()));
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(spy.count(), 1);
QCOMPARE(frame->evaluateJavaScript("document.images.length").toInt(), 1);
@@ -2494,15 +2470,15 @@ void tst_QWebFrame::popupFocus()
combo->hidePopup();
QTRY_VERIFY(view.hasFocus() && !combo->view()->hasFocus()); // Focus should be back on the WebView
- // triple the flashing time, should at least blink twice already
- int delay = qApp->cursorFlashTime() * 3;
+ // double the flashing time, should at least blink once already
+ int delay = qApp->cursorFlashTime() * 2;
// focus the lineedit and check if it blinks
QTest::mouseClick(&view, Qt::LeftButton, 0, QPoint(200, 25));
m_popupTestView = &view;
view.installEventFilter( this );
QTest::qWait(delay);
- QVERIFY2(m_popupTestPaintCount >= 4,
+ QVERIFY2(m_popupTestPaintCount >= 3,
"The input field should have a blinking caret");
}
@@ -2646,7 +2622,7 @@ void tst_QWebFrame::hasSetFocus()
QSignalSpy loadSpy(m_page, SIGNAL(loadFinished(bool)));
m_page->mainFrame()->setHtml(html);
- QTest::qWait(200);
+ waitForSignal(m_page->mainFrame(), SIGNAL(loadFinished(bool)), 200);
QCOMPARE(loadSpy.size(), 1);
QList<QWebFrame*> children = m_page->mainFrame()->childFrames();
@@ -2656,7 +2632,7 @@ void tst_QWebFrame::hasSetFocus()
"</body></html>");
frame->setHtml(innerHtml);
- QTest::qWait(200);
+ waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
QCOMPARE(loadSpy.size(), 2);
m_page->mainFrame()->setFocus();
@@ -2743,16 +2719,51 @@ void tst_QWebFrame::evaluateWillCauseRepaint()
view.setHtml(html);
view.show();
- QTest::qWait(200);
+ QTest::qWaitForWindowShown(&view);
view.page()->mainFrame()->evaluateJavaScript(
"document.getElementById('junk').style.display = 'none';");
- ::waitForSignal(view.page(), SIGNAL(repaintRequested( const QRect &)));
-
- QTest::qWait(2000);
+ ::waitForSignal(view.page(), SIGNAL(repaintRequested(QRect)));
}
+class TestFactory : public QObject
+{
+ Q_OBJECT
+public:
+ TestFactory()
+ : obj(0), counter(0)
+ {}
+
+ Q_INVOKABLE QObject* getNewObject()
+ {
+ delete obj;
+ obj = new QObject(this);
+ obj->setObjectName(QLatin1String("test") + QString::number(++counter));
+ return obj;
+
+ }
+
+ QObject* obj;
+ int counter;
+};
+
+void tst_QWebFrame::qObjectWrapperWithSameIdentity()
+{
+ m_view->setHtml("<script>function triggerBug() { document.getElementById('span1').innerText = test.getNewObject().objectName; }</script>"
+ "<body><span id='span1'>test</span></body>");
+
+ QWebFrame* mainFrame = m_view->page()->mainFrame();
+ QCOMPARE(mainFrame->toPlainText(), QString("test"));
+
+ mainFrame->addToJavaScriptWindowObject("test", new TestFactory, QScriptEngine::ScriptOwnership);
+
+ mainFrame->evaluateJavaScript("triggerBug();");
+ QCOMPARE(mainFrame->toPlainText(), QString("test1"));
+
+ mainFrame->evaluateJavaScript("triggerBug();");
+ QCOMPARE(mainFrame->toPlainText(), QString("test2"));
+}
QTEST_MAIN(tst_QWebFrame)
#include "tst_qwebframe.moc"
diff --git a/WebKit/qt/tests/qwebinspector/qwebinspector.pro b/WebKit/qt/tests/qwebinspector/qwebinspector.pro
new file mode 100644
index 0000000..520887e
--- /dev/null
+++ b/WebKit/qt/tests/qwebinspector/qwebinspector.pro
@@ -0,0 +1,6 @@
+TEMPLATE = app
+TARGET = tst_qwebinspector
+include(../../../../WebKit.pri)
+SOURCES += tst_qwebinspector.cpp
+QT += testlib network
+QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
diff --git a/WebKit/qt/tests/qwebinspector/tst_qwebinspector.cpp b/WebKit/qt/tests/qwebinspector/tst_qwebinspector.cpp
new file mode 100644
index 0000000..12cd630
--- /dev/null
+++ b/WebKit/qt/tests/qwebinspector/tst_qwebinspector.cpp
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <QtTest/QtTest>
+
+#include <qdir.h>
+#include <qwebinspector.h>
+#include <qwebpage.h>
+#include <qwebsettings.h>
+
+class tst_QWebInspector : public QObject {
+ Q_OBJECT
+
+private slots:
+ void attachAndDestroy();
+};
+
+void tst_QWebInspector::attachAndDestroy()
+{
+ { // External inspector + manual destruction of page first
+ QWebPage* page = new QWebPage();
+ page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+ QWebInspector* inspector = new QWebInspector();
+ inspector->setPage(page);
+ page->updatePositionDependentActions(QPoint(0, 0));
+ page->triggerAction(QWebPage::InspectElement);
+
+ delete page;
+ delete inspector;
+ }
+ { // External inspector + manual destruction of inspector first
+ QWebPage* page = new QWebPage();
+ page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+ QWebInspector* inspector = new QWebInspector();
+ inspector->setPage(page);
+ page->updatePositionDependentActions(QPoint(0, 0));
+ page->triggerAction(QWebPage::InspectElement);
+
+ delete inspector;
+ delete page;
+ }
+ { // Internal inspector
+ QWebPage page;
+ page.settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+ page.updatePositionDependentActions(QPoint(0, 0));
+ page.triggerAction(QWebPage::InspectElement);
+ }
+}
+
+QTEST_MAIN(tst_QWebInspector)
+
+#include "tst_qwebinspector.moc"
diff --git a/WebKit/qt/tests/qwebpage/qwebpage.pro b/WebKit/qt/tests/qwebpage/qwebpage.pro
index 6b28efd..7853b28 100644
--- a/WebKit/qt/tests/qwebpage/qwebpage.pro
+++ b/WebKit/qt/tests/qwebpage/qwebpage.pro
@@ -5,7 +5,7 @@ SOURCES += tst_qwebpage.cpp
RESOURCES += tst_qwebpage.qrc
QT += testlib network
QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
-DEFINES += SRCDIR=\\\"$$PWD/\\\"
+!symbian:DEFINES += SRCDIR=\\\"$$PWD/\\\"
symbian {
TARGET.UID3 = 0xA000E53E
diff --git a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
index 0cf85ee..2a52631 100644
--- a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
+++ b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
@@ -21,6 +21,9 @@
#include <QtTest/QtTest>
+#include <qgraphicsscene.h>
+#include <qgraphicsview.h>
+#include <qgraphicswebview.h>
#include <qwebelement.h>
#include <qwebpage.h>
#include <qwidget.h>
@@ -37,6 +40,10 @@
#include <QPushButton>
#include <QDir>
+#if defined(Q_OS_SYMBIAN)
+# define SRCDIR ""
+#endif
+
// Will try to wait for the condition while allowing event processing
#define QTRY_COMPARE(__expr, __expected) \
do { \
@@ -78,6 +85,22 @@ static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000)
return timeoutSpy.isEmpty();
}
+class EventSpy : public QObject, public QList<QEvent::Type>
+{
+ Q_OBJECT
+public:
+ EventSpy(QObject* objectToSpy)
+ {
+ objectToSpy->installEventFilter(this);
+ }
+
+ virtual bool eventFilter(QObject* receiver, QEvent* event)
+ {
+ append(event->type());
+ return false;
+ }
+};
+
class tst_QWebPage : public QObject
{
Q_OBJECT
@@ -120,15 +143,20 @@ private slots:
void testOptionalJSObjects();
void testEnablePersistentStorage();
void consoleOutput();
+ void inputMethods_data();
void inputMethods();
void defaultTextEncoding();
void errorPageExtension();
+ void errorPageExtensionInIFrames();
+ void errorPageExtensionInFrameset();
void crashTests_LazyInitializationOfMainFrame();
void screenshot_data();
void screenshot();
+ void originatingObjectInNetworkRequests();
+
private:
QWebView* m_view;
QWebPage* m_page;
@@ -234,7 +262,6 @@ void tst_QWebPage::loadFinished()
{
qRegisterMetaType<QWebFrame*>("QWebFrame*");
qRegisterMetaType<QNetworkRequest*>("QNetworkRequest*");
- QSignalSpy spyNetworkRequestStarted(m_page, SIGNAL(networkRequestStarted(QWebFrame*, QNetworkRequest*)));
QSignalSpy spyLoadStarted(m_view, SIGNAL(loadStarted()));
QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
@@ -245,7 +272,6 @@ void tst_QWebPage::loadFinished()
QTest::qWait(3000);
- QVERIFY(spyNetworkRequestStarted.count() > 1);
QVERIFY(spyLoadStarted.count() > 1);
QVERIFY(spyLoadFinished.count() > 1);
@@ -346,9 +372,11 @@ public:
TestNetworkManager(QObject* parent) : QNetworkAccessManager(parent) {}
QList<QUrl> requestedUrls;
+ QList<QNetworkRequest> requests;
protected:
virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest &request, QIODevice* outgoingData) {
+ requests.append(request);
requestedUrls.append(request.url());
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
@@ -422,7 +450,7 @@ void tst_QWebPage::modified()
m_page->mainFrame()->setUrl(QUrl("data:text/html,<body>This is fourth page"));
QVERIFY(m_page->history()->count() == 2);
m_page->mainFrame()->setUrl(QUrl("data:text/html,<body>This is fifth page"));
- QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*, QWebHistoryItem*))));
+ QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*))));
}
void tst_QWebPage::contextMenuCrash()
@@ -450,7 +478,6 @@ void tst_QWebPage::database()
QVERIFY(QWebSettings::offlineStorageDefaultQuota() == 1024 * 1024);
m_page->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
- m_page->settings()->setAttribute(QWebSettings::SessionStorageEnabled, true);
m_page->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
QString dbFileName = path + "Databases.db";
@@ -459,7 +486,7 @@ void tst_QWebPage::database()
QFile::remove(dbFileName);
qRegisterMetaType<QWebFrame*>("QWebFrame*");
- QSignalSpy spy(m_page, SIGNAL(databaseQuotaExceeded(QWebFrame *, QString)));
+ QSignalSpy spy(m_page, SIGNAL(databaseQuotaExceeded(QWebFrame*,QString)));
m_view->setHtml(QString("<html><head><script>var db; db=openDatabase('testdb', '1.0', 'test database API', 50000); </script></head><body><div></div></body></html>"), QUrl("http://www.myexample.com"));
QTRY_COMPARE(spy.count(), 1);
m_page->mainFrame()->evaluateJavaScript("var db2; db2=openDatabase('testdb', '1.0', 'test database API', 50000);");
@@ -637,20 +664,41 @@ class PluginCounterPage : public QWebPage {
public:
int m_count;
QPointer<QObject> m_widget;
- PluginCounterPage(QObject* parent = 0) : QWebPage(parent), m_count(0), m_widget(0)
+ QObject* m_pluginParent;
+ PluginCounterPage(QObject* parent = 0)
+ : QWebPage(parent)
+ , m_count(0)
+ , m_widget(0)
+ , m_pluginParent(0)
{
settings()->setAttribute(QWebSettings::PluginsEnabled, true);
}
+ ~PluginCounterPage()
+ {
+ if (m_pluginParent)
+ m_pluginParent->deleteLater();
+ }
};
template<class T>
class PluginTracerPage : public PluginCounterPage {
public:
- PluginTracerPage(QObject* parent = 0) : PluginCounterPage(parent) {}
+ PluginTracerPage(QObject* parent = 0)
+ : PluginCounterPage(parent)
+ {
+ // this is a dummy parent object for the created plugin
+ m_pluginParent = new T;
+ }
virtual QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&)
{
m_count++;
- return m_widget = new T();
+ m_widget = new T;
+ // need a cast to the specific type, as QObject::setParent cannot be called,
+ // because it is not virtual. Instead it is necesary to call QWidget::setParent,
+ // which also takes a QWidget* instead of a QObject*. Therefore we need to
+ // upcast to T*, which is a QWidget.
+ static_cast<T*>(m_widget.data())->setParent(static_cast<T*>(m_pluginParent));
+ return m_widget;
}
};
@@ -716,6 +764,8 @@ void tst_QWebPage::createViewlessPlugin()
page->mainFrame()->setHtml(content);
QCOMPARE(page->m_count, 1);
QVERIFY(page->m_widget);
+ QVERIFY(page->m_pluginParent);
+ QVERIFY(page->m_widget->parent() == page->m_pluginParent);
delete page;
}
@@ -1262,28 +1312,101 @@ void tst_QWebPage::frameAt()
frameAtHelper(webPage, webPage->mainFrame(), webPage->mainFrame()->pos());
}
+void tst_QWebPage::inputMethods_data()
+{
+ QTest::addColumn<QString>("viewType");
+ QTest::newRow("QWebView") << "QWebView";
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+ QTest::newRow("QGraphicsWebView") << "QGraphicsWebView";
+#endif
+}
+
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+static Qt::InputMethodHints inputMethodHints(QObject* object)
+{
+ if (QGraphicsObject* o = qobject_cast<QGraphicsObject*>(object))
+ return o->inputMethodHints();
+ if (QWidget* w = qobject_cast<QWidget*>(object))
+ return w->inputMethodHints();
+ return Qt::InputMethodHints();
+}
+#endif
+
+static bool inputMethodEnabled(QObject* object)
+{
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+ if (QGraphicsObject* o = qobject_cast<QGraphicsObject*>(object))
+ return o->flags() & QGraphicsItem::ItemAcceptsInputMethod;
+#endif
+ if (QWidget* w = qobject_cast<QWidget*>(object))
+ return w->testAttribute(Qt::WA_InputMethodEnabled);
+ return false;
+}
+
void tst_QWebPage::inputMethods()
{
- m_view->page()->mainFrame()->setHtml("<html><body>" \
+ QFETCH(QString, viewType);
+ QWebPage* page = new QWebPage;
+ QObject* view = 0;
+ QObject* container = 0;
+ if (viewType == "QWebView") {
+ QWebView* wv = new QWebView;
+ wv->setPage(page);
+ view = wv;
+ container = view;
+ }
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+ else if (viewType == "QGraphicsWebView") {
+ QGraphicsWebView* wv = new QGraphicsWebView;
+ wv->setPage(page);
+ view = wv;
+
+ QGraphicsView* gv = new QGraphicsView;
+ QGraphicsScene* scene = new QGraphicsScene(gv);
+ gv->setScene(scene);
+ scene->addItem(wv);
+ wv->setGeometry(QRect(0, 0, 500, 500));
+
+ container = gv;
+ }
+#endif
+ else
+ QVERIFY2(false, "Unknown view type");
+
+ page->mainFrame()->setHtml("<html><body>" \
"<input type='text' id='input1' style='font-family: serif' value='' maxlength='20'/><br>" \
"<input type='password'/>" \
"</body></html>");
- m_view->page()->mainFrame()->setFocus();
+ page->mainFrame()->setFocus();
+
+ EventSpy viewEventSpy(container);
- QWebElementCollection inputs = m_view->page()->mainFrame()->documentElement().findAll("input");
+ QWebElementCollection inputs = page->mainFrame()->documentElement().findAll("input");
QMouseEvent evpres(QEvent::MouseButtonPress, inputs.at(0).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
- m_view->page()->event(&evpres);
+ page->event(&evpres);
QMouseEvent evrel(QEvent::MouseButtonRelease, inputs.at(0).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
- m_view->page()->event(&evrel);
+ page->event(&evrel);
+
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+ QVERIFY(!viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
+#endif
+ viewEventSpy.clear();
+
+ page->event(&evpres);
+ page->event(&evrel);
+
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+ QVERIFY(viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
+#endif
//ImMicroFocus
- QVariant variant = m_view->page()->inputMethodQuery(Qt::ImMicroFocus);
+ QVariant variant = page->inputMethodQuery(Qt::ImMicroFocus);
QRect focusRect = variant.toRect();
QVERIFY(inputs.at(0).geometry().contains(variant.toRect().topLeft()));
//ImFont
- variant = m_view->page()->inputMethodQuery(Qt::ImFont);
+ variant = page->inputMethodQuery(Qt::ImFont);
QFont font = variant.value<QFont>();
QCOMPARE(QString("-webkit-serif"), font.family());
@@ -1292,45 +1415,45 @@ void tst_QWebPage::inputMethods()
//Insert text.
{
QInputMethodEvent eventText("QtWebKit", inputAttributes);
- QSignalSpy signalSpy(m_view->page(), SIGNAL(microFocusChanged()));
- m_view->page()->event(&eventText);
+ QSignalSpy signalSpy(page, SIGNAL(microFocusChanged()));
+ page->event(&eventText);
QCOMPARE(signalSpy.count(), 0);
}
{
QInputMethodEvent eventText("", inputAttributes);
eventText.setCommitString(QString("QtWebKit"), 0, 0);
- m_view->page()->event(&eventText);
+ page->event(&eventText);
}
#if QT_VERSION >= 0x040600
//ImMaximumTextLength
- variant = m_view->page()->inputMethodQuery(Qt::ImMaximumTextLength);
+ variant = page->inputMethodQuery(Qt::ImMaximumTextLength);
QCOMPARE(20, variant.toInt());
//Set selection
inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 3, 2, QVariant());
QInputMethodEvent eventSelection("",inputAttributes);
- m_view->page()->event(&eventSelection);
+ page->event(&eventSelection);
//ImAnchorPosition
- variant = m_view->page()->inputMethodQuery(Qt::ImAnchorPosition);
+ variant = page->inputMethodQuery(Qt::ImAnchorPosition);
int anchorPosition = variant.toInt();
QCOMPARE(anchorPosition, 3);
//ImCursorPosition
- variant = m_view->page()->inputMethodQuery(Qt::ImCursorPosition);
+ variant = page->inputMethodQuery(Qt::ImCursorPosition);
int cursorPosition = variant.toInt();
QCOMPARE(cursorPosition, 5);
//ImCurrentSelection
- variant = m_view->page()->inputMethodQuery(Qt::ImCurrentSelection);
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
QString selectionValue = variant.value<QString>();
QCOMPARE(selectionValue, QString("eb"));
#endif
//ImSurroundingText
- variant = m_view->page()->inputMethodQuery(Qt::ImSurroundingText);
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
QString value = variant.value<QString>();
QCOMPARE(value, QString("QtWebKit"));
@@ -1341,29 +1464,46 @@ void tst_QWebPage::inputMethods()
QInputMethodEvent::Attribute newSelection(QInputMethodEvent::Selection, 0, 0, QVariant());
attributes.append(newSelection);
QInputMethodEvent event("composition", attributes);
- m_view->page()->event(&event);
+ page->event(&event);
}
// A ongoing composition should not change the surrounding text before it is committed.
- variant = m_view->page()->inputMethodQuery(Qt::ImSurroundingText);
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
value = variant.value<QString>();
QCOMPARE(value, QString("QtWebKit"));
#endif
//ImhHiddenText
QMouseEvent evpresPassword(QEvent::MouseButtonPress, inputs.at(1).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
- m_view->page()->event(&evpresPassword);
+ page->event(&evpresPassword);
QMouseEvent evrelPassword(QEvent::MouseButtonRelease, inputs.at(1).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
- m_view->page()->event(&evrelPassword);
+ page->event(&evrelPassword);
- QVERIFY(m_view->testAttribute(Qt::WA_InputMethodEnabled));
+ QVERIFY(inputMethodEnabled(view));
#if QT_VERSION >= 0x040600
- QVERIFY(m_view->inputMethodHints() & Qt::ImhHiddenText);
+ QVERIFY(inputMethodHints(view) & Qt::ImhHiddenText);
+
+ page->event(&evpres);
+ page->event(&evrel);
+ QVERIFY(!(inputMethodHints(view) & Qt::ImhHiddenText));
+#endif
+
+ page->mainFrame()->setHtml("<html><body><p>nothing to input here");
+ viewEventSpy.clear();
+
+ QWebElement para = page->mainFrame()->findFirstElement("p");
+ {
+ QMouseEvent evpres(QEvent::MouseButtonPress, para.geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
+ page->event(&evpres);
+ QMouseEvent evrel(QEvent::MouseButtonRelease, para.geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
+ page->event(&evrel);
+ }
- m_view->page()->event(&evpres);
- m_view->page()->event(&evrel);
- QVERIFY(!(m_view->inputMethodHints() & Qt::ImhHiddenText));
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+ QVERIFY(!viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
#endif
+
+ delete container;
}
// import a little DRT helper function to trigger the garbage collector
@@ -1394,10 +1534,17 @@ void tst_QWebPage::protectBindingsRuntimeObjectsFromCollector()
void tst_QWebPage::localURLSchemes()
{
int i = QWebSecurityOrigin::localSchemes().size();
+
QWebSecurityOrigin::removeLocalScheme("file");
QTRY_COMPARE(QWebSecurityOrigin::localSchemes().size(), i);
QWebSecurityOrigin::addLocalScheme("file");
QTRY_COMPARE(QWebSecurityOrigin::localSchemes().size(), i);
+
+ QWebSecurityOrigin::removeLocalScheme("qrc");
+ QTRY_COMPARE(QWebSecurityOrigin::localSchemes().size(), i - 1);
+ QWebSecurityOrigin::addLocalScheme("qrc");
+ QTRY_COMPARE(QWebSecurityOrigin::localSchemes().size(), i);
+
QString myscheme = "myscheme";
QWebSecurityOrigin::addLocalScheme(myscheme);
QTRY_COMPARE(QWebSecurityOrigin::localSchemes().size(), i + 1);
@@ -1438,11 +1585,6 @@ void tst_QWebPage::testOptionalJSObjects()
QCOMPARE(testFlag(webPage2, QWebSettings::LocalStorageEnabled, "localStorage", true), true);
QCOMPARE(testFlag(webPage1, QWebSettings::LocalStorageEnabled, "localStorage", false), false);
QCOMPARE(testFlag(webPage2, QWebSettings::LocalStorageEnabled, "localStorage", false), true);
-
- QCOMPARE(testFlag(webPage1, QWebSettings::SessionStorageEnabled, "sessionStorage", false), false);
- QCOMPARE(testFlag(webPage2, QWebSettings::SessionStorageEnabled, "sessionStorage", true), true);
- QCOMPARE(testFlag(webPage1, QWebSettings::SessionStorageEnabled, "sessionStorage", false), false);
- QCOMPARE(testFlag(webPage2, QWebSettings::SessionStorageEnabled, "sessionStorage", false), true);
}
void tst_QWebPage::testEnablePersistentStorage()
@@ -1508,15 +1650,10 @@ public:
virtual bool extension(Extension, const ExtensionOption* option, ExtensionReturn* output)
{
- const ErrorPageExtensionOption* info = static_cast<const ErrorPageExtensionOption*>(option);
ErrorPageExtensionReturn* errorPage = static_cast<ErrorPageExtensionReturn*>(output);
- if (info->frame == mainFrame()) {
- errorPage->content = "data:text/html,error";
- return true;
- }
-
- return false;
+ errorPage->content = "data:text/html,error";
+ return true;
}
};
@@ -1527,11 +1664,10 @@ void tst_QWebPage::errorPageExtension()
QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
- page->mainFrame()->load(QUrl("qrc:///frametest/index.html"));
+ m_view->setUrl(QUrl("data:text/html,foo"));
QTRY_COMPARE(spyLoadFinished.count(), 1);
page->mainFrame()->setUrl(QUrl("http://non.existent/url"));
- QTest::qWait(2000);
QTRY_COMPARE(spyLoadFinished.count(), 2);
QCOMPARE(page->mainFrame()->toPlainText(), QString("data:text/html,error"));
QCOMPARE(page->history()->count(), 2);
@@ -1539,6 +1675,53 @@ void tst_QWebPage::errorPageExtension()
QCOMPARE(page->history()->canGoBack(), true);
QCOMPARE(page->history()->canGoForward(), false);
+ page->triggerAction(QWebPage::Back);
+ QTest::qWait(2000);
+ QCOMPARE(page->history()->canGoBack(), false);
+ QCOMPARE(page->history()->canGoForward(), true);
+
+ page->triggerAction(QWebPage::Forward);
+ QTest::qWait(2000);
+ QCOMPARE(page->history()->canGoBack(), true);
+ QCOMPARE(page->history()->canGoForward(), false);
+
+ page->triggerAction(QWebPage::Back);
+ QTest::qWait(2000);
+ QCOMPARE(page->history()->canGoBack(), false);
+ QCOMPARE(page->history()->canGoForward(), true);
+ QCOMPARE(page->history()->currentItem().url(), QUrl("data:text/html,foo"));
+
+ m_view->setPage(0);
+}
+
+void tst_QWebPage::errorPageExtensionInIFrames()
+{
+ ErrorPage* page = new ErrorPage;
+ m_view->setPage(page);
+
+ m_view->setHtml(QString("data:text/html,"
+ "<h1>h1</h1>"
+ "<iframe src='data:text/html,<p/>p'></iframe>"
+ "<iframe src='non-existent.html'></iframe>"));
+ QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
+ QTRY_COMPARE(spyLoadFinished.count(), 1);
+
+ QCOMPARE(page->mainFrame()->childFrames()[1]->toPlainText(), QString("data:text/html,error"));
+
+ m_view->setPage(0);
+}
+
+void tst_QWebPage::errorPageExtensionInFrameset()
+{
+ ErrorPage* page = new ErrorPage;
+ m_view->setPage(page);
+
+ m_view->load(QUrl("qrc:///frametest/index.html"));
+
+ QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
+ QTRY_COMPARE(spyLoadFinished.count(), 1);
+ QCOMPARE(page->mainFrame()->childFrames()[1]->toPlainText(), QString("data:text/html,error"));
+
m_view->setPage(0);
}
@@ -1609,5 +1792,27 @@ void tst_QWebPage::screenshot()
QDir::setCurrent(QApplication::applicationDirPath());
}
+void tst_QWebPage::originatingObjectInNetworkRequests()
+{
+ TestNetworkManager* networkManager = new TestNetworkManager(m_page);
+ m_page->setNetworkAccessManager(networkManager);
+ networkManager->requests.clear();
+
+ m_view->setHtml(QString("data:text/html,<frameset cols=\"25%,75%\"><frame src=\"data:text/html,"
+ "<head><meta http-equiv='refresh' content='1'></head>foo \">"
+ "<frame src=\"data:text/html,bar\"></frameset>"), QUrl());
+ QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+
+ QCOMPARE(networkManager->requests.count(), 2);
+
+ QList<QWebFrame*> childFrames = m_page->mainFrame()->childFrames();
+ QCOMPARE(childFrames.count(), 2);
+
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+ for (int i = 0; i < 2; ++i)
+ QVERIFY(qobject_cast<QWebFrame*>(networkManager->requests.at(i).originatingObject()) == childFrames.at(i));
+#endif
+}
+
QTEST_MAIN(tst_QWebPage)
#include "tst_qwebpage.moc"
diff --git a/WebKit/qt/tests/qwebview/data/frame_a.html b/WebKit/qt/tests/qwebview/data/frame_a.html
new file mode 100644
index 0000000..9ff68f1
--- /dev/null
+++ b/WebKit/qt/tests/qwebview/data/frame_a.html
@@ -0,0 +1,2 @@
+<a href="http://google.com" target="frame_b"><img src="" width=100 height=100 alt="Google"></a>
+<a href="http://yahoo.com" target="frame_b"><img src="" width=100 height=100 alt="Yahoo"></a>
diff --git a/WebKit/qt/tests/qwebview/data/index.html b/WebKit/qt/tests/qwebview/data/index.html
new file mode 100644
index 0000000..c53ad09
--- /dev/null
+++ b/WebKit/qt/tests/qwebview/data/index.html
@@ -0,0 +1,4 @@
+<frameset cols="25%,75%">
+ <frame src="frame_a.html" name="frame_a">
+ <frame src="frame_b.html" name="frame_b">
+</frameset>
diff --git a/WebKit/qt/tests/qwebview/qwebview.pro b/WebKit/qt/tests/qwebview/qwebview.pro
index e67bb7a..735537b 100644
--- a/WebKit/qt/tests/qwebview/qwebview.pro
+++ b/WebKit/qt/tests/qwebview/qwebview.pro
@@ -4,6 +4,7 @@ include(../../../../WebKit.pri)
SOURCES += tst_qwebview.cpp
QT += testlib network
QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
+RESOURCES += tst_qwebview.qrc
DEFINES += SRCDIR=\\\"$$PWD/\\\"
symbian {
diff --git a/WebKit/qt/tests/qwebview/tst_qwebview.cpp b/WebKit/qt/tests/qwebview/tst_qwebview.cpp
index 9204223..bd2f185 100644
--- a/WebKit/qt/tests/qwebview/tst_qwebview.cpp
+++ b/WebKit/qt/tests/qwebview/tst_qwebview.cpp
@@ -20,6 +20,7 @@
*/
#include <qtest.h>
+#include "../util.h"
#include <qpainter.h>
#include <qwebview.h>
@@ -41,12 +42,12 @@ public slots:
private slots:
void renderHints();
- void guessUrlFromString_data();
- void guessUrlFromString();
void getWebKitVersion();
void reusePage_data();
void reusePage();
+
+ void crashTests();
};
// This will be called before the first test function is executed.
@@ -105,68 +106,6 @@ void tst_QWebView::renderHints()
QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
}
-void tst_QWebView::guessUrlFromString_data()
-{
- QTest::addColumn<QString>("string");
- QTest::addColumn<QUrl>("guessUrlFromString");
-
- // Null
- QTest::newRow("null") << QString() << QUrl();
-
- // File
- QDirIterator it(QDir::homePath());
- QString fileString;
- int c = 0;
- while (it.hasNext()) {
- it.next();
- QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath());
- }
-
- // basic latin1
- QTest::newRow("unicode-0") << QString::fromUtf8("å.com/") << QUrl::fromEncoded(QString::fromUtf8("http://å.com/").toUtf8(), QUrl::TolerantMode);
- // unicode
- QTest::newRow("unicode-1") << QString::fromUtf8("λ.com/") << QUrl::fromEncoded(QString::fromUtf8("http://λ.com/").toUtf8(), QUrl::TolerantMode);
-
- // no scheme
- QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org");
- QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org");
- QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org");
- QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit");
-
- // QUrl's tolerant parser should already handle this
- QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html");
-
- // Make sure the :80, i.e. port doesn't screw anything up
- QUrl portUrl("http://webkit.org");
- portUrl.setPort(80);
- QTest::newRow("port-0") << "webkit.org:80" << portUrl;
- QTest::newRow("port-1") << "http://webkit.org:80" << portUrl;
-
- // mailto doesn't have a ://, but is valid
- QUrl mailto("ben@meyerhome.net");
- mailto.setScheme("mailto");
- QTest::newRow("mailto") << "mailto:ben@meyerhome.net" << mailto;
-
- // misc
- QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost");
- QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80");
- QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html");
-
- // FYI: The scheme in the resulting url user
- QUrl authUrl("user:pass@domain.com");
- QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl;
-}
-
-// public static QUrl guessUrlFromString(QString const& string)
-void tst_QWebView::guessUrlFromString()
-{
- QFETCH(QString, string);
- QFETCH(QUrl, guessUrlFromString);
-
- QUrl url = QWebView::guessUrlFromString(string);
- QCOMPARE(url, guessUrlFromString);
-}
-
void tst_QWebView::getWebKitVersion()
{
QVERIFY(qWebKitVersion().toDouble() > 0);
@@ -193,18 +132,18 @@ void tst_QWebView::reusePage()
mainFrame->setHtml(html, QUrl::fromLocalFile(QDir::currentPath()));
if (html.contains("</embed>")) {
// some reasonable time for the PluginStream to feed test.swf to flash and start painting
- QTest::qWait(2000);
+ waitForSignal(view1, SIGNAL(loadFinished(bool)), 2000);
}
view1->show();
- QTest::qWait(2000);
+ QTest::qWaitForWindowShown(view1);
delete view1;
QVERIFY(page != 0); // deleting view must not have deleted the page, since it's not a child of view
QWebView *view2 = new QWebView;
view2->setPage(page);
view2->show(); // in Windowless mode, you should still be able to see the plugin here
- QTest::qWait(2000);
+ QTest::qWaitForWindowShown(view2);
delete view2;
delete page; // must not crash
@@ -212,6 +151,46 @@ void tst_QWebView::reusePage()
QDir::setCurrent(QApplication::applicationDirPath());
}
+// Class used in crashTests
+class WebViewCrashTest : public QObject {
+ Q_OBJECT
+ QWebView* m_view;
+public:
+ bool m_executed;
+
+
+ WebViewCrashTest(QWebView* view)
+ : m_view(view)
+ , m_executed(false)
+ {
+ view->connect(view, SIGNAL(loadProgress(int)), this, SLOT(loading(int)));
+ }
+
+private slots:
+ void loading(int progress)
+ {
+ if (progress >= 20 && progress < 90) {
+ QVERIFY(!m_executed);
+ m_view->stop();
+ m_executed = true;
+ }
+ }
+};
+
+
+// Should not crash.
+void tst_QWebView::crashTests()
+{
+ // Test if loading can be stopped in loadProgress handler without crash.
+ // Test page should have frames.
+ QWebView view;
+ WebViewCrashTest tester(&view);
+ QUrl url("qrc:///data/index.html");
+ view.load(url);
+ QTRY_VERIFY(tester.m_executed); // If fail it means that the test wasn't executed.
+}
+
+
QTEST_MAIN(tst_QWebView)
#include "tst_qwebview.moc"
diff --git a/WebKit/qt/tests/qwebview/tst_qwebview.qrc b/WebKit/qt/tests/qwebview/tst_qwebview.qrc
new file mode 100644
index 0000000..ede34a9
--- /dev/null
+++ b/WebKit/qt/tests/qwebview/tst_qwebview.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>data/index.html</file>
+ <file>data/frame_a.html</file>
+</qresource>
+</RCC>
+
diff --git a/WebKit/qt/tests/tests.pro b/WebKit/qt/tests/tests.pro
index 81cc8f3..b967ca9 100644
--- a/WebKit/qt/tests/tests.pro
+++ b/WebKit/qt/tests/tests.pro
@@ -1,4 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS = qwebframe qwebpage qwebelement qgraphicswebview qwebhistoryinterface qwebplugindatabase qwebview qwebhistory
+SUBDIRS = qwebframe qwebpage qwebelement qgraphicswebview qwebhistoryinterface qwebview qwebhistory qwebinspector
greaterThan(QT_MINOR_VERSION, 4): SUBDIRS += benchmarks/painting/tst_painting.pro benchmarks/loading/tst_loading.pro
diff --git a/WebKit/qt/tests/util.h b/WebKit/qt/tests/util.h
index 7f7e613..15af262 100644
--- a/WebKit/qt/tests/util.h
+++ b/WebKit/qt/tests/util.h
@@ -18,6 +18,33 @@
*/
// Functions and macros that really need to be in QTestLib
+#include <QEventLoop>
+#include <QSignalSpy>
+#include <QTimer>
+
+/**
+ * Starts an event loop that runs until the given signal is received.
+ * Optionally the event loop
+ * can return earlier on a timeout.
+ *
+ * \return \p true if the requested signal was received
+ * \p false on timeout
+ */
+static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000)
+{
+ QEventLoop loop;
+ QObject::connect(obj, signal, &loop, SLOT(quit()));
+ QTimer timer;
+ QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
+ if (timeout > 0) {
+ QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ timer.setSingleShot(true);
+ timer.start(timeout);
+ }
+ loop.exec();
+ return timeoutSpy.isEmpty();
+}
+
// Will try to wait for the condition while allowing event processing
#define QTRY_VERIFY(__expr) \
do { \
@@ -45,4 +72,3 @@
} \
QCOMPARE(__expr, __expected); \
} while(0)
-