diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-29 15:57:18 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-31 21:31:45 +0000 |
commit | ef1f608f76f02f11b4bdcc8d52fa41cdf4cdf5c3 (patch) | |
tree | 047a52a007af9f835f077d5061861557296ae7a8 /tests | |
parent | 23c652c3c1680f42adfd5c6500280b103ce1d095 (diff) |
Preserve webchannel and userscripts when restoring history
Most page-state is set in webcontentsadapter::initialize except user
scripts and webchannel. This patch ensures those are initialized too
when changing to a new adapter during history restore.
Change-Id: I4dca23ddab50480b1a72252a038834ce1802ad77
Task-number: QTBUG-50751
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Reviewed-by: David Rosca <nowrep@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 8fd71c701..690cf70e4 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -33,6 +33,7 @@ #include <QStyle> #include <QtTest/QtTest> #include <QTextCharFormat> +#include <QWebChannel> #include <private/qinputmethod_p.h> #include <qnetworkcookiejar.h> #include <qnetworkreply.h> @@ -42,6 +43,8 @@ #include <qwebenginehistory.h> #include <qwebenginepage.h> #include <qwebengineprofile.h> +#include <qwebenginescript.h> +#include <qwebenginescriptcollection.h> #include <qwebenginesettings.h> #include <qwebengineview.h> #include <qimagewriter.h> @@ -237,6 +240,8 @@ private Q_SLOTS: void loadInSignalHandlers_data(); void loadInSignalHandlers(); + void restoreHistory(); + private: QWebEngineView* m_view; QWebEnginePage* m_page; @@ -5079,5 +5084,36 @@ void tst_QWebEnginePage::loadInSignalHandlers() QCOMPARE(m_page->url(), urlForSetter); } +void tst_QWebEnginePage::restoreHistory() +{ + QWebChannel *channel = new QWebChannel; + QWebEnginePage *page = new QWebEnginePage; + page->setWebChannel(channel); + + QWebEngineScript script; + script.setName(QStringLiteral("script")); + page->scripts().insert(script); + + QSignalSpy spy(page, SIGNAL(loadFinished(bool))); + page->load(QUrl(QStringLiteral("qrc:/resources/test1.html"))); + QTRY_COMPARE(spy.count(), 1); + + QCOMPARE(page->webChannel(), channel); + QVERIFY(page->scripts().contains(script)); + + QByteArray data; + QDataStream out(&data, QIODevice::ReadWrite); + out << *page->history(); + QDataStream in(&data, QIODevice::ReadOnly); + in >> *page->history(); + QTRY_COMPARE(spy.count(), 2); + + QCOMPARE(page->webChannel(), channel); + QVERIFY(page->scripts().contains(script)); + + delete page; + delete channel; +} + QTEST_MAIN(tst_QWebEnginePage) #include "tst_qwebenginepage.moc" |