summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/print_view_manager_qt.cpp61
-rw-r--r--src/core/print_view_manager_qt.h11
-rw-r--r--src/core/web_contents_adapter.cpp34
-rw-r--r--src/core/web_contents_adapter_client.h1
-rw-r--r--src/webengine/api/qquickwebengineview.cpp6
-rw-r--r--src/webengine/api/qquickwebengineview_p.h3
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h1
-rw-r--r--src/webengine/doc/src/webengineview.qdoc24
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp31
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h2
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h1
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp11
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp13
13 files changed, 161 insertions, 38 deletions
diff --git a/src/core/print_view_manager_qt.cpp b/src/core/print_view_manager_qt.cpp
index 0231df8bd..6006c3bad 100644
--- a/src/core/print_view_manager_qt.cpp
+++ b/src/core/print_view_manager_qt.cpp
@@ -63,7 +63,8 @@ namespace {
static const qreal kMicronsToMillimeter = 1000.0f;
static std::vector<char>
-GetStdVectorFromHandle(base::SharedMemoryHandle handle, uint32_t data_size) {
+GetStdVectorFromHandle(base::SharedMemoryHandle handle, uint32_t data_size)
+{
std::unique_ptr<base::SharedMemory> shared_buf(
new base::SharedMemory(handle, true));
@@ -76,7 +77,8 @@ GetStdVectorFromHandle(base::SharedMemoryHandle handle, uint32_t data_size) {
}
static scoped_refptr<base::RefCountedBytes>
-GetBytesFromHandle(base::SharedMemoryHandle handle, uint32_t data_size) {
+GetBytesFromHandle(base::SharedMemoryHandle handle, uint32_t data_size)
+{
std::unique_ptr<base::SharedMemory> shared_buf(
new base::SharedMemory(handle, true));
@@ -91,7 +93,10 @@ GetBytesFromHandle(base::SharedMemoryHandle handle, uint32_t data_size) {
// Write the PDF file to disk.
static void SavePdfFile(scoped_refptr<base::RefCountedBytes> data,
- const base::FilePath& path) {
+ const base::FilePath& path,
+ const QtWebEngineCore::PrintViewManagerQt::PrintToPDFFileCallback
+ &saveCallback)
+{
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
DCHECK_GT(data->size(), 0U);
@@ -100,8 +105,10 @@ static void SavePdfFile(scoped_refptr<base::RefCountedBytes> data,
base::File file(path,
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
- if (file.IsValid())
- metafile.SaveTo(&file);
+ bool success = file.IsValid() && metafile.SaveTo(&file);
+ content::BrowserThread::PostTask(content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(saveCallback, success));
}
static base::DictionaryValue *createPrintSettings()
@@ -172,30 +179,43 @@ PrintViewManagerQt::~PrintViewManagerQt()
}
#if defined(ENABLE_BASIC_PRINTING)
-bool PrintViewManagerQt::PrintToPDF(const QPageLayout &pageLayout, bool printInColor, const QString &filePath)
+void PrintViewManagerQt::PrintToPDFFileWithCallback(const QPageLayout &pageLayout,
+ bool printInColor, const QString &filePath,
+ const PrintToPDFFileCallback& callback)
{
- if (m_printSettings || !filePath.length())
- return false;
+ if (callback.is_null())
+ return;
+
+ if (m_printSettings || !filePath.length()) {
+ content::BrowserThread::PostTask(content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(callback, false));
+ return;
+ }
m_pdfOutputPath = toFilePath(filePath);
+ m_pdfSaveCallback = callback;
if (!PrintToPDFInternal(pageLayout, printInColor)) {
+ content::BrowserThread::PostTask(content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(callback, false));
resetPdfState();
- return false;
}
- return true;
}
-bool PrintViewManagerQt::PrintToPDFWithCallback(const QPageLayout &pageLayout, bool printInColor, const PrintToPDFCallback& callback)
+void PrintViewManagerQt::PrintToPDFWithCallback(const QPageLayout &pageLayout,
+ bool printInColor,
+ const PrintToPDFCallback& callback)
{
if (callback.is_null())
- return false;
+ return;
// If there already is a pending print in progress, don't try starting another one.
if (m_printSettings) {
content::BrowserThread::PostTask(content::BrowserThread::UI,
FROM_HERE,
base::Bind(callback, std::vector<char>()));
- return false;
+ return;
}
m_pdfPrintCallback = callback;
@@ -205,9 +225,7 @@ bool PrintViewManagerQt::PrintToPDFWithCallback(const QPageLayout &pageLayout, b
base::Bind(callback, std::vector<char>()));
resetPdfState();
- return false;
}
- return true;
}
bool PrintViewManagerQt::PrintToPDFInternal(const QPageLayout &pageLayout, bool printInColor)
@@ -218,7 +236,8 @@ bool PrintViewManagerQt::PrintToPDFInternal(const QPageLayout &pageLayout, bool
m_printSettings.reset(createPrintSettingsFromQPageLayout(pageLayout));
m_printSettings->SetBoolean(printing::kSettingShouldPrintBackgrounds
, web_contents()->GetRenderViewHost()->GetWebkitPreferences().should_print_backgrounds);
- m_printSettings->SetInteger(printing::kSettingColor, printInColor ? printing::COLOR : printing::GRAYSCALE);
+ m_printSettings->SetInteger(printing::kSettingColor,
+ printInColor ? printing::COLOR : printing::GRAYSCALE);
return Send(new PrintMsg_InitiatePrintPreview(routing_id(), false));
}
@@ -255,6 +274,7 @@ void PrintViewManagerQt::resetPdfState()
{
m_pdfOutputPath.clear();
m_pdfPrintCallback.Reset();
+ m_pdfSaveCallback.Reset();
m_printSettings.reset();
}
@@ -273,20 +293,23 @@ void PrintViewManagerQt::OnMetafileReadyForPrinting(
// Create local copies so we can reset the state and take a new pdf print job.
base::Callback<void(const std::vector<char>&)> pdf_print_callback = m_pdfPrintCallback;
+ base::Callback<void(bool)> pdf_save_callback = m_pdfSaveCallback;
base::FilePath pdfOutputPath = m_pdfOutputPath;
resetPdfState();
if (!pdf_print_callback.is_null()) {
- std::vector<char> data_vector = GetStdVectorFromHandle(params.metafile_data_handle, params.data_size);
+ std::vector<char> data_vector = GetStdVectorFromHandle(params.metafile_data_handle,
+ params.data_size);
content::BrowserThread::PostTask(content::BrowserThread::UI,
FROM_HERE,
base::Bind(pdf_print_callback, data_vector));
} else {
- scoped_refptr<base::RefCountedBytes> data_bytes = GetBytesFromHandle(params.metafile_data_handle, params.data_size);
+ scoped_refptr<base::RefCountedBytes> data_bytes
+ = GetBytesFromHandle(params.metafile_data_handle, params.data_size);
content::BrowserThread::PostTask(content::BrowserThread::FILE,
FROM_HERE,
- base::Bind(&SavePdfFile, data_bytes, pdfOutputPath));
+ base::Bind(&SavePdfFile, data_bytes, pdfOutputPath, pdf_save_callback));
}
}
diff --git a/src/core/print_view_manager_qt.h b/src/core/print_view_manager_qt.h
index 668516096..b2ba73b27 100644
--- a/src/core/print_view_manager_qt.h
+++ b/src/core/print_view_manager_qt.h
@@ -81,10 +81,16 @@ class PrintViewManagerQt
public:
~PrintViewManagerQt() override;
typedef base::Callback<void(const std::vector<char> &result)> PrintToPDFCallback;
+ typedef base::Callback<void(bool success)> PrintToPDFFileCallback;
#if defined(ENABLE_BASIC_PRINTING)
// Method to print a page to a Pdf document with page size \a pageSize in location \a filePath.
- bool PrintToPDF(const QPageLayout &pageLayout, bool printInColor, const QString &filePath);
- bool PrintToPDFWithCallback(const QPageLayout &pageLayout, bool printInColor, const PrintToPDFCallback &callback);
+ void PrintToPDFFileWithCallback(const QPageLayout &pageLayout,
+ bool printInColor,
+ const QString &filePath,
+ const PrintToPDFFileCallback& callback);
+ void PrintToPDFWithCallback(const QPageLayout &pageLayout,
+ bool printInColor,
+ const PrintToPDFCallback &callback);
#endif // ENABLE_BASIC_PRINTING
// PrintedPagesSource implementation.
@@ -114,6 +120,7 @@ protected:
base::FilePath m_pdfOutputPath;
PrintToPDFCallback m_pdfPrintCallback;
+ PrintToPDFFileCallback m_pdfSaveCallback;
private:
friend class content::WebContentsUserData<PrintViewManagerQt>;
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index abf9aa3a3..030d3ea89 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -184,11 +184,20 @@ static void callbackOnEvaluateJS(WebContentsAdapterClient *adapterClient, quint6
}
#if defined(ENABLE_BASIC_PRINTING)
-static void callbackOnPrintingFinished(WebContentsAdapterClient *adapterClient, int requestId, const std::vector<char>& result)
+static void callbackOnPrintingFinished(WebContentsAdapterClient *adapterClient,
+ int requestId,
+ const std::vector<char>& result)
{
if (requestId)
adapterClient->didPrintPage(requestId, QByteArray(result.data(), result.size()));
}
+
+static void callbackOnPdfSavingFinished(WebContentsAdapterClient *adapterClient,
+ const QString& filePath,
+ bool success)
+{
+ adapterClient->didPrintPageToPdf(filePath, success);
+}
#endif
static content::WebContents *createBlankWebContents(WebContentsAdapterClient *adapterClient, content::BrowserContext *browserContext)
@@ -963,19 +972,28 @@ void WebContentsAdapter::wasHidden()
void WebContentsAdapter::printToPDF(const QPageLayout &pageLayout, const QString &filePath)
{
#if defined(ENABLE_BASIC_PRINTING)
- PrintViewManagerQt::FromWebContents(webContents())->PrintToPDF(pageLayout, true, filePath);
+ Q_D(WebContentsAdapter);
+ PrintViewManagerQt::PrintToPDFFileCallback callback = base::Bind(&callbackOnPdfSavingFinished,
+ d->adapterClient,
+ filePath);
+ PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFFileWithCallback(pageLayout,
+ true,
+ filePath,
+ callback);
#endif // if defined(ENABLE_BASIC_PRINTING)
}
-quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayout, const bool colorMode)
+quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayout,
+ const bool colorMode)
{
#if defined(ENABLE_BASIC_PRINTING)
Q_D(WebContentsAdapter);
- PrintViewManagerQt::PrintToPDFCallback callback = base::Bind(&callbackOnPrintingFinished
- , d->adapterClient
- , d->nextRequestId);
- PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback(pageLayout, colorMode
- , callback);
+ PrintViewManagerQt::PrintToPDFCallback callback = base::Bind(&callbackOnPrintingFinished,
+ d->adapterClient,
+ d->nextRequestId);
+ PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback(pageLayout,
+ colorMode,
+ callback);
return d->nextRequestId++;
#else
return 0;
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 4e15df753..3112e4484 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -347,6 +347,7 @@ public:
virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) = 0;
virtual void didFindText(quint64 requestId, int matchCount) = 0;
virtual void didPrintPage(quint64 requestId, const QByteArray &result) = 0;
+ virtual void didPrintPageToPdf(const QString &filePath, bool success) = 0;
virtual void passOnFocus(bool reverse) = 0;
// returns the last QObject (QWidget/QQuickItem) based object in the accessibility
// hierarchy before going into the BrowserAccessibility tree
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index fbd3ef9ed..76d1ca8b5 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -1103,6 +1103,12 @@ void QQuickWebEngineViewPrivate::didPrintPage(quint64 requestId, const QByteArra
callback.call(args);
}
+void QQuickWebEngineViewPrivate::didPrintPageToPdf(const QString &filePath, bool success)
+{
+ Q_Q(QQuickWebEngineView);
+ Q_EMIT q->pdfPrintingFinished(filePath, success);
+}
+
void QQuickWebEngineViewPrivate::showValidationMessage(const QRect &anchor, const QString &mainText, const QString &subText)
{
#ifdef ENABLE_QML_TESTSUPPORT_API
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index d83958147..27224fadd 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -98,7 +98,7 @@ private:
const bool m_toggleOn;
};
-#define LATEST_WEBENGINEVIEW_REVISION 4
+#define LATEST_WEBENGINEVIEW_REVISION 5
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_OBJECT
@@ -512,6 +512,7 @@ Q_SIGNALS:
Q_REVISION(4) void colorDialogRequested(QQuickWebEngineColorDialogRequest *request);
Q_REVISION(4) void fileDialogRequested(QQuickWebEngineFileDialogRequest *request);
Q_REVISION(4) void formValidationMessageRequested(QQuickWebEngineFormValidationMessageRequest *request);
+ Q_REVISION(5) void pdfPrintingFinished(const QString &filePath, bool success);
#ifdef ENABLE_QML_TESTSUPPORT_API
void testSupportChanged();
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index d692140ef..2ecd70d78 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -123,6 +123,7 @@ public:
virtual void didFetchDocumentInnerText(quint64, const QString&) Q_DECL_OVERRIDE { }
virtual void didFindText(quint64, int) Q_DECL_OVERRIDE;
virtual void didPrintPage(quint64 requestId, const QByteArray &result) Q_DECL_OVERRIDE;
+ virtual void didPrintPageToPdf(const QString &filePath, bool success) Q_DECL_OVERRIDE;
virtual void passOnFocus(bool reverse) Q_DECL_OVERRIDE;
virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE;
virtual void authenticationRequired(QSharedPointer<QtWebEngineCore::AuthenticationDialogController>) Q_DECL_OVERRIDE;
diff --git a/src/webengine/doc/src/webengineview.qdoc b/src/webengine/doc/src/webengineview.qdoc
index 418da9f9d..8135cad53 100644
--- a/src/webengine/doc/src/webengineview.qdoc
+++ b/src/webengine/doc/src/webengineview.qdoc
@@ -1109,11 +1109,31 @@
*/
/*!
+ \qmlsignal WebEngineView::pdfPrintingFinished(string filePath, bool success)
+ \since QtWebEngine 1.5
+
+ This signal is emitted when printing the web page into a PDF file has
+ finished.
+ \a filePath will contain the path the file was requested to be created
+ at, and \a success will be \c true if the file was successfully created and
+ \c false otherwise.
+
+ \sa printToPdf()
+*/
+
+/*!
\qmlmethod void WebEngineView::printToPdf(const QString &filePath, PrintedPageSizeId pageSizeId, PrintedPageOrientation orientation)
\since QtWebEngine 1.3
- Prints the WebEngineView's current content to a PDF document and stores it under \a filePath. The document's size will be determined
- by the value of \a pageSizeId and its orientation will be determined using \a orientation.
+ Prints the WebEngineView's current content to a PDF document and stores it
+ under \a filePath. The document's size will be determined by the value of
+ \a pageSizeId and its orientation will be determined using \a orientation.
+
+ This method issues an asynchronous request for printing the web page into a
+ PDF and returns immediately. To be informed about the result of the
+ request, connect to the signal pdfPrintingFinished().
+
+ \sa pdfPrintingFinished()
*/
/*!
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 16e9438c9..c22736cab 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -359,6 +359,12 @@ void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, bool isE
updateNavigationActions();
}
+void QWebEnginePagePrivate::didPrintPageToPdf(const QString &filePath, bool success)
+{
+ Q_Q(QWebEnginePage);
+ Q_EMIT q->pdfPrintingFinished(filePath, success);
+}
+
void QWebEnginePagePrivate::focusContainer()
{
if (view)
@@ -729,6 +735,19 @@ QWebEnginePage::QWebEnginePage(QObject* parent)
*/
/*!
+ \fn void QWebEnginePage::pdfPrintingFinished(const QString &filePath, bool success)
+ \since 5.9
+
+ This signal is emitted when printing the web page into a PDF file has
+ finished.
+ \a filePath will contain the path the file was requested to be created
+ at, and \a success will be \c true if the file was successfully created and
+ \c false otherwise.
+
+ \sa printToPdf()
+*/
+
+/*!
\property QWebEnginePage::scrollPosition
\since 5.7
@@ -1936,11 +1955,19 @@ QSizeF QWebEnginePage::contentsSize() const
}
/*!
- Renders the current content of the page into a PDF document and saves it in the location specified in \a filePath.
- The page size and orientation of the produced PDF document are taken from the values specified in \a pageLayout.
+ Renders the current content of the page into a PDF document and saves it
+ in the location specified in \a filePath.
+ The page size and orientation of the produced PDF document are taken from
+ the values specified in \a pageLayout.
+
+ This method issues an asynchronous request for printing the web page into
+ a PDF and returns immediately.
+ To be informed about the result of the request, connect to the signal
+ pdfPrintingFinished().
If a file already exists at the provided file path, it will be overwritten.
\since 5.7
+ \sa pdfPrintingFinished()
*/
void QWebEnginePage::printToPdf(const QString &filePath, const QPageLayout &pageLayout)
{
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index c6c7add1b..2ff9ad928 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -322,6 +322,8 @@ Q_SIGNALS:
void audioMutedChanged(bool muted);
void recentlyAudibleChanged(bool recentlyAudible);
+ void pdfPrintingFinished(const QString &filePath, bool success);
+
protected:
virtual QWebEnginePage *createWindow(WebWindowType type);
virtual QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes);
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 0ad077a0e..99caeac86 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -119,6 +119,7 @@ public:
virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) Q_DECL_OVERRIDE;
virtual void didFindText(quint64 requestId, int matchCount) Q_DECL_OVERRIDE;
virtual void didPrintPage(quint64 requestId, const QByteArray &result) Q_DECL_OVERRIDE;
+ virtual void didPrintPageToPdf(const QString &filePath, bool success) Q_DECL_OVERRIDE;
virtual void passOnFocus(bool reverse) Q_DECL_OVERRIDE;
virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE;
virtual void authenticationRequired(QSharedPointer<QtWebEngineCore::AuthenticationDialogController>) Q_DECL_OVERRIDE;
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index 2a43c9c1c..236358e9c 100644
--- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
+++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
@@ -505,9 +505,13 @@ void tst_QQuickWebEngineView::printToPdf()
view->setUrl(urlFromTestPath("html/basic_page.html"));
QVERIFY(waitForLoadSucceeded(view));
+ QSignalSpy savePdfSpy(view, SIGNAL(pdfPrintingFinished(const QString&, bool)));
QString path = tempDir.path() + "/print_success.pdf";
view->printToPdf(path, QQuickWebEngineView::A4, QQuickWebEngineView::Portrait);
- QTRY_VERIFY(QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+ QList<QVariant> successArguments = savePdfSpy.takeFirst();
+ QVERIFY2(successArguments.at(0).toString() == path, "File path for first saved PDF does not match arguments");
+ QVERIFY2(successArguments.at(1).toBool() == true, "Printing to PDF file failed though it should succeed");
#if !defined(Q_OS_WIN)
path = tempDir.path() + "/print_//fail.pdf";
@@ -515,7 +519,10 @@ void tst_QQuickWebEngineView::printToPdf()
path = tempDir.path() + "/print_|fail.pdf";
#endif // #if !defined(Q_OS_WIN)
view->printToPdf(path, QQuickWebEngineView::A4, QQuickWebEngineView::Portrait);
- QTRY_VERIFY(!QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+ QList<QVariant> failedArguments = savePdfSpy.takeFirst();
+ QVERIFY2(failedArguments.at(0).toString() == path, "File path for second saved PDF does not match arguments");
+ QVERIFY2(failedArguments.at(1).toBool() == false, "Printing to PDF file succeeded though it should fail");
}
void tst_QQuickWebEngineView::stopSettingFocusWhenDisabled()
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 287af511f..d7fff3a66 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -4899,10 +4899,15 @@ void tst_QWebEnginePage::printToPdf()
page.load(QUrl("qrc:///resources/basic_printing_page.html"));
QTRY_VERIFY(spy.count() == 1);
+ QSignalSpy savePdfSpy(&page, SIGNAL(pdfPrintingFinished(const QString&, bool)));
QPageLayout layout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0.0, 0.0, 0.0, 0.0));
QString path = tempDir.path() + "/print_1_success.pdf";
page.printToPdf(path, layout);
- QTRY_VERIFY(QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+
+ QList<QVariant> successArguments = savePdfSpy.takeFirst();
+ QVERIFY2(successArguments.at(0).toString() == path, "File path for first saved PDF does not match arguments");
+ QVERIFY2(successArguments.at(1).toBool() == true, "Printing to PDF file failed though it should succeed");
#if !defined(Q_OS_WIN)
path = tempDir.path() + "/print_//2_failed.pdf";
@@ -4910,7 +4915,11 @@ void tst_QWebEnginePage::printToPdf()
path = tempDir.path() + "/print_|2_failed.pdf";
#endif
page.printToPdf(path, QPageLayout());
- QTRY_VERIFY(!QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+
+ QList<QVariant> failedArguments = savePdfSpy.takeFirst();
+ QVERIFY2(failedArguments.at(0).toString() == path, "File path for second saved PDF does not match arguments");
+ QVERIFY2(failedArguments.at(1).toBool() == false, "Printing to PDF file succeeded though it should fail");
CallbackSpy<QByteArray> successfulSpy;
page.printToPdf(successfulSpy.ref(), layout);