diff options
Diffstat (limited to 'src/3rdparty/webkit/WebKit/qt')
21 files changed, 740 insertions, 25 deletions
diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp index 07d027d..7cdc00e 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.cpp @@ -28,6 +28,7 @@ #include "PageGroup.h" #include <QSharedData> +#include <QDebug> /*! \class QWebHistoryItem @@ -213,6 +214,8 @@ bool QWebHistoryItem::isValid() const number of items is given by count(), and the history can be cleared with the clear() function. + QWebHistory's state can be saved with saveState() and loaded with restoreState(). + \sa QWebHistoryItem, QWebHistoryInterface, QWebPage */ @@ -405,9 +408,13 @@ int QWebHistory::currentItemIndex() const */ QWebHistoryItem QWebHistory::itemAt(int i) const { - WebCore::HistoryItem *item = d->lst->itemAtIndex(i); - - QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(item); + QWebHistoryItemPrivate *priv; + if (i < 0 || i >= count()) + priv = new QWebHistoryItemPrivate(0); + else { + WebCore::HistoryItem *item = d->lst->entries()[i].get(); + priv = new QWebHistoryItemPrivate(item); + } return QWebHistoryItem(priv); } @@ -441,3 +448,129 @@ void QWebHistory::setMaximumItemCount(int count) d->lst->setCapacity(count); } +/*! + \enum QWebHistory::HistoryStateVersion + + This enum describes the versions available for QWebHistory's saveState() function: + + \value HistoryVersion_1 Version 1 (Qt 4.6) + \value DefaultHistoryVersion The current default version in 1. +*/ + +/*! + \since 4.6 + + Restores the state of QWebHistory from the given \a buffer. Returns true + if the history was successfully restored; otherwise returns false. + + \sa saveState() +*/ +bool QWebHistory::restoreState(const QByteArray& buffer) +{ + QDataStream stream(buffer); + int version; + bool result = false; + stream >> version; + + switch (version) { + case HistoryVersion_1: { + int count; + int currentIndex; + stream >> count >> currentIndex; + + clear(); + // only if there are elements + if (count) { + // after clear() is new clear HistoryItem (at the end we had to remove it) + WebCore::HistoryItem *nullItem = d->lst->currentItem(); + for (int i = 0;i < count;i++) { + WTF::PassRefPtr<WebCore::HistoryItem> item = WebCore::HistoryItem::create(); + item->restoreState(stream, version); + d->lst->addItem(item); + } + d->lst->removeItem(nullItem); + goToItem(itemAt(currentIndex)); + result = stream.status() == QDataStream::Ok; + } + break; + } + default: {} // result is false; + } + + return result; +}; + +/*! + \since 4.6 + Saves the state of this QWebHistory into a QByteArray. + + Saves the current state of this QWebHistory. The version number, \a version, is + stored as part of the data. + + To restore the saved state, pass the return value to restoreState(). + + \sa restoreState() +*/ +QByteArray QWebHistory::saveState(HistoryStateVersion version) const +{ + QByteArray buffer; + QDataStream stream(&buffer, QIODevice::WriteOnly); + stream << version; + + switch (version) { + case HistoryVersion_1: { + stream << count() << currentItemIndex(); + + const WebCore::HistoryItemVector &items = d->lst->entries(); + for (int i = 0; i < items.size(); i++) + items[i].get()->saveState(stream, version); + + if (stream.status() != QDataStream::Ok) + buffer = QByteArray(); // make buffer isNull()==true and isEmpty()==true + break; + } + default: + buffer.clear(); + + } + + return buffer; +} + +/*! + \since 4.6 + \fn QDataStream& operator<<(QDataStream& stream, const QWebHistory& history) + \relates QWebHistory + + Saves the given \a history into the specified \a stream. This is a convenience function + and is equivalent to calling the saveState() method. + + \sa QWebHistory::saveState() +*/ + +QDataStream& operator<<(QDataStream& stream, const QWebHistory& history) +{ + return stream << history.saveState(); +} + +/*! + \fn QDataStream& operator>>(QDataStream& stream, QWebHistory& history) + \relates QWebHistory + \since 4.6 + + Loads a QWebHistory from the specified \a stream into the given \a history. + This is a convenience function and it is equivalent to calling the restoreState() + method. + + \sa QWebHistory::restoreState() +*/ + +QDataStream& operator>>(QDataStream& stream, QWebHistory& history) +{ + QByteArray buffer; + stream >> buffer; + history.restoreState(buffer); + return stream; +} + + diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h index c39077d..1a048f4 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory.h @@ -42,6 +42,9 @@ public: QWebHistoryItem &operator=(const QWebHistoryItem &other); ~QWebHistoryItem(); + //bool restoreState(QByteArray& buffer); + //QByteArray saveState(QWebHistory::HistoryStateVersion version = DefaultHistoryVersion) const; + QUrl originalUrl() const; QUrl url() const; @@ -60,13 +63,29 @@ private: friend class QWebHistory; friend class QWebPage; friend class WebCore::FrameLoaderClientQt; + friend class QWebHistoryItemPrivate; + //friend QDataStream & operator<<(QDataStream& out,const QWebHistoryItem& hist); + //friend QDataStream & operator>>(QDataStream& in,QWebHistoryItem& hist); QExplicitlySharedDataPointer<QWebHistoryItemPrivate> d; }; +//QWEBKIT_EXPORT QDataStream & operator<<(QDataStream& out,const QWebHistoryItem& hist); +//QWEBKIT_EXPORT QDataStream & operator>>(QDataStream& in,QWebHistoryItem& hist); + + class QWebHistoryPrivate; class QWEBKIT_EXPORT QWebHistory { public: + enum HistoryStateVersion { + HistoryVersion_1, + /*, HistoryVersion_2, */ + DefaultHistoryVersion = HistoryVersion_1 + }; + + bool restoreState(const QByteArray& buffer); + QByteArray saveState(HistoryStateVersion version = DefaultHistoryVersion) const; + void clear(); QList<QWebHistoryItem> items() const; @@ -98,10 +117,15 @@ private: friend class QWebPage; friend class QWebPagePrivate; + friend QWEBKIT_EXPORT QDataStream& operator>>(QDataStream&, QWebHistory&); + friend QWEBKIT_EXPORT QDataStream& operator<<(QDataStream&, const QWebHistory&); Q_DISABLE_COPY(QWebHistory) QWebHistoryPrivate *d; }; +QWEBKIT_EXPORT QDataStream& operator<<(QDataStream& stream, const QWebHistory& history); +QWEBKIT_EXPORT QDataStream& operator>>(QDataStream& stream, QWebHistory& history); + #endif diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory_p.h b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory_p.h index 32e69fe..4bee62b 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory_p.h +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebhistory_p.h @@ -22,10 +22,16 @@ #include "BackForwardList.h" #include "HistoryItem.h" +#include <QtCore/qglobal.h> +#include <QtCore/qshareddata.h> -class QWebHistoryItemPrivate : public QSharedData +class Q_AUTOTEST_EXPORT QWebHistoryItemPrivate : public QSharedData { public: + static QExplicitlySharedDataPointer<QWebHistoryItemPrivate> get(QWebHistoryItem *q) + { + return q->d; + } QWebHistoryItemPrivate(WebCore::HistoryItem *i) { if (i) @@ -37,6 +43,25 @@ public: if (item) item->deref(); } + + /* QByteArray saveStateWithoutVersionControl(QWebHistory::HistoryStateVersion version) + { + QByteArray buffer; + switch(version){ + case QWebHistory::HistoryVersion1: + buffer=item->saveState(version); + break; + default:{} + } + return buffer; + } + + bool restoreStateWithoutVersionControl(QWebHistory::HistoryStateVersion version,QDataStream& stream) + { + + } +*/ + WebCore::HistoryItem *item; }; diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp index 3370f15..5899a1b 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp @@ -796,7 +796,7 @@ void QWebPagePrivate::keyPressEvent(QKeyEvent *ev) defaultFont = view->font(); QFontMetrics fm(defaultFont); int fontHeight = fm.height(); - if (!handleScrolling(ev)) { + if (!handleScrolling(ev, frame)) { switch (ev->key()) { case Qt::Key_Back: q->triggerAction(QWebPage::Back); @@ -999,7 +999,7 @@ void QWebPagePrivate::shortcutOverrideEvent(QKeyEvent* event) } } -bool QWebPagePrivate::handleScrolling(QKeyEvent *ev) +bool QWebPagePrivate::handleScrolling(QKeyEvent *ev, Frame *frame) { ScrollDirection direction; ScrollGranularity granularity; @@ -1046,10 +1046,7 @@ bool QWebPagePrivate::handleScrolling(QKeyEvent *ev) } } - if (!mainFrame->d->frame->eventHandler()->scrollOverflow(direction, granularity)) - mainFrame->d->frame->view()->scroll(direction, granularity); - - return true; + return frame->eventHandler()->scrollRecursively(direction, granularity); } /*! @@ -1115,6 +1112,7 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const changes the behaviour to a case sensitive find operation. \value FindWrapsAroundDocument Makes findText() restart from the beginning of the document if the end was reached and the text was not found. + \value HighlightAllOccurrences Highlights all existing occurrences of a specific string. */ /*! @@ -2197,7 +2195,7 @@ bool QWebPage::swallowContextMenuEvent(QContextMenuEvent *event) if (QWebFrame* webFrame = d->frameAt(event->pos())) { Frame* frame = QWebFramePrivate::core(webFrame); - if (Scrollbar* scrollbar = frame->view()->scrollbarUnderMouse(PlatformMouseEvent(event, 1))) { + if (Scrollbar* scrollbar = frame->view()->scrollbarUnderPoint(PlatformMouseEvent(event, 1).pos())) { return scrollbar->contextMenu(PlatformMouseEvent(event, 1)); } } @@ -2356,8 +2354,18 @@ bool QWebPage::supportsExtension(Extension extension) const } /*! - Finds the next occurrence of the string, \a subString, in the page, using the given \a options. - Returns true of \a subString was found and selects the match visually; otherwise returns false. + Finds the specified string, \a subString, in the page, using the given \a options. + + If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences + that exist in the page. All subsequent calls will extend the highlight, rather than + replace it, with occurrences of the new string. + + If the HighlightAllOccurrences flag is not passed, the function will select an occurrence + and all subsequent calls will replace the current occurrence with the next one. + + To clear the selection, just pass an empty string. + + Returns true if \a subString was found; otherwise returns false. */ bool QWebPage::findText(const QString &subString, FindFlags options) { @@ -2365,13 +2373,22 @@ bool QWebPage::findText(const QString &subString, FindFlags options) if (options & FindCaseSensitively) caseSensitivity = ::TextCaseSensitive; - ::FindDirection direction = ::FindDirectionForward; - if (options & FindBackward) - direction = ::FindDirectionBackward; + if (options & HighlightAllOccurrences) { + if (subString.isEmpty()) { + d->page->unmarkAllTextMatches(); + return true; + } else { + return d->page->markAllMatchesForText(subString, caseSensitivity, true, 0); + } + } else { + ::FindDirection direction = ::FindDirectionForward; + if (options & FindBackward) + direction = ::FindDirectionBackward; - const bool shouldWrap = options & FindWrapsAroundDocument; + const bool shouldWrap = options & FindWrapsAroundDocument; - return d->page->findString(subString, caseSensitivity, direction, shouldWrap); + return d->page->findString(subString, caseSensitivity, direction, shouldWrap); + } } /*! diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.h b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.h index 7edc060..86822d2 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.h +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.h @@ -172,7 +172,8 @@ public: enum FindFlag { FindBackward = 1, FindCaseSensitively = 2, - FindWrapsAroundDocument = 4 + FindWrapsAroundDocument = 4, + HighlightAllOccurrences = 8 }; Q_DECLARE_FLAGS(FindFlags, FindFlag) diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage_p.h b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage_p.h index a897bf1..984bec1 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage_p.h +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage_p.h @@ -45,6 +45,7 @@ namespace WebCore class Element; class Node; class Page; + class Frame; #ifndef QT_NO_CURSOR class SetCursorEvent : public QEvent { @@ -113,7 +114,7 @@ public: void shortcutOverrideEvent(QKeyEvent*); void leaveEvent(QEvent *); - bool handleScrolling(QKeyEvent*); + bool handleScrolling(QKeyEvent*, WebCore::Frame*); #ifndef QT_NO_SHORTCUT static QWebPage::WebAction editorActionForKeyEvent(QKeyEvent* event); diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp index 3c56b93..c634a7f 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp @@ -646,9 +646,18 @@ void QWebView::setRenderHint(QPainter::RenderHint hint, bool enabled) /*! - Finds the next occurrence of the string, \a subString, in the page, using - the given \a options. Returns true of \a subString was found and selects - the match visually; otherwise returns false. + Finds the specified string, \a subString, in the page, using the given \a options. + + If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences + that exist in the page. All subsequent calls will extend the highlight, rather than + replace it, with occurrences of the new string. + + If the HighlightAllOccurrences flag is not passed, the function will select an occurrence + and all subsequent calls will replace the current occurrence with the next one. + + To clear the selection, just pass an empty string. + + Returns true if \a subString was found; otherwise returns false. \sa selectedText(), selectionChanged() */ diff --git a/src/3rdparty/webkit/WebKit/qt/ChangeLog b/src/3rdparty/webkit/WebKit/qt/ChangeLog index c2ed475..dffa5e5 100644 --- a/src/3rdparty/webkit/WebKit/qt/ChangeLog +++ b/src/3rdparty/webkit/WebKit/qt/ChangeLog @@ -1,3 +1,150 @@ +2009-06-29 Simon Hausmann <simon.hausmann@nokia.com> + + Fix the Qt build, add missing isSpeaking() implementation to + ContextMenuClient. + + * WebCoreSupport/ContextMenuClientQt.cpp: + (WebCore::ContextMenuClientQt::isSpeaking): + * WebCoreSupport/ContextMenuClientQt.h: + +2009-06-28 Sriram Yadavalli <sriram.yadavalli@nokia.com> + + Reviewed by Eric Seidel. + + [Qt] Fix build break for Qt + https://bugs.webkit.org/show_bug.cgi?id=26779 + + * Api/qwebpage.cpp: + (QWebPage::swallowContextMenuEvent): + +2009-06-27 Simon Hausmann <simon.hausmann@nokia.com> + + Build fix for Qt under Windows. + + * Api/qwebhistory.h: Use consistent export linkage for the datastream operators. + +2009-06-26 Brian Weinstein <bweinstein@apple.com> + + Reviewed by Simon Fraser. + + Changed call of scrollbarUnderMouse to scrollbarUnderPoint to match new API. + + * Api/qwebpage.cpp: + (QWebPage::swallowContextMenuEvent): + +2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> + + Reviewed by Simon Hausmann. + + Add support for saving and loading of QWebHistory to and from a QByteArray. + + This includes streaming operators for QWebHistory. for convenience. + + New autotests that test QWebHistory and QWebHistoryItem serialization. + + * Api/qwebhistory.cpp: + (QWebHistory::restoreState): + (QWebHistory::saveState): + (operator<<): + (operator>>): + * Api/qwebhistory.h: + * Api/qwebhistory_p.h: + * tests/qwebhistory/tst_qwebhistory.cpp: + (tst_QWebHistory::): + (tst_QWebHistory::init): + (tst_QWebHistory::title): + (tst_QWebHistory::count): + (tst_QWebHistory::back): + (tst_QWebHistory::forward): + (tst_QWebHistory::itemAt): + (tst_QWebHistory::goToItem): + (tst_QWebHistory::items): + (tst_QWebHistory::serialize_1): + (tst_QWebHistory::serialize_2): + (tst_QWebHistory::serialize_3): + (tst_QWebHistory::saveAndRestore_1): + (tst_QWebHistory::saveAndRestore_2): + (tst_QWebHistory::saveAndRestore_3): + +2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> + + Reviewed by Simon Hausmann. + + Fix the behaviour of QWebHistory::itemAt to interpret the specified index as absolute index. + + Returns an invalid QWebHistoryItem if the index is out of range. + + * Api/qwebhistory.cpp: + (QWebHistory::itemAt): + * tests/qwebhistory/tst_qwebhistory.cpp: + (tst_QWebHistory::itemAt): + +2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> + + Reviewed by Simon Hausmann. + + Added a few autotest to QWebHistory. + + * tests/qwebhistory/data/page1.html: Added. + * tests/qwebhistory/data/page2.html: Added. + * tests/qwebhistory/data/page3.html: Added. + * tests/qwebhistory/data/page4.html: Added. + * tests/qwebhistory/data/page5.html: Added. + * tests/qwebhistory/data/page6.html: Added. + * tests/qwebhistory/qwebhistory.pro: Added. + * tests/qwebhistory/tst_qwebhistory.cpp: Added. + (tst_QWebHistory::): + (tst_QWebHistory::tst_QWebHistory): + (tst_QWebHistory::~tst_QWebHistory): + (tst_QWebHistory::init): + (tst_QWebHistory::cleanup): + (tst_QWebHistory::title): + (tst_QWebHistory::count): + (tst_QWebHistory::back): + (tst_QWebHistory::forward): + (tst_QWebHistory::goToItem): + (tst_QWebHistory::items): + * tests/qwebhistory/tst_qwebhistory.qrc: Added. + * tests/tests.pro: + +2009-06-26 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> + + Reviewed by Simon Hausmann. + + Fix support for documenting functions prefixed with QWEBKIT_EXPORT + + Add QWEBKIT_EXPORT to the list of macros to ignore by qdoc. + + * docs/qtwebkit.qdocconf: + +2009-06-26 Yongjun Zhang <yongjun.zhang@nokia.com> + + Reviewed by Eric Seidel. + + Bug 20303: [Qt] Key events are not working in frames. + + Send scrolling events to current focused frame, bubble the event + up to parent frame if it is not handled. Use EventHandler's new + shared scrolling code. + + * Api/qwebpage.cpp: + (QWebPagePrivate::keyPressEvent): + (QWebPagePrivate::handleScrolling): + * Api/qwebpage_p.h: + +2009-06-25 Jakub Wieczorek <faw217@gmail.com> + + Reviewed by Adam Treat. + + Add highlight functionality to the QWebPage::findText() method. Introduced is + new HighlightAllOccurrences flag which passed to the function will make it mark + all existing occurrences of specified string in the page. + + * Api/qwebpage.cpp: + (QWebPage::findText): + * Api/qwebpage.h: + * Api/qwebview.cpp: + 2009-06-19 Daniel Teske <qt-info@nokia.com> Reviewed by Simon Hausmann. diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp index ae9d718..ed79946 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp @@ -67,6 +67,12 @@ void ContextMenuClientQt::speak(const String&) notImplemented(); } +bool ContextMenuClientQt::isSpeaking() +{ + notImplemented(); + return false; +} + void ContextMenuClientQt::stopSpeaking() { notImplemented(); diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.h b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.h index ad6bfae..8440ff5 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.h +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ContextMenuClientQt.h @@ -44,6 +44,7 @@ namespace WebCore { virtual void downloadURL(const KURL& url); virtual void lookUpInDictionary(Frame*); virtual void speak(const String&); + virtual bool isSpeaking(); virtual void stopSpeaking(); virtual void searchWithGoogle(const Frame*); }; diff --git a/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdocconf b/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdocconf index e60e586..6343b17 100644 --- a/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdocconf +++ b/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdocconf @@ -146,7 +146,8 @@ Cpp.ignoretokens = QAXFACTORY_EXPORT \ QT_END_NAMESPACE \ QT_END_INCLUDE_NAMESPACE \ PHONON_EXPORT \ - EXTENSIONSYSTEM_EXPORT + EXTENSIONSYSTEM_EXPORT \ + QWEBKIT_EXPORT Cpp.ignoredirectives = Q_DECLARE_HANDLE \ Q_DECLARE_INTERFACE \ Q_DECLARE_METATYPE \ diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page1.html b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page1.html new file mode 100644 index 0000000..82fa4af --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page1.html @@ -0,0 +1 @@ +<title>page1</title><body><h1>page1</h1></body> diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page2.html b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page2.html new file mode 100644 index 0000000..5307bdc --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page2.html @@ -0,0 +1 @@ +<title>page2</title><body><h1>page2</h1></body> diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page3.html b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page3.html new file mode 100644 index 0000000..4e5547c --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page3.html @@ -0,0 +1 @@ +<title>page3</title><body><h1>page3</h1></body> diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page4.html b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page4.html new file mode 100644 index 0000000..3c57aed --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page4.html @@ -0,0 +1 @@ +<title>page4</title><body><h1>page4</h1></body> diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page5.html b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page5.html new file mode 100644 index 0000000..8593552 --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page5.html @@ -0,0 +1 @@ +<title>page5</title><body><h1>page5</h1></body> diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page6.html b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page6.html new file mode 100644 index 0000000..c5bbc6f --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page6.html @@ -0,0 +1 @@ +<title>page6</title><body><h1>page6</h1></body> diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/qwebhistory.pro b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/qwebhistory.pro new file mode 100644 index 0000000..fd1074c --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/qwebhistory.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +TARGET = tst_qwebhistory +include(../../../../WebKit.pri) +SOURCES += tst_qwebhistory.cpp +RESOURCES += tst_qwebhistory.qrc +QT += testlib network +QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp new file mode 100644 index 0000000..5b55613 --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp @@ -0,0 +1,326 @@ +/* + Copyright (C) 2008 Holger Hans Peter Freyther + + 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 "qwebpage.h" +#include "qwebview.h" +#include "qwebframe.h" +#include "qwebhistory.h" +#include "qdebug.h" + +class tst_QWebHistory : public QObject +{ + Q_OBJECT + +public: + tst_QWebHistory(); + virtual ~tst_QWebHistory(); + +protected : + void loadPage(int nr) + { + frame->load(QUrl("qrc:/data/page" + QString::number(nr) + ".html")); + waitForLoadFinished.exec(); + } + +public slots: + void init(); + void cleanup(); + +private slots: + void title(); + void count(); + void back(); + void forward(); + void itemAt(); + void goToItem(); + void items(); + void serialize_1(); //QWebHistory countity + void serialize_2(); //QWebHistory index + void serialize_3(); //QWebHistoryItem + void saveAndRestore_1(); //simple checks saveState and restoreState + void saveAndRestore_2(); //bad parameters saveState and restoreState + void saveAndRestore_3(); //try use different version + +private: + QWebPage* page; + QWebFrame* frame; + QWebHistory* hist; + QEventLoop waitForLoadFinished; //operation on history are asynchronous! + int histsize; +}; + +tst_QWebHistory::tst_QWebHistory() +{ +} + +tst_QWebHistory::~tst_QWebHistory() +{ +} + +void tst_QWebHistory::init() +{ + page = new QWebPage(this); + frame = page->mainFrame(); + connect(page, SIGNAL(loadFinished(bool)), &waitForLoadFinished, SLOT(quit())); + + for (int i = 1;i < 6;i++) { + loadPage(i); + } + hist = page->history(); + histsize = 5; +} + +void tst_QWebHistory::cleanup() +{ + delete page; +} + +/** + * Check QWebHistoryItem::title() method + */ +void tst_QWebHistory::title() +{ + QCOMPARE(hist->currentItem().title(), QString("page5")); +} + +/** + * Check QWebHistory::count() method + */ +void tst_QWebHistory::count() +{ + QCOMPARE(hist->count(), histsize); +} + +/** + * Check QWebHistory::back() method + */ +void tst_QWebHistory::back() +{ + for (int i = histsize;i > 1;i--) { + QCOMPARE(page->mainFrame()->toPlainText(), QString("page") + QString::number(i)); + hist->back(); + waitForLoadFinished.exec(); + } +} + +/** + * Check QWebHistory::forward() method + */ +void tst_QWebHistory::forward() +{ + //rewind history :-) + while (hist->canGoBack()) { + hist->back(); + waitForLoadFinished.exec(); + } + + for (int i = 1;i < histsize;i++) { + QCOMPARE(page->mainFrame()->toPlainText(), QString("page") + QString::number(i)); + hist->forward(); + waitForLoadFinished.exec(); + } +} + +/** + * Check QWebHistory::itemAt() method + */ +void tst_QWebHistory::itemAt() +{ + for (int i = 1;i < histsize;i++) { + QCOMPARE(hist->itemAt(i - 1).title(), QString("page") + QString::number(i)); + QVERIFY(hist->itemAt(i - 1).isValid()); + } + //check out of range values + QVERIFY(!hist->itemAt(-1).isValid()); + QVERIFY(!hist->itemAt(histsize).isValid()); +} + +/** + * Check QWebHistory::goToItem() method + */ +void tst_QWebHistory::goToItem() +{ + QWebHistoryItem current = hist->currentItem(); + hist->back(); + waitForLoadFinished.exec(); + hist->back(); + waitForLoadFinished.exec(); + QVERIFY(hist->currentItem().title() != current.title()); + hist->goToItem(current); + waitForLoadFinished.exec(); + QCOMPARE(hist->currentItem().title(), current.title()); +} + +/** + * Check QWebHistory::items() method + */ +void tst_QWebHistory::items() +{ + QList<QWebHistoryItem> items = hist->items(); + //check count + QCOMPARE(histsize, items.count()); + + //check order + for (int i = 1;i <= histsize;i++) { + QCOMPARE(items.at(i - 1).title(), QString("page") + QString::number(i)); + } +} + +/** + * Check history state after serialization (pickle, persistent..) method + * Checks history size, history order + */ +void tst_QWebHistory::serialize_1() +{ + QByteArray tmp; //buffer + QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved + QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded + + save << *hist; + QVERIFY(save.status() == QDataStream::Ok); + QCOMPARE(hist->count(), histsize); + + //check size of history + //load next page to find differences + loadPage(6); + QCOMPARE(hist->count(), histsize + 1); + load >> *hist; + QVERIFY(load.status() == QDataStream::Ok); + QCOMPARE(hist->count(), histsize); + + //check order of historyItems + QList<QWebHistoryItem> items = hist->items(); + for (int i = 1;i <= histsize;i++) { + QCOMPARE(items.at(i - 1).title(), QString("page") + QString::number(i)); + } +} + +/** + * Check history state after serialization (pickle, persistent..) method + * Checks history currentIndex value + */ +void tst_QWebHistory::serialize_2() +{ + QByteArray tmp; //buffer + QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved + QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded + + int oldCurrentIndex = hist->currentItemIndex(); + + hist->back(); + waitForLoadFinished.exec(); + hist->back(); + waitForLoadFinished.exec(); + //check if current index was changed (make sure that it is not last item) + QVERIFY(hist->currentItemIndex() != oldCurrentIndex); + //save current index + oldCurrentIndex = hist->currentItemIndex(); + + save << *hist; + QVERIFY(save.status() == QDataStream::Ok); + load >> *hist; + QVERIFY(load.status() == QDataStream::Ok); + + //check current index + QCOMPARE(hist->currentItemIndex(), oldCurrentIndex); +} + +/** + * Check history state after serialization (pickle, persistent..) method + * Checks QWebHistoryItem public property after serialization + */ +void tst_QWebHistory::serialize_3() +{ + QByteArray tmp; //buffer + QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved + QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded + + //prepare two different history items + QWebHistoryItem a = hist->currentItem(); + a.setUserData("A - user data"); + + //check properties BEFORE serialization + QString title(a.title()); + QDateTime lastVisited(a.lastVisited()); + QUrl originalUrl(a.originalUrl()); + QUrl url(a.url()); + QVariant userData(a.userData()); + + save << *hist; + QVERIFY(save.status() == QDataStream::Ok); + QVERIFY(!load.atEnd()); + hist->clear(); + QVERIFY(hist->count() == 1); + load >> *hist; + QVERIFY(load.status() == QDataStream::Ok); + QWebHistoryItem b = hist->currentItem(); + + //check properties AFTER serialization + QCOMPARE(b.title(), title); + QCOMPARE(b.lastVisited(), lastVisited); + QCOMPARE(b.originalUrl(), originalUrl); + QCOMPARE(b.url(), url); + QCOMPARE(b.userData(), userData); + + //Check if all data was read + QVERIFY(load.atEnd()); +} + +/** Simple checks should be a bit redundant to streaming operators */ +void tst_QWebHistory::saveAndRestore_1() +{ + hist->back(); + waitForLoadFinished.exec(); + QByteArray buffer(hist->saveState()); + hist->clear(); + QVERIFY(hist->count() == 1); + hist->restoreState(buffer); + + //check only few values, do not make full test + //because most of the code is shared with streaming operators + //and these are checked before + QCOMPARE(hist->count(), histsize); + QCOMPARE(hist->currentItemIndex(), histsize - 2); + QCOMPARE(hist->itemAt(0).title(), QString("page1")); + QCOMPARE(hist->itemAt(histsize - 1).title(), QString("page") + QString::number(histsize)); +} + +/** Check returns value if there are bad parameters. Actually, result + * is no so importent. The test shouldn't crash :-) */ +void tst_QWebHistory::saveAndRestore_2() +{ + QByteArray buffer; + hist->restoreState(buffer); + QVERIFY(hist->count() == 1); + QVERIFY(hist->itemAt(0).isValid()); +} + +/** Try to use bad version value */ +void tst_QWebHistory::saveAndRestore_3() +{ + QByteArray tmp = hist->saveState((QWebHistory::HistoryStateVersion)29999); + QVERIFY(hist->saveState((QWebHistory::HistoryStateVersion)29999).isEmpty()); + QVERIFY(hist->count() == histsize); + QVERIFY(hist->itemAt(3).isValid()); +} + +QTEST_MAIN(tst_QWebHistory) +#include "tst_qwebhistory.moc" diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.qrc b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.qrc new file mode 100644 index 0000000..7c5ff0e --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.qrc @@ -0,0 +1,11 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>data/page1.html</file> + <file>data/page2.html</file> + <file>data/page3.html</file> + <file>data/page4.html</file> + <file>data/page5.html</file> + <file>data/page6.html</file> +</qresource> +</RCC> + diff --git a/src/3rdparty/webkit/WebKit/qt/tests/tests.pro b/src/3rdparty/webkit/WebKit/qt/tests/tests.pro index e898ca0..076046f 100644 --- a/src/3rdparty/webkit/WebKit/qt/tests/tests.pro +++ b/src/3rdparty/webkit/WebKit/qt/tests/tests.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs -SUBDIRS = qwebframe qwebpage qwebelement qwebhistoryinterface qwebview +SUBDIRS = qwebframe qwebpage qwebelement qwebhistoryinterface qwebview qwebhistory |