diff options
author | Charles Yin <charles.yin@nokia.com> | 2012-03-16 15:09:18 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-16 10:24:22 +0100 |
commit | c7fb7a678251a6fc090d851b897f67d561b66625 (patch) | |
tree | 14dcbdea24912863c1e892b2243b7f0250983c60 /src | |
parent | 9b0f381f2a6304467ec0dae019b356e1c63c0725 (diff) |
Fix broken qWaitForWindowShown() behavior
qWaitForWindowShown() should check window->isActive() instead of
window->isExposed() and return false if timeout.
Add two new qWaitForWindowActive() and qWaitForWindowExposed()
functions.
Change-Id: Idd9601805c2e84b0d36ddd5471031b627d289953
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qtestcase.cpp | 33 | ||||
-rw-r--r-- | src/testlib/qtestsystem.h | 26 |
2 files changed, 55 insertions, 4 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 001a14a121..a26fa71eb4 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -862,7 +862,7 @@ QT_BEGIN_NAMESPACE /*! \fn bool QTest::qWaitForWindowShown(QWidget *window) \since 4.6 - Waits until the \a window is shown in the screen. This is mainly useful for + Waits until the \a window is shown on the screen. This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen. Returns true. @@ -870,6 +870,37 @@ QT_BEGIN_NAMESPACE \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 24 */ +/*! \fn bool QTest::qWaitForWindowShown(QWindow *window, int timeout) + \since 5.0 + + Waits for \a timeout milliseconds or until the \a window is shown on the screen. + This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some + time after being asked to show itself on the screen. + + Returns true if \c window is show in \a timout milliseconds, otherwise returns false. + + \sa QTest::qWaitForWindowActive(), QTest::qWaitForWindowExposed() +*/ + +/*! \fn bool QTest::qWaitForWindowActive(QWindow *window, int timeout) + \since 5.0 + + Waits for \a timeout milliseconds or until the \a window is active. + + Returns true if \c window is active in \a timout milliseconds, otherwise returns false. + + \sa QTest::qWaitForWindowActive(), QTest::qWaitForWindowShown(), QWindow::isActive() +*/ + +/*! \fn bool QTest::qWaitForWindowExposed(QWindow *window, int timeout) + \since 5.0 + + Waits for \a timeout milliseconds or until the \a window is exposed. + Returns true if \c window is exposed in \a timout milliseconds, otherwise returns false. + + \sa QTest::qWaitForWindowShown(), QTest::qWaitForWindowExposed(), QWindow::isExposed() +*/ + /*! \class QTest::QTouchEventSequence \inmodule QtTest diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index ade5f4c8ac..095f791cac 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -76,19 +76,39 @@ namespace QTest return true; } - inline static bool qWaitForWindowShown(QWindow *window) + inline static bool qWaitForWindowActive(QWindow *window, int timeout = 1000) + { + QElapsedTimer timer; + timer.start(); + while (!window->isActive()) { + int remaining = timeout - int(timer.elapsed()); + if (remaining <= 0) + break; + QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QTest::qSleep(10); + } + return window->isActive(); + } + + inline static bool qWaitForWindowExposed(QWindow *window, int timeout = 1000) { QElapsedTimer timer; timer.start(); while (!window->isExposed()) { - int remaining = int(timer.elapsed()) - 1000; + int remaining = timeout - int(timer.elapsed()); if (remaining <= 0) break; QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QTest::qSleep(10); } - return true; + return window->isExposed(); + } + + inline static bool qWaitForWindowShown(QWindow *window, int timeout = 1000) + { + return qWaitForWindowActive(window, timeout); } } |