summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-08-19 17:48:19 +0200
committerJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-08-20 18:16:15 +0200
commitdddfe170077e022f0d428569fe8d5298736a2b68 (patch)
tree87d6045362ce89da7427b7b385b56a4619aab0f5
parent75d9159924fcb2b4c11a43c87e8e62332fdf38fd (diff)
Implement the basic parts of QWebEngineHistory.
Mark the remaining methods as not implemented to allow enabling most of the dependent code in the demo browser and in API tests. Add two new tests to cover cases that might be problematic with the index-based implementation. This also renames WebContentsAdapter::navigateHistory to navigateToOffset in order to avoid confusion with navigateToIndex. Change-Id: I7c5cb9f5f878e34206fdfe48334a2dc7d9d95a1d Reviewed-by: Zeno Albisser <zeno.albisser@digia.com> Reviewed-by: Andras Becsi <andras.becsi@digia.com>
-rw-r--r--examples/widgets/browser/browsermainwindow.cpp7
-rw-r--r--lib/quick/qquickwebengineview.cpp4
-rw-r--r--lib/web_contents_adapter.cpp54
-rw-r--r--lib/web_contents_adapter.h10
-rw-r--r--lib/widgets/Api/qwebenginehistory.cpp212
-rw-r--r--lib/widgets/Api/qwebenginehistory.h8
-rw-r--r--lib/widgets/Api/qwebenginehistory_p.h14
-rw-r--r--lib/widgets/Api/qwebenginepage.cpp4
-rw-r--r--lib/widgets/Api/qwebengineview.cpp5
-rw-r--r--tests/widgets/qwebenginehistory/tst_qwebenginehistory.cpp91
-rw-r--r--tests/widgets/qwebenginepage/tst_qwebenginepage.cpp6
11 files changed, 337 insertions, 78 deletions
diff --git a/examples/widgets/browser/browsermainwindow.cpp b/examples/widgets/browser/browsermainwindow.cpp
index c7679fbe1..2d6c02288 100644
--- a/examples/widgets/browser/browsermainwindow.cpp
+++ b/examples/widgets/browser/browsermainwindow.cpp
@@ -891,7 +891,6 @@ void BrowserMainWindow::slotAboutToShowBackMenu()
m_historyBackMenu->clear();
if (!currentTab())
return;
-#if defined(QWEBENGINEHISTORY)
QWebEngineHistory *history = currentTab()->history();
int historyCount = history->count();
for (int i = history->backItems(historyCount).count() - 1; i >= 0; --i) {
@@ -903,7 +902,6 @@ void BrowserMainWindow::slotAboutToShowBackMenu()
action->setText(item.title());
m_historyBackMenu->addAction(action);
}
-#endif
}
void BrowserMainWindow::slotAboutToShowForwardMenu()
@@ -911,7 +909,6 @@ void BrowserMainWindow::slotAboutToShowForwardMenu()
m_historyForwardMenu->clear();
if (!currentTab())
return;
-#if defined(QWEBENGINEHISTORY)
QWebEngineHistory *history = currentTab()->history();
int historyCount = history->count();
for (int i = 0; i < history->forwardItems(history->count()).count(); ++i) {
@@ -923,7 +920,6 @@ void BrowserMainWindow::slotAboutToShowForwardMenu()
action->setText(item.title());
m_historyForwardMenu->addAction(action);
}
-#endif
}
void BrowserMainWindow::slotAboutToShowWindowMenu()
@@ -961,15 +957,12 @@ void BrowserMainWindow::slotShowWindow()
void BrowserMainWindow::slotOpenActionUrl(QAction *action)
{
-#if defined(QWEBENGINEHISTORY)
-
int offset = action->data().toInt();
QWebEngineHistory *history = currentTab()->history();
if (offset < 0)
history->goToItem(history->backItems(-1*offset).first()); // back
else if (offset > 0)
history->goToItem(history->forwardItems(history->count() - offset + 1).back()); // forward
-#endif
}
void BrowserMainWindow::geometryChangeRequested(const QRect &geometry)
diff --git a/lib/quick/qquickwebengineview.cpp b/lib/quick/qquickwebengineview.cpp
index 9a728cd78..80ddc287f 100644
--- a/lib/quick/qquickwebengineview.cpp
+++ b/lib/quick/qquickwebengineview.cpp
@@ -121,13 +121,13 @@ void QQuickWebEngineView::setUrl(const QUrl& url)
void QQuickWebEngineView::goBack()
{
Q_D(QQuickWebEngineView);
- d->adapter->navigateHistory(-1);
+ d->adapter->navigateToOffset(-1);
}
void QQuickWebEngineView::goForward()
{
Q_D(QQuickWebEngineView);
- d->adapter->navigateHistory(1);
+ d->adapter->navigateToOffset(1);
}
void QQuickWebEngineView::reload()
diff --git a/lib/web_contents_adapter.cpp b/lib/web_contents_adapter.cpp
index 73970094e..1c9976cbb 100644
--- a/lib/web_contents_adapter.cpp
+++ b/lib/web_contents_adapter.cpp
@@ -42,6 +42,7 @@
#include "content_browser_client_qt.h"
#include "browser_context_qt.h"
+#include "type_conversion.h"
#include "web_contents_adapter_client.h"
#include "web_contents_delegate_qt.h"
#include "web_contents_view_qt.h"
@@ -88,17 +89,12 @@ bool WebContentsAdapter::canGoForward() const
{
return webContents()->GetController().CanGoForward();
}
+
bool WebContentsAdapter::isLoading() const
{
return webContents()->IsLoading();
}
-void WebContentsAdapter::navigateHistory(int offset)
-{
- webContents()->GetController().GoToOffset(offset);
- webContents()->GetView()->Focus();
-}
-
void WebContentsAdapter::stop()
{
content::NavigationController& controller = webContents()->GetController();
@@ -135,6 +131,52 @@ QString WebContentsAdapter::pageTitle() const
return entry ? toQt(entry->GetTitle()) : QString();
}
+void WebContentsAdapter::navigateToIndex(int offset)
+{
+ webContents()->GetController().GoToIndex(offset);
+ webContents()->GetView()->Focus();
+}
+
+void WebContentsAdapter::navigateToOffset(int offset)
+{
+ webContents()->GetController().GoToOffset(offset);
+ webContents()->GetView()->Focus();
+}
+
+int WebContentsAdapter::navigationEntryCount()
+{
+ return webContents()->GetController().GetEntryCount();
+}
+
+int WebContentsAdapter::currentNavigationEntryIndex()
+{
+ return webContents()->GetController().GetCurrentEntryIndex();
+}
+
+QUrl WebContentsAdapter::getNavigationEntryOriginalUrl(int index)
+{
+ content::NavigationEntry *entry = webContents()->GetController().GetEntryAtIndex(index);
+ return entry ? toQt(entry->GetOriginalRequestURL()) : QUrl();
+}
+
+QUrl WebContentsAdapter::getNavigationEntryUrl(int index)
+{
+ content::NavigationEntry *entry = webContents()->GetController().GetEntryAtIndex(index);
+ return entry ? toQt(entry->GetURL()) : QUrl();
+}
+
+QString WebContentsAdapter::getNavigationEntryTitle(int index)
+{
+ content::NavigationEntry *entry = webContents()->GetController().GetEntryAtIndex(index);
+ return entry ? toQt(entry->GetTitle()) : QString();
+}
+
+void WebContentsAdapter::clearNavigationHistory()
+{
+ if (webContents()->GetController().CanPruneAllButVisible())
+ webContents()->GetController().PruneAllButVisible();
+}
+
content::WebContents *WebContentsAdapter::webContents() const
{
Q_D(const WebContentsAdapter);
diff --git a/lib/web_contents_adapter.h b/lib/web_contents_adapter.h
index c9d3a67ad..2bc6b9881 100644
--- a/lib/web_contents_adapter.h
+++ b/lib/web_contents_adapter.h
@@ -62,13 +62,21 @@ public:
bool canGoBack() const;
bool canGoForward() const;
bool isLoading() const;
- void navigateHistory(int);
void stop();
void reload();
void load(const QUrl&);
QUrl activeUrl() const;
QString pageTitle() const;
+ void navigateToIndex(int);
+ void navigateToOffset(int);
+ int navigationEntryCount();
+ int currentNavigationEntryIndex();
+ QUrl getNavigationEntryOriginalUrl(int index);
+ QUrl getNavigationEntryUrl(int index);
+ QString getNavigationEntryTitle(int index);
+ void clearNavigationHistory();
+
private:
inline content::WebContents* webContents() const;
Q_DECLARE_PRIVATE(WebContentsAdapter);
diff --git a/lib/widgets/Api/qwebenginehistory.cpp b/lib/widgets/Api/qwebenginehistory.cpp
index ca8d3a8d1..3f580d814 100644
--- a/lib/widgets/Api/qwebenginehistory.cpp
+++ b/lib/widgets/Api/qwebenginehistory.cpp
@@ -45,11 +45,108 @@
#include "qwebenginepage_p.h"
#include "web_contents_adapter.h"
+QWebEngineHistoryItemPrivate::QWebEngineHistoryItemPrivate(WebContentsAdapter *adapter, int index)
+ : adapter(adapter)
+ , index(index)
+{
+}
+
+QWebEngineHistoryItem::QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *d)
+ : d(d)
+{
+}
+
+QWebEngineHistoryItem::QWebEngineHistoryItem(const QWebEngineHistoryItem &other)
+ : d(other.d)
+{
+}
+
+QWebEngineHistoryItem &QWebEngineHistoryItem::operator=(const QWebEngineHistoryItem &other)
+{
+ d = other.d;
+ return *this;
+}
+
+QWebEngineHistoryItem::~QWebEngineHistoryItem()
+{
+}
+
+QUrl QWebEngineHistoryItem::originalUrl() const
+{
+ Q_D(const QWebEngineHistoryItem);
+ return d->adapter ? d->adapter->getNavigationEntryOriginalUrl(d->index) : QUrl();
+}
+
+QUrl QWebEngineHistoryItem::url() const
+{
+ Q_D(const QWebEngineHistoryItem);
+ return d->adapter ? d->adapter->getNavigationEntryUrl(d->index) : QUrl();
+}
+
+QString QWebEngineHistoryItem::title() const
+{
+ Q_D(const QWebEngineHistoryItem);
+ return d->adapter ? d->adapter->getNavigationEntryTitle(d->index) : QString();
+}
+
+QDateTime QWebEngineHistoryItem::lastVisited() const
+{
+ qWarning("Not implemented: %s", __func__);
+ return QDateTime();
+}
+
+QIcon QWebEngineHistoryItem::icon() const
+{
+ qWarning("Not implemented: %s", __func__);
+ return QIcon();
+}
+
+QVariant QWebEngineHistoryItem::userData() const
+{
+ return QVariant();
+}
+
+void QWebEngineHistoryItem::setUserData(const QVariant& userData)
+{
+ qWarning("Not implemented: %s", __func__);
+}
+
+bool QWebEngineHistoryItem::isValid() const
+{
+ Q_D(const QWebEngineHistoryItem);
+ if (!d->adapter)
+ return false;
+ return d->index >= 0 && d->index < d->adapter->navigationEntryCount();
+}
+
QWebEngineHistoryPrivate::QWebEngineHistoryPrivate(WebContentsAdapter *adapter)
: adapter(adapter)
{
}
+QWebEngineHistoryPrivate::~QWebEngineHistoryPrivate()
+{
+ // Invalidate shared item references possibly still out there.
+ QList<QWebEngineHistoryItem>::iterator it, end;
+ for (it = items.begin(), end = items.end(); it != end; ++it)
+ it->d->adapter = 0;
+}
+
+void QWebEngineHistoryPrivate::updateItems() const
+{
+ // Keep track of items we return to be able to invalidate them
+ // and avoid dangling references to our adapter.
+ int entryCount = adapter->navigationEntryCount();
+ while (items.size() > entryCount) {
+ items.last().d->adapter = 0;
+ items.removeLast();
+ }
+ while (items.size() < entryCount) {
+ int nextIndex = items.size();
+ items.append(QWebEngineHistoryItem(new QWebEngineHistoryItemPrivate(adapter, nextIndex)));
+ }
+}
+
QWebEngineHistory::QWebEngineHistory(QWebEngineHistoryPrivate *d)
: d_ptr(d)
{
@@ -59,6 +156,37 @@ QWebEngineHistory::~QWebEngineHistory()
{
}
+void QWebEngineHistory::clear()
+{
+ Q_D(const QWebEngineHistory);
+ d->adapter->clearNavigationHistory();
+}
+
+QList<QWebEngineHistoryItem> QWebEngineHistory::items() const
+{
+ Q_D(const QWebEngineHistory);
+ d->updateItems();
+ return d->items;
+}
+
+QList<QWebEngineHistoryItem> QWebEngineHistory::backItems(int maxItems) const
+{
+ Q_D(const QWebEngineHistory);
+ d->updateItems();
+ const int end = currentItemIndex();
+ const int start = std::max(0, end - maxItems);
+ return d->items.mid(start, end - start);
+}
+
+QList<QWebEngineHistoryItem> QWebEngineHistory::forwardItems(int maxItems) const
+{
+ Q_D(const QWebEngineHistory);
+ d->updateItems();
+ const int start = currentItemIndex() + 1;
+ const int end = std::min(count(), start + maxItems);
+ return d->items.mid(start, end - start);
+}
+
bool QWebEngineHistory::canGoBack() const
{
Q_D(const QWebEngineHistory);
@@ -70,3 +198,87 @@ bool QWebEngineHistory::canGoForward() const
Q_D(const QWebEngineHistory);
return d->adapter->canGoForward();
}
+
+void QWebEngineHistory::back()
+{
+ Q_D(const QWebEngineHistory);
+ d->adapter->navigateToOffset(-1);
+}
+
+void QWebEngineHistory::forward()
+{
+ Q_D(const QWebEngineHistory);
+ d->adapter->navigateToOffset(1);
+}
+
+void QWebEngineHistory::goToItem(const QWebEngineHistoryItem &item)
+{
+ Q_D(const QWebEngineHistory);
+ Q_ASSERT(item.d->adapter == d->adapter);
+ d->adapter->navigateToIndex(item.d->index);
+}
+
+QWebEngineHistoryItem QWebEngineHistory::backItem() const
+{
+ return itemAt(currentItemIndex() - 1);
+}
+
+QWebEngineHistoryItem QWebEngineHistory::currentItem() const
+{
+ Q_D(const QWebEngineHistory);
+ d->updateItems();
+ return d->items[currentItemIndex()];
+}
+
+QWebEngineHistoryItem QWebEngineHistory::forwardItem() const
+{
+ return itemAt(currentItemIndex() + 1);
+}
+
+QWebEngineHistoryItem QWebEngineHistory::itemAt(int i) const
+{
+ Q_D(const QWebEngineHistory);
+ if (i >= 0 && i < count()) {
+ d->updateItems();
+ return d->items[i];
+ } else {
+ // Return an invalid item right away.
+ QWebEngineHistoryItem item(new QWebEngineHistoryItemPrivate(0, i));
+ Q_ASSERT(!item.isValid());
+ return item;
+ }
+}
+
+int QWebEngineHistory::currentItemIndex() const
+{
+ Q_D(const QWebEngineHistory);
+ return d->adapter->currentNavigationEntryIndex();
+}
+
+int QWebEngineHistory::count() const
+{
+ Q_D(const QWebEngineHistory);
+ return d->adapter->navigationEntryCount();
+}
+
+int QWebEngineHistory::maximumItemCount() const
+{
+ return 100;
+}
+
+void QWebEngineHistory::setMaximumItemCount(int count)
+{
+ qWarning("Not implemented: %s", __func__);
+}
+
+QDataStream& operator<<(QDataStream& stream, const QWebEngineHistory& history)
+{
+ qWarning("Not implemented: %s", __func__);
+ return stream;
+}
+
+QDataStream& operator>>(QDataStream& stream, QWebEngineHistory& history)
+{
+ qWarning("Not implemented: %s", __func__);
+ return stream;
+}
diff --git a/lib/widgets/Api/qwebenginehistory.h b/lib/widgets/Api/qwebenginehistory.h
index fb98bb94d..a1097df1c 100644
--- a/lib/widgets/Api/qwebenginehistory.h
+++ b/lib/widgets/Api/qwebenginehistory.h
@@ -28,6 +28,8 @@
#include <QtGui/qicon.h>
#include <QtWebEngineWidgets/qtwebenginewidgetsglobal.h>
+class QWebEngineHistory;
+class QWebEngineHistoryItemPrivate;
class QWebEnginePage;
class QWebEnginePagePrivate;
@@ -49,6 +51,12 @@ public:
void setUserData(const QVariant& userData);
bool isValid() const;
+private:
+ QWebEngineHistoryItem(QWebEngineHistoryItemPrivate *priv);
+ Q_DECLARE_PRIVATE_D(d.data(), QWebEngineHistoryItem);
+ QExplicitlySharedDataPointer<QWebEngineHistoryItemPrivate> d;
+ friend class QWebEngineHistory;
+ friend class QWebEngineHistoryPrivate;
};
diff --git a/lib/widgets/Api/qwebenginehistory_p.h b/lib/widgets/Api/qwebenginehistory_p.h
index 1a6d7e17e..52439b93f 100644
--- a/lib/widgets/Api/qwebenginehistory_p.h
+++ b/lib/widgets/Api/qwebenginehistory_p.h
@@ -42,14 +42,28 @@
#ifndef QWEBENGINEHISTORY_P_H
#define QWEBENGINEHISTORY_P_H
+#include <QtCore/qshareddata.h>
+
class WebContentsAdapter;
+class QWebEngineHistoryItemPrivate : public QSharedData
+{
+public:
+ QWebEngineHistoryItemPrivate(WebContentsAdapter *adapter = 0, int index = 0);
+
+ WebContentsAdapter *adapter;
+ int index;
+};
+
class QWebEngineHistoryPrivate
{
public:
QWebEngineHistoryPrivate(WebContentsAdapter *adapter);
+ ~QWebEngineHistoryPrivate();
+ void updateItems() const;
WebContentsAdapter *adapter;
+ mutable QList<QWebEngineHistoryItem> items;
};
#endif // QWEBENGINEHISTORY_P_H
diff --git a/lib/widgets/Api/qwebenginepage.cpp b/lib/widgets/Api/qwebenginepage.cpp
index 037d05aee..0bc6d85e1 100644
--- a/lib/widgets/Api/qwebenginepage.cpp
+++ b/lib/widgets/Api/qwebenginepage.cpp
@@ -228,10 +228,10 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
Q_D(QWebEnginePage);
switch (action) {
case Back:
- d->adapter->navigateHistory(-1);
+ d->adapter->navigateToOffset(-1);
break;
case Forward:
- d->adapter->navigateHistory(1);
+ d->adapter->navigateToOffset(1);
break;
case Stop:
d->adapter->stop();
diff --git a/lib/widgets/Api/qwebengineview.cpp b/lib/widgets/Api/qwebengineview.cpp
index 1bf1acf4d..6ae19ca75 100644
--- a/lib/widgets/Api/qwebengineview.cpp
+++ b/lib/widgets/Api/qwebengineview.cpp
@@ -114,6 +114,11 @@ void QWebEngineView::load(const QUrl& url)
page()->load(url);
}
+QWebEngineHistory* QWebEngineView::history() const
+{
+ return page()->history();
+}
+
QString QWebEngineView::title() const
{
return page()->title();
diff --git a/tests/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
index 536df75e3..29f2ed694 100644
--- a/tests/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
+++ b/tests/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
@@ -53,6 +53,7 @@ private Q_SLOTS:
void itemAt();
void goToItem();
void items();
+ void backForwardItems();
void serialize_1(); //QWebEngineHistory countity
void serialize_2(); //QWebEngineHistory index
void serialize_3(); //QWebEngineHistoryItem
@@ -65,6 +66,7 @@ private Q_SLOTS:
void popPushState_data();
void popPushState();
void clear();
+ void historyItemFromDeletedPage();
void restoreIncompatibleVersion1();
@@ -106,11 +108,7 @@ void tst_QWebEngineHistory::cleanup()
*/
void tst_QWebEngineHistory::title()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QCOMPARE(hist->currentItem().title(), QString("page5"));
-#endif
}
/**
@@ -118,11 +116,7 @@ void tst_QWebEngineHistory::title()
*/
void tst_QWebEngineHistory::count()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QCOMPARE(hist->count(), histsize);
-#endif
}
/**
@@ -174,9 +168,6 @@ void tst_QWebEngineHistory::forward()
*/
void tst_QWebEngineHistory::itemAt()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
for (int i = 1;i < histsize;i++) {
QCOMPARE(hist->itemAt(i - 1).title(), QString("page") + QString::number(i));
QVERIFY(hist->itemAt(i - 1).isValid());
@@ -184,7 +175,6 @@ void tst_QWebEngineHistory::itemAt()
//check out of range values
QVERIFY(!hist->itemAt(-1).isValid());
QVERIFY(!hist->itemAt(histsize).isValid());
-#endif
}
/**
@@ -192,9 +182,6 @@ void tst_QWebEngineHistory::itemAt()
*/
void tst_QWebEngineHistory::goToItem()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QWebEngineHistoryItem current = hist->currentItem();
hist->back();
loadFinishedBarrier->ensureSignalEmitted();
@@ -204,7 +191,6 @@ void tst_QWebEngineHistory::goToItem()
hist->goToItem(current);
loadFinishedBarrier->ensureSignalEmitted();
QCOMPARE(hist->currentItem().title(), current.title());
-#endif
}
/**
@@ -212,9 +198,6 @@ void tst_QWebEngineHistory::goToItem()
*/
void tst_QWebEngineHistory::items()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QList<QWebEngineHistoryItem> items = hist->items();
//check count
QCOMPARE(histsize, items.count());
@@ -223,7 +206,19 @@ void tst_QWebEngineHistory::items()
for (int i = 1;i <= histsize;i++) {
QCOMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
}
-#endif
+}
+
+void tst_QWebEngineHistory::backForwardItems()
+{
+ hist->back();
+ loadFinishedBarrier->ensureSignalEmitted();
+ hist->back();
+ loadFinishedBarrier->ensureSignalEmitted();
+ QCOMPARE(hist->items().size(), 5);
+ QCOMPARE(hist->backItems(100).size(), 2);
+ QCOMPARE(hist->backItems(1).size(), 1);
+ QCOMPARE(hist->forwardItems(100).size(), 2);
+ QCOMPARE(hist->forwardItems(1).size(), 1);
}
/**
@@ -232,9 +227,6 @@ void tst_QWebEngineHistory::items()
*/
void tst_QWebEngineHistory::serialize_1()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QByteArray tmp; //buffer
QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved
QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded
@@ -256,7 +248,6 @@ void tst_QWebEngineHistory::serialize_1()
for (int i = 1;i <= histsize;i++) {
QCOMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
}
-#endif
}
/**
@@ -265,9 +256,6 @@ void tst_QWebEngineHistory::serialize_1()
*/
void tst_QWebEngineHistory::serialize_2()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QByteArray tmp; //buffer
QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved
QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded
@@ -303,7 +291,6 @@ void tst_QWebEngineHistory::serialize_2()
hist->forward();
loadFinishedBarrier->ensureSignalEmitted();
QCOMPARE(hist->currentItemIndex(), initialCurrentIndex);
-#endif
}
/**
@@ -312,9 +299,6 @@ void tst_QWebEngineHistory::serialize_2()
*/
void tst_QWebEngineHistory::serialize_3()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QByteArray tmp; //buffer
QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved
QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded
@@ -348,10 +332,8 @@ void tst_QWebEngineHistory::serialize_3()
//Check if all data was read
QVERIFY(load.atEnd());
-#endif
}
-#if defined(QWEBENGINEHISTORY)
static void saveHistory(QWebEngineHistory* history, QByteArray* in)
{
in->clear();
@@ -364,27 +346,19 @@ static void restoreHistory(QWebEngineHistory* history, QByteArray* out)
QDataStream load(out, QIODevice::ReadOnly);
load >> *history;
}
-#endif
void tst_QWebEngineHistory::saveAndRestore_crash_1()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QByteArray buffer;
saveHistory(hist, &buffer);
for (unsigned i = 0; i < 5; i++) {
restoreHistory(hist, &buffer);
saveHistory(hist, &buffer);
}
-#endif
}
void tst_QWebEngineHistory::saveAndRestore_crash_2()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QByteArray buffer;
saveHistory(hist, &buffer);
QWebEnginePage* page2 = new QWebEnginePage(this);
@@ -394,14 +368,10 @@ void tst_QWebEngineHistory::saveAndRestore_crash_2()
saveHistory(hist2, &buffer);
}
delete page2;
-#endif
}
void tst_QWebEngineHistory::saveAndRestore_crash_3()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QByteArray buffer;
saveHistory(hist, &buffer);
QWebEnginePage* page2 = new QWebEnginePage(this);
@@ -417,13 +387,12 @@ void tst_QWebEngineHistory::saveAndRestore_crash_3()
hist2->clear();
}
delete page2;
-#endif
}
void tst_QWebEngineHistory::saveAndRestore_crash_4()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
+#if !defined(QWEBENGINESETTINGS)
+ QSKIP("QWEBENGINESETTINGS");
#else
QByteArray buffer;
saveHistory(hist, &buffer);
@@ -471,9 +440,6 @@ void tst_QWebEngineHistory::popPushState()
/** ::clear */
void tst_QWebEngineHistory::clear()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
QByteArray buffer;
QAction* actionBack = page->action(QWebEnginePage::Back);
@@ -490,7 +456,24 @@ void tst_QWebEngineHistory::clear()
hist2->clear();
QVERIFY(hist2->count() == 0); // Do not change anything.
delete page2;
-#endif
+}
+
+void tst_QWebEngineHistory::historyItemFromDeletedPage()
+{
+ QList<QWebEngineHistoryItem> items = page->history()->items();
+ delete page;
+ page = 0;
+
+ foreach (QWebEngineHistoryItem item, items) {
+ QVERIFY(!item.isValid());
+ QCOMPARE(item.originalUrl(), QUrl());
+ QCOMPARE(item.url(), QUrl());
+ QCOMPARE(item.title(), QString());
+ QCOMPARE(item.lastVisited(), QDateTime());
+ QCOMPARE(item.icon(), QIcon());
+ item.setUserData(42);
+ QCOMPARE(item.userData(), QVariant());
+ }
}
// static void dumpCurrentVersion(QWebEngineHistory* history)
@@ -508,9 +491,6 @@ void tst_QWebEngineHistory::clear()
void tst_QWebEngineHistory::restoreIncompatibleVersion1()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
// Uncomment this code to generate a dump similar to the one below with the current stream version.
// dumpCurrentVersion(hist);
static const unsigned char version1Dump[] = {
@@ -588,7 +568,6 @@ void tst_QWebEngineHistory::restoreIncompatibleVersion1()
QVERIFY(!hist->canGoBack());
QVERIFY(!hist->canGoForward());
QVERIFY(stream.status() == QDataStream::ReadCorruptData);
-#endif
}
QTEST_MAIN(tst_QWebEngineHistory)
diff --git a/tests/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 0c11c6c16..562afcf55 100644
--- a/tests/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -2751,9 +2751,6 @@ public:
void tst_QWebEnginePage::errorPageExtension()
{
-#if !defined(QWEBENGINEHISTORY)
- QSKIP("QWEBENGINEHISTORY");
-#else
ErrorPage page;
m_view->setPage(&page);
@@ -2764,7 +2761,9 @@ void tst_QWebEnginePage::errorPageExtension()
page.setUrl(QUrl("http://non.existent/url"));
QTRY_COMPARE(spyLoadFinished.count(), 2);
+#if defined(QWEBENGINEPAGE_TOPLAINTEXT)
QCOMPARE(page.toPlainText(), QString("error"));
+#endif
QCOMPARE(page.history()->count(), 2);
QCOMPARE(page.history()->currentItem().url(), QUrl("http://non.existent/url"));
QCOMPARE(page.history()->canGoBack(), true);
@@ -2784,7 +2783,6 @@ void tst_QWebEnginePage::errorPageExtension()
QTRY_COMPARE(page.history()->currentItem().url(), QUrl("data:text/html,foo"));
m_view->setPage(0);
-#endif
}
void tst_QWebEnginePage::errorPageExtensionInIFrames()