summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2010-05-20 10:52:16 +0200
committerBradley T. Hughes <bradley.hughes@nokia.com>2010-05-20 12:01:51 +0200
commit16f44ee07db46ad362a464afc2c6e6567c933870 (patch)
tree9343457968535bd69b96a9e61568b725cd9ff576 /tests
parenta41534cbabd0aee90c38b9a1a133835863a7f54b (diff)
QApplication::closeAllWindows() should ignore windows being closed
It is very common to display a dialog in response to a close event. Closing the window again will result in QWidget::close() returning true. This confuses QApplication::closeAllWindows(), since the window is still visible even though it was closed (or is closing). Solve this by ignoring windows that have the is_closing flag set in their widget data. Task-number: QTBUG-7635 Reviewed-by: Denis Dzyubenko
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qapplication/tst_qapplication.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/auto/qapplication/tst_qapplication.cpp b/tests/auto/qapplication/tst_qapplication.cpp
index 459ac2ba13..43fbba104a 100644
--- a/tests/auto/qapplication/tst_qapplication.cpp
+++ b/tests/auto/qapplication/tst_qapplication.cpp
@@ -106,6 +106,7 @@ private slots:
void lastWindowClosed();
void quitOnLastWindowClosed();
+ void closeAllWindows();
void testDeleteLater();
void testDeleteLaterProcessEvents();
@@ -745,6 +746,83 @@ void tst_QApplication::quitOnLastWindowClosed()
}
}
+class PromptOnCloseWidget : public QWidget
+{
+public:
+ void closeEvent(QCloseEvent *event)
+ {
+ QMessageBox *messageBox = new QMessageBox(this);
+ messageBox->setWindowTitle("Unsaved data");
+ messageBox->setText("Would you like to save or discard your current data?");
+ messageBox->setStandardButtons(QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel);
+ messageBox->setDefaultButton(QMessageBox::Save);
+
+ messageBox->show();
+ QTest::qWaitForWindowShown(messageBox);
+
+ // verify that all windows are visible
+ foreach (QWidget *w, qApp->topLevelWidgets())
+ QVERIFY(w->isVisible());
+ // flush event queue
+ qApp->processEvents();
+ // close all windows
+ qApp->closeAllWindows();
+
+ if (messageBox->standardButton(messageBox->clickedButton()) == QMessageBox::Cancel)
+ event->ignore();
+ else
+ event->accept();
+
+ delete messageBox;
+ }
+};
+
+void tst_QApplication::closeAllWindows()
+{
+ int argc = 0;
+ QApplication app(argc, 0, QApplication::GuiServer);
+
+ // create some windows
+ new QWidget;
+ new QWidget;
+ new QWidget;
+
+ // show all windows
+ foreach (QWidget *w, app.topLevelWidgets()) {
+ w->show();
+ QTest::qWaitForWindowShown(w);
+ }
+ // verify that they are visible
+ foreach (QWidget *w, app.topLevelWidgets())
+ QVERIFY(w->isVisible());
+ // empty event queue
+ app.processEvents();
+ // close all windows
+ app.closeAllWindows();
+ // all windows should no longer be visible
+ foreach (QWidget *w, app.topLevelWidgets())
+ QVERIFY(!w->isVisible());
+
+ // add a window that prompts the user when closed
+ PromptOnCloseWidget *promptOnCloseWidget = new PromptOnCloseWidget;
+ // show all windows
+ foreach (QWidget *w, app.topLevelWidgets()) {
+ w->show();
+ QTest::qWaitForWindowShown(w);
+ }
+ // close the last window to open the prompt (eventloop recurses)
+ promptOnCloseWidget->close();
+ // all windows should not be visible, except the one that opened the prompt
+ foreach (QWidget *w, app.topLevelWidgets()) {
+ if (w == promptOnCloseWidget)
+ QVERIFY(w->isVisible());
+ else
+ QVERIFY(!w->isVisible());
+ }
+
+ qDeleteAll(app.topLevelWidgets());
+}
+
bool isPathListIncluded(const QStringList &l, const QStringList &r)
{
int size = r.count();