From eb7bf1825ede649ae35ebec91ef430686ae2c70a Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 2 Oct 2016 13:18:34 +0200 Subject: Popup: don't steal focus on close from another opening popup In the Gallery example, the settings dialog does not get focus (or to be exact, loses it immediately), because the closing menu incorrectly transfers focus back to the tool button that opened the menu. Change-Id: I5328d8e825de9a977619688dc4478e6592db654f Reviewed-by: J-P Nurmi --- tests/auto/popup/tst_popup.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/auto/popup/tst_popup.cpp') diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp index 6d1e1e3c..af6ccf34 100644 --- a/tests/auto/popup/tst_popup.cpp +++ b/tests/auto/popup/tst_popup.cpp @@ -64,6 +64,7 @@ private slots: void closePolicy(); void activeFocusOnClose1(); void activeFocusOnClose2(); + void activeFocusOnClose3(); void hover_data(); void hover(); void wheel_data(); @@ -454,6 +455,38 @@ void tst_popup::activeFocusOnClose2() QVERIFY(popup1->hasActiveFocus()); } +void tst_popup::activeFocusOnClose3() +{ + // Test that a closing popup that had focus doesn't steal focus from + // another popup that the focus was transferred to. + QQuickApplicationHelper helper(this, QStringLiteral("activeFocusOnClose3.qml")); + QQuickApplicationWindow *window = helper.appWindow; + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickPopup *popup1 = helper.appWindow->property("popup1").value(); + QVERIFY(popup1); + + QQuickPopup *popup2 = helper.appWindow->property("popup2").value(); + QVERIFY(popup2); + + popup1->open(); + QVERIFY(popup1->isVisible()); + QTRY_VERIFY(popup1->hasActiveFocus()); + + popup2->open(); + popup1->close(); + + QSignalSpy closedSpy(popup1, SIGNAL(closed())); + QVERIFY(closedSpy.isValid()); + QVERIFY(closedSpy.wait()); + + QVERIFY(!popup1->isVisible()); + QVERIFY(popup2->isVisible()); + QTRY_VERIFY(popup2->hasActiveFocus()); +} + void tst_popup::hover_data() { QTest::addColumn("source"); -- cgit v1.2.3