tst_qwidget: remove QEXPECT_FAIL for QTBUG-8911
[profile/ivi/qtbase.git] / tests / auto / widgets / kernel / qwidget / tst_qwidget.cpp
index bca6c2b..ce4eb28 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the test suite of the Qt Toolkit.
 **
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
@@ -56,7 +56,6 @@
 #include <qstyle.h>
 #include <qwidget.h>
 #include <qwindowsstyle.h>
-#include <qinputcontext.h>
 #include <qdesktopwidget.h>
 #include <private/qwidget_p.h>
 #include <private/qapplication_p.h>
 #include <QtGui/qpaintengine.h>
 #include <QtGui/qbackingstore.h>
 #include <QtGui/qguiapplication.h>
+#include <QtGui/qscreen.h>
 #include <qmenubar.h>
+#include <qcompleter.h>
 #include <qtableview.h>
+#include <qtreewidget.h>
 
 #include <QtWidgets/QGraphicsView>
 #include <QtWidgets/QGraphicsProxyWidget>
 
-#ifdef Q_WS_QWS
-# include <qscreen_qws.h>
-#endif
-
-// I *MUST* have QtTest afterwards or this test won't work with newer headers
-#if defined(Q_WS_MAC)
-# include <private/qt_mac_p.h>
-#undef verify
+#if defined(Q_OS_MAC)
 #include "tst_qwidget_mac_helpers.h"  // Abstract the ObjC stuff out so not everyone must run an ObjC++ compile.
 #endif
 
 #include <QtTest/QtTest>
 
-#if defined(Q_OS_WIN)
+#ifdef Q_OS_WIN
 #  include <QtCore/qt_windows.h>
 #  include <QtGui/private/qguiapplication_p.h>
-#  include <QtGui/QPlatformNativeInterface>
-#  include <QtGui/QPlatformIntegration>
+#include <qpa/qplatformnativeinterface.h>
+#include <qpa/qplatformintegration.h>
 
 static HWND winHandleOf(const QWidget *w)
 {
@@ -101,27 +96,32 @@ static HWND winHandleOf(const QWidget *w)
     qWarning() << "Cannot obtain native handle for " << w;
     return 0;
 }
-#endif
 
-#if defined(Q_WS_WIN)
-#  include <qt_windows.h>
-#  if !defined(Q_OS_WINCE)
-#define Q_CHECK_PAINTEVENTS \
+#  ifdef Q_OS_WINCE
+#    define Q_CHECK_PAINTEVENTS
+#    ifdef Q_OS_WINCE_WM
+#      include <qguifunctions_wince.h>
+// taken from qguifunctions_wce.cpp
+#      define SPI_GETPLATFORMTYPE 257
+static bool qt_wince_is_platform(const QString &platformString) {
+    wchar_t tszPlatform[64];
+    if (SystemParametersInfo(SPI_GETPLATFORMTYPE,
+                             sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0))
+      if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform))
+            return true;
+    return false;
+}
+static inline bool qt_wince_is_smartphone() { return qt_wince_is_platform(QString::fromLatin1("Smartphone")); }
+#    endif // Q_OS_WINCE_WM
+#  else //  Q_OS_WINCE
+#    define Q_CHECK_PAINTEVENTS \
     if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \
         QSKIP("desktop is not visible, this test would fail");
-#  else
-#    define Q_CHECK_PAINTEVENTS
-#  endif
-#elif defined(Q_WS_X11)
-#  include <private/qt_x11_p.h>
-#  include <qx11info_x11.h>
-#elif defined(Q_WS_QWS)
-# include <qwindowsystem_qws.h>
-#endif
+#  endif //  !Q_OS_WINCE
+#else // Q_OS_WIN
+#  define Q_CHECK_PAINTEVENTS
+#endif // else Q_OS_WIN
 
-#if !defined(Q_WS_WIN)
-#define Q_CHECK_PAINTEVENTS
-#endif
 
 #if defined(Q_OS_WINCE_WM)
 #include <qguifunctions_wince.h>
@@ -140,7 +140,7 @@ bool qt_wince_is_smartphone() {
 }
 #endif
 
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
 #include <Security/AuthSession.h>
 bool macHasAccessToWindowsServer()
 {
@@ -151,11 +151,6 @@ bool macHasAccessToWindowsServer()
 }
 #endif
 
-
-#if defined(Bool)
-#undef Bool
-#endif
-
 class tst_QWidget : public QObject
 {
     Q_OBJECT
@@ -176,6 +171,7 @@ private slots:
     void palettePropagation();
     void palettePropagation2();
     void enabledPropagation();
+    void popupEnterLeave();
 #ifndef QT_NO_DRAGANDDROP
     void acceptDropsPropagation();
 #endif
@@ -190,24 +186,18 @@ private slots:
     void focusChainOnHide();
     void focusChainOnReparent();
     void setTabOrder();
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
     void activation();
 #endif
     void reparent();
-#ifndef Q_WS_X11
     void windowState();
-#endif
     void showMaximized();
     void showFullScreen();
     void showMinimized();
     void showMinimizedKeepsFocus();
-#ifndef Q_WS_QWS
     void icon();
-#endif
     void hideWhenFocusWidgetIsChild();
-#ifndef Q_OS_IRIX
     void normalGeometry();
-#endif
     void setGeometry();
 #ifndef Q_OS_WINCE
     void windowOpacity();
@@ -218,15 +208,12 @@ private slots:
     void stackUnder();
 #endif
     void testContentsPropagation();
-#ifndef Q_OS_IRIX
     void saveRestoreGeometry();
     void restoreVersion1Geometry_data();
     void restoreVersion1Geometry();
-#endif
 
     void widgetAt();
-#ifdef Q_WS_MAC
-    void retainHIView();
+#ifdef Q_OS_MAC
     void sheetOpacity();
     void setMask();
 #endif
@@ -257,21 +244,17 @@ private slots:
     void update();
     void isOpaque();
 
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
     void scroll();
 #endif
 
-#ifndef Q_WS_X11
     // tests QWidget::setGeometry()
     void setWindowGeometry_data();
     void setWindowGeometry();
-#endif
 
-#if !defined(Q_WS_X11) && !defined(Q_OS_IRIX)
     // tests QWidget::move() and resize()
     void windowMoveResize_data();
     void windowMoveResize();
-#endif
 
     void moveChild_data();
     void moveChild();
@@ -281,12 +264,9 @@ private slots:
     void subtractOpaqueSiblings();
 #endif
 
-#ifdef Q_WS_WIN
-    void getDC();
-#ifndef Q_OS_WINCE
+#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
     void setGeometry_win();
 #endif
-#endif
 
     void setLocale();
     void deleteStyle();
@@ -295,11 +275,10 @@ private slots:
     void setCursor();
     void setToolTip();
     void testWindowIconChangeEventPropagation();
-#ifdef Q_WS_X11
+
     void minAndMaxSizeWithX11BypassWindowManagerHint();
-    void showHideShow();
+    void showHideShowX11();
     void clean_qt_x11_enforce_cursor();
-#endif
 
     void childEvents();
     void render();
@@ -321,41 +300,30 @@ private slots:
 
     void setContentsMargins();
 
-#ifndef Q_OS_IRIX
     void moveWindowInShowEvent_data();
     void moveWindowInShowEvent();
-#endif
 
     void repaintWhenChildDeleted();
     void hideOpaqueChildWhileHidden();
-#if !defined(Q_OS_WINCE) && !defined(Q_WS_QWS)
+#if !defined(Q_OS_WINCE)
     void updateWhileMinimized();
 #endif
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
     void alienWidgets();
-#endif
     void adjustSize();
     void adjustSize_data();
     void updateGeometry();
     void updateGeometry_data();
     void sendUpdateRequestImmediately();
-#ifndef Q_OS_IRIX
     void doubleRepaint();
-#endif
-#ifndef Q_WS_MAC
     void resizeInPaintEvent();
     void opaqueChildren();
-#endif
 
     void setMaskInResizeEvent();
     void moveInResizeEvent();
 
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
-    // We don't support immediate repaint right after show on
-    // other platforms. Must be compatible with Qt 4.3.
     void immediateRepaintAfterShow();
     void immediateRepaintAfterInvalidateBuffer();
-#endif
+
     void effectiveWinId();
     void effectiveWinId2();
     void customDpi();
@@ -364,15 +332,13 @@ private slots:
     void quitOnCloseAttribute();
     void moveRect();
 
-#if defined (Q_WS_WIN)
+#if defined (Q_OS_WIN)
     void gdiPainting();
     void paintOnScreenPossible();
 #endif
     void reparentStaticWidget();
     void QTBUG6883_reparentStaticWidget2();
-#ifdef Q_WS_QWS
-    void updateOutsideSurfaceClip();
-#endif
+
     void translucentWidget();
 
     void setClearAndResizeMask();
@@ -383,9 +349,6 @@ private slots:
 #endif
     void windowFlags();
     void initialPosForDontShowOnScreenWidgets();
-#ifdef Q_WS_X11
-    void paintOutsidePaintEvent();
-#endif
     void updateOnDestroyedSignal();
     void toplevelLineEditFocus();
     void inputFocus_task257832();
@@ -412,46 +375,29 @@ private slots:
     void taskQTBUG_7532_tabOrderWithFocusProxy();
     void movedAndResizedAttributes();
     void childAt();
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     void childAt_unifiedToolBar();
     void taskQTBUG_11373();
 #endif
     void taskQTBUG_17333_ResizeInfiniteRecursion();
 
     void nativeChildFocus();
+    void grab();
 
 private:
     bool ensureScreenSize(int width, int height);
     QWidget *testWidget;
+
+    const QString m_platform;
 };
 
 bool tst_QWidget::ensureScreenSize(int width, int height)
 {
     QSize available;
-#ifdef Q_WS_QWS
-    available = QDesktopWidget().availableGeometry().size();
-    if (available.width() < width || available.height() < height) {
-        QScreen *screen = QScreen::instance();
-        if (!screen)
-            return false;
-        screen->setMode(width, height, screen->depth());
-    }
-#endif // Q_WS_QWS
-
     available = QDesktopWidget().availableGeometry().size();
     return (available.width() >= width && available.height() >= height);
 }
 
-class MyInputContext : public QInputContext
-{
-public:
-    MyInputContext() : QInputContext() {}
-    QString identifierName() { return QString("NoName"); }
-    QString language() { return QString("NoLanguage"); }
-    void reset() {}
-    bool isComposing() const { return false; }
-};
-
 // Testing get/set functions
 void tst_QWidget::getSetCheck()
 {
@@ -473,9 +419,6 @@ void tst_QWidget::getSetCheck()
     obj1.setMinimumWidth(INT_MIN);
     QCOMPARE(obj1.minimumWidth(), 0); // A widgets width can never be less than 0
     obj1.setMinimumWidth(INT_MAX);
-#ifndef Q_WS_QWS  //QWS doesn't allow toplevels to be bigger than the screen
-    QCOMPARE(obj1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
-#endif
 
     child1.setMinimumWidth(0);
     QCOMPARE(child1.minimumWidth(), 0);
@@ -491,9 +434,6 @@ void tst_QWidget::getSetCheck()
     obj1.setMinimumHeight(INT_MIN);
     QCOMPARE(obj1.minimumHeight(), 0); // A widgets height can never be less than 0
     obj1.setMinimumHeight(INT_MAX);
-#ifndef Q_WS_QWS    //QWS doesn't allow toplevels to be bigger than the screen
-    QCOMPARE(obj1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
-#endif
 
     child1.setMinimumHeight(0);
     QCOMPARE(child1.minimumHeight(), 0);
@@ -587,13 +527,6 @@ void tst_QWidget::getSetCheck()
     obj1.setAcceptDrops(true);
     QCOMPARE(true, obj1.acceptDrops());
 
-    // QInputContext * QWidget::inputContext()
-    MyInputContext *var13 = new MyInputContext;
-    qApp->setInputContext(var13);
-    QCOMPARE((QInputContext *)0, obj1.inputContext()); // The widget by default doesn't have the WA_InputMethodEnabled attribute
-    obj1.setAttribute(Qt::WA_InputMethodEnabled);
-    QCOMPARE(static_cast<QInputContext *>(var13), obj1.inputContext());
-
     // bool QWidget::autoFillBackground()
     // void QWidget::setAutoFillBackground(bool)
     obj1.setAutoFillBackground(false);
@@ -602,15 +535,14 @@ void tst_QWidget::getSetCheck()
     QCOMPARE(true, obj1.autoFillBackground());
 
     delete var1;
-#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
     obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
-    HWND handle = obj1.winId();
-    long flags = GetWindowLong(handle, GWL_STYLE);
-    QVERIFY(flags & WS_POPUP);
+    const HWND handle = reinterpret_cast<HWND>(obj1.winId());   // explicitly create window handle
+    QVERIFY(GetWindowLong(handle, GWL_STYLE) & WS_POPUP);
 #endif
 }
 
-tst_QWidget::tst_QWidget()
+tst_QWidget::tst_QWidget() : m_platform(qApp->platformName().toLower())
 {
     QFont font;
     font.setBold(true);
@@ -726,7 +658,7 @@ void BezierViewer::paintEvent( QPaintEvent* )
 
     /* Write number of vertices */
     painter.setPen( Qt::red );
-    painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, TRUE ) );
+    painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, true ) );
     QString caption;
     caption.setNum( bezier.size() );
     caption += QString::fromLatin1( " vertices" );
@@ -759,24 +691,24 @@ void tst_QWidget::fontPropagation()
     childWidget->show();
     QCOMPARE( font, childWidget->font() );
 
-    font.setBold( TRUE );
+    font.setBold( true );
     testWidget->setFont( font );
     QCOMPARE( font, testWidget->font() );
     QCOMPARE( font, childWidget->font() );
 
     QFont newFont = font;
-    newFont.setItalic( TRUE );
+    newFont.setItalic( true );
     childWidget->setFont( newFont );
     QWidget* grandChildWidget = new QWidget( childWidget );
     QCOMPARE( font, testWidget->font() );
     QCOMPARE( newFont, grandChildWidget->font() );
 
-    font.setUnderline( TRUE );
+    font.setUnderline( true );
     testWidget->setFont( font );
 
     // the child and grand child should now have merged bold and
     // underline
-    newFont.setUnderline( TRUE );
+    newFont.setUnderline( true );
 
     QCOMPARE( newFont, childWidget->font() );
     QCOMPARE( newFont, grandChildWidget->font() );
@@ -1074,32 +1006,32 @@ void tst_QWidget::enabledPropagation()
     QVERIFY( testWidget->isEnabled() );
     QVERIFY( childWidget->isEnabled() );
 
-    testWidget->setEnabled( FALSE );
+    testWidget->setEnabled( false );
     QVERIFY( !testWidget->isEnabled() );
     QVERIFY( !childWidget->isEnabled() );
 
-    testWidget->setDisabled( FALSE );
+    testWidget->setDisabled( false );
     QVERIFY( testWidget->isEnabled() );
     QVERIFY( childWidget->isEnabled() );
 
     QWidget* grandChildWidget = new QWidget( childWidget );
     QVERIFY( grandChildWidget->isEnabled() );
 
-    testWidget->setDisabled( TRUE );
+    testWidget->setDisabled( true );
     QVERIFY( !testWidget->isEnabled() );
     QVERIFY( !childWidget->isEnabled() );
     QVERIFY( !grandChildWidget->isEnabled() );
 
-    grandChildWidget->setEnabled( FALSE );
-    testWidget->setEnabled( TRUE );
+    grandChildWidget->setEnabled( false );
+    testWidget->setEnabled( true );
     QVERIFY( testWidget->isEnabled() );
     QVERIFY( childWidget->isEnabled() );
     QVERIFY( !grandChildWidget->isEnabled() );
 
-    grandChildWidget->setEnabled( TRUE );
-    testWidget->setEnabled( FALSE );
-    childWidget->setDisabled( TRUE );
-    testWidget->setEnabled( TRUE );
+    grandChildWidget->setEnabled( true );
+    testWidget->setEnabled( false );
+    childWidget->setDisabled( true );
+    testWidget->setEnabled( true );
     QVERIFY( testWidget->isEnabled() );
     QVERIFY( !childWidget->isEnabled() );
     QVERIFY( !grandChildWidget->isEnabled() );
@@ -1162,7 +1094,7 @@ void tst_QWidget::isEnabledTo()
     QVERIFY( childWidget->isEnabledTo( testWidget ) );
     QVERIFY( grandChildWidget->isEnabledTo( testWidget ) );
 
-    childWidget->setEnabled( FALSE );
+    childWidget->setEnabled( false );
     QVERIFY( !childWidget->isEnabledTo( testWidget ) );
     QVERIFY( grandChildWidget->isEnabledTo( childWidget ) );
     QVERIFY( !grandChildWidget->isEnabledTo( testWidget ) );
@@ -1245,7 +1177,7 @@ void tst_QWidget::visible_setWindowOpacity()
     QVERIFY( !testWidget->isVisible() );
     testWidget->setWindowOpacity(0.5);
 #ifdef Q_OS_WIN
-    QVERIFY(::IsWindowVisible(winHandleOf(testWidget)) ==  FALSE);
+    QVERIFY(!::IsWindowVisible(winHandleOf(testWidget)));
 #endif
     testWidget->setWindowOpacity(1.0);
 }
@@ -1638,12 +1570,12 @@ public:
 
     void tab()
     {
-       focusNextPrevChild(TRUE);
+       focusNextPrevChild(true);
     }
 
     void backTab()
     {
-       focusNextPrevChild(FALSE);
+       focusNextPrevChild(false);
     }
 };
 
@@ -1710,11 +1642,7 @@ void tst_QWidget::setTabOrder()
     container.show();
     container.activateWindow();
     qApp->setActiveWindow(&container);
-#ifdef Q_WS_X11
-    QTest::qWaitForWindowShown(&container);
-    QTest::qWait(50);
-#endif
-
+    QTest::qWaitForWindowShown(container.windowHandle());
     QTest::qWait(100);
 
     QTRY_VERIFY(lastEdit->hasFocus());
@@ -1728,7 +1656,7 @@ void tst_QWidget::setTabOrder()
     QVERIFY(firstEdit->hasFocus());
 }
 
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
 void tst_QWidget::activation()
 {
     Q_CHECK_PAINTEVENTS
@@ -1765,7 +1693,7 @@ void tst_QWidget::activation()
     QVERIFY(qApp->activeWindow() == &widget1);
     widget2.showNormal();
     QTest::qWait(waitTime);
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#ifndef Q_OS_WINCE
     if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
         QEXPECT_FAIL("", "MS introduced new behavior after XP", Continue);
 #endif
@@ -1775,12 +1703,12 @@ void tst_QWidget::activation()
     QTest::qWait(waitTime);
     QVERIFY(qApp->activeWindow() == &widget1);
 }
-#endif
+#endif // Q_OS_WIN
 
-// Many window managers do not support window state properly, which causes this test to fail.
-#ifndef Q_WS_X11
 void tst_QWidget::windowState()
 {
+    if (m_platform == QStringLiteral("xcb"))
+        QSKIP("X11: Many window managers do not support window state properly, which causes this test to fail.");
 #ifdef Q_OS_WINCE_WM
     QPoint pos(500, 500);
     QSize size(200, 200);
@@ -1898,7 +1826,6 @@ void tst_QWidget::windowState()
     QTRY_COMPARE(widget1.pos(), pos);
     QTRY_COMPARE(widget1.size(), size);
 }
-#endif
 
 void tst_QWidget::showMaximized()
 {
@@ -2242,25 +2169,19 @@ void tst_QWidget::showMinimizedKeepsFocus()
         window.showMinimized();
         QTest::qWait(30);
         QTRY_VERIFY(window.isMinimized());
-#ifdef Q_WS_QWS
-        QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue);
-#endif
         QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0));
-#ifdef Q_WS_QWS
-        QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue);
-#endif
         QTRY_COMPARE(qApp->focusWidget(), static_cast<QWidget*>(0));
 
         window.showNormal();
         qApp->setActiveWindow(&window);
         QTest::qWaitForWindowShown(&window);
         QTest::qWait(30);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
         if (!macHasAccessToWindowsServer())
             QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue);
 #endif
         QTRY_COMPARE(window.focusWidget(), firstchild);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
         if (!macHasAccessToWindowsServer())
             QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue);
 #endif
@@ -2306,68 +2227,16 @@ void tst_QWidget::reparent()
     child.setGeometry(childPos.x(), childPos.y(), child.width(), child.height());
     child.show();
 
-#ifdef Q_WS_X11
-    // On X11, the window manager will apply NorthWestGravity rules to 'child', which
-    // means the top-left corner of the window frame will be placed at 'childPos',
-    // causing this test to fail
-#else
+    if (m_platform == QStringLiteral("xcb"))
+        QEXPECT_FAIL("", "On X11, the window manager will apply NorthWestGravity rules to 'child', which"
+                         " means the top-left corner of the window frame will be placed at 'childPos'"
+                         " causing this test to fail.", Continue);
+
     QCOMPARE(child.geometry().topLeft(), childPos);
-#endif
     QTRY_COMPARE(childTLW.pos(), tlwPos);
-
-    // This following part of the test only makes sense on Windows.
-#ifdef Q_WS_WIN
-    QWidget childTLWChild(&childTLW);
-    childTLWChild.setObjectName("childTLWChild");
-
-    QWidget grandChild(&child);
-    grandChild.setObjectName("grandChild");
-    grandChild.setGeometry(10, 10, 160, 110);
-    QPalette pal3;
-    pal3.setColor(grandChild.backgroundRole(), Qt::red);
-    grandChild.setPalette(pal3);
-    //grandChild.setPaletteBackgroundColor(Qt::red);
-
-    QWidget grandChildTLW(&grandChild, Qt::Window);
-    grandChildTLW.setObjectName("grandChildTLW");
-    grandChildTLW.setGeometry(200, 200, 50, 50);
-    QPalette pal4;
-    pal4.setColor(grandChildTLW.backgroundRole(), Qt::yellow);
-    grandChildTLW.setPalette(pal4);
-    //grandChildTLW.setPaletteBackgroundColor(Qt::yellow);
-
-    QWidget grandChildTLWChild(&grandChildTLW);
-    grandChildTLWChild.setObjectName("grandChildTLWChild");
-
-    QVERIFY(IsWindow(childTLW.winId()));
-    QVERIFY(IsWindow(childTLWChild.winId()));
-    QVERIFY(IsWindow(grandChildTLW.winId()));
-    QVERIFY(IsWindow(grandChildTLWChild.winId()));
-
-    parent.show();
-
-    QVERIFY(IsWindow(childTLW.winId()));
-    QVERIFY(IsWindow(childTLWChild.winId()));
-    QVERIFY(IsWindow(grandChildTLW.winId()));
-    QVERIFY(IsWindow(grandChildTLWChild.winId()));
-
-    child.setParent(&parent);
-    child.move(10,10);
-    child.show();
-
-    // this appears to stabelize results
-    qApp->processEvents();
-
-    QVERIFY(IsWindow(childTLW.winId()));
-    QVERIFY(IsWindow(childTLWChild.winId()));
-
-    QVERIFY(IsWindow(grandChildTLW.winId()));
-    QVERIFY(IsWindow(grandChildTLWChild.winId()));
-#endif
 }
 
 // Qt/Embedded does it differently.
-#ifndef Q_WS_QWS
 void tst_QWidget::icon()
 {
     QPixmap p(20,20);
@@ -2382,7 +2251,6 @@ void tst_QWidget::icon()
     testWidget->showNormal();
     QVERIFY(!testWidget->windowIcon().isNull());
 }
-#endif
 
 void tst_QWidget::hideWhenFocusWidgetIsChild()
 {
@@ -2403,10 +2271,9 @@ void tst_QWidget::hideWhenFocusWidgetIsChild()
     edit->setFocus();
     qApp->processEvents();
     QString actualFocusWidget, expectedFocusWidget;
-#ifdef Q_WS_X11
-    if (!qApp->focusWidget())
-        QSKIP("Your window manager is too broken for this test");
-#endif
+    if (!qApp->focusWidget() && m_platform == QStringLiteral("xcb"))
+        QSKIP("X11: Your window manager is too broken for this test");
+
     QVERIFY(qApp->focusWidget());
     actualFocusWidget.sprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className());
     expectedFocusWidget.sprintf("%p %s %s", edit, edit->objectName().toLatin1().constData(), edit->metaObject()->className());
@@ -2422,8 +2289,6 @@ void tst_QWidget::hideWhenFocusWidgetIsChild()
     delete parentWidget;
 }
 
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
 void tst_QWidget::normalGeometry()
 {
     QWidget parent;
@@ -2525,7 +2390,6 @@ void tst_QWidget::normalGeometry()
     QTest::qWait(10);
     QTRY_COMPARE(parent.normalGeometry(), geom);
 }
-#endif
 
 void tst_QWidget::setGeometry()
 {
@@ -2646,7 +2510,7 @@ public:
 
 void tst_QWidget::lostUpdatesOnHide()
 {
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
     UpdateWidget widget;
     widget.setAttribute(Qt::WA_DontShowOnScreen);
     widget.show();
@@ -2860,17 +2724,13 @@ void tst_QWidget::stackUnder()
     parent->show();
     QTest::qWaitForWindowShown(parent);
     QTest::qWait(10);
-#ifdef Q_WS_QWS
-    QApplication::sendPostedEvents(); //glib workaround
-#endif
-
     QList<QObject *> list1;
     list1 << child1 << child2 << child3 << child4;
     QVERIFY(parent->children() == list1);
 
     foreach (UpdateWidget *child, allChildren) {
         int expectedPaintEvents = child == child4 ? 1 : 0;
-#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
+#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
         if (expectedPaintEvents == 1 && child->numPaintEvents == 2)
             QEXPECT_FAIL(0, "Mac and Windows issues double repaints for Z-Order change", Continue);
 #endif
@@ -2909,7 +2769,7 @@ void tst_QWidget::stackUnder()
 #ifdef Q_OS_WINCE
             qApp->processEvents();
 #endif
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
             QEXPECT_FAIL(0, "See QTBUG-493", Continue);
 #endif
             QCOMPARE(child->numPaintEvents, 0);
@@ -2969,13 +2829,9 @@ protected:
 void tst_QWidget::testContentsPropagation()
 {
     ContentsPropagationWidget widget;
-#ifdef Q_WS_QWS
-    widget.resize(500,500);
-#else
     widget.setFixedSize(500, 500);
-#endif
     widget.setContentsPropagation(false);
-    QPixmap widgetSnapshot = QPixmap::grabWidget(&widget);
+    QPixmap widgetSnapshot = widget.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
 
     QPixmap correct(500, 500);
     drawPolygon(&correct, 500, 500);
@@ -2985,7 +2841,7 @@ void tst_QWidget::testContentsPropagation()
     QVERIFY(widgetSnapshot.toImage() != correct.toImage());
 
     widget.setContentsPropagation(true);
-    widgetSnapshot = QPixmap::grabWidget(&widget);
+    widgetSnapshot = widgetSnapshot = widget.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
     //widgetSnapshot.save("snap2.png", "PNG");
 
     QCOMPARE(widgetSnapshot, correct);
@@ -2995,8 +2851,7 @@ void tst_QWidget::testContentsPropagation()
     Test that saving and restoring window geometry with
     saveGeometry() and restoreGeometry() works.
 */
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
+
 void tst_QWidget::saveRestoreGeometry()
 {
     const QPoint position(100, 100);
@@ -3125,10 +2980,7 @@ void tst_QWidget::saveRestoreGeometry()
         QTRY_COMPARE(widget.geometry(), geom);
     }
 }
-#endif
 
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
 void tst_QWidget::restoreVersion1Geometry_data()
 {
     QTest::addColumn<QString>("fileName");
@@ -3203,9 +3055,7 @@ void tst_QWidget::restoreVersion1Geometry()
         widgetToSave.move(expectedPosition);
         widgetToSave.resize(expectedSize);
         widgetToSave.show();
-#ifdef Q_WS_X11
-        qt_x11_wait_for_window_manager(&widget);
-#endif
+        QTest::qWaitForWindowShown(widget.windowHandle());
         QTest::qWait(500); // stabilize
         widgetToSave.setWindowState(Qt::WindowStates(expectedWindowState));
         QTest::qWait(500); // stabilize
@@ -3220,7 +3070,6 @@ void tst_QWidget::restoreVersion1Geometry()
     }
 #endif
 }
-#endif
 
 void tst_QWidget::widgetAt()
 {
@@ -3276,11 +3125,13 @@ void tst_QWidget::widgetAt()
 #if defined(Q_OS_WINCE)
     QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191
 #endif
-    /// ### fixme: Check platforms
-    QEXPECT_FAIL("", "Window mask not implemented on Lighthouse QTBUG-22326", Continue);
+    if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive))
+        QEXPECT_FAIL("", "Window mask not implemented on Mac QTBUG-22326", Continue);
 
-    QTRY_COMPARE(QApplication::widgetAt(100,100)->objectName(), w1->objectName());
-    QTRY_COMPARE(QApplication::widgetAt(101,101)->objectName(), w2->objectName());
+    QTRY_VERIFY((wr = QApplication::widgetAt(100,100)));
+    QTRY_COMPARE(wr->objectName(), w1->objectName());
+    QTRY_VERIFY((wr = QApplication::widgetAt(101,101)));
+    QTRY_COMPARE(wr->objectName(), w2->objectName());
 
     QBitmap bitmap(w2->size());
     QPainter p(&bitmap);
@@ -3294,8 +3145,8 @@ void tst_QWidget::widgetAt()
 #if defined(Q_OS_WINCE)
     QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191
 #endif
-    /// ### fixme: Check platforms
-    QEXPECT_FAIL("", "Window mask not implemented on Lighthouse  QTBUG-22326", Continue);
+    if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive))
+        QEXPECT_FAIL("", "Window mask not implemented on Mac QTBUG-22326", Continue);
     QTRY_VERIFY(QApplication::widgetAt(100,100) == w1);
     QTRY_VERIFY(QApplication::widgetAt(101,101) == w2);
 
@@ -3303,57 +3154,6 @@ void tst_QWidget::widgetAt()
     delete w1;
 }
 
-#if defined(Q_WS_X11)
-bool getProperty(Display *display, Window target, Atom type, Atom property,
-                 unsigned char** data, unsigned long* count)
-{
-    Atom atom_return;
-    int size;
-    unsigned long nitems, bytes_left;
-
-    int ret = XGetWindowProperty(display, target, property,
-                                 0l, 1l, false,
-                                 type, &atom_return, &size,
-                                 &nitems, &bytes_left, data);
-    if (ret != Success || nitems < 1)
-        return false;
-
-    if (bytes_left != 0) {
-        XFree(*data);
-        unsigned long remain = ((size / 8) * nitems) + bytes_left;
-        ret = XGetWindowProperty(display, target,
-                                 property, 0l, remain, false,
-                                 type, &atom_return, &size,
-                                 &nitems, &bytes_left, data);
-        if (ret != Success)
-            return false;
-    }
-
-    *count = nitems;
-    return true;
-}
-
-QString textPropertyToString(Display *display, XTextProperty& text_prop)
-{
-    QString ret;
-    if (text_prop.value && text_prop.nitems > 0) {
-        if (text_prop.encoding == XA_STRING) {
-            ret = reinterpret_cast<char *>(text_prop.value);
-        } else {
-            text_prop.nitems = strlen(reinterpret_cast<char *>(text_prop.value));
-            char **list;
-            int num;
-            if (XmbTextPropertyToTextList(display, &text_prop, &list, &num) == Success
-                && num > 0 && *list) {
-                ret = QString::fromLocal8Bit(*list);
-                XFreeStringList(list);
-            }
-        }
-    }
-    return ret;
-}
-#endif
-
 void tst_QWidget::task110173()
 {
     QWidget w;
@@ -3481,99 +3281,7 @@ void tst_QWidget::testDeletionInEventHandlers()
     delete w;
 }
 
-#ifdef Q_WS_MAC
-
-/*
-    Test that retaining and releasing the HIView returned by QWidget::winId()
-    works even if the widget itself is deleted.
-*/
-void tst_QWidget::retainHIView()
-{
-    // Single window
-    {
-        const WidgetViewPair window  = createAndRetain();
-        delete window.first;
-        QVERIFY(testAndRelease(window.second));
-    }
-
-    // Child widget
-    {
-        const WidgetViewPair parent = createAndRetain();
-        const WidgetViewPair child = createAndRetain(parent.first);
-
-        delete parent.first;
-        QVERIFY(testAndRelease(parent.second));
-        QVERIFY(testAndRelease(child.second));
-    }
-
-    // Multiple children
-    {
-        const WidgetViewPair parent = createAndRetain();
-        const WidgetViewPair child1 = createAndRetain(parent.first);
-        const WidgetViewPair child2 = createAndRetain(parent.first);
-
-        delete parent.first;
-        QVERIFY(testAndRelease(parent.second));
-        QVERIFY(testAndRelease(child1.second));
-        QVERIFY(testAndRelease(child2.second));
-    }
-
-    // Grandchild widget
-    {
-        const WidgetViewPair parent = createAndRetain();
-        const WidgetViewPair child = createAndRetain(parent.first);
-        const WidgetViewPair grandchild = createAndRetain(child.first);
-
-        delete parent.first;
-        QVERIFY(testAndRelease(parent.second));
-        QVERIFY(testAndRelease(child.second));
-        QVERIFY(testAndRelease(grandchild.second));
-    }
-
-    // Reparent child widget
-    {
-        const WidgetViewPair parent1 = createAndRetain();
-        const WidgetViewPair parent2 = createAndRetain();
-        const WidgetViewPair child = createAndRetain(parent1.first);
-
-        child.first->setParent(parent2.first);
-
-        delete parent1.first;
-        QVERIFY(testAndRelease(parent1.second));
-        delete parent2.first;
-        QVERIFY(testAndRelease(parent2.second));
-        QVERIFY(testAndRelease(child.second));
-    }
-
-    // Reparent window
-    {
-        const WidgetViewPair window1 = createAndRetain();
-        const WidgetViewPair window2 = createAndRetain();
-        const WidgetViewPair child1 = createAndRetain(window1.first);
-        const WidgetViewPair child2 = createAndRetain(window2.first);
-
-        window2.first->setParent(window1.first);
-
-        delete window2.first;
-        QVERIFY(testAndRelease(window2.second));
-        QVERIFY(testAndRelease(child2.second));
-        delete window1.first;
-        QVERIFY(testAndRelease(window1.second));
-        QVERIFY(testAndRelease(child1.second));
-    }
-
-    // Delete child widget
-    {
-        const WidgetViewPair parent = createAndRetain();
-        const WidgetViewPair child = createAndRetain(parent.first);
-
-        delete child.first;
-        QVERIFY(testAndRelease(child.second));
-        delete parent.first;
-        QVERIFY(testAndRelease(parent.second));
-    }
-}
-
+#ifdef Q_OS_MAC
 void tst_QWidget::sheetOpacity()
 {
     QWidget tmpWindow;
@@ -3608,7 +3316,7 @@ public:
 */
 bool verifyWidgetMask(QWidget *widget, QRect mask)
 {
-    const QImage image = QPixmap::grabWindow(widget->winId()).toImage();
+    const QImage image = widget->grab(QRect(QPoint(0, 0), widget->size())).toImage();
 
     const QImage masked = image.copy(mask);
     QImage red(masked);
@@ -3761,7 +3469,7 @@ void tst_QWidget::optimizedResizeMove()
 
 void tst_QWidget::optimizedResize_topLevel()
 {
-#if defined(Q_WS_MAC) || defined(Q_WS_QWS)
+#if defined(Q_OS_MAC)
     QSKIP("We do not yet have static contents support for *top-levels* on this platform");
 #endif
 
@@ -3776,7 +3484,7 @@ void tst_QWidget::optimizedResize_topLevel()
     topLevel.partial = false;
     topLevel.paintedRegion = QRegion();
 
-#ifndef Q_WS_WIN
+#ifndef Q_OS_WIN
     topLevel.resize(topLevel.size() + QSize(10, 10));
 #else
     // Static contents does not work when programmatically resizing
@@ -3786,7 +3494,7 @@ void tst_QWidget::optimizedResize_topLevel()
     // WM_RESIZE in QApplication). This is a corner case, though.
     // See task 243708
     const QRect frame = topLevel.frameGeometry();
-    MoveWindow(topLevel.winId(), frame.x(), frame.y(),
+    MoveWindow(winHandleOf(&topLevel), frame.x(), frame.y(),
                frame.width() + 10, frame.height() + 10,
                true);
 #endif
@@ -3826,28 +3534,10 @@ void tst_QWidget::childDeletesItsSibling()
 
 }
 
-#ifdef Q_WS_QWS
-# define SET_SAFE_SIZE(w) \
-    do { \
-        QSize safeSize(qt_screen->width() - 250, qt_screen->height() - 250);      \
-         if (!safeSize.isValid()) \
-             QSKIP("Screen size too small"); \
-         if (defaultSize.width() > safeSize.width() || defaultSize.height() > safeSize.height()) { \
-             defaultSize = safeSize; \
-             w.resize(defaultSize); \
-             w.setAttribute(Qt::WA_Resized, false); \
-         } \
-    } while (false)
-#else
-# define SET_SAFE_SIZE(w)
-#endif
-
-
 void tst_QWidget::setMinimumSize()
 {
     QWidget w;
     QSize defaultSize = w.size();
-    SET_SAFE_SIZE(w);
 
     w.setMinimumSize(defaultSize + QSize(100, 100));
     QCOMPARE(w.size(), defaultSize + QSize(100, 100));
@@ -3877,7 +3567,6 @@ void tst_QWidget::setMaximumSize()
 {
     QWidget w;
     QSize defaultSize = w.size();
-    SET_SAFE_SIZE(w);
 
     w.setMinimumSize(defaultSize + QSize(100, 100));
     QCOMPARE(w.size(), defaultSize + QSize(100, 100));
@@ -3897,7 +3586,6 @@ void tst_QWidget::setFixedSize()
 {
     QWidget w;
     QSize defaultSize = w.size();
-    SET_SAFE_SIZE(w);
 
     w.setFixedSize(defaultSize + QSize(100, 100));
     QCOMPARE(w.size(), defaultSize + QSize(100, 100));
@@ -4379,7 +4067,7 @@ static inline bool isOpaque(QWidget *widget)
 
 void tst_QWidget::isOpaque()
 {
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
     QWidget w;
     QVERIFY(::isOpaque(&w));
 
@@ -4451,7 +4139,7 @@ void tst_QWidget::isOpaque()
 #endif
 }
 
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
 /*
     Test that scrolling of a widget invalidates the correct regions
 */
@@ -4549,7 +4237,7 @@ Q_DECLARE_METATYPE(QList<QRect>)
 
 // Since X11 WindowManager operations are all async, and we have no way to know if the window
 // manager has finished playing with the window geometry, this test can't be reliable on X11.
-#ifndef Q_WS_X11
+
 void tst_QWidget::setWindowGeometry_data()
 {
     QTest::addColumn<QList<QRect> >("rects");
@@ -4598,7 +4286,7 @@ void tst_QWidget::setWindowGeometry_data()
                           .arg(rect.y())
                           .arg(rect.width())
                           .arg(rect.height())
-                          .arg(windowFlag, 0, 16).toAscii())
+                          .arg(windowFlag, 0, 16).toLatin1())
                 << l
                 << windowFlag;
         }
@@ -4607,6 +4295,9 @@ void tst_QWidget::setWindowGeometry_data()
 
 void tst_QWidget::setWindowGeometry()
 {
+    if (m_platform == QStringLiteral("xcb"))
+         QSKIP("X11: Skip this test due to Window manager positioning issues.");
+
     QFETCH(QList<QRect>, rects);
     QFETCH(int, windowFlags);
     QRect rect = rects.takeFirst();
@@ -4727,9 +4418,8 @@ void tst_QWidget::setWindowGeometry()
         QTRY_COMPARE(widget.geometry(), rect);
     }
 }
-#endif
 
-#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
 void tst_QWidget::setGeometry_win()
 {
     QWidget widget;
@@ -4742,16 +4432,15 @@ void tst_QWidget::setGeometry_win()
     widget.setWindowState(widget.windowState() | Qt::WindowMaximized);
     widget.show();
     RECT rt;
-    ::GetWindowRect(widget.internalWinId(), &rt);
+    ::GetWindowRect(winHandleOf(&widget), &rt);
     QVERIFY(rt.left <= 0);
     QVERIFY(rt.top <= 0);
 }
-#endif
+#endif // defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
 
 // Since X11 WindowManager operation are all async, and we have no way to know if the window
 // manager has finished playing with the window geometry, this test can't be reliable on X11.
-// 4DWM issues on IRIX also makes this test fail.
-#if !defined(Q_WS_X11) && !defined(Q_OS_IRIX)
+
 void tst_QWidget::windowMoveResize_data()
 {
     setWindowGeometry_data();
@@ -4759,6 +4448,9 @@ void tst_QWidget::windowMoveResize_data()
 
 void tst_QWidget::windowMoveResize()
 {
+    if (m_platform == QStringLiteral("xcb"))
+         QSKIP("X11: Skip this test due to Window manager positioning issues.");
+
     QFETCH(QList<QRect>, rects);
     QFETCH(int, windowFlags);
 
@@ -4801,9 +4493,9 @@ void tst_QWidget::windowMoveResize()
         QTRY_COMPARE(widget.size(), rect.size());
 
         // move() while shown
-        foreach (QRect r, rects) {
-#ifdef Q_WS_X11
-            if ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0) {
+        foreach (const QRect &r, rects) {
+            if (m_platform == QStringLiteral("xcb")
+               && ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0)) {
                 QEXPECT_FAIL("130,100 0x200, flags 0",
                              "First resize after show of zero-sized gets wrong win_gravity.",
                              Continue);
@@ -4814,7 +4506,7 @@ void tst_QWidget::windowMoveResize()
                              "First resize after show of zero-sized gets wrong win_gravity.",
                              Continue);
             }
-#endif
+
             widget.move(r.topLeft());
             widget.resize(r.size());
             QApplication::processEvents();
@@ -4838,7 +4530,7 @@ void tst_QWidget::windowMoveResize()
             widget.move(r.topLeft());
             widget.resize(r.size());
             QApplication::processEvents();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_MAC)
             if (r.width() == 0 && r.height() > 0) {
                 widget.move(r.topLeft());
                 widget.resize(r.size());
@@ -4907,7 +4599,7 @@ void tst_QWidget::windowMoveResize()
             widget.move(r.topLeft());
             widget.resize(r.size());
             QApplication::processEvents();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_MAC)
             if (r.width() == 0 && r.height() > 0) {
                 widget.move(r.topLeft());
                 widget.resize(r.size());
@@ -4936,7 +4628,6 @@ void tst_QWidget::windowMoveResize()
         QTRY_COMPARE(widget.size(), rect.size());
     }
 }
-#endif
 
 class ColorWidget : public QWidget
 {
@@ -4964,10 +4655,12 @@ public:
 
 #define VERIFY_COLOR(region, color) {                                   \
     const QRegion r = QRegion(region);                                  \
+    QScreen *screen = qApp->primaryScreen();                            \
+    const WId desktopWinId = QDesktopWidget().winId();                      \
     for (int i = 0; i < r.rects().size(); ++i) {                        \
         const QRect rect = r.rects().at(i);                             \
         for (int t = 0; t < 5; t++) {                                   \
-            const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(), \
+            const QPixmap pixmap = screen->grabWindow(desktopWinId,     \
                                                    rect.left(), rect.top(), \
                                                    rect.width(), rect.height()); \
             QCOMPARE(pixmap.size(), rect.size());                       \
@@ -4986,6 +4679,51 @@ public:
     }                                                                   \
 }
 
+void tst_QWidget::popupEnterLeave()
+{
+    QWidget parent;
+    parent.setWindowFlags(Qt::FramelessWindowHint);
+    parent.setGeometry(10, 10, 200, 100);
+
+    ColorWidget alien(&parent, Qt::black);
+    alien.setGeometry(0, 0, 10, 10);
+    alien.show();
+
+    parent.show();
+
+    QTest::qWaitForWindowShown(parent.windowHandle());
+
+    QWindowSystemInterface::handleMouseEvent(parent.windowHandle(), QPointF(5, 5), QPointF(), Qt::LeftButton, Qt::NoModifier);
+    QTest::qWait(100);
+    QWindowSystemInterface::handleMouseEvent(parent.windowHandle(), QPointF(5, 5), QPointF(), Qt::NoButton, Qt::NoModifier);
+    QTest::qWait(100);
+
+    QStringList wordList;
+    wordList << "alpha" << "omega" << "omicron" << "zeta";
+
+    QLineEdit popup(&parent);
+
+    QCompleter completer(wordList);
+    completer.setCaseSensitivity(Qt::CaseInsensitive);
+    popup.setCompleter(&completer);
+    popup.setWindowFlags(Qt::Popup);
+    popup.setGeometry(20, 20, 80, 20);
+
+    popup.show();
+
+    QTest::qWaitForWindowShown(popup.windowHandle());
+
+    QTest::qWait(100);
+
+    QWindowSystemInterface::handleMouseEvent(popup.windowHandle(), QPointF(-5, -5), QPointF(), Qt::LeftButton, Qt::NoModifier);
+    QTest::qWait(100);
+    QWindowSystemInterface::handleMouseEvent(popup.windowHandle(), QPointF(-5, -5), QPointF(), Qt::NoButton, Qt::NoModifier);
+    QTest::qWait(100);
+
+    QTest::qWait(1000);
+    QVERIFY(!popup.underMouse());
+}
+
 void tst_QWidget::moveChild_data()
 {
     QTest::addColumn<QPoint>("offset");
@@ -5036,7 +4774,7 @@ void tst_QWidget::moveChild()
     QTRY_COMPARE(pos, child.pos());
 
     QCOMPARE(parent.r, QRegion(oldGeometry) - child.geometry());
-#if !defined(Q_WS_MAC)
+#if !defined(Q_OS_MAC)
     // should be scrolled in backingstore
     QCOMPARE(child.r, QRegion());
 #endif
@@ -5125,19 +4863,6 @@ void tst_QWidget::deleteStyle()
     qApp->processEvents();
 }
 
-#ifdef Q_WS_WIN
-void tst_QWidget::getDC()
-{
-    QWidget widget;
-    widget.setGeometry(0, 0, 2, 4);
-
-    HDC dc = widget.getDC();
-    QVERIFY(dc != 0);
-
-    widget.releaseDC(dc);
-}
-#endif
-
 class TopLevelFocusCheck: public QWidget
 {
     Q_OBJECT
@@ -5194,9 +4919,6 @@ void tst_QWidget::multipleToplevelFocusCheck()
     QApplication::processEvents();
     QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2));
     QTest::mouseClick(&w2, Qt::LeftButton);
-#ifdef Q_WS_QWS
-    QEXPECT_FAIL("", "embedded toplevels take focus anyway", Continue);
-#endif
     QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0);
 
     QTest::mouseDClick(&w2, Qt::LeftButton);
@@ -5217,6 +4939,27 @@ void tst_QWidget::multipleToplevelFocusCheck()
     QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0);
 }
 
+class FocusWidget: public QWidget
+{
+protected:
+    virtual bool event(QEvent *ev)
+    {
+        if (ev->type() == QEvent::FocusAboutToChange)
+            widgetDuringFocusAboutToChange = qApp->focusWidget();
+        return QWidget::event(ev);
+    }
+    virtual void focusOutEvent(QFocusEvent *)
+    {
+        widgetDuringFocusOut = qApp->focusWidget();
+    }
+
+public:
+    FocusWidget(QWidget *parent) : QWidget(parent), widgetDuringFocusAboutToChange(0), widgetDuringFocusOut(0) {}
+
+    QWidget *widgetDuringFocusAboutToChange;
+    QWidget *widgetDuringFocusOut;
+};
+
 void tst_QWidget::setFocus()
 {
     {
@@ -5283,20 +5026,16 @@ void tst_QWidget::setFocus()
         // window and children show, but window *is* active, children get focus
         QWidget window;
 
-        QWidget child1(&window);
+        FocusWidget child1(&window);
         child1.setFocusPolicy(Qt::StrongFocus);
 
         QWidget child2(&window);
         child2.setFocusPolicy(Qt::StrongFocus);
 
         window.show();
-#ifdef Q_WS_X11
-        QApplication::setActiveWindow(&window);
-        QTest::qWaitForWindowShown(&window);
-#else
         window.activateWindow();
-        QApplication::processEvents();
-#endif
+        QTest::qWaitForWindowShown(&window);
+        QTRY_VERIFY(qGuiApp->focusWindow());
 
         child1.setFocus();
         QTRY_VERIFY(child1.hasFocus());
@@ -5307,6 +5046,10 @@ void tst_QWidget::setFocus()
         QVERIFY(child2.hasFocus());
         QCOMPARE(window.focusWidget(), &child2);
         QCOMPARE(QApplication::focusWidget(), &child2);
+
+        // focus changed in between the events
+        QCOMPARE(child1.widgetDuringFocusAboutToChange, &child1);
+        QCOMPARE(child1.widgetDuringFocusOut, &child2);
     }
 
     {
@@ -5314,12 +5057,9 @@ void tst_QWidget::setFocus()
         QWidget window;
 
         window.show();
-#ifdef Q_WS_X11
-        QApplication::setActiveWindow(&window);
-        QTest::qWaitForWindowShown(&window);
-#else
         window.activateWindow();
-#endif
+        QTest::qWaitForWindowShown(&window);
+        QTRY_VERIFY(qGuiApp->focusWindow());
 
         QWidget child1(&window);
         child1.setFocusPolicy(Qt::StrongFocus);
@@ -5333,10 +5073,6 @@ void tst_QWidget::setFocus()
         QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0));
 
         child1.show();
-#ifdef Q_WS_X11
-        QApplication::setActiveWindow(&child1);
-        child1.activateWindow();
-#endif
         QApplication::processEvents();
         QTRY_VERIFY(child1.hasFocus());
         QCOMPARE(window.focusWidget(), &child1);
@@ -5359,12 +5095,9 @@ void tst_QWidget::setFocus()
         QWidget window;
 
         window.show();
-#ifdef Q_WS_X11
-        QApplication::setActiveWindow(&window);
-        QTest::qWaitForWindowShown(&window);
-#else
         window.activateWindow();
-#endif
+        QTest::qWaitForWindowShown(&window);
+        QTRY_VERIFY(qGuiApp->focusWindow());
 
         QWidget child1(&window);
         child1.setFocusPolicy(Qt::StrongFocus);
@@ -5661,9 +5394,10 @@ void tst_QWidget::testWindowIconChangeEventPropagation()
     qApp->setWindowIcon(QIcon());
 }
 
-#ifdef Q_WS_X11
 void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
 {
+    if (m_platform != QStringLiteral("xcb"))
+        QSKIP("This test is for X11 only.");
     // Same size as in QWidget::create_sys().
     const QSize desktopSize = QApplication::desktop()->size();
     const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10);
@@ -5676,7 +5410,7 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
     QCOMPARE(widget.size(), newMaximumSize);
 
     widget.show();
-    qt_x11_wait_for_window_manager(&widget);
+    QTest::qWaitForWindowShown(widget.windowHandle());
     QCOMPARE(widget.size(), newMaximumSize);
     }
 
@@ -5688,7 +5422,7 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
     QCOMPARE(widget.size(), newMinimumSize);
 
     widget.show();
-    qt_x11_wait_for_window_manager(&widget);
+    QTest::qWaitForWindowShown(widget.windowHandle());
     QCOMPARE(widget.size(), newMinimumSize);
     }
 }
@@ -5719,10 +5453,16 @@ public:
         }
     }
 
-    bool x11Event(XEvent *event)
+    bool nativeEvent(const QByteArray &eventType, void *message, long *)
     {
-        if (state == 1 && event->type == MapNotify)
-            gotExpectedMapNotify = true;
+        enum { XCB_MAP_NOTIFY = 19 };
+
+        if (state == 1 && eventType == QByteArrayLiteral("xcb_generic_event_t")) {
+            // XCB events have a uint8 response_type member at the beginning.
+            const unsigned char responseType = *(const unsigned char *)(message);
+            if ((responseType & ~0x80) == XCB_MAP_NOTIFY)
+                gotExpectedMapNotify = true;
+        }
         return false;
     }
 
@@ -5730,8 +5470,11 @@ signals:
     void done();
 };
 
-void tst_QWidget::showHideShow()
+void tst_QWidget::showHideShowX11()
 {
+    if (m_platform != QStringLiteral("xcb"))
+        QSKIP("This test is for X11 only.");
+
     ShowHideShowWidget w;
     w.show();
     w.hide();
@@ -5745,6 +5488,9 @@ void tst_QWidget::showHideShow()
 
 void tst_QWidget::clean_qt_x11_enforce_cursor()
 {
+    if (m_platform != QStringLiteral("xcb"))
+        QSKIP("This test is for X11 only.");
+
     {
         QWidget window;
         QWidget *w = new QWidget(&window);
@@ -5771,7 +5517,6 @@ void tst_QWidget::clean_qt_x11_enforce_cursor()
 
     // If the test didn't crash, then it passed.
 }
-#endif
 
 class EventRecorder : public QObject
 {
@@ -5809,7 +5554,6 @@ private:
 void tst_QWidget::childEvents()
 {
     EventRecorder::EventList expected;
-    bool accessibilityEnabled = false;
 
     // Move away the cursor; otherwise it might result in an enter event if it's
     // inside the widget when the widget is shown.
@@ -5851,8 +5595,6 @@ void tst_QWidget::childEvents()
             << qMakePair(&widget, QEvent::Resize)
             << qMakePair(&widget, QEvent::Show);
 
-        if (accessibilityEnabled)
-            expected << qMakePair(&widget, QEvent::AccessibilityPrepare);
         expected << qMakePair(&widget, QEvent::ShowToParent);
         QCOMPARE(spy.eventList(), expected);
         spy.clear();
@@ -5936,8 +5678,6 @@ void tst_QWidget::childEvents()
             << qMakePair(&widget, QEvent::Resize)
             << qMakePair(&widget, QEvent::Show);
 
-        if (accessibilityEnabled)
-            expected << qMakePair(&widget, QEvent::AccessibilityPrepare);
         expected << qMakePair(&widget, QEvent::ShowToParent);
         QCOMPARE(spy.eventList(), expected);
         spy.clear();
@@ -6024,8 +5764,6 @@ void tst_QWidget::childEvents()
             << qMakePair(&widget, QEvent::Resize)
             << qMakePair(&widget, QEvent::Show);
 
-        if (accessibilityEnabled)
-            expected << qMakePair(&widget, QEvent::AccessibilityPrepare);
         expected << qMakePair(&widget, QEvent::ShowToParent);
         QCOMPARE(spy.eventList(), expected);
         spy.clear();
@@ -6099,9 +5837,9 @@ void tst_QWidget::render()
     qApp->sendPostedEvents();
     QTest::qWait(250);
 
-    QImage sourceImage = QPixmap::grabWidget(&source).toImage();
+    const QImage sourceImage = source.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
     qApp->processEvents();
-    QImage targetImage = QPixmap::grabWidget(&target).toImage();
+    QImage targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
     qApp->processEvents();
     QCOMPARE(sourceImage, targetImage);
 
@@ -6112,7 +5850,7 @@ void tst_QWidget::render()
     qApp->processEvents();
     qApp->sendPostedEvents();
 
-    targetImage = QPixmap::grabWidget(&target).toImage();
+    targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
     QVERIFY(sourceImage != targetImage);
 
     QCOMPARE(targetImage.pixel(target.width() / 2, 29), QColor(Qt::red).rgb());
@@ -6131,7 +5869,9 @@ void tst_QWidget::render()
         child.show();
 
         qApp->processEvents();
-        QCOMPARE(QPixmap::grabWidget(&child), QPixmap::grabWidget(&window));
+        const QPixmap childPixmap = child.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
+        const QPixmap windowPixmap = window.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
+        QCOMPARE(childPixmap, windowPixmap);
     }
 
     { // Check that the target offset is correct.
@@ -6169,7 +5909,7 @@ void tst_QWidget::render()
 // in testing the geometry so just workaround the palette issue for now.
 static void workaroundPaletteIssue(QWidget *widget)
 {
-#ifndef Q_WS_WIN
+#ifndef Q_OS_WIN
     return;
 #endif
     if (!widget)
@@ -6494,7 +6234,8 @@ void tst_QWidget::render_task188133()
 
     // Make sure QWidget::render does not trigger QWidget::repaint/update
     // and asserts for Qt::WA_WState_Created.
-    QPixmap pixmap = QPixmap::grabWidget(&mainWindow);
+    const QPixmap pixmap = mainWindow.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
+    Q_UNUSED(pixmap)
 }
 
 void tst_QWidget::render_task211796()
@@ -6557,10 +6298,10 @@ void tst_QWidget::render_windowOpacity()
     child.setAutoFillBackground(true);
 
     QPixmap expected(child.size());
-#ifdef Q_WS_X11
-    if (expected.depth() < 24)
+
+    if (m_platform == QStringLiteral("xcb") && expected.depth() < 24)
         QSKIP("This test won't give correct results with dithered pixmaps");
-#endif
+
     expected.fill(Qt::green);
     QPainter painter(&expected);
     painter.setOpacity(opacity);
@@ -6674,7 +6415,7 @@ void tst_QWidget::render_systemClip()
     // rrrrrrrrrr
     // ...
 
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
     for (int i = 0; i < image.height(); ++i) {
         for (int j = 0; j < image.width(); ++j) {
             if (i < 50 && j < i)
@@ -7021,8 +6762,6 @@ void tst_QWidget::setContentsMargins()
     QCOMPARE(newSize, label3.sizeHint());
 }
 
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
 void tst_QWidget::moveWindowInShowEvent_data()
 {
     QTest::addColumn<QPoint>("initial");
@@ -7060,18 +6799,15 @@ void tst_QWidget::moveWindowInShowEvent()
 
     // show it
     widget.show();
-    #ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(&widget);
-    #endif
+    QTest::qWaitForWindowShown(widget.windowHandle());
     QTest::qWait(100);
     // it should have moved
     QCOMPARE(widget.pos(), position);
 }
-#endif
 
 void tst_QWidget::repaintWhenChildDeleted()
 {
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
     if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) {
         QTest::qWait(1000);
     }
@@ -7144,7 +6880,7 @@ void tst_QWidget::hideOpaqueChildWhileHidden()
 }
 
 // This test doesn't make sense without support for showMinimized().
-#if !defined(Q_OS_WINCE) && !defined(Q_WS_QWS)
+#if !defined(Q_OS_WINCE)
 void tst_QWidget::updateWhileMinimized()
 {
     UpdateWidget widget;
@@ -7177,7 +6913,6 @@ void tst_QWidget::updateWhileMinimized()
 }
 #endif
 
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
 class PaintOnScreenWidget: public QWidget
 {
 public:
@@ -7185,7 +6920,7 @@ public:
         :QWidget(parent, f)
     {
     }
-#if defined(Q_WS_WIN)
+#if defined(Q_OS_WIN)
     // This is the only way to enable PaintOnScreen on Windows.
     QPaintEngine * paintEngine () const {return 0;}
 #endif
@@ -7193,6 +6928,9 @@ public:
 
 void tst_QWidget::alienWidgets()
 {
+    if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows"))
+        QSKIP("This test is only for X11/Windows.");
+
     qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
     QWidget parent;
     QWidget child(&parent);
@@ -7200,9 +6938,7 @@ void tst_QWidget::alienWidgets()
     QWidget greatGrandChild(&grandChild);
     parent.show();
 
-#ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(&parent);
-#endif
+    QTest::qWaitForWindowShown(parent.windowHandle());
 
     // Verify that the WA_WState_Created attribute is set
     // and the top-level is the only native window.
@@ -7273,36 +7009,20 @@ void tst_QWidget::alienWidgets()
         widget.show();
         QVERIFY(widget.testAttribute(Qt::WA_WState_Created));
         QVERIFY(!widget.internalWinId());
-#ifdef Q_WS_X11
-        widget.handle();
-#else
-        widget.getDC();
-#endif
-        QVERIFY(widget.internalWinId());
-    }
 
-#ifdef Q_WS_X11
-#ifndef QT_NO_XRENDER
-    { // Enforce a native window when calling QWidget::x11PictureHandle().
-        QWidget widget(&parent);
-        widget.show();
-        QVERIFY(widget.testAttribute(Qt::WA_WState_Created));
-        QVERIFY(!widget.internalWinId());
-        widget.x11PictureHandle();
+        widget.winId();
         QVERIFY(widget.internalWinId());
     }
-#endif
 
-    { // Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes
-      // on alien widgets (see task 194231).
+    if (m_platform == QStringLiteral("xcb")) {
+        // Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes
+        // on alien widgets (see task 194231).
         QWidget dummy;
         QVERIFY(dummy.winId());
         QWidget widget(&dummy);
         widget.setAttribute(Qt::WA_X11NetWmWindowTypeToolBar);
         QVERIFY(!widget.internalWinId());
     }
-#endif
-
 
     { // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show().
         QWidget topLevel;
@@ -7409,7 +7129,6 @@ void tst_QWidget::alienWidgets()
         QVERIFY(toolBar->testAttribute(Qt::WA_NativeWindow));
     }
 }
-#endif // Q_WS_WIN / Q_WS_X11
 
 class ASWidget : public QWidget
 {
@@ -7637,21 +7356,12 @@ void tst_QWidget::updateGeometry()
 
 void tst_QWidget::sendUpdateRequestImmediately()
 {
-#ifdef Q_WS_MAC
-    if (!QApplicationPrivate::graphicsSystem())
-        QSKIP("We only send update requests on the Mac when passing -graphicssystem");
-#endif
-
     UpdateWidget updateWidget;
     updateWidget.show();
-#ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(&updateWidget);
-#endif
+
+    QTest::qWaitForWindowShown(updateWidget.windowHandle());
 
     qApp->processEvents();
-#ifdef Q_WS_QWS
-    QApplication::sendPostedEvents(); //glib workaround
-#endif
     updateWidget.reset();
 
     QCOMPARE(updateWidget.numUpdateRequestEvents, 0);
@@ -7659,11 +7369,9 @@ void tst_QWidget::sendUpdateRequestImmediately()
     QCOMPARE(updateWidget.numUpdateRequestEvents, 1);
 }
 
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
 void tst_QWidget::doubleRepaint()
 {
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_MAC)
     if (!macHasAccessToWindowsServer())
         QSKIP("Not having window server access causes the wrong number of repaints to be issues");
 #endif
@@ -7692,10 +7400,7 @@ void tst_QWidget::doubleRepaint()
    QTest::qWait(10);
    QCOMPARE(widget.numPaintEvents, 0);
 }
-#endif
 
-#ifndef Q_WS_MAC
-// This test only makes sense on the Mac when passing -graphicssystem.
 void tst_QWidget::resizeInPaintEvent()
 {
     QWidget window;
@@ -7736,9 +7441,7 @@ void tst_QWidget::opaqueChildren()
     greatGrandChild.setAutoFillBackground(true); // Opaque child widget.
 
     widget.show();
-#ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(&widget);
-#endif
+    QTest::qWaitForWindowShown(widget.windowHandle());
     QTest::qWait(100);
 
     // Child, grandChild and greatGrandChild are outside the ancestor clip.
@@ -7759,7 +7462,6 @@ void tst_QWidget::opaqueChildren()
     greatGrandChild.setAutoFillBackground(false);
     QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), QRegion());
 }
-#endif
 
 
 class MaskSetWidget : public QWidget
@@ -7868,10 +7570,11 @@ void tst_QWidget::moveInResizeEvent()
     QTRY_COMPARE(testWidget.geometry(), expectedGeometry);
 }
 
-
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
 void tst_QWidget::immediateRepaintAfterShow()
 {
+    if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows"))
+        QSKIP("We don't support immediate repaint right after show on other platforms.");
+
     UpdateWidget widget;
     widget.show();
     qApp->processEvents();
@@ -7885,11 +7588,12 @@ void tst_QWidget::immediateRepaintAfterShow()
 
 void tst_QWidget::immediateRepaintAfterInvalidateBuffer()
 {
+    if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows"))
+        QSKIP("We don't support immediate repaint right after show on other platforms.");
+
     QWidget *widget = new UpdateWidget;
     widget->show();
-#ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(widget);
-#endif
+    QTest::qWaitForWindowShown(widget->windowHandle());
     QTest::qWait(200);
 
     static_cast<UpdateWidget *>(widget)->numPaintEvents = 0;
@@ -7907,7 +7611,6 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer()
 
     delete widget;
 }
-#endif
 
 void tst_QWidget::effectiveWinId()
 {
@@ -8062,31 +7765,44 @@ void tst_QWidget::moveRect()
     child.move(10, 10); // Don't crash.
 }
 
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
 class GDIWidget : public QDialog
 {
+    Q_OBJECT
 public:
     GDIWidget() { setAttribute(Qt::WA_PaintOnScreen); }
     QPaintEngine *paintEngine() const { return 0; }
 
 
     void paintEvent(QPaintEvent *) {
-        HDC hdc = getDC();
+        QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface();
+        const HDC hdc = (HDC)ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle());
+        if (!hdc) {
+            qWarning("%s: Unable to obtain native DC.", Q_FUNC_INFO);
+            QTimer::singleShot(0, this, SLOT(reject()));
+            return;
+        }
         SelectObject(hdc, CreateSolidBrush(RGB(255, 0, 0)));
         Rectangle(hdc, 0, 0, 10, 10);
 
-        releaseDC(hdc);
-
-        QImage im = QPixmap::grabWindow(winId(), 0, 0, width(), height()).toImage();
-        color = im.pixel(1, 1);
+        ni->nativeResourceForWindow(QByteArrayLiteral("releaseDC"), windowHandle());
 
-        accept();
+        QTimer::singleShot(0, this, SLOT(slotTimer()));
     }
 
     QSize sizeHint() const {
         return QSize(400, 300);
     }
 
+private slots:
+    void slotTimer() {
+        QScreen *screen = windowHandle()->screen();
+        const QImage im = screen->grabWindow(internalWinId(), 0, 0, -1, -1).toImage();
+        color = im.pixel(1, 1);
+        accept();
+    }
+
+public:
     QColor color;
 };
 
@@ -8109,7 +7825,7 @@ void tst_QWidget::paintOnScreenPossible()
     w2.setAttribute(Qt::WA_PaintOnScreen);
     QVERIFY(w2.testAttribute(Qt::WA_PaintOnScreen));
 }
-#endif
+#endif // Q_OS_WIN
 
 void tst_QWidget::reparentStaticWidget()
 {
@@ -8210,34 +7926,6 @@ void tst_QWidget::QTBUG6883_reparentStaticWidget2()
     //do not crash
 }
 
-#ifdef Q_WS_QWS
-void tst_QWidget::updateOutsideSurfaceClip()
-{
-    UpdateWidget widget;
-    widget.setWindowFlags(Qt::FramelessWindowHint);
-    widget.resize(100, 100);
-    widget.raise();
-    widget.show();
-    QTest::qWait(200);
-    widget.reset();
-
-    // Move widget partially outside buffer and change the surface clip.
-    widget.move(-50, 0);
-    QTest::qWait(100);
-
-    // Update region is outside the surface clip and should not trigger a repaint.
-    widget.update(0, 0, 20, 20);
-    QTest::qWait(100);
-    QCOMPARE(widget.numPaintEvents, 0);
-
-    // Now, move the widget back so that the update region is inside the clip
-    // and make sure we get a repaint of the dirty area.
-    widget.move(0, 0);
-    QTest::qWait(100);
-    QCOMPARE(widget.numPaintEvents, 1);
-    QCOMPARE(widget.paintedRegion, QRegion(0, 0, 20, 20));
-}
-#endif
 class ColorRedWidget : public QWidget
 {
 public:
@@ -8259,22 +7947,21 @@ void tst_QWidget::translucentWidget()
     ColorRedWidget label;
     label.setFixedSize(16,16);
     label.setAttribute(Qt::WA_TranslucentBackground);
-    label.move(qApp->desktop()->availableGeometry().topLeft());
+    const QPoint labelPos = qApp->desktop()->availableGeometry().topLeft();
+    label.move(labelPos);
     label.show();
-#ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(&label);
-#endif
+    QTest::qWaitForWindowShown(label.windowHandle());
     QTest::qWait(200);
 
     QPixmap widgetSnapshot;
 
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
     QWidget *desktopWidget = QApplication::desktop()->screen(0);
     if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA)
-        widgetSnapshot = QPixmap::grabWindow(desktopWidget->winId(), 0,0, label.width(), label.height());
+        widgetSnapshot = qApp->primaryScreen()->grabWindow(desktopWidget->winId(), labelPos.x(), labelPos.y(), label.width(), label.height());
     else
 #endif
-        widgetSnapshot = QPixmap::grabWindow(label.winId());
+        widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
     QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32);
     QImage expected = pm.toImage().convertToFormat(QImage::Format_RGB32);
     QCOMPARE(actual.size(),expected.size());
@@ -8326,10 +8013,10 @@ void tst_QWidget::setClearAndResizeMask()
     const QRegion topLevelMask(0, 0, 100, 100, QRegion::Ellipse);
     topLevel.setMask(topLevelMask);
     QCOMPARE(topLevel.mask(), topLevelMask);
-#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms.
-    // and ensure that the top-level doesn't get any update.
-    QCOMPARE(topLevel.numPaintEvents, 0);
-#endif
+    // Ensure that the top-level doesn't get any update.
+    // We don't control what's happening on platforms other than X11, Windows
+    if (m_platform == QStringLiteral("xcb") || m_platform == QStringLiteral("windows"))
+        QCOMPARE(topLevel.numPaintEvents, 0);
 
     topLevel.reset();
 
@@ -8339,11 +8026,12 @@ void tst_QWidget::setClearAndResizeMask()
     QTest::qWait(10);
     QRegion outsideOldMask(topLevel.rect());
     outsideOldMask -= topLevelMask;
-#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms.
-    // and ensure that the top-level gets an update for the area outside the old mask.
-    QTRY_VERIFY(topLevel.numPaintEvents > 0);
-    QTRY_COMPARE(topLevel.paintedRegion, outsideOldMask);
-#endif
+    // Ensure that the top-level gets an update for the area outside the old mask.
+    // We don't control what's happening on platforms other than X11, Windows
+    if (m_platform == QStringLiteral("xcb") || m_platform == QStringLiteral("windows")) {
+        QTRY_VERIFY(topLevel.numPaintEvents > 0);
+        QTRY_COMPARE(topLevel.paintedRegion, outsideOldMask);
+    }
 
     UpdateWidget child(&topLevel);
     child.setAutoFillBackground(true); // NB! Opaque child.
@@ -8361,7 +8049,7 @@ void tst_QWidget::setClearAndResizeMask()
     QTRY_COMPARE(child.mask(), childMask);
     QTest::qWait(50);
     // and ensure that the child widget doesn't get any update.
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     // Mac always issues a full update when calling setMask, and we cannot force it to not do so.
     if (child.internalWinId())
         QCOMPARE(child.numPaintEvents, 1);
@@ -8384,7 +8072,7 @@ void tst_QWidget::setClearAndResizeMask()
     // and ensure that that the child widget gets an update for the area outside the old mask.
     QTRY_COMPARE(child.numPaintEvents, 1);
     outsideOldMask = child.rect();
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     // Mac always issues a full update when calling setMask, and we cannot force it to not do so.
     if (!child.internalWinId())
 #endif
@@ -8399,7 +8087,7 @@ void tst_QWidget::setClearAndResizeMask()
     // Mask child widget with a mask that is bigger than the rect
     child.setMask(QRegion(0, 0, 1000, 1000));
     QTest::qWait(100);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     // Mac always issues a full update when calling setMask, and we cannot force it to not do so.
     if (child.internalWinId())
         QTRY_COMPARE(child.numPaintEvents, 1);
@@ -8412,7 +8100,7 @@ void tst_QWidget::setClearAndResizeMask()
     // ...and the same applies when clearing the mask.
     child.clearMask();
     QTest::qWait(100);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     // Mac always issues a full update when calling setMask, and we cannot force it to not do so.
     if (child.internalWinId())
         QTRY_VERIFY(child.numPaintEvents > 0);
@@ -8442,7 +8130,7 @@ void tst_QWidget::setClearAndResizeMask()
 
     QTimer::singleShot(100, &resizeChild, SLOT(shrinkMask()));
     QTest::qWait(200);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     // Mac always issues a full update when calling setMask, and we cannot force it to not do so.
     if (child.internalWinId())
         QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
@@ -8454,7 +8142,7 @@ void tst_QWidget::setClearAndResizeMask()
     const QRegion oldMask = resizeChild.mask();
     QTimer::singleShot(0, &resizeChild, SLOT(enlargeMask()));
     QTest::qWait(100);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     // Mac always issues a full update when calling setMask, and we cannot force it to not do so.
     if (child.internalWinId())
         QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
@@ -8647,9 +8335,8 @@ void tst_QWidget::syntheticEnterLeave()
 
     window.show();
     window.raise();
-#ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(&window);
-#endif
+
+    QTest::qWaitForWindowShown(window.windowHandle());
     QTest::qWait(300);
 
 #define RESET_EVENT_COUNTS \
@@ -8750,9 +8437,7 @@ void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave()
      SELChild child(&parent);
      child.resize(200, 200);
      parent.show();
- #ifdef Q_WS_X11
-     qt_x11_wait_for_window_manager(&parent);
- #endif
+     QTest::qWaitForWindowShown(parent.windowHandle());
      QTest::qWait(150);
 
      QCursor::setPos(child.mapToGlobal(QPoint(100, 100)));
@@ -8829,42 +8514,6 @@ void tst_QWidget::initialPosForDontShowOnScreenWidgets()
     }
 }
 
-#ifdef Q_WS_X11
-void tst_QWidget::paintOutsidePaintEvent()
-{
-    QWidget widget;
-    widget.resize(200, 200);
-
-    QWidget child1(&widget);
-    child1.resize(100, 100);
-    child1.setPalette(Qt::red);
-    child1.setAutoFillBackground(true);
-
-    QWidget child2(&widget);
-    child2.setGeometry(50, 50, 100, 100);
-    child2.setPalette(Qt::blue);
-    child2.setAutoFillBackground(true);
-
-    widget.show();
-    QTest::qWaitForWindowShown(&widget);
-    QTest::qWait(60);
-
-    const QPixmap before = QPixmap::grabWindow(widget.winId());
-
-    // Child 1 should be clipped by child 2, so nothing should change.
-    child1.setAttribute(Qt::WA_PaintOutsidePaintEvent);
-    QPainter painter(&child1);
-    painter.fillRect(child1.rect(), Qt::red);
-    painter.end();
-    XSync(QX11Info::display(), false); // Flush output buffer.
-    QTest::qWait(60);
-
-    const QPixmap after = QPixmap::grabWindow(widget.winId());
-
-    QCOMPARE(before, after);
-}
-#endif
-
 class MyEvilObject : public QObject
 {
     Q_OBJECT
@@ -8890,9 +8539,7 @@ void tst_QWidget::updateOnDestroyedSignal()
     child->setPalette(Qt::red);
 
     widget.show();
-#ifdef Q_WS_X11
-    qt_x11_wait_for_window_manager(&widget);
-#endif
+    QTest::qWaitForWindowShown(widget.windowHandle());
     QTest::qWait(200);
 
     // Please do not crash.
@@ -8945,9 +8592,7 @@ void tst_QWidget::destroyBackingStore()
 
     w.update();
     QApplication::processEvents();
-#ifdef Q_WS_QWS
-    QApplication::processEvents();
-#endif
+
     QCOMPARE(w.numPaintEvents, 1);
 
     // Check one more time, because the second time around does more caching.
@@ -8955,7 +8600,7 @@ void tst_QWidget::destroyBackingStore()
     QApplication::processEvents();
     QCOMPARE(w.numPaintEvents, 2);
 }
-#endif
+#endif // QT_BUILD_INTERNAL
 
 // Helper function
 QWidgetBackingStore* backingStore(QWidget &widget)
@@ -9001,8 +8646,9 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779()
 
     QPixmap correct(main.size());
     correct.fill(Qt::green);
+    const QPixmap mainPixmap = main.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
 
-    QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage().convertToFormat(QImage::Format_RGB32),
+    QTRY_COMPARE(mainPixmap.toImage().convertToFormat(QImage::Format_RGB32),
                  correct.toImage().convertToFormat(QImage::Format_RGB32));
     QApplication::restoreOverrideCursor();
 }
@@ -9011,15 +8657,13 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779()
 void tst_QWidget::inputFocus_task257832()
 {
       QLineEdit *widget = new QLineEdit;
-      QInputContext *context = widget->inputContext();
-      if (!context)
-            QSKIP("No input context");
       widget->setFocus();
       widget->winId();    // make sure, widget has been created
-      context->setFocusWidget(widget);
-      QCOMPARE(context->focusWidget(), static_cast<QWidget*>(widget));
+      widget->show();
+      QTRY_VERIFY(widget->hasFocus());
+      QCOMPARE(qApp->inputMethod()->inputItem(), static_cast<QWidget*>(widget));
       widget->setReadOnly(true);
-      QVERIFY(!context->focusWidget());
+      QVERIFY(!qApp->inputMethod()->inputItem());
       delete widget;
 }
 
@@ -9128,23 +8772,10 @@ void tst_QWidget::openModal_taskQTBUG_5804()
     delete win;
 }
 
-class InputContextTester : public QInputContext
-{
-    Q_OBJECT
-public:
-    QString identifierName() { return QString(); }
-    bool isComposing() const { return false; }
-    QString language() { return QString(); }
-    void reset() { ++resets; }
-    int resets;
-};
-
 void tst_QWidget::focusProxyAndInputMethods()
 {
-    InputContextTester *inputContext = new InputContextTester;
     QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint);
     toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
-    qApp->setInputContext(inputContext); // ownership is transferred
 
     QWidget *child = new QWidget(toplevel);
     child->setFocusProxy(toplevel);
@@ -9167,20 +8798,13 @@ void tst_QWidget::focusProxyAndInputMethods()
     // and that the input method gets the focus proxy passed
     // as the focus widget instead of the child widget.
     // otherwise input method queries go to the wrong widget
+    QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
 
-    QCOMPARE(inputContext->focusWidget(), toplevel);
+    toplevel->setAttribute(Qt::WA_InputMethodEnabled, false);
+    QVERIFY(!qApp->inputPanel()->inputItem());
 
-    child->setAttribute(Qt::WA_InputMethodEnabled, false);
-    QVERIFY(!inputContext->focusWidget());
-
-    child->setAttribute(Qt::WA_InputMethodEnabled, true);
-    QCOMPARE(inputContext->focusWidget(), toplevel);
-
-    child->setEnabled(false);
-    QVERIFY(!inputContext->focusWidget());
-
-    child->setEnabled(true);
-    QCOMPARE(inputContext->focusWidget(), toplevel);
+    toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
+    QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
 
     delete toplevel;
 }
@@ -9238,7 +8862,7 @@ void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy()
 
 void tst_QWidget::movedAndResizedAttributes()
 {
-#if defined (Q_OS_MAC) || defined(Q_WS_QWS)
+#if defined (Q_OS_MAC)
     QEXPECT_FAIL("", "FixMe, QTBUG-8941 and QTBUG-8977", Abort);
     QVERIFY(false);
 #else
@@ -9281,9 +8905,6 @@ void tst_QWidget::movedAndResizedAttributes()
     w.showNormal();
     w.move(10,10);
     QVERIFY(w.testAttribute(Qt::WA_Moved));
-#if defined(Q_OS_WIN)
-    QEXPECT_FAIL("", "FixMe, QTBUG-8911", Abort);
-#endif
     QVERIFY(!w.testAttribute(Qt::WA_Resized));
 
     w.resize(100, 100);
@@ -9347,7 +8968,7 @@ void tst_QWidget::childAt()
     QCOMPARE(parent.childAt(120, 120), grandChild);
 }
 
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
 void tst_QWidget::childAt_unifiedToolBar()
 {
     QLabel *label = new QLabel(QLatin1String("foo"));
@@ -9441,5 +9062,78 @@ void tst_QWidget::nativeChildFocus()
     QTest::qWait(1000);
 }
 
+static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
+{
+    QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32);
+    QImage actualImage = actual.toImage().convertToFormat(QImage::Format_RGB32);
+
+    if (expectedImage.size() != actualImage.size()) {
+        qWarning("Image size comparison failed: expected: %dx%d, got %dx%d",
+                 expectedImage.size().width(), expectedImage.size().height(),
+                 actualImage.size().width(), actualImage.size().height());
+        return false;
+    }
+
+    const int size = actual.width() * actual.height();
+    const int threshold = QPixmap::defaultDepth() == 16 ? 10 : 2;
+
+    QRgb *a = (QRgb *)actualImage.bits();
+    QRgb *e = (QRgb *)expectedImage.bits();
+    for (int i = 0; i < size; ++i) {
+        const QColor ca(a[i]);
+        const QColor ce(e[i]);
+        if (qAbs(ca.red() - ce.red()) > threshold
+            || qAbs(ca.green() - ce.green()) > threshold
+            || qAbs(ca.blue() - ce.blue()) > threshold) {
+            qWarning("Color mismatch at pixel #%d: Expected: %d,%d,%d, got %d,%d,%d",
+                     i, ce.red(), ce.green(), ce.blue(), ca.red(), ca.green(), ca.blue());
+            return false;
+        }
+    }
+
+    return true;
+}
+
+void tst_QWidget::grab()
+{
+    for (int opaque = 0; opaque < 2; ++opaque) {
+        QWidget widget;
+        QImage image(128, 128, opaque ? QImage::Format_RGB32 : QImage::Format_ARGB32_Premultiplied);
+        for (int row = 0; row < image.height(); ++row) {
+            QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row));
+            for (int col = 0; col < image.width(); ++col)
+                line[col] = qRgba(rand() & 255, row, col, opaque ? 255 : 127);
+        }
+
+        QPalette pal = widget.palette();
+        pal.setBrush(QPalette::Window, QBrush(image));
+        widget.setPalette(pal);
+        widget.resize(128, 128);
+
+        QPixmap expected(64, 64);
+        if (!opaque)
+            expected.fill(Qt::transparent);
+
+        QPainter p(&expected);
+        p.translate(-64, -64);
+        p.drawTiledPixmap(0, 0, 128, 128, pal.brush(QPalette::Window).texture(), 0, 0);
+        p.end();
+
+        QPixmap actual = widget.grab(QRect(64, 64, 64, 64));
+        QVERIFY(lenientCompare(actual, expected));
+
+        actual = widget.grab(QRect(64, 64, -1, -1));
+        QVERIFY(lenientCompare(actual, expected));
+
+        // Make sure a widget that is not yet shown is grabbed correctly.
+        QTreeWidget widget2;
+        actual = widget2.grab(QRect());
+        widget2.show();
+        expected = widget2.grab(QRect());
+
+        QVERIFY(lenientCompare(actual, expected));
+    }
+}
+
 QTEST_MAIN(tst_QWidget)
 #include "tst_qwidget.moc"