summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qwindow
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-11-13 11:08:31 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-11-15 18:25:04 +0100
commitc3a1fe7bd754abc1fc1370e574567aa79b237e31 (patch)
treea341ab05b2df264d6d25b5d1921f50dc0ee0b974 /tests/auto/gui/kernel/qwindow
parent0a0f7b864b0902fcedcc8cd26dd28779d36242ff (diff)
Prevent reparenting of foreign window embedding container
A foreign window used to embed a Qt window into it should not end up with changes to its own parent, as its only job is to give the embedded Qt window a parent handle. Pick-to: 6.6 Change-Id: If1bc89658fedf449d266bc0cc750c90b6a841a68 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel/qwindow')
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
index a43939a21b..ac0f78be2d 100644
--- a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
@@ -25,6 +25,7 @@ private slots:
void initialState();
void embedForeignWindow();
+ void embedInForeignWindow();
};
void tst_ForeignWindow::fromWinId()
@@ -94,5 +95,49 @@ void tst_ForeignWindow::embedForeignWindow()
QTRY_COMPARE(nativeWindow.parentWinId(), originalParentWinId);
}
+void tst_ForeignWindow::embedInForeignWindow()
+{
+ // When a foreign window is used as a container to embed a Qt UI
+ // in a foreign window hierarchy, the foreign window merely acts
+ // as a parent, and should not be modified.
+
+ {
+ // At a minimum, we must be able to reparent into the window
+ NativeWindow nativeWindow;
+ QVERIFY(nativeWindow);
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow));
+
+ QWindow embeddedWindow;
+ embeddedWindow.setParent(foreignWindow.get());
+ QTRY_VERIFY(nativeWindow.isParentOf(embeddedWindow.winId()));
+ }
+
+ {
+ // The foreign window's native window should not be reparent as a
+ // result of creating the foreign window, adding and removing children,
+ // or destroying the foreign window.
+
+ NativeWindow topLevelNativeWindow;
+ NativeWindow childNativeWindow;
+ childNativeWindow.setParent(topLevelNativeWindow);
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(childNativeWindow));
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ QWindow embeddedWindow;
+ embeddedWindow.setParent(foreignWindow.get());
+ QTRY_VERIFY(childNativeWindow.isParentOf(embeddedWindow.winId()));
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ embeddedWindow.setParent(nullptr);
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ foreignWindow.reset();
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+ }
+}
+
#include <tst_foreignwindow.moc>
QTEST_MAIN(tst_ForeignWindow)