summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebKit/qt/tests/qwebhistory
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/webkit/WebKit/qt/tests/qwebhistory')
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page1.html1
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page2.html1
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page3.html1
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page4.html1
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page5.html1
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/data/page6.html1
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/qwebhistory.pro7
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp326
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebhistory/tst_qwebhistory.qrc11
9 files changed, 350 insertions, 0 deletions
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>
+