From 75ae3f8d80955f30f9fee987511149531db2779b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20Br=C3=BCning?= <michael.bruning@qt.io>
Date: Thu, 11 Apr 2019 18:47:54 +0200
Subject: [PATCH] Add unit test for verifying QWebEnginePage::contentsSize
 correctness

An adaptation to Chromium 70 caused a regression in this.

Change-Id: I8928694b9f99cd420afd858d3a1023228276bae0
Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
---
 .../qwebenginepage/tst_qwebenginepage.cpp     | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 9ba242e68..19f9b6df1 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -200,6 +200,7 @@ private Q_SLOTS:
     void notificationRequest_data();
     void notificationRequest();
     void sendNotification();
+    void contentsSize();
 
 private:
     static QPoint elementCenter(QWebEnginePage *page, const QString &id);
@@ -3357,6 +3358,34 @@ void tst_QWebEnginePage::sendNotification()
     QTRY_VERIFY2(page.messages.contains("onclose"), page.messages.join("\n").toLatin1().constData());
 }
 
+void tst_QWebEnginePage::contentsSize()
+{
+    m_view->resize(800, 600);
+    m_view->show();
+
+    QSignalSpy loadSpy(m_page, &QWebEnginePage::loadFinished);
+    QSignalSpy contentsSizeChangedSpy(m_page, &QWebEnginePage::contentsSizeChanged);
+
+    m_view->setHtml(QString("<html><body style=\"width: 1600px; height: 1200px;\"><p>hi</p></body></html>"));
+
+    QTRY_COMPARE(loadSpy.count(), 1);
+    QTRY_COMPARE(contentsSizeChangedSpy.count(), 1);
+
+    // Verify the page's contents size is not limited by the view's size.
+    QCOMPARE(m_page->contentsSize().width(), 1608);
+    QCOMPARE(m_page->contentsSize().height(), 1216);
+
+    // Verify resizing the view does not affect the contents size.
+    m_view->resize(2400, 1800);
+    QCOMPARE(m_page->contentsSize().width(), 1608);
+    QCOMPARE(m_page->contentsSize().height(), 1216);
+
+    // Verify resizing the view does not affect the contents size.
+    m_view->resize(1600, 1200);
+    QCOMPARE(m_page->contentsSize().width(), 1608);
+    QCOMPARE(m_page->contentsSize().height(), 1216);
+}
+
 static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")};
 W_QTEST_MAIN(tst_QWebEnginePage, params)
 
-- 
GitLab