summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginepage
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-03-31 17:36:22 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2016-06-16 15:53:32 +0000
commit3398abfc1b5b789d11592aada0b5860e36a50041 (patch)
tree0c18602e09e9f3a250d8de6fa8618e2895aa07dc /tests/auto/widgets/qwebenginepage
parent939d104cc5a8208a0bef94ca14889ccd584a3526 (diff)
Introduce QWebEnginePage::save
Add the convenience method QWebEnginePage::save for saving pages without the need to explicitly handle download requests. Task-number: QTBUG-51798 Change-Id: I8910ce8cb7c9370d72f2b209c4d2de07c614f6d6 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebenginepage')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index e50692226..b39c07fc2 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -41,6 +41,7 @@
#include <qnetworkreply.h>
#include <qnetworkrequest.h>
#include <qpa/qplatforminputcontext.h>
+#include <qwebenginedownloaditem.h>
#include <qwebenginefullscreenrequest.h>
#include <qwebenginehistory.h>
#include <qwebenginepage.h>
@@ -159,6 +160,7 @@ private Q_SLOTS:
void undoActionHaveCustomText();
void renderWidgetHostViewNotShowTopLevel();
void getUserMediaRequest();
+ void savePage();
void crashTests_LazyInitializationOfMainFrame();
@@ -3409,6 +3411,41 @@ void tst_QWebEnginePage::getUserMediaRequest()
delete page;
}
+void tst_QWebEnginePage::savePage()
+{
+ QWebEngineView view;
+ QWebEnginePage *page = view.page();
+
+ connect(page->profile(), &QWebEngineProfile::downloadRequested,
+ [] (QWebEngineDownloadItem *item)
+ {
+ connect(item, &QWebEngineDownloadItem::finished,
+ &QTestEventLoop::instance(), &QTestEventLoop::exitLoop, Qt::QueuedConnection);
+ });
+
+ const QString urlPrefix = QStringLiteral("data:text/html,<h1>");
+ const QString text = QStringLiteral("There is Thingumbob shouting!");
+ page->load(QUrl(urlPrefix + text));
+ waitForSignal(page, SIGNAL(loadFinished(bool)));
+ QCOMPARE(toPlainTextSync(page), text);
+
+ // Save the loaded page as HTML.
+ QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX");
+ const QString filePath = tempDir.path() + "/thingumbob.html";
+ page->save(filePath, QWebEngineDownloadItem::CompleteHtmlSaveFormat);
+ QTestEventLoop::instance().enterLoop(10);
+
+ // Load something else.
+ page->load(QUrl(urlPrefix + QLatin1String("It's a Snark!")));
+ waitForSignal(page, SIGNAL(loadFinished(bool)));
+ QVERIFY(toPlainTextSync(page) != text);
+
+ // Load the saved page and compare the contents.
+ page->load(QUrl::fromLocalFile(filePath));
+ waitForSignal(page, SIGNAL(loadFinished(bool)));
+ QCOMPARE(toPlainTextSync(page), text);
+}
+
void tst_QWebEnginePage::openWindowDefaultSize()
{
TestPage page;