diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-04-27 10:03:12 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-04-27 10:03:43 +0200 |
commit | 10e66c6dd0b8a8dd17252d6408c13b689fac6995 (patch) | |
tree | fbdddb33a818b5495b24f3949f7406b0b916e78c /tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | |
parent | d0852f90a24673ccc9ef0b93e224ba37b674644d (diff) | |
parent | 75412200db05ddc5ee2b9aea367b580d8b0c438e (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
configure.pri
src/pdf/api/qpdfpagerenderer.h
Change-Id: I7e68277080e29238bbfe8511539ea75b2db89489
Diffstat (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 78f1b4bdb..098656390 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -226,6 +226,7 @@ private Q_SLOTS: void customUserAgentInNewTab(); void renderProcessCrashed(); void renderProcessPid(); + void backgroundColor(); private: static QPoint elementCenter(QWebEnginePage *page, const QString &id); @@ -826,6 +827,7 @@ void tst_QWebEnginePage::localStorageVisibility() // Toggle local setting for every page and... webPage1.settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); webPage2.settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); + // TODO: note this setting is flaky, consider settings().commit() // ...first check second page (for storage to appear) as applying settings is batched and done asynchronously QTRY_VERIFY(evaluateJavaScriptSync(&webPage2, QString("(window.localStorage != undefined)")).toBool()); // Switching the feature off does not actively remove the object from webPage1. @@ -4387,6 +4389,49 @@ void tst_QWebEnginePage::renderProcessPid() QCOMPARE(m_page->renderProcessPid(), 0); } +void tst_QWebEnginePage::backgroundColor() +{ + QWebEngineProfile profile; + QWebEngineView view; + QWebEnginePage *page = new QWebEnginePage(&profile, &view); + + view.resize(640, 480); + view.setStyleSheet("background: yellow"); + view.show(); + QPoint center(view.size().width() / 2, view.size().height() / 2); + + QCOMPARE(page->backgroundColor(), Qt::white); + QTRY_COMPARE(view.grab().toImage().pixelColor(center), Qt::white); + + page->setBackgroundColor(Qt::red); + view.setPage(page); + + QCOMPARE(page->backgroundColor(), Qt::red); + QTRY_COMPARE(view.grab().toImage().pixelColor(center), Qt::red); + + page->setHtml(QString("<html>" + "<head><style>html, body { margin:0; padding:0; }</style></head>" + "<body><div style=\"width:100%; height:10px; background-color:black\"/></body>" + "</html>")); + QSignalSpy spyFinished(page, &QWebEnginePage::loadFinished); + QVERIFY(spyFinished.wait()); + // Make sure the page is rendered and the test is not grabbing the color of the RenderWidgetHostViewQtDelegateWidget. + QTRY_COMPARE(view.grab().toImage().pixelColor(QPoint(5, 5)), Qt::black); + + QCOMPARE(page->backgroundColor(), Qt::red); + QCOMPARE(view.grab().toImage().pixelColor(center), Qt::red); + + page->setBackgroundColor(Qt::transparent); + + QCOMPARE(page->backgroundColor(), Qt::transparent); + QTRY_COMPARE(view.grab().toImage().pixelColor(center), Qt::yellow); + + page->setBackgroundColor(Qt::green); + + QCOMPARE(page->backgroundColor(), Qt::green); + QTRY_COMPARE(view.grab().toImage().pixelColor(center), Qt::green); +} + static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")}; W_QTEST_MAIN(tst_QWebEnginePage, params) |