From 34a7c2cde9ea3fb2d4c297d60a4e16c9d99cdf9b Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 5 Jul 2018 16:12:23 +0200 Subject: Add printRequest() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds printRequested() signal for web content. This signal is emitted on javascript window.print(). This change updates also qt printview manager implementation, fixes a corner case and warnings about ipc unconsumed attachments. Task-number: QTBUG-69237 Task-number: QTBUG-53745 Change-Id: I0c47b732e27e929ac6db237fb562b7d5f9b959c2 Reviewed-by: Michael BrĂ¼ning --- tests/auto/widgets/printing/tst_printing.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/printing/tst_printing.cpp b/tests/auto/widgets/printing/tst_printing.cpp index c29227c0c..2fd12b8ec 100644 --- a/tests/auto/widgets/printing/tst_printing.cpp +++ b/tests/auto/widgets/printing/tst_printing.cpp @@ -43,6 +43,7 @@ class tst_Printing : public QObject Q_OBJECT private slots: void printToPdfBasic(); + void printRequest(); #if QT_CONFIG(webengine_poppler_cpp) void printToPdfPoppler(); #endif @@ -88,6 +89,25 @@ void tst_Printing::printToPdfBasic() QCOMPARE(failedInvalidLayoutSpy.waitForResult().length(), 0); } +void tst_Printing::printRequest() +{ + QWebEnginePage webPage; + QPageLayout layout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0.0, 0.0, 0.0, 0.0)); + QSignalSpy loadFinishedSpy(&webPage, &QWebEnginePage::loadFinished); + QSignalSpy printRequestedSpy(&webPage, &QWebEnginePage::printRequested); + QSignalSpy savePdfSpy(&webPage, &QWebEnginePage::pdfPrintingFinished); + CallbackSpy resultSpy; + + webPage.load(QUrl("qrc:///resources/basic_printing_page.html")); + QTRY_VERIFY(loadFinishedSpy.count() == 1); + webPage.runJavaScript("window.print()"); + QTRY_VERIFY(printRequestedSpy.count() == 1); + //check if printing still works + webPage.printToPdf(resultSpy.ref(), layout); + const QByteArray data = resultSpy.waitForResult(); + QVERIFY(data.length() > 0); +} + #if QT_CONFIG(webengine_poppler_cpp) void tst_Printing::printToPdfPoppler() { -- cgit v1.2.3