From 2628e897fe3738ee86dacccea72e4a5b6aed9715 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Mon, 31 Jan 2022 11:02:52 +0100 Subject: [PATCH] Add tab close button in QTabBar baseline test Fixes: QTBUG-99772 Pick-to: 6.3 Change-Id: I01e0fc78880baae12f46005e4a88db41bea89d65 Reviewed-by: Eirik Aavitsland --- .../baseline/widgets/tst_baseline_widgets.cpp | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/baseline/widgets/tst_baseline_widgets.cpp b/tests/baseline/widgets/tst_baseline_widgets.cpp index d49e9b494f..5ab4d484bd 100644 --- a/tests/baseline/widgets/tst_baseline_widgets.cpp +++ b/tests/baseline/widgets/tst_baseline_widgets.cpp @@ -459,13 +459,14 @@ void tst_Widgets::tst_QTabBar_data() QTest::addColumn("shape"); QTest::addColumn("numberTabs"); QTest::addColumn("fixedWidth"); + QTest::addColumn("isClosable"); // fixedWidth <0 will be interpreted as variable width - QTest::newRow("RoundedNorth_3_variableWidth") << QTabBar::RoundedNorth << 3 << -1; - QTest::newRow("RoundedEast_3_variableWidth") << QTabBar::RoundedEast << 3 << -1; - QTest::newRow("RoundedWest_3_variableWidth") << QTabBar::RoundedWest << 3 << -1; - QTest::newRow("RoundedSouth_3_variableWidth") << QTabBar::RoundedSouth << 3 << -1; - QTest::newRow("RoundedNorth_20_fixedWidth") << QTabBar::RoundedNorth << 20 << 250; + QTest::newRow("RoundedNorth_3_variableWidth") << QTabBar::RoundedNorth << 3 << -1 << false; + QTest::newRow("RoundedEast_3_variableWidth") << QTabBar::RoundedEast << 3 << -1 << false; + QTest::newRow("RoundedWest_3_variableWidth") << QTabBar::RoundedWest << 3 << -1 << false; + QTest::newRow("RoundedSouth_3_variableWidth") << QTabBar::RoundedSouth << 3 << -1 << false; + QTest::newRow("RoundedNorth_20_fixedWidth") << QTabBar::RoundedNorth << 20 << 250 << true; } void tst_Widgets::tst_QTabBar() @@ -473,9 +474,11 @@ void tst_Widgets::tst_QTabBar() QFETCH(QTabBar::Shape, shape); QFETCH(int, numberTabs); QFETCH(int, fixedWidth); + QFETCH(bool, isClosable); QTabBar bar (testWindow()); bar.setShape(shape); + bar.setTabsClosable(isClosable); if (fixedWidth > 0) bar.setFixedWidth(fixedWidth); @@ -505,6 +508,27 @@ void tst_Widgets::tst_QTabBar() QTest::mouseRelease(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0); QVERIFY(bar.currentIndex() == 1); } + + // test press/release on close button + if (isClosable) { + + // CloseButton is either left or right + QWidget *leftButton = bar.tabButton(bar.currentIndex(),QTabBar::ButtonPosition::LeftSide); + QWidget *rightButton = bar.tabButton(bar.currentIndex(),QTabBar::ButtonPosition::RightSide); + QAbstractButton *button = qobject_cast(leftButton); + if (button == nullptr) + button = qobject_cast(rightButton); + + if (button != nullptr) { + clickTarget = button->rect().center(); + QTest::mousePress(button,Qt::MouseButton::LeftButton, + Qt::KeyboardModifiers(), clickTarget,0); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressCloseFirstTab"); + QTest::mouseRelease(button,Qt::MouseButton::LeftButton, + Qt::KeyboardModifiers(), clickTarget,0); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "releaseCloseFirstTab"); + } + } } #define main _realmain