summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2016-05-25 16:14:41 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-07-12 10:16:27 +0000
commit1e83a2d1b61b13323163dfe8cac64dad397cb202 (patch)
treebd933d2217a184be83bf60c957381a1b3e2cd447 /tests
parent03e0f8043264f054564da9efe82b453e6bf11fc5 (diff)
Propagate the view's screen coordinates on global position change
Suppose having a QWebEngineView as one of many child widgets in a layout. Resize some child widget such that the position of the QWebEngineView changes (without changing the position of the top-level window). Chromium must be informed of the changed global position, otherwise popups will be opened at the old position. Also see commit 7f941a34, which originally introduced the coordinate propagation for top-level window moves. Task-number: QTBUG-51244 Change-Id: Ieb372e8d7554700d5e8d1e2148ab778094ea3878 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/qwebenginepage/BLACKLIST3
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp113
2 files changed, 116 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/BLACKLIST b/tests/auto/widgets/qwebenginepage/BLACKLIST
index 91858f299..045783c94 100644
--- a/tests/auto/widgets/qwebenginepage/BLACKLIST
+++ b/tests/auto/widgets/qwebenginepage/BLACKLIST
@@ -1,3 +1,6 @@
+[comboBoxPopupPositionAfterMove]
+linux
+
[geolocationRequestJS]
*
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index fb3f8ff4e..ede50e63f 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -23,10 +23,12 @@
#include <QClipboard>
#include <QDir>
#include <QGraphicsWidget>
+#include <QHBoxLayout>
#include <QLineEdit>
#include <QMainWindow>
#include <QMenu>
#include <QMimeDatabase>
+#include <QOpenGLWidget>
#include <QPaintEngine>
#include <QPushButton>
#include <QStateMachine>
@@ -113,6 +115,8 @@ private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void thirdPartyCookiePolicy();
+ void comboBoxPopupPositionAfterMove();
+ void comboBoxPopupPositionAfterChildMove();
void contextMenuCopy();
void contextMenuPopulatedOnce();
void acceptNavigationRequest();
@@ -238,6 +242,8 @@ private Q_SLOTS:
void mouseButtonTranslation();
private:
+ static QPoint elementCenter(QWebEnginePage *page, const QString &id);
+
QWebEngineView* m_view;
QWebEnginePage* m_page;
QWebEngineView* m_inputFieldsTestView;
@@ -3113,6 +3119,96 @@ void tst_QWebEnginePage::thirdPartyCookiePolicy()
#endif
}
+static QWindow *findNewTopLevelWindow(const QWindowList &oldTopLevelWindows)
+{
+ const auto tlws = QGuiApplication::topLevelWindows();
+ for (auto w : tlws) {
+ if (!oldTopLevelWindows.contains(w)) {
+ return w;
+ }
+ }
+ return nullptr;
+}
+
+void tst_QWebEnginePage::comboBoxPopupPositionAfterMove()
+{
+ QScreen *screen = QGuiApplication::primaryScreen();
+ QWebEngineView view;
+ view.move(screen->availableGeometry().topLeft());
+ view.resize(640, 480);
+ view.show();
+
+ QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
+ view.setHtml(QLatin1String("<html><head></head><body><select id='foo'>"
+ "<option>fran</option><option>troz</option>"
+ "</select></body></html>"));
+ QTRY_COMPARE(loadSpy.count(), 1);
+ const auto oldTlws = QGuiApplication::topLevelWindows();
+ QWindow *window = view.windowHandle();
+ QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(),
+ elementCenter(view.page(), "foo"));
+
+ QWindow *popup = nullptr;
+ QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws));
+ QPoint popupPos = popup->position();
+
+ // Close the popup by clicking somewhere into the page.
+ QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(1, 1));
+ QTRY_VERIFY(!QGuiApplication::topLevelWindows().contains(popup));
+
+ // Move the top-level QWebEngineView a little and check the popup's position.
+ const QPoint offset(12, 13);
+ view.move(screen->availableGeometry().topLeft() + offset);
+ QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(),
+ elementCenter(view.page(), "foo"));
+ QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws));
+ QCOMPARE(popupPos + offset, popup->position());
+}
+
+void tst_QWebEnginePage::comboBoxPopupPositionAfterChildMove()
+{
+ QWidget mainWidget;
+ mainWidget.setLayout(new QHBoxLayout);
+
+ QWidget spacer;
+ spacer.setMinimumWidth(50);
+ mainWidget.layout()->addWidget(&spacer);
+
+ QWebEngineView view;
+ mainWidget.layout()->addWidget(&view);
+
+ QScreen *screen = QGuiApplication::primaryScreen();
+ mainWidget.move(screen->availableGeometry().topLeft());
+ mainWidget.resize(640, 480);
+ mainWidget.show();
+
+ QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
+ view.setHtml(QLatin1String("<html><head></head><body><select autofocus id='foo'>"
+ "<option value=\"narf\">narf</option><option>zort</option>"
+ "</select></body></html>"));
+ QTRY_COMPARE(loadSpy.count(), 1);
+ const auto oldTlws = QGuiApplication::topLevelWindows();
+ QWindow *window = view.window()->windowHandle();
+ QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(),
+ view.mapTo(view.window(), elementCenter(view.page(), "foo")));
+
+ QWindow *popup = nullptr;
+ QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws));
+ QPoint popupPos = popup->position();
+
+ // Close the popup by clicking somewhere into the page.
+ QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(),
+ view.mapTo(view.window(), QPoint(1, 1)));
+ QTRY_VERIFY(!QGuiApplication::topLevelWindows().contains(popup));
+
+ // Resize the "spacer" widget, and implicitly change the global position of the QWebEngineView.
+ spacer.setMinimumWidth(100);
+ QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(),
+ view.mapTo(view.window(), elementCenter(view.page(), "foo")));
+ QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws));
+ QCOMPARE(popupPos + QPoint(50, 0), popup->position());
+}
+
#ifdef Q_OS_MAC
void tst_QWebEnginePage::macCopyUnicodeToClipboard()
{
@@ -4992,5 +5088,22 @@ void tst_QWebEnginePage::mouseButtonTranslation()
delete view;
}
+QPoint tst_QWebEnginePage::elementCenter(QWebEnginePage *page, const QString &id)
+{
+ QVariantList rectList = evaluateJavaScriptSync(page,
+ "(function(){"
+ "var elem = document.getElementById('" + id + "');"
+ "var rect = elem.getBoundingClientRect();"
+ "return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];"
+ "})()").toList();
+
+ if (rectList.count() != 2) {
+ qWarning("elementCenter failed.");
+ return QPoint();
+ }
+
+ return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt());
+}
+
QTEST_MAIN(tst_QWebEnginePage)
#include "tst_qwebenginepage.moc"