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 <christian.stenger@qt.io>
This commit is contained in:
Ulf Hermann
2017-03-23 10:54:15 +01:00
parent aa80b23f99
commit 5605337f6a

View File

@@ -116,38 +116,42 @@ void FlameGraphViewTest::testContextMenu()
targetHeight = (testMenu.height() + prevHeight) / 2;
}
QTimer timer;
timer.setInterval(50);
timer.start();
connect(&timer, &QTimer::timeout, this, [&]() {
auto activePopup = qApp->activePopupWidget();
if (!activePopup || !activePopup->windowHandle()->isExposed())
return;
QTest::mouseMove(activePopup, QPoint(targetWidth, targetHeight));
QTest::mouseClick(activePopup, Qt::LeftButton, Qt::NoModifier,
QPoint(targetWidth, targetHeight));
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(&view, QPoint(250, 250));
QSignalSpy spy(&view, SIGNAL(showFullRange()));
QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(250, 250));
QVERIFY(qApp->notify(&view, &event));
QTimer timer;
timer.setInterval(50);
int menuClicks = 0;
connect(&timer, &QTimer::timeout, this, [&]() {
auto activePopup = qApp->activePopupWidget();
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::mouseMove(activePopup, QPoint(-10, -10));
QTest::mouseClick(activePopup, Qt::LeftButton, Qt::NoModifier, QPoint(-10, -10));
}
});
timer.start();
QTRY_VERIFY(menuClicks > 0);
QCOMPARE(spy.count(), 0);
manager.restrictToRange(1, 10);
QVERIFY(qApp->notify(&view, &event));
if (spy.count() != 1)
QVERIFY(manager.isRestrictedToRange());
QTRY_COMPARE(spy.count(), 1);
QVERIFY(menuClicks > 1);
timer.stop();
}
void FlameGraphViewTest::cleanupTestCase()