diff options
Diffstat (limited to 'tests/auto/widgets')
5 files changed, 229 insertions, 12 deletions
diff --git a/tests/auto/widgets/kernel/qapplication/test/test.pro b/tests/auto/widgets/kernel/qapplication/test/test.pro index 92409e4bfe..7f75501474 100644 --- a/tests/auto/widgets/kernel/qapplication/test/test.pro +++ b/tests/auto/widgets/kernel/qapplication/test/test.pro @@ -1,5 +1,5 @@ CONFIG += testcase -CONFIG -= app_bundle debug_and_release_target +CONFIG -= debug_and_release_target QT += widgets widgets-private testlib QT += core-private gui-private diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 731a8c5d91..54f1a1bf1e 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -8957,8 +8957,13 @@ void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave() void tst_QWidget::windowFlags() { QWidget w; + const auto baseFlags = w.windowFlags(); w.setWindowFlags(w.windowFlags() | Qt::FramelessWindowHint); QVERIFY(w.windowFlags() & Qt::FramelessWindowHint); + w.setWindowFlag(Qt::WindowStaysOnTopHint, true); + QCOMPARE(w.windowFlags(), baseFlags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + w.setWindowFlag(Qt::FramelessWindowHint, false); + QCOMPARE(w.windowFlags(), baseFlags | Qt::WindowStaysOnTopHint); } void tst_QWidget::initialPosForDontShowOnScreenWidgets() diff --git a/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro b/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro index 17fc1d28b5..50069b7e3e 100644 --- a/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro +++ b/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro @@ -1,5 +1,4 @@ CONFIG += testcase -mac:CONFIG -= app_bundle TARGET = tst_qwindowcontainer QT += widgets testlib SOURCES += tst_qwindowcontainer.cpp diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index a5b33ed8e7..2d335c532a 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -118,6 +118,7 @@ private slots: #if !defined(Q_OS_DARWIN) void check_shortcutPress(); void check_menuPosition(); + void taskQTBUG46812_doNotLeaveMenubarHighlighted(); #endif void task223138_triggered(); void task256322_highlight(); @@ -228,9 +229,14 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb) menu = mb->addMenu(QStringLiteral("accel1")); action = menu->addAction(QStringLiteral("&Open...") ); action->setShortcut(Qt::Key_O); + result.actions << action; + + action = menu->addAction(QStringLiteral("action")); + action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Z)); + result.actions << action; + result.menus << menu; connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*))); - result.actions << action; m_lastSimpleAcceleratorId = 0; m_simpleActivatedCount = 0; @@ -316,7 +322,7 @@ inline TestMenu tst_QMenuBar::initWindowWithComplexMenuBar(QMainWindow &w) return initComplexMenuBar(w.menuBar()); } -// On Mac/WinCE, native key events are needed to test menu action activation +// On Mac native key events are needed to test menu action activation #if !defined(Q_OS_DARWIN) void tst_QMenuBar::accel() { @@ -334,7 +340,7 @@ void tst_QMenuBar::accel() } #endif -// On Mac/WinCE, native key events are needed to test menu action activation +// On Mac native key events are needed to test menu action activation #if !defined(Q_OS_DARWIN) void tst_QMenuBar::activatedCount() { @@ -525,7 +531,7 @@ void tst_QMenuBar::insertItem_QString_QObject() QVERIFY(actions.size() < 4); // there is no menu 4! } -// On Mac/WinCE, native key events are needed to test menu action activation +// On Mac native key events are needed to test menu action activation #if !defined(Q_OS_DARWIN) void tst_QMenuBar::check_accelKeys() { @@ -598,7 +604,7 @@ void tst_QMenuBar::check_accelKeys() } #endif -// On Mac/WinCE, native key events are needed to test menu action activation +// On Mac native key events are needed to test menu action activation #if !defined(Q_OS_DARWIN) void tst_QMenuBar::check_cursorKeys1() { @@ -632,7 +638,7 @@ void tst_QMenuBar::check_cursorKeys1() } #endif -// Qt/Mac,WinCE does not use the native popups/menubar +// Qt/Mac does not use the native popups/menubar #if !defined(Q_OS_DARWIN) void tst_QMenuBar::check_cursorKeys2() { @@ -665,7 +671,7 @@ void tst_QMenuBar::check_cursorKeys2() /*! If a popupmenu is active you can use Left to move to the menu to the left of it. */ -// Qt/Mac,WinCE does not use the native popups/menubar +// Qt/Mac does not use the native popups/menubar #if !defined(Q_OS_DARWIN) void tst_QMenuBar::check_cursorKeys3() { @@ -780,7 +786,7 @@ void tst_QMenuBar::check_endKey() If Down is pressed next the popup is activated again. */ -// Qt/Mac,WinCE does not use the native popups/menubar +// Qt/Mac does not use the native popups/menubar #if !defined(Q_OS_DARWIN) void tst_QMenuBar::check_escKey() { @@ -1014,7 +1020,7 @@ void tst_QMenuBar::check_altClosePress() QTRY_VERIFY(!w.menuBar()->activeAction()); } -// Qt/Mac,WinCE does not use the native popups/menubar +// Qt/Mac does not use the native popups/menubar #if !defined(Q_OS_DARWIN) void tst_QMenuBar::check_shortcutPress() { @@ -1057,7 +1063,7 @@ private: const Qt::LayoutDirection m_oldDirection; }; -// Qt/Mac,WinCE does not use the native popups/menubar +// Qt/Mac does not use the native popups/menubar #if !defined(Q_OS_DARWIN) void tst_QMenuBar::check_menuPosition() { @@ -1519,6 +1525,41 @@ void tst_QMenuBar::slotForTaskQTBUG53205() taskQTBUG53205MenuBar->setParent(parent); } +// Qt/Mac does not use the native popups/menubar +#if !defined(Q_OS_DARWIN) +void tst_QMenuBar::taskQTBUG46812_doNotLeaveMenubarHighlighted() +{ + QMainWindow mainWindow; + QWidget *centralWidget = new QWidget; + centralWidget->setFocusPolicy(Qt::StrongFocus); + mainWindow.setCentralWidget(centralWidget); + initWindowWithSimpleMenuBar(mainWindow); + + mainWindow.show(); + QApplication::setActiveWindow(&mainWindow); + QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); + + QVERIFY(!mainWindow.menuBar()->hasFocus()); + QCOMPARE(m_simpleActivatedCount, 0); + + QTest::keyPress(&mainWindow, Qt::Key_Alt, Qt::AltModifier); + QVERIFY(!mainWindow.menuBar()->hasFocus()); + QCOMPARE(m_simpleActivatedCount, 0); + + QTest::keyPress(&mainWindow, Qt::Key_Z, Qt::AltModifier); + QVERIFY(!mainWindow.menuBar()->hasFocus()); + QCOMPARE(m_simpleActivatedCount, 2); // the action AND the menu will activate + + QTest::keyRelease(&mainWindow, Qt::Key_Alt, Qt::NoModifier); + QVERIFY(!mainWindow.menuBar()->hasFocus()); + QCOMPARE(m_simpleActivatedCount, 2); + + QTest::keyRelease(&mainWindow, Qt::Key_Z, Qt::NoModifier); + QVERIFY(!mainWindow.menuBar()->hasFocus()); + QCOMPARE(m_simpleActivatedCount, 2); +} +#endif + #ifdef Q_OS_MACOS extern bool tst_qmenubar_taskQTBUG56275(QMenuBar *); diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index f490446c8a..c4cd771f92 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -77,6 +77,10 @@ private slots: void rubberBandNotInSplitter(); void saveAndRestoreStateOfNotYetShownSplitter(); void saveAndRestoreHandleWidth(); + void replaceWidget_data(); + void replaceWidget(); + void replaceWidgetWithSplitterChild_data(); + void replaceWidgetWithSplitterChild(); // task-specific tests below me: void task187373_addAbstractScrollAreas(); @@ -645,9 +649,177 @@ public: MyFriendlySplitter(QWidget *parent = 0) : QSplitter(parent) {} void setRubberBand(int pos) { QSplitter::setRubberBand(pos); } + void moveSplitter(int pos, int index) { QSplitter::moveSplitter(pos, index); } + friend class tst_QSplitter; }; +class EventCounterSpy : public QObject +{ +public: + EventCounterSpy(QWidget *parentWidget) : QObject(parentWidget) + { } + + bool eventFilter(QObject *watched, QEvent *event) override + { + // Watch for events in the parent widget and all its children + if (watched == parent() || watched->parent() == parent()) { + if (event->type() == QEvent::Resize) + resizeCount++; + else if (event->type() == QEvent::Paint) + paintCount++; + } + + return QObject::eventFilter(watched, event); + } + + int resizeCount = 0; + int paintCount = 0; +}; + +void tst_QSplitter::replaceWidget_data() +{ + QTest::addColumn<int>("index"); + QTest::addColumn<bool>("visible"); + QTest::addColumn<bool>("collapsed"); + + QTest::newRow("negative index") << -1 << true << false; + QTest::newRow("index too large") << 80 << true << false; + QTest::newRow("visible, not collapsed") << 3 << true << false; + QTest::newRow("visible, collapsed") << 3 << true << true; + QTest::newRow("not visible, not collapsed") << 3 << false << false; + QTest::newRow("not visible, collapsed") << 3 << false << true; +} + +void tst_QSplitter::replaceWidget() +{ + QFETCH(int, index); + QFETCH(bool, visible); + QFETCH(bool, collapsed); + + // Setup + MyFriendlySplitter sp; + const int count = 7; + for (int i = 0; i < count; i++) { + // We use labels instead of plain widgets to + // make it easier to fix eventual regressions. + QLabel *w = new QLabel(QString::asprintf("WIDGET #%d", i)); + sp.addWidget(w); + } + sp.setWindowTitle(QString::asprintf("index %d, visible %d, collapsed %d", index, visible, collapsed)); + sp.show(); + QVERIFY(QTest::qWaitForWindowExposed(&sp)); + + // Configure splitter + QWidget *oldWidget = sp.widget(index); + const QRect oldGeom = oldWidget ? oldWidget->geometry() : QRect(); + if (oldWidget) { + // Collapse first, then hide, if necessary + if (collapsed) { + sp.setCollapsible(index, true); + sp.moveSplitter(oldWidget->x() + 1, index + 1); + } + if (!visible) + oldWidget->hide(); + } + + // Replace widget + QTest::qWait(100); // Flush event queue + const QList<int> sizes = sp.sizes(); + // Shorter label: The important thing is to ensure we can set + // the same size on the new widget. Because of QLabel's sizing + // constraints (they can expand but not shrink) the easiest is + // to set a shorter label. + QLabel *newWidget = new QLabel(QLatin1String("<b>NEW</b>")); + + EventCounterSpy *ef = new EventCounterSpy(&sp); + qApp->installEventFilter(ef); + const QWidget *res = sp.replaceWidget(index, newWidget); + QTest::qWait(100); // Give visibility and resizing some time + qApp->removeEventFilter(ef); + + // Check + if (index < 0 || index >= count) { + QVERIFY(!res); + QVERIFY(!newWidget->parentWidget()); + QCOMPARE(ef->resizeCount, 0); + QCOMPARE(ef->paintCount, 0); + } else { + QCOMPARE(res, oldWidget); + QVERIFY(!res->parentWidget()); + QVERIFY(!res->isVisible()); + QCOMPARE(newWidget->parentWidget(), &sp); + QCOMPARE(newWidget->isVisible(), visible); + if (visible && !collapsed) + QCOMPARE(newWidget->geometry(), oldGeom); + QCOMPARE(newWidget->size().isEmpty(), !visible || collapsed); + const int expectedResizeCount = visible ? 1 : 0; // new widget only + const int expectedPaintCount = visible && !collapsed ? 2 : 0; // splitter and new widget + QCOMPARE(ef->resizeCount, expectedResizeCount); + QCOMPARE(ef->paintCount, expectedPaintCount); + delete res; + } + QCOMPARE(sp.count(), count); + QCOMPARE(sp.sizes(), sizes); +} + +void tst_QSplitter::replaceWidgetWithSplitterChild_data() +{ + QTest::addColumn<int>("srcIndex"); + QTest::addColumn<int>("dstIndex"); + + QTest::newRow("replace with null widget") << -2 << 3; + QTest::newRow("replace with itself") << 3 << 3; + QTest::newRow("replace with sibling, after recalc") << 1 << 4; + QTest::newRow("replace with sibling, before recalc") << -1 << 4; +} + +void tst_QSplitter::replaceWidgetWithSplitterChild() +{ + QFETCH(int, srcIndex); + QFETCH(int, dstIndex); + + // Setup + MyFriendlySplitter sp; + const int count = 7; + for (int i = 0; i < count; i++) { + // We use labels instead of plain widgets to + // make it easier to fix eventual regressions. + QLabel *w = new QLabel(QString::asprintf("WIDGET #%d", i)); + sp.addWidget(w); + } + sp.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char(' ') + QLatin1String(QTest::currentDataTag())); + sp.show(); + QVERIFY(QTest::qWaitForWindowExposed(&sp)); + + QTest::qWait(100); // Flush event queue before new widget creation + const QList<int> sizes = sp.sizes(); + QWidget *sibling = srcIndex == -1 ? (new QLabel("<b>NEW</b>", &sp)) : sp.widget(srcIndex); + + EventCounterSpy *ef = new EventCounterSpy(&sp); + qApp->installEventFilter(ef); + const QWidget *res = sp.replaceWidget(dstIndex, sibling); + QTest::qWait(100); // Give visibility and resizing some time + qApp->removeEventFilter(ef); + + QVERIFY(!res); + if (srcIndex == -1) { + // Create and replace before recalc. The sibling is scheduled to be + // added after replaceWidget(), when QSplitter receives a child event. + QVERIFY(ef->resizeCount > 0); + QVERIFY(ef->paintCount > 0); + QCOMPARE(sp.count(), count + 1); + QCOMPARE(sp.sizes().mid(0, count), sizes); + QCOMPARE(sp.sizes().last(), sibling->width()); + } else { + // No-op for the rest + QCOMPARE(ef->resizeCount, 0); + QCOMPARE(ef->paintCount, 0); + QCOMPARE(sp.count(), count); + QCOMPARE(sp.sizes(), sizes); + } +} + void tst_QSplitter::rubberBandNotInSplitter() { MyFriendlySplitter split; |