Commit 5605337f authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Improve robustness of flamegraph view test

If the context menu disappears for whatever reason, just open a new one.
Making sure that the context menu stays around when we don't do anything
is not Qt Creator's job, so we don't have to test for it. Also, when
trying to remove the context menu, click a spot that's certainly inside
the screen.

Change-Id: If6e574d84bedf2ab552c8c29d756501e9d2282bd
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent aa80b23f
......@@ -116,38 +116,42 @@ void FlameGraphViewTest::testContextMenu()
targetHeight = (testMenu.height() + prevHeight) / 2;
}
QTest::mouseMove(&view, QPoint(250, 250));
QSignalSpy spy(&view, SIGNAL(showFullRange()));
QTimer timer;
timer.setInterval(50);
timer.start();
int menuClicks = 0;
connect(&timer, &QTimer::timeout, this, [&]() {
auto activePopup = qApp->activePopupWidget();
if (!activePopup || !activePopup->windowHandle()->isExposed())
if (!activePopup || !activePopup->windowHandle()->isExposed()) {
QContextMenuEvent *event = new QContextMenuEvent(QContextMenuEvent::Mouse,
QPoint(250, 250));
qApp->postEvent(&view, event);
return;
}
QTest::mouseMove(activePopup, QPoint(targetWidth, targetHeight));
QTest::mouseClick(activePopup, Qt::LeftButton, Qt::NoModifier,
QPoint(targetWidth, targetHeight));
++menuClicks;
if (!manager.isRestrictedToRange()) {
// click somewhere else to remove the menu and return to outer function
QTest::mouseClick(qApp->activePopupWidget(), Qt::LeftButton, Qt::NoModifier,
QPoint(500, 500));
QTest::mouseMove(activePopup, QPoint(-10, -10));
QTest::mouseClick(activePopup, Qt::LeftButton, Qt::NoModifier, QPoint(-10, -10));
}
});
QTest::mouseMove(&view, QPoint(250, 250));
QSignalSpy spy(&view, SIGNAL(showFullRange()));
QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(250, 250));
QVERIFY(qApp->notify(&view, &event));
timer.start();
QTRY_VERIFY(menuClicks > 0);
QCOMPARE(spy.count(), 0);
manager.restrictToRange(1, 10);
QVERIFY(qApp->notify(&view, &event));
if (spy.count() != 1)
QTRY_COMPARE(spy.count(), 1);
QVERIFY(manager.isRestrictedToRange());
QTRY_COMPARE(spy.count(), 1);
QVERIFY(menuClicks > 1);
timer.stop();
}
void FlameGraphViewTest::cleanupTestCase()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment