[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

kenneth at webkit.org kenneth at webkit.org
Wed Apr 7 23:12:04 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 6dbdf32f419a74a6cf6a495b3281c0b3a1e7e477
Author: kenneth at webkit.org <kenneth at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Oct 28 13:18:55 2009 +0000

    [Qt] QWebHistory::saveState() is inconsistent with the Qt API
    https://bugs.webkit.org/show_bug.cgi?id=30710
    
    Patch by Kenneth Rohde Christiansen <kenneth at webkit.org> on 2009-10-28
    Reviewed by Holger Freyther.
    
    Remove the QWebHistory::saveState() and ::restoreState() as
    they are inconsistent with the Qt API.
    
    Update unittests to reflect the change.
    
    * Api/qwebhistory.cpp:
    (operator<<):
    (operator>>):
    * Api/qwebhistory.h:
    * tests/qwebhistory/tst_qwebhistory.cpp:
    (saveHistory):
    (restoreHistory):
    (tst_QWebHistory::saveAndRestore_crash_1):
    (tst_QWebHistory::saveAndRestore_crash_2):
    (tst_QWebHistory::saveAndRestore_crash_3):
    (tst_QWebHistory::clear):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50214 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/qt/Api/qwebhistory.cpp b/WebKit/qt/Api/qwebhistory.cpp
index 5752d66..3df58fc 100644
--- a/WebKit/qt/Api/qwebhistory.cpp
+++ b/WebKit/qt/Api/qwebhistory.cpp
@@ -226,7 +226,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().
+  QWebHistory's state can be saved to a QDataStream using the >> operator and loaded
+  by using the << operator.
 
   \sa QWebHistoryItem, QWebHistoryInterface, QWebPage
 */
@@ -477,77 +478,32 @@ void QWebHistory::setMaximumItemCount(int 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
+  \fn QDataStream& operator<<(QDataStream& stream, const QWebHistory& history)
+  \relates QWebHistory
 
-  Restores the state of QWebHistory from the given \a buffer. Returns true
-  if the history was successfully restored; otherwise returns false.
+  \brief The operator<< function streams a history into a data stream.
 
-  \sa saveState()
+  It saves the \a history into the specified \a stream.
 */
-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;
-    }
-
-    d->page()->updateNavigationActions();
-
-    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
+QDataStream& operator<<(QDataStream& target, const QWebHistory& history)
 {
+    QWebHistoryPrivate* d = history.d;
+
     QByteArray buffer;
     QDataStream stream(&buffer, QIODevice::WriteOnly);
+    int version = QWebHistory::DefaultHistoryVersion;
     stream << version;
 
     switch (version) {
-    case HistoryVersion_1: {
-        stream << count() << currentItemIndex();
+    case QWebHistory::HistoryVersion_1: {
+        stream << history.count() << history.currentItemIndex();
 
         const WebCore::HistoryItemVector &items = d->lst->entries();
         for (unsigned i = 0; i < items.size(); i++)
@@ -559,29 +515,9 @@ QByteArray QWebHistory::saveState(HistoryStateVersion version) const
     }
     default:
         buffer.clear();
-
     }
 
-    return buffer;
-}
-
-/*!
-  \since 4.6
-  \fn QDataStream& operator<<(QDataStream& stream, const QWebHistory& history)
-  \relates QWebHistory
-
-  \brief The operator<< function streams a history into a data stream.
-
-  It saves the \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();
+    return target << buffer;
 }
 
 /*!
@@ -592,18 +528,48 @@ QDataStream& operator<<(QDataStream& stream, const QWebHistory& history)
   \brief The operator>> function loads a history from a data stream.
 
   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)
+QDataStream& operator>>(QDataStream& source, QWebHistory& history)
 {
+    QWebHistoryPrivate* d = history.d;
+
     QByteArray buffer;
-    stream >> buffer;
-    history.restoreState(buffer);
-    return stream;
+    source >> buffer;
+
+    QDataStream stream(buffer);
+    int version;
+    bool result = false;
+    stream >> version;
+
+    switch (version) {
+    case QWebHistory::HistoryVersion_1: {
+        int count;
+        int currentIndex;
+        stream >> count >> currentIndex;
+
+        history.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);
+            history.goToItem(history.itemAt(currentIndex));
+            result = stream.status() == QDataStream::Ok;
+        }
+        break;
+    }
+    default: {} // result is false;
+    }
+
+    d->page()->updateNavigationActions();
+
+    return source;
 }
 
 QWebPagePrivate* QWebHistoryPrivate::page()
diff --git a/WebKit/qt/Api/qwebhistory.h b/WebKit/qt/Api/qwebhistory.h
index e46f124..854a278 100644
--- a/WebKit/qt/Api/qwebhistory.h
+++ b/WebKit/qt/Api/qwebhistory.h
@@ -42,9 +42,6 @@ public:
     QWebHistoryItem &operator=(const QWebHistoryItem &other);
     ~QWebHistoryItem();
 
-    //bool restoreState(QByteArray& buffer);
-    //QByteArray saveState(QWebHistory::HistoryStateVersion version = DefaultHistoryVersion) const;
-
     QUrl originalUrl() const;
     QUrl url() const;
 
@@ -69,9 +66,6 @@ private:
     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 {
@@ -82,9 +76,6 @@ public:
         DefaultHistoryVersion = HistoryVersion_1
     };
 
-    bool restoreState(const QByteArray& buffer);
-    QByteArray saveState(HistoryStateVersion version = DefaultHistoryVersion) const;
-
     void clear();
 
     QList<QWebHistoryItem> items() const;
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index 11813d0..751e718 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,27 @@
+2009-10-28  Kenneth Rohde Christiansen  <kenneth at webkit.org>
+
+        Reviewed by Holger Freyther.
+
+        [Qt] QWebHistory::saveState() is inconsistent with the Qt API
+        https://bugs.webkit.org/show_bug.cgi?id=30710
+
+        Remove the QWebHistory::saveState() and ::restoreState() as
+        they are inconsistent with the Qt API.
+
+        Update unittests to reflect the change.
+
+        * Api/qwebhistory.cpp:
+        (operator<<):
+        (operator>>):
+        * Api/qwebhistory.h:
+        * tests/qwebhistory/tst_qwebhistory.cpp:
+        (saveHistory):
+        (restoreHistory):
+        (tst_QWebHistory::saveAndRestore_crash_1):
+        (tst_QWebHistory::saveAndRestore_crash_2):
+        (tst_QWebHistory::saveAndRestore_crash_3):
+        (tst_QWebHistory::clear):
+
 2009-10-27  Antonio Gomes  <tonikitoo at webkit.org>
 
         Reviewed by Holger Freyther.
diff --git a/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp b/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp
index 4f4d3c4..ec2d497 100644
--- a/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp
+++ b/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp
@@ -56,9 +56,6 @@ private slots:
     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
     void saveAndRestore_crash_1();
     void saveAndRestore_crash_2();
     void saveAndRestore_crash_3();
@@ -294,67 +291,40 @@ void tst_QWebHistory::serialize_3()
     QVERIFY(load.atEnd());
 }
 
-/** Simple checks should be a bit redundant to streaming operators */
-void tst_QWebHistory::saveAndRestore_1() 
+static void saveHistory(QWebHistory* history, QByteArray* in)
 {
-    QAction* actionBack = page->action(QWebPage::Back);
-    hist->back();
-    waitForLoadFinished.exec();
-    QVERIFY(actionBack->isEnabled());
-    QByteArray buffer(hist->saveState());
-    hist->clear();
-    QVERIFY(!actionBack->isEnabled());
-    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));
-    QVERIFY(actionBack->isEnabled());
+    in->clear();
+    QDataStream save(in, QIODevice::WriteOnly);
+    save << *history;
 }
 
-/** Check returns value if there are bad parameters. Actually, result
-  * is no so importent. The test shouldn't crash :-) */
-void tst_QWebHistory::saveAndRestore_2() 
+static void restoreHistory(QWebHistory* history, QByteArray* out)
 {
-    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());
+    QDataStream load(out, QIODevice::ReadOnly);
+    load >> *history;
 }
 
 /** The test shouldn't crash */
 void tst_QWebHistory::saveAndRestore_crash_1()
 {
-    QByteArray tmp = hist->saveState();
-    for (unsigned i = 0; i < 5; i++){
-        hist->restoreState(tmp);
-        hist->saveState();
+    QByteArray buffer;
+    saveHistory(hist, &buffer);
+    for (unsigned i = 0; i < 5; i++) {
+        restoreHistory(hist, &buffer);
+        saveHistory(hist, &buffer);
     }
 }
 
 /** The test shouldn't crash */
 void tst_QWebHistory::saveAndRestore_crash_2()
 {
-    QByteArray tmp = hist->saveState();
+    QByteArray buffer;
+    saveHistory(hist, &buffer);
     QWebPage* page2 = new QWebPage(this);
     QWebHistory* hist2 = page2->history();
-    for (unsigned i = 0; i < 5; i++){
-        hist2->restoreState(tmp);
-        hist2->saveState();
+    for (unsigned i = 0; i < 5; i++) {
+        restoreHistory(hist2, &buffer);
+        saveHistory(hist2, &buffer);
     }
     delete page2;
 }
@@ -362,17 +332,18 @@ void tst_QWebHistory::saveAndRestore_crash_2()
 /** The test shouldn't crash */
 void tst_QWebHistory::saveAndRestore_crash_3()
 {
-    QByteArray tmp = hist->saveState();
+    QByteArray buffer;
+    saveHistory(hist, &buffer);
     QWebPage* page2 = new QWebPage(this);
     QWebHistory* hist1 = hist;
     QWebHistory* hist2 = page2->history();
-    for (unsigned i = 0; i < 5; i++){
-        hist1->restoreState(tmp);
-        hist2->restoreState(tmp);
+    for (unsigned i = 0; i < 5; i++) {
+        restoreHistory(hist1, &buffer);
+        restoreHistory(hist2, &buffer);
         QVERIFY(hist1->count() == hist2->count());
         QVERIFY(hist1->count() == histsize);
         hist2->back();
-        tmp = hist2->saveState();
+        saveHistory(hist2, &buffer);
         hist2->clear();
     }
     delete page2;
@@ -381,15 +352,16 @@ void tst_QWebHistory::saveAndRestore_crash_3()
 /** ::clear */
 void tst_QWebHistory::clear()
 {
+    QByteArray buffer;
+
     QAction* actionBack = page->action(QWebPage::Back);
     QVERIFY(actionBack->isEnabled());
-    hist->saveState();
+    saveHistory(hist, &buffer);
     QVERIFY(hist->count() > 1);
     hist->clear();
     QVERIFY(hist->count() == 1);  // Leave current item.
     QVERIFY(!actionBack->isEnabled());
 
-
     QWebPage* page2 = new QWebPage(this);
     QWebHistory* hist2 = page2->history();
     QVERIFY(hist2->count() == 0);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list