diff --git a/tests/auto/widgets/widgets/qmenubar/BLACKLIST b/tests/auto/widgets/widgets/qmenubar/BLACKLIST index ee08086e83..e2194e69ca 100644 --- a/tests/auto/widgets/widgets/qmenubar/BLACKLIST +++ b/tests/auto/widgets/widgets/qmenubar/BLACKLIST @@ -1,5 +1,3 @@ [check_menuPosition] ubuntu-14.04 ubuntu-16.04 -[task256322_highlight] -osx diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index bc50e4f1d8..12afb77281 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -48,6 +48,18 @@ QT_FORWARD_DECLARE_CLASS(QMainWindow) #include +// Helper to calculate the action position in window coordinates +static inline QPoint widgetToWindowPos(const QWidget *w, const QPoint &pos) +{ + const QWindow *window = w->window()->windowHandle(); + Q_ASSERT(window); + return window->mapFromGlobal(w->mapToGlobal(pos)); +} + +static QPoint menuBarActionWindowPos(const QMenuBar *mb, QAction *a) +{ + return widgetToWindowPos(mb, mb->actionGeometry(a).center()); +} class Menu : public QMenu { @@ -1194,21 +1206,19 @@ void tst_QMenuBar::check_menuPosition() menu.close(); } -# ifndef QT_NO_CURSOR // QTBUG-28031: Click at bottom-right corner. { w.move(400, 200); LayoutDirectionSaver directionSaver(Qt::RightToLeft); QMenuBar *mb = w.menuBar(); - const QPoint localPos = mb->actionGeometry(menu.menuAction()).bottomRight() - QPoint(1, 1); - const QPoint globalPos = mb->mapToGlobal(localPos); - QCursor::setPos(globalPos); - QTest::mouseClick(mb, Qt::LeftButton, 0, localPos); + const QPoint bottomRight = mb->actionGeometry(menu.menuAction()).bottomRight() - QPoint(1, 1); + const QPoint localPos = widgetToWindowPos(mb, bottomRight); + const QPoint globalPos = w.mapToGlobal(localPos); + QTest::mouseClick(w.windowHandle(), Qt::LeftButton, 0, localPos); QTRY_VERIFY(menu.isActiveWindow()); QCOMPARE(menu.geometry().right() - 1, globalPos.x()); menu.close(); } -# endif // QT_NO_CURSOR } #endif @@ -1246,10 +1256,8 @@ void tst_QMenuBar::task223138_triggered() void tst_QMenuBar::task256322_highlight() { - if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive) - || !QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive)) { - QSKIP("Highlighting does not work correctly for minimal/offscreen platforms"); - } + if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive)) + QSKIP("Highlighting does not work correctly for minimal platform"); QMainWindow win; win.menuBar()->setNativeMenuBar(false); //we can't check the geometry of native menubars @@ -1266,31 +1274,26 @@ void tst_QMenuBar::task256322_highlight() QApplication::setActiveWindow(&win); QVERIFY(QTest::qWaitForWindowActive(&win)); - QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center()); - QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file).center()); - QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center()); + const QPoint filePos = menuBarActionWindowPos(win.menuBar(), file); + QWindow *window = win.windowHandle(); + QTest::mousePress(window, Qt::LeftButton, 0, filePos); + QTest::mouseMove(window, filePos); + QTest::mouseRelease(window, Qt::LeftButton, 0, filePos); QTRY_VERIFY(menu.isVisible()); QVERIFY(!menu2.isVisible()); QCOMPARE(win.menuBar()->activeAction(), file); - QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file2).center()); - QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file2).center()); + const QPoint file2Pos = menuBarActionWindowPos(win.menuBar(), file2); + QTest::mouseMove(window, file2Pos); QTRY_VERIFY(!menu.isVisible()); - QVERIFY(menu2.isVisible()); + QTRY_VERIFY(menu2.isVisible()); QCOMPARE(win.menuBar()->activeAction(), file2); - QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file2).center()); - QPoint nothingCenter = win.menuBar()->actionGeometry(nothing).center(); - QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, nothingCenter); - QTest::mouseMove(win.menuBar(), nothingCenter); + QPoint nothingCenter = menuBarActionWindowPos(win.menuBar(), nothing); + QTest::mouseMove(window, nothingCenter); QTRY_VERIFY(!menu2.isVisible()); QVERIFY(!menu.isVisible()); -#ifdef Q_OS_MAC - if (win.menuBar()->activeAction() != nothing) - QEXPECT_FAIL("", "QTBUG-30565: Unstable test", Continue); -#endif QTRY_COMPARE(win.menuBar()->activeAction(), nothing); - QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, nothingCenter); } void tst_QMenuBar::menubarSizeHint() @@ -1427,9 +1430,6 @@ void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu QMainWindow mainWindow; mainWindow.resize(300, 200); centerOnScreen(&mainWindow); -#ifndef QT_NO_CURSOR - QCursor::setPos(mainWindow.geometry().topLeft() - QPoint(100, 0)); -#endif QMenuBar *menuBar = mainWindow.menuBar(); menuBar->setNativeMenuBar(false); QMenu *fileMenu = menuBar->addMenu(QStringLiteral("OpenCloseOpen")); @@ -1437,14 +1437,17 @@ void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu mainWindow.show(); QApplication::setActiveWindow(&mainWindow); QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); - const QPoint center = menuBar->actionGeometry(fileMenu->menuAction()).center(); - const QPoint globalPos = menuBar->mapToGlobal(center); - QTest::mouseMove(menuBar, center); - QTest::mouseClick(menuBar, Qt::LeftButton, 0, center); + + const QPoint center = menuBarActionWindowPos(mainWindow.menuBar(), fileMenu->menuAction()); + const QPoint globalPos = mainWindow.mapToGlobal(center); + + QWindow *window = mainWindow.windowHandle(); + QTest::mouseMove(window, center); + QTest::mouseClick(window, Qt::LeftButton, 0, center); QTRY_VERIFY(fileMenu->isVisible()); - QTest::mouseClick(fileMenu, Qt::LeftButton, 0, fileMenu->mapFromGlobal(globalPos)); + QTest::mouseClick(window, Qt::LeftButton, 0, fileMenu->mapFromGlobal(globalPos)); QTRY_VERIFY(!fileMenu->isVisible()); - QTest::mouseClick(menuBar, Qt::LeftButton, 0, center); + QTest::mouseClick(window, Qt::LeftButton, 0, center); QTRY_VERIFY(fileMenu->isVisible()); }