2012-12-03 11:31:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-12-03 11:31:18 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-12-03 11:31:18 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-12-03 11:31:18 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-12-03 11:31:18 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qwindow.h>
|
|
|
|
#include <qwidget.h>
|
|
|
|
|
2013-11-15 10:26:38 +00:00
|
|
|
#include <qdockwidget.h>
|
|
|
|
#include <qmainwindow.h>
|
2014-12-03 08:41:10 +00:00
|
|
|
#include <qscreen.h>
|
|
|
|
#include <qscopedpointer.h>
|
2017-02-26 16:18:40 +00:00
|
|
|
#include <qevent.h>
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Window : public QWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Window()
|
|
|
|
: numberOfExposes(0)
|
|
|
|
, numberOfObscures(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void exposeEvent(QExposeEvent *) {
|
|
|
|
if (isExposed())
|
|
|
|
++numberOfExposes;
|
|
|
|
else
|
|
|
|
++numberOfObscures;
|
|
|
|
}
|
|
|
|
|
|
|
|
int numberOfExposes;
|
|
|
|
int numberOfObscures;
|
|
|
|
};
|
|
|
|
|
|
|
|
class tst_QWindowContainer: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2014-12-03 08:41:10 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
tst_QWindowContainer() : m_availableGeometry(QGuiApplication::primaryScreen()->availableGeometry()) {}
|
|
|
|
|
2012-12-03 11:31:18 +00:00
|
|
|
private slots:
|
|
|
|
void testShow();
|
|
|
|
void testPositionAndSize();
|
|
|
|
void testExposeObscure();
|
|
|
|
void testOwnership();
|
|
|
|
void testBehindTheScenesDeletion();
|
|
|
|
void testUnparenting();
|
|
|
|
void testActivation();
|
2013-10-18 10:36:47 +00:00
|
|
|
void testAncestorChange();
|
2013-11-15 10:26:38 +00:00
|
|
|
void testDockWidget();
|
2016-01-15 01:29:57 +00:00
|
|
|
void testNativeContainerParent();
|
2017-02-26 16:18:40 +00:00
|
|
|
void testPlatformSurfaceEvent();
|
2014-12-03 08:41:10 +00:00
|
|
|
void cleanup();
|
2012-12-03 11:31:18 +00:00
|
|
|
|
2014-12-03 08:41:10 +00:00
|
|
|
private:
|
|
|
|
const QRect m_availableGeometry;
|
|
|
|
};
|
2012-12-03 11:31:18 +00:00
|
|
|
|
2014-12-03 08:41:10 +00:00
|
|
|
void tst_QWindowContainer::cleanup()
|
|
|
|
{
|
|
|
|
QVERIFY(QGuiApplication::topLevelWindows().isEmpty());
|
|
|
|
}
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
void tst_QWindowContainer::testShow()
|
|
|
|
{
|
|
|
|
QWidget root;
|
2014-12-03 08:41:10 +00:00
|
|
|
root.setWindowTitle(QTest::currentTestFunction());
|
|
|
|
root.setGeometry(m_availableGeometry.x() + 100, m_availableGeometry.y() + 100, 400, 400);
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
Window *window = new Window();
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window, &root);
|
|
|
|
|
|
|
|
container->setGeometry(50, 50, 200, 200);
|
|
|
|
|
|
|
|
root.show();
|
|
|
|
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QWindowContainer::testPositionAndSize()
|
|
|
|
{
|
|
|
|
QWindow *window = new QWindow();
|
2014-12-03 08:41:10 +00:00
|
|
|
window->setGeometry(m_availableGeometry.x() + 300, m_availableGeometry.y() + 400, 500, 600);
|
2012-12-03 11:31:18 +00:00
|
|
|
|
2014-12-03 08:41:10 +00:00
|
|
|
QScopedPointer<QWidget> container(QWidget::createWindowContainer(window));
|
|
|
|
container->setWindowTitle(QTest::currentTestFunction());
|
2012-12-03 11:31:18 +00:00
|
|
|
container->setGeometry(50, 50, 200, 200);
|
|
|
|
|
|
|
|
|
|
|
|
container->show();
|
2014-12-03 08:41:10 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(container.data()));
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
QCOMPARE(window->x(), 0);
|
|
|
|
QCOMPARE(window->y(), 0);
|
|
|
|
QCOMPARE(window->width(), container->width());
|
|
|
|
QCOMPARE(window->height(), container->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QWindowContainer::testExposeObscure()
|
|
|
|
{
|
|
|
|
Window *window = new Window();
|
|
|
|
|
2014-12-03 08:41:10 +00:00
|
|
|
QScopedPointer<QWidget> container(QWidget::createWindowContainer(window));
|
|
|
|
container->setWindowTitle(QTest::currentTestFunction());
|
|
|
|
container->setGeometry(m_availableGeometry.x() + 50, m_availableGeometry.y() + 50, 200, 200);
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
container->show();
|
2014-12-03 08:41:10 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(container.data()));
|
2012-12-03 11:31:18 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
|
|
|
|
|
|
|
QVERIFY(window->numberOfExposes > 0);
|
|
|
|
|
|
|
|
container->hide();
|
|
|
|
|
|
|
|
QElapsedTimer timer;
|
|
|
|
timer.start();
|
|
|
|
while (window->numberOfObscures == 0 && timer.elapsed() < 5000) {
|
|
|
|
QTest::qWait(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(window->numberOfObscures > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QWindowContainer::testOwnership()
|
|
|
|
{
|
|
|
|
QPointer<QWindow> window(new QWindow());
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window);
|
|
|
|
|
|
|
|
delete container;
|
|
|
|
|
2016-09-30 13:16:55 +00:00
|
|
|
QCOMPARE(window.data(), nullptr);
|
2012-12-03 11:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QWindowContainer::testBehindTheScenesDeletion()
|
|
|
|
{
|
|
|
|
QWindow *window = new QWindow();
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window);
|
|
|
|
|
|
|
|
delete window;
|
|
|
|
|
|
|
|
// The child got removed, showing not should not have any side effects,
|
|
|
|
// such as for instance, crashing...
|
|
|
|
container->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(container));
|
|
|
|
delete container;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QWindowContainer::testActivation()
|
|
|
|
{
|
|
|
|
QWidget root;
|
2014-12-03 08:41:10 +00:00
|
|
|
root.setWindowTitle(QTest::currentTestFunction());
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
QWindow *window = new QWindow();
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window, &root);
|
|
|
|
|
|
|
|
container->setGeometry(100, 100, 200, 100);
|
2014-12-03 08:41:10 +00:00
|
|
|
root.setGeometry(m_availableGeometry.x() + 100, m_availableGeometry.y() + 100, 400, 300);
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
root.show();
|
|
|
|
root.activateWindow();
|
2013-10-18 10:36:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&root));
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(root.windowHandle()));
|
2014-08-17 16:38:41 +00:00
|
|
|
QCOMPARE(QGuiApplication::focusWindow(), root.windowHandle());
|
2012-12-03 11:31:18 +00:00
|
|
|
|
2013-06-17 07:54:46 +00:00
|
|
|
// Verify that all states in the root widget indicate it is active
|
|
|
|
QVERIFY(root.windowHandle()->isActive());
|
|
|
|
QVERIFY(root.isActiveWindow());
|
|
|
|
QCOMPARE(root.palette().currentColorGroup(), QPalette::Active);
|
|
|
|
|
2012-12-03 11:31:18 +00:00
|
|
|
// Under KDE (ubuntu 12.10), we experience that doing two activateWindow in a row
|
|
|
|
// does not work. The second gets ignored by the window manager, even though the
|
|
|
|
// timestamp in the xcb connection is unique for both.
|
2015-09-24 07:25:25 +00:00
|
|
|
if (!QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive))
|
2012-12-03 11:31:18 +00:00
|
|
|
QTest::qWait(100);
|
|
|
|
|
|
|
|
window->requestActivate();
|
2014-08-17 16:38:41 +00:00
|
|
|
QTRY_COMPARE(QGuiApplication::focusWindow(), window);
|
2013-06-17 07:54:46 +00:00
|
|
|
|
|
|
|
// Verify that all states in the root widget still indicate it is active
|
|
|
|
QVERIFY(root.windowHandle()->isActive());
|
|
|
|
QVERIFY(root.isActiveWindow());
|
|
|
|
QCOMPARE(root.palette().currentColorGroup(), QPalette::Active);
|
2012-12-03 11:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QWindowContainer::testUnparenting()
|
|
|
|
{
|
|
|
|
QWindow *window = new QWindow();
|
2014-12-03 08:41:10 +00:00
|
|
|
QScopedPointer<QWidget> container(QWidget::createWindowContainer(window));
|
|
|
|
container->setWindowTitle(QTest::currentTestFunction());
|
|
|
|
container->setGeometry(m_availableGeometry.x() + 100, m_availableGeometry.y() + 100, 200, 100);
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
window->setParent(0);
|
|
|
|
|
|
|
|
container->show();
|
|
|
|
|
2014-12-03 08:41:10 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(container.data()));
|
2012-12-03 11:31:18 +00:00
|
|
|
|
|
|
|
// Window should not be made visible by container..
|
|
|
|
QVERIFY(!window->isVisible());
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:36:47 +00:00
|
|
|
void tst_QWindowContainer::testAncestorChange()
|
|
|
|
{
|
|
|
|
QWidget root;
|
2014-12-03 08:41:10 +00:00
|
|
|
root.setWindowTitle(QStringLiteral("Root ") + QTest::currentTestFunction());
|
2013-10-18 10:36:47 +00:00
|
|
|
QWidget *left = new QWidget(&root);
|
|
|
|
QWidget *right = new QWidget(&root);
|
|
|
|
|
2014-12-03 08:41:10 +00:00
|
|
|
|
|
|
|
root.setGeometry(m_availableGeometry.x() + 50, m_availableGeometry.y() + 50, 200, 100);
|
2013-10-18 10:36:47 +00:00
|
|
|
left->setGeometry(0, 0, 100, 100);
|
|
|
|
right->setGeometry(100, 0, 100, 100);
|
|
|
|
|
|
|
|
QWindow *window = new QWindow();
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window, left);
|
|
|
|
container->setGeometry(0, 0, 100, 100);
|
|
|
|
|
|
|
|
// Root
|
|
|
|
// + left
|
|
|
|
// | + container
|
|
|
|
// | + window
|
|
|
|
// + right
|
|
|
|
root.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&root));
|
|
|
|
QCOMPARE(window->geometry(), QRect(0, 0, 100, 100));
|
|
|
|
|
|
|
|
container->setParent(right);
|
|
|
|
// Root
|
|
|
|
// + left
|
|
|
|
// + right
|
|
|
|
// + container
|
|
|
|
// + window
|
|
|
|
QCOMPARE(window->geometry(), QRect(100, 0, 100, 100));
|
|
|
|
|
|
|
|
QWidget *newRoot = new QWidget(&root);
|
2014-12-03 08:41:10 +00:00
|
|
|
newRoot->setWindowTitle(QStringLiteral("newRoot ") + QTest::currentTestFunction());
|
2013-10-18 10:36:47 +00:00
|
|
|
newRoot->setGeometry(50, 50, 200, 200);
|
|
|
|
right->setParent(newRoot);
|
|
|
|
// Root
|
|
|
|
// + left
|
|
|
|
// + newRoot
|
|
|
|
// + right
|
|
|
|
// + container
|
|
|
|
// + window
|
|
|
|
QCOMPARE(window->geometry(), QRect(150, 50, 100, 100));
|
|
|
|
newRoot->move(0, 0);
|
|
|
|
QCOMPARE(window->geometry(), QRect(100, 0, 100, 100));
|
|
|
|
|
|
|
|
newRoot->setParent(0);
|
2014-12-03 08:41:10 +00:00
|
|
|
QScopedPointer<QWidget> newRootGuard(newRoot);
|
|
|
|
newRoot->setGeometry(m_availableGeometry.x() + 100, m_availableGeometry.y() + 100, 200, 200);
|
2013-10-18 10:36:47 +00:00
|
|
|
newRoot->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(newRoot));
|
2013-11-15 10:26:38 +00:00
|
|
|
QCOMPARE(newRoot->windowHandle(), window->parent());
|
2013-10-18 10:36:47 +00:00
|
|
|
// newRoot
|
|
|
|
// + right
|
|
|
|
// + container
|
|
|
|
// + window
|
|
|
|
QCOMPARE(window->geometry(), QRect(100, 0, 100, 100));
|
|
|
|
}
|
|
|
|
|
2013-11-15 10:26:38 +00:00
|
|
|
|
|
|
|
void tst_QWindowContainer::testDockWidget()
|
|
|
|
{
|
|
|
|
QMainWindow mainWindow;
|
2014-12-03 08:41:10 +00:00
|
|
|
mainWindow.setWindowTitle(QTest::currentTestFunction());
|
2013-11-15 10:26:38 +00:00
|
|
|
mainWindow.resize(200, 200);
|
2014-12-03 08:41:10 +00:00
|
|
|
mainWindow.move(m_availableGeometry.center() - QPoint(100, 100));
|
2013-11-15 10:26:38 +00:00
|
|
|
|
2014-12-03 08:41:10 +00:00
|
|
|
QDockWidget *dock = new QDockWidget(QStringLiteral("Dock ") + QTest::currentTestFunction());
|
2013-11-15 10:26:38 +00:00
|
|
|
QWindow *window = new QWindow();
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window);
|
|
|
|
dock->setWidget(container);
|
|
|
|
mainWindow.addDockWidget(Qt::RightDockWidgetArea, dock);
|
|
|
|
|
|
|
|
mainWindow.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&mainWindow));
|
2014-08-17 16:38:41 +00:00
|
|
|
QCOMPARE(window->parent(), mainWindow.window()->windowHandle());
|
2013-11-15 10:26:38 +00:00
|
|
|
|
|
|
|
QTest::qWait(1000);
|
|
|
|
dock->setFloating(true);
|
|
|
|
QTRY_VERIFY(window->parent() != mainWindow.window()->windowHandle());
|
|
|
|
|
|
|
|
QTest::qWait(1000);
|
|
|
|
dock->setFloating(false);
|
2015-07-30 13:16:36 +00:00
|
|
|
QTRY_COMPARE(window->parent(), mainWindow.window()->windowHandle());
|
2013-11-15 10:26:38 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 01:29:57 +00:00
|
|
|
void tst_QWindowContainer::testNativeContainerParent()
|
|
|
|
{
|
|
|
|
QWidget root;
|
|
|
|
root.setWindowTitle(QTest::currentTestFunction());
|
|
|
|
root.setGeometry(m_availableGeometry.x() + 50, m_availableGeometry.y() + 50, 200, 200);
|
|
|
|
|
|
|
|
Window *window = new Window();
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window, &root);
|
|
|
|
container->setAttribute(Qt::WA_NativeWindow);
|
|
|
|
container->setGeometry(50, 50, 150, 150);
|
|
|
|
|
|
|
|
root.show();
|
|
|
|
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
|
|
|
QTRY_COMPARE(window->parent(), container->windowHandle());
|
|
|
|
}
|
|
|
|
|
2017-02-26 16:18:40 +00:00
|
|
|
class EventWindow : public QWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EventWindow(bool *surfaceDestroyFlag) : m_surfaceDestroyFlag(surfaceDestroyFlag) { }
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool *m_surfaceDestroyFlag;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool EventWindow::event(QEvent *e)
|
|
|
|
{
|
|
|
|
if (e->type() == QEvent::PlatformSurface) {
|
|
|
|
if (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)
|
|
|
|
*m_surfaceDestroyFlag = true;
|
|
|
|
}
|
|
|
|
return QWindow::event(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QWindowContainer::testPlatformSurfaceEvent()
|
|
|
|
{
|
|
|
|
// Verify that SurfaceAboutToBeDestroyed is delivered and the
|
|
|
|
// window subclass still gets a chance to process it.
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
QPointer<EventWindow> window(new EventWindow(&ok));
|
|
|
|
window->create();
|
|
|
|
QWidget *container = QWidget::createWindowContainer(window);
|
|
|
|
|
|
|
|
delete container;
|
|
|
|
|
|
|
|
QCOMPARE(window.data(), nullptr);
|
|
|
|
QVERIFY(ok);
|
|
|
|
}
|
|
|
|
|
2012-12-03 11:31:18 +00:00
|
|
|
QTEST_MAIN(tst_QWindowContainer)
|
|
|
|
|
|
|
|
#include "tst_qwindowcontainer.moc"
|