Auto tests: use Qt::AA_DontUseNativeDialogs where appropriate
These auto tests were trying to not create native dialogs, but setting the QFileDialog::DontUseNativeDialog option is too late to control the creation of the platform helper. It is already created at construction time, unless Qt::AA_DontUseNativeDialogs is set. Task-number: QTBUG-55276 Task-number: QTBUG-55281 Change-Id: Icf474e97059ac03a5fa01bd3a17f07203da5770a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
007f92c6ee
commit
9aeaa363e5
@ -80,18 +80,6 @@ static inline bool isCaseSensitiveFileSystem(const QString &path)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
class QNonNativeFileDialog : public QFileDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QNonNativeFileDialog(QWidget *parent = 0, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString())
|
||||
: QFileDialog(parent, caption, directory, filter)
|
||||
{
|
||||
setOption(QFileDialog::DontUseNativeDialog, true);
|
||||
}
|
||||
};
|
||||
|
||||
class tst_QFiledialog : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -180,9 +168,11 @@ void tst_QFiledialog::initTestCase()
|
||||
|
||||
void tst_QFiledialog::init()
|
||||
{
|
||||
// all tests, except widgetlessNativeDialog, use non-native dialogs
|
||||
QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
|
||||
QFileDialogPrivate::setLastVisitedDirectory(QUrl());
|
||||
// populate the sidebar with some default settings
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
#if defined(Q_OS_WINCE)
|
||||
QTest::qWait(1000);
|
||||
#endif
|
||||
@ -204,7 +194,7 @@ public:
|
||||
// emitted any time the selection model emits current changed
|
||||
void tst_QFiledialog::currentChangedSignal()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
|
||||
|
||||
@ -230,8 +220,7 @@ void tst_QFiledialog::currentChangedSignal()
|
||||
#if defined QT_BUILD_INTERNAL
|
||||
void tst_QFiledialog::directoryEnteredSignal()
|
||||
{
|
||||
QNonNativeFileDialog fd(0, "", QDir::root().path());
|
||||
fd.setOptions(QFileDialog::DontUseNativeDialog);
|
||||
QFileDialog fd(0, "", QDir::root().path());
|
||||
QSidebar *sidebar = fd.findChild<QSidebar*>("sidebar");
|
||||
QVERIFY(sidebar);
|
||||
if (sidebar->model()->rowCount() < 2)
|
||||
@ -296,9 +285,8 @@ void tst_QFiledialog::filesSelectedSignal_data()
|
||||
// emitted when the dialog closes with the selected files
|
||||
void tst_QFiledialog::filesSelectedSignal()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setOptions(QFileDialog::DontUseNativeDialog);
|
||||
QDir testDir(SRCDIR);
|
||||
fd.setDirectory(testDir);
|
||||
QFETCH(QFileDialog::FileMode, fileMode);
|
||||
@ -340,7 +328,7 @@ void tst_QFiledialog::filesSelectedSignal()
|
||||
// only emitted when the combo box is activated
|
||||
void tst_QFiledialog::filterSelectedSignal()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
fd.show();
|
||||
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(QString)));
|
||||
@ -368,7 +356,7 @@ void tst_QFiledialog::args()
|
||||
QString caption = "caption";
|
||||
QString directory = QDir::tempPath();
|
||||
QString filter = "*.mp3";
|
||||
QNonNativeFileDialog fd(parent, caption, directory, filter);
|
||||
QFileDialog fd(parent, caption, directory, filter);
|
||||
QCOMPARE(fd.parent(), (QObject *)parent);
|
||||
QCOMPARE(fd.windowTitle(), caption);
|
||||
#ifndef Q_OS_WIN
|
||||
@ -379,7 +367,7 @@ void tst_QFiledialog::args()
|
||||
|
||||
void tst_QFiledialog::directory()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
|
||||
QVERIFY(model);
|
||||
@ -413,12 +401,12 @@ void tst_QFiledialog::directory()
|
||||
#else
|
||||
QCOMPARE(list.at(0)->rootIndex().data().toString(), temp.dirName());
|
||||
#endif
|
||||
QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", tempPath);
|
||||
QFileDialog *dlg = new QFileDialog(0, "", tempPath);
|
||||
QCOMPARE(model->index(tempPath), model->index(dlg->directory().absolutePath()));
|
||||
QCOMPARE(model->index(tempPath).data(QFileSystemModel::FileNameRole).toString(),
|
||||
model->index(dlg->directory().absolutePath()).data(QFileSystemModel::FileNameRole).toString());
|
||||
delete dlg;
|
||||
dlg = new QNonNativeFileDialog();
|
||||
dlg = new QFileDialog();
|
||||
QCOMPARE(model->index(tempPath), model->index(dlg->directory().absolutePath()));
|
||||
delete dlg;
|
||||
}
|
||||
@ -475,10 +463,9 @@ void tst_QFiledialog::completer()
|
||||
}
|
||||
|
||||
// ### flesh this out more
|
||||
QNonNativeFileDialog fd(0, QLatin1String(QTest::currentTestFunction())
|
||||
QFileDialog fd(0, QLatin1String(QTest::currentTestFunction())
|
||||
+ QStringLiteral(" \"") + QLatin1String(QTest::currentDataTag())
|
||||
+ QLatin1Char('"'), startPath);
|
||||
fd.setOptions(QFileDialog::DontUseNativeDialog);
|
||||
fd.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&fd));
|
||||
QVERIFY(fd.isVisible());
|
||||
@ -573,8 +560,7 @@ void tst_QFiledialog::completer()
|
||||
|
||||
void tst_QFiledialog::completer_up()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
fd.setOptions(QFileDialog::DontUseNativeDialog);
|
||||
QFileDialog fd;
|
||||
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
|
||||
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(QString)));
|
||||
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(QStringList)));
|
||||
@ -597,7 +583,7 @@ void tst_QFiledialog::completer_up()
|
||||
|
||||
void tst_QFiledialog::acceptMode()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.show();
|
||||
|
||||
QToolButton* newButton = fd.findChild<QToolButton*>("newFolderButton");
|
||||
@ -619,7 +605,7 @@ void tst_QFiledialog::acceptMode()
|
||||
|
||||
void tst_QFiledialog::confirmOverwrite()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QCOMPARE(fd.confirmOverwrite(), true);
|
||||
fd.setConfirmOverwrite(true);
|
||||
QCOMPARE(fd.confirmOverwrite(), true);
|
||||
@ -631,7 +617,7 @@ void tst_QFiledialog::confirmOverwrite()
|
||||
|
||||
void tst_QFiledialog::defaultSuffix()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QCOMPARE(fd.defaultSuffix(), QString());
|
||||
fd.setDefaultSuffix("txt");
|
||||
QCOMPARE(fd.defaultSuffix(), QString("txt"));
|
||||
@ -643,7 +629,7 @@ void tst_QFiledialog::defaultSuffix()
|
||||
|
||||
void tst_QFiledialog::fileMode()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QCOMPARE(fd.fileMode(), QFileDialog::AnyFile);
|
||||
fd.setFileMode(QFileDialog::ExistingFile);
|
||||
QCOMPARE(fd.fileMode(), QFileDialog::ExistingFile);
|
||||
@ -657,7 +643,7 @@ void tst_QFiledialog::fileMode()
|
||||
|
||||
void tst_QFiledialog::caption()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setWindowTitle("testing");
|
||||
fd.setFileMode(QFileDialog::Directory);
|
||||
QCOMPARE(fd.windowTitle(), QString("testing"));
|
||||
@ -665,8 +651,7 @@ void tst_QFiledialog::caption()
|
||||
|
||||
void tst_QFiledialog::filters()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
fd.setOptions(QFileDialog::DontUseNativeDialog);
|
||||
QFileDialog fd;
|
||||
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
|
||||
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(QString)));
|
||||
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(QStringList)));
|
||||
@ -701,7 +686,7 @@ void tst_QFiledialog::filters()
|
||||
QCOMPARE(spyFilterSelected.count(), 0);
|
||||
|
||||
//Let check if filters with whitespaces
|
||||
QNonNativeFileDialog fd2;
|
||||
QFileDialog fd2;
|
||||
QStringList expected;
|
||||
expected << "C++ Source Files(*.cpp)";
|
||||
expected << "Any(*.*)";
|
||||
@ -719,7 +704,7 @@ void tst_QFiledialog::filters()
|
||||
|
||||
void tst_QFiledialog::selectFilter()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(QString)));
|
||||
QCOMPARE(fd.selectedNameFilter(), QString("All Files (*)"));
|
||||
QStringList filters;
|
||||
@ -742,7 +727,7 @@ void tst_QFiledialog::selectFilter()
|
||||
|
||||
void tst_QFiledialog::history()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
|
||||
QVERIFY(model);
|
||||
@ -784,7 +769,7 @@ void tst_QFiledialog::history()
|
||||
|
||||
void tst_QFiledialog::iconProvider()
|
||||
{
|
||||
QNonNativeFileDialog *fd = new QNonNativeFileDialog();
|
||||
QFileDialog *fd = new QFileDialog();
|
||||
QVERIFY(fd->iconProvider() != 0);
|
||||
QFileIconProvider *ip = new QFileIconProvider();
|
||||
fd->setIconProvider(ip);
|
||||
@ -795,7 +780,7 @@ void tst_QFiledialog::iconProvider()
|
||||
|
||||
void tst_QFiledialog::isReadOnly()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
|
||||
QPushButton* newButton = fd.findChild<QPushButton*>("newFolderButton");
|
||||
QAction* renameAction = fd.findChild<QAction*>("qt_rename_action");
|
||||
@ -819,7 +804,7 @@ void tst_QFiledialog::isReadOnly()
|
||||
|
||||
void tst_QFiledialog::itemDelegate()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QVERIFY(fd.itemDelegate() != 0);
|
||||
QItemDelegate *id = new QItemDelegate(&fd);
|
||||
fd.setItemDelegate(id);
|
||||
@ -828,7 +813,7 @@ void tst_QFiledialog::itemDelegate()
|
||||
|
||||
void tst_QFiledialog::labelText()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QDialogButtonBox buttonBox;
|
||||
QPushButton *cancelButton = buttonBox.addButton(QDialogButtonBox::Cancel);
|
||||
QCOMPARE(fd.labelText(QFileDialog::LookIn), QString("Look in:"));
|
||||
@ -851,7 +836,7 @@ void tst_QFiledialog::labelText()
|
||||
|
||||
void tst_QFiledialog::resolveSymlinks()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
|
||||
// default
|
||||
QCOMPARE(fd.resolveSymlinks(), true);
|
||||
@ -877,7 +862,7 @@ void tst_QFiledialog::selectFile()
|
||||
{
|
||||
QFETCH(QString, file);
|
||||
QFETCH(int, count);
|
||||
QScopedPointer<QNonNativeFileDialog> fd(new QNonNativeFileDialog);
|
||||
QScopedPointer<QFileDialog> fd(new QFileDialog);
|
||||
QFileSystemModel *model = fd->findChild<QFileSystemModel*>("qt_filesystem_model");
|
||||
QVERIFY(model);
|
||||
fd->setDirectory(QDir::currentPath());
|
||||
@ -914,7 +899,7 @@ void tst_QFiledialog::selectFileWrongCaseSaveAs()
|
||||
QString wrongCasePath = path;
|
||||
for (int c = 0; c < wrongCasePath.size(); c += 2)
|
||||
wrongCasePath[c] = wrongCasePath.at(c).isLower() ? wrongCasePath.at(c).toUpper() : wrongCasePath.at(c).toLower();
|
||||
QNonNativeFileDialog fd(0, "QTBUG-38162", wrongCasePath);
|
||||
QFileDialog fd(0, "QTBUG-38162", wrongCasePath);
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
fd.selectFile(wrongCasePath);
|
||||
const QLineEdit *lineEdit = fd.findChild<QLineEdit*>("fileNameEdit");
|
||||
@ -928,7 +913,7 @@ void tst_QFiledialog::selectFiles()
|
||||
QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString()));
|
||||
const QString tempPath = tempDir.path();
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setDirectory(tempPath);
|
||||
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
|
||||
@ -978,7 +963,7 @@ void tst_QFiledialog::selectFiles()
|
||||
|
||||
{
|
||||
//If the selection is invalid then we fill the line edit but without the /
|
||||
QNonNativeFileDialog dialog( 0, "Save" );
|
||||
QFileDialog dialog( 0, "Save" );
|
||||
dialog.setFileMode( QFileDialog::AnyFile );
|
||||
dialog.setAcceptMode( QFileDialog::AcceptSave );
|
||||
dialog.selectFile(tempPath + QStringLiteral("/blah"));
|
||||
@ -992,7 +977,7 @@ void tst_QFiledialog::selectFiles()
|
||||
|
||||
void tst_QFiledialog::viewMode()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.show();
|
||||
|
||||
@ -1030,7 +1015,7 @@ void tst_QFiledialog::viewMode()
|
||||
|
||||
void tst_QFiledialog::proxymodel()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QCOMPARE(fd.proxyModel(), (QAbstractProxyModel*)0);
|
||||
|
||||
fd.setProxyModel(0);
|
||||
@ -1046,7 +1031,7 @@ void tst_QFiledialog::proxymodel()
|
||||
|
||||
void tst_QFiledialog::setEmptyNameFilter()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setNameFilter(QString());
|
||||
fd.setNameFilters(QStringList());
|
||||
}
|
||||
@ -1087,7 +1072,7 @@ void tst_QFiledialog::setNameFilter()
|
||||
QFETCH(QString, selectFilter);
|
||||
QFETCH(QString, expectedSelectedFilter);
|
||||
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setNameFilters(filters);
|
||||
fd.setNameFilterDetailsVisible(nameFilterDetailsVisible);
|
||||
fd.selectNameFilter(selectFilter);
|
||||
@ -1096,7 +1081,7 @@ void tst_QFiledialog::setNameFilter()
|
||||
|
||||
void tst_QFiledialog::focus()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setDirectory(QDir::currentPath());
|
||||
fd.show();
|
||||
QApplication::setActiveWindow(&fd);
|
||||
@ -1118,7 +1103,7 @@ void tst_QFiledialog::focus()
|
||||
|
||||
void tst_QFiledialog::historyBack()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
|
||||
QVERIFY(model);
|
||||
QToolButton *backButton = fd.findChild<QToolButton*>("backButton");
|
||||
@ -1165,7 +1150,7 @@ void tst_QFiledialog::historyBack()
|
||||
|
||||
void tst_QFiledialog::historyForward()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setDirectory(QDir::currentPath());
|
||||
QToolButton *backButton = fd.findChild<QToolButton*>("backButton");
|
||||
QVERIFY(backButton);
|
||||
@ -1241,7 +1226,7 @@ void tst_QFiledialog::disableSaveButton()
|
||||
QFETCH(QString, path);
|
||||
QFETCH(bool, isEnabled);
|
||||
|
||||
QNonNativeFileDialog fd(0, "caption", path);
|
||||
QFileDialog fd(0, "caption", path);
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
QDialogButtonBox *buttonBox = fd.findChild<QDialogButtonBox*>("buttonBox");
|
||||
QPushButton *button = buttonBox->button(QDialogButtonBox::Save);
|
||||
@ -1268,7 +1253,7 @@ void tst_QFiledialog::saveButtonText()
|
||||
QFETCH(QString, label);
|
||||
QFETCH(QString, caption);
|
||||
|
||||
QNonNativeFileDialog fd(0, "auto test", QDir::temp().absolutePath());
|
||||
QFileDialog fd(0, "auto test", QDir::temp().absolutePath());
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
if (!label.isNull())
|
||||
fd.setLabelText(QFileDialog::Accept, label);
|
||||
@ -1283,10 +1268,9 @@ void tst_QFiledialog::saveButtonText()
|
||||
|
||||
void tst_QFiledialog::clearLineEdit()
|
||||
{
|
||||
QNonNativeFileDialog fd(0, "caption", "foo");
|
||||
QFileDialog fd(0, "caption", "foo");
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setFileMode(QFileDialog::AnyFile);
|
||||
fd.setOptions(QFileDialog::DontUseNativeDialog);
|
||||
fd.show();
|
||||
|
||||
//play it really safe by creating a directory
|
||||
@ -1320,7 +1304,7 @@ void tst_QFiledialog::clearLineEdit()
|
||||
|
||||
// selecting a dir the text should be cleared so one can just hit ok
|
||||
// and it selects that directory
|
||||
fd.setFileMode(QNonNativeFileDialog::Directory);
|
||||
fd.setFileMode(QFileDialog::Directory);
|
||||
fd.setDirectory(QDir::home());
|
||||
|
||||
QTest::qWait(1000);
|
||||
@ -1341,7 +1325,7 @@ void tst_QFiledialog::clearLineEdit()
|
||||
|
||||
void tst_QFiledialog::enableChooseButton()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setFileMode(QFileDialog::Directory);
|
||||
fd.show();
|
||||
QDialogButtonBox *buttonBox = fd.findChild<QDialogButtonBox*>("buttonBox");
|
||||
@ -1354,6 +1338,7 @@ void tst_QFiledialog::widgetlessNativeDialog()
|
||||
{
|
||||
if (!QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::FileDialog))
|
||||
QSKIP("This platform always uses widgets to realize its QFileDialog, instead of the native file dialog.");
|
||||
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, false);
|
||||
QFileDialog fd;
|
||||
fd.setWindowModality(Qt::ApplicationModal);
|
||||
fd.show();
|
||||
@ -1377,10 +1362,9 @@ void tst_QFiledialog::trailingDotsAndSpaces()
|
||||
#ifndef Q_OS_WIN
|
||||
QSKIP("This is only tested on Windows");
|
||||
#endif
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setFileMode(QFileDialog::ExistingFile);
|
||||
fd.setOptions(QFileDialog::DontUseNativeDialog);
|
||||
fd.show();
|
||||
QLineEdit *lineEdit = fd.findChild<QLineEdit *>("fileNameEdit");
|
||||
QVERIFY(lineEdit);
|
||||
@ -1456,35 +1440,28 @@ public slots:
|
||||
void tst_QFiledialog::rejectModalDialogs()
|
||||
{
|
||||
// QTBUG-38672 , static functions should return empty Urls
|
||||
const QFileDialog::Options options = QFileDialog::DontUseNativeDialog;
|
||||
DialogRejecter dr;
|
||||
|
||||
QUrl url = QFileDialog::getOpenFileUrl(0, QStringLiteral("getOpenFileUrl"),
|
||||
QUrl(), QString(), Q_NULLPTR, options);
|
||||
QUrl url = QFileDialog::getOpenFileUrl(0, QStringLiteral("getOpenFileUrl"));
|
||||
QVERIFY(url.isEmpty());
|
||||
QVERIFY(!url.isValid());
|
||||
|
||||
url = QFileDialog::getExistingDirectoryUrl(0, QStringLiteral("getExistingDirectoryUrl"),
|
||||
QUrl(), options | QFileDialog::ShowDirsOnly);
|
||||
url = QFileDialog::getExistingDirectoryUrl(0, QStringLiteral("getExistingDirectoryUrl"));
|
||||
QVERIFY(url.isEmpty());
|
||||
QVERIFY(!url.isValid());
|
||||
|
||||
url = QFileDialog::getSaveFileUrl(0, QStringLiteral("getSaveFileUrl"),
|
||||
QUrl(), QString(), Q_NULLPTR, options);
|
||||
url = QFileDialog::getSaveFileUrl(0, QStringLiteral("getSaveFileUrl"));
|
||||
QVERIFY(url.isEmpty());
|
||||
QVERIFY(!url.isValid());
|
||||
|
||||
// Same test with local files
|
||||
QString file = QFileDialog::getOpenFileName(0, QStringLiteral("getOpenFileName"),
|
||||
QString(), QString(), Q_NULLPTR, options);
|
||||
QString file = QFileDialog::getOpenFileName(0, QStringLiteral("getOpenFileName"));
|
||||
QVERIFY(file.isEmpty());
|
||||
|
||||
file = QFileDialog::getExistingDirectory(0, QStringLiteral("getExistingDirectory"),
|
||||
QString(), options | QFileDialog::ShowDirsOnly);
|
||||
file = QFileDialog::getExistingDirectory(0, QStringLiteral("getExistingDirectory"));
|
||||
QVERIFY(file.isEmpty());
|
||||
|
||||
file = QFileDialog::getSaveFileName(0, QStringLiteral("getSaveFileName"),
|
||||
QString(), QString(), Q_NULLPTR, options);
|
||||
file = QFileDialog::getSaveFileName(0, QStringLiteral("getSaveFileName"));
|
||||
QVERIFY(file.isEmpty());
|
||||
}
|
||||
|
||||
|
@ -65,17 +65,6 @@ Q_GUI_EXPORT void qt_test_resetFetchedRoot();
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
class QNonNativeFileDialog : public QFileDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QNonNativeFileDialog(QWidget *parent = 0, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString())
|
||||
: QFileDialog(parent, caption, directory, filter)
|
||||
{
|
||||
setOption(QFileDialog::DontUseNativeDialog, true);
|
||||
}
|
||||
};
|
||||
|
||||
static QByteArray msgDoesNotExist(const QString &name)
|
||||
{
|
||||
return (QLatin1Char('"') + QDir::toNativeSeparators(name)
|
||||
@ -148,6 +137,7 @@ private:
|
||||
tst_QFileDialog2::tst_QFileDialog2()
|
||||
: tempDir(QDir::tempPath() + "/tst_qfiledialog2.XXXXXX")
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
|
||||
#if defined(Q_OS_WINCE)
|
||||
qApp->setAutoMaximizeThreshold(-1);
|
||||
#endif
|
||||
@ -176,7 +166,7 @@ void tst_QFileDialog2::init()
|
||||
{
|
||||
QFileDialogPrivate::setLastVisitedDirectory(QUrl());
|
||||
// populate the sidebar with some default settings
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
#if defined(Q_OS_WINCE)
|
||||
QTest::qWait(1000);
|
||||
#endif
|
||||
@ -195,7 +185,7 @@ void tst_QFileDialog2::listRoot()
|
||||
QTest::qWait(1500);
|
||||
qt_test_resetFetchedRoot();
|
||||
QString dir(QDir::currentPath());
|
||||
QNonNativeFileDialog fd(0, QString(), dir);
|
||||
QFileDialog fd(0, QString(), dir);
|
||||
fd.show();
|
||||
QCOMPARE(qt_test_isFetchedRoot(),false);
|
||||
fd.setDirectory("");
|
||||
@ -210,15 +200,15 @@ void tst_QFileDialog2::listRoot()
|
||||
|
||||
void tst_QFileDialog2::heapCorruption()
|
||||
{
|
||||
QVector<QNonNativeFileDialog*> dialogs;
|
||||
QVector<QFileDialog*> dialogs;
|
||||
for (int i=0; i < 10; i++) {
|
||||
QNonNativeFileDialog *f = new QNonNativeFileDialog(NULL);
|
||||
QFileDialog *f = new QFileDialog(NULL);
|
||||
dialogs << f;
|
||||
}
|
||||
qDeleteAll(dialogs);
|
||||
}
|
||||
|
||||
struct FriendlyQFileDialog : public QNonNativeFileDialog
|
||||
struct FriendlyQFileDialog : public QFileDialog
|
||||
{
|
||||
friend class tst_QFileDialog2;
|
||||
Q_DECLARE_PRIVATE(QFileDialog)
|
||||
@ -249,7 +239,6 @@ void tst_QFileDialog2::deleteDirAndFiles()
|
||||
t->close();
|
||||
delete t;
|
||||
FriendlyQFileDialog fd;
|
||||
fd.setOption(QFileDialog::DontUseNativeDialog);
|
||||
fd.d_func()->removeDirectory(tempPath);
|
||||
QFileInfo info(tempPath);
|
||||
QTest::qWait(2000);
|
||||
@ -259,7 +248,7 @@ void tst_QFileDialog2::deleteDirAndFiles()
|
||||
|
||||
void tst_QFileDialog2::filter()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QAction *hiddenAction = fd.findChild<QAction*>("qt_show_hidden_action");
|
||||
QVERIFY(hiddenAction);
|
||||
QVERIFY(hiddenAction->isEnabled());
|
||||
@ -272,7 +261,7 @@ void tst_QFileDialog2::filter()
|
||||
|
||||
void tst_QFileDialog2::showNameFilterDetails()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QComboBox *filters = fd.findChild<QComboBox*>("fileTypeCombo");
|
||||
QVERIFY(filters);
|
||||
QVERIFY(fd.isNameFilterDetailsVisible());
|
||||
@ -304,7 +293,7 @@ void tst_QFileDialog2::unc()
|
||||
QString dir(QDir::currentPath());
|
||||
#endif
|
||||
QVERIFY2(QFile::exists(dir), msgDoesNotExist(dir).constData());
|
||||
QNonNativeFileDialog fd(0, QString(), dir);
|
||||
QFileDialog fd(0, QString(), dir);
|
||||
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
|
||||
QVERIFY(model);
|
||||
QCOMPARE(model->index(fd.directory().absolutePath()), model->index(dir));
|
||||
@ -312,7 +301,7 @@ void tst_QFileDialog2::unc()
|
||||
|
||||
void tst_QFileDialog2::emptyUncPath()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.show();
|
||||
QLineEdit *lineEdit = fd.findChild<QLineEdit*>("fileNameEdit");
|
||||
QVERIFY(lineEdit);
|
||||
@ -381,7 +370,7 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior()
|
||||
QVERIFY(ctx.file.permissions() & QFile::WriteUser);
|
||||
ctx.file.close();
|
||||
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setDirectory(ctx.test.absolutePath());
|
||||
fd.show();
|
||||
@ -422,7 +411,7 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior()
|
||||
|
||||
void tst_QFileDialog2::task178897_minimumSize()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QSize oldMs = fd.layout()->minimumSize();
|
||||
QStringList history = fd.history();
|
||||
history << QDir::toNativeSeparators("/verylongdirectory/"
|
||||
@ -462,7 +451,7 @@ void tst_QFileDialog2::task180459_lastDirectory()
|
||||
if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive))
|
||||
QSKIP("Insignificant on OSX"); //QTBUG-39183
|
||||
//first visit the temp directory and close the dialog
|
||||
QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", tempDir.path());
|
||||
QFileDialog *dlg = new QFileDialog(0, "", tempDir.path());
|
||||
QFileSystemModel *model = dlg->findChild<QFileSystemModel*>("qt_filesystem_model");
|
||||
QVERIFY(model);
|
||||
QCOMPARE(model->index(tempDir.path()), model->index(dlg->directory().absolutePath()));
|
||||
@ -473,7 +462,7 @@ void tst_QFileDialog2::task180459_lastDirectory()
|
||||
QFETCH(bool, isEnabled);
|
||||
QFETCH(QString, result);
|
||||
|
||||
dlg = new QNonNativeFileDialog(0, "", path);
|
||||
dlg = new QFileDialog(0, "", path);
|
||||
model = dlg->findChild<QFileSystemModel*>("qt_filesystem_model");
|
||||
QVERIFY(model);
|
||||
dlg->setAcceptMode(QFileDialog::AcceptSave);
|
||||
@ -549,14 +538,14 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
class CrashDialog : public QNonNativeFileDialog
|
||||
class CrashDialog : public QFileDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CrashDialog(QWidget *parent, const QString &caption, const
|
||||
QString &dir, const QString &filter)
|
||||
: QNonNativeFileDialog(parent, caption, dir, filter)
|
||||
: QFileDialog(parent, caption, dir, filter)
|
||||
{
|
||||
sortProxy *proxyModel = new sortProxy(this);
|
||||
setProxyModel(proxyModel);
|
||||
@ -566,7 +555,7 @@ QString &dir, const QString &filter)
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QFileDialog2::task227304_proxyOnFileDialog()
|
||||
{
|
||||
QNonNativeFileDialog fd(0, "", QDir::currentPath(), 0);
|
||||
QFileDialog fd(0, "", QDir::currentPath(), 0);
|
||||
fd.setProxyModel(new FilterDirModel(QDir::currentPath()));
|
||||
fd.show();
|
||||
QLineEdit *edit = fd.findChild<QLineEdit*>("fileNameEdit");
|
||||
@ -589,7 +578,7 @@ void tst_QFileDialog2::task227304_proxyOnFileDialog()
|
||||
dialog->close();
|
||||
fd.close();
|
||||
|
||||
QNonNativeFileDialog fd2(0, "I should not crash with a proxy", tempDir.path(), 0);
|
||||
QFileDialog fd2(0, "I should not crash with a proxy", tempDir.path(), 0);
|
||||
QSortFilterProxyModel *pm = new QSortFilterProxyModel;
|
||||
fd2.setProxyModel(pm);
|
||||
fd2.show();
|
||||
@ -617,7 +606,7 @@ void tst_QFileDialog2::task227930_correctNavigationKeyboardBehavior()
|
||||
QVERIFY(file2.open(QIODevice::WriteOnly | QIODevice::Text));
|
||||
current.cdUp();
|
||||
current.mkdir("test2");
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setDirectory(current.absolutePath());
|
||||
fd.show();
|
||||
@ -648,7 +637,7 @@ void tst_QFileDialog2::task227930_correctNavigationKeyboardBehavior()
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
||||
void tst_QFileDialog2::task226366_lowerCaseHardDriveWindows()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setDirectory(QDir::root().path());
|
||||
fd.show();
|
||||
QLineEdit *edit = fd.findChild<QLineEdit*>("fileNameEdit");
|
||||
@ -674,7 +663,7 @@ void tst_QFileDialog2::task226366_lowerCaseHardDriveWindows()
|
||||
|
||||
void tst_QFileDialog2::completionOnLevelAfterRoot()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
||||
fd.setDirectory("C:/");
|
||||
QDir current = fd.directory();
|
||||
@ -741,7 +730,7 @@ void tst_QFileDialog2::task233037_selectingDirectory()
|
||||
{
|
||||
QDir current = QDir::currentPath();
|
||||
current.mkdir("test");
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setDirectory(current.absolutePath());
|
||||
fd.setAcceptMode( QFileDialog::AcceptSave);
|
||||
@ -775,7 +764,7 @@ void tst_QFileDialog2::task235069_hideOnEscape()
|
||||
QFETCH(QFileDialog::ViewMode, viewMode);
|
||||
QDir current = QDir::currentPath();
|
||||
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
QSignalSpy spyFinished(&fd, &QDialog::finished);
|
||||
QVERIFY(spyFinished.isValid());
|
||||
QSignalSpy spyRejected(&fd, &QDialog::rejected);
|
||||
@ -823,7 +812,7 @@ void tst_QFileDialog2::task203703_returnProperSeparator()
|
||||
{
|
||||
QDir current = QDir::currentPath();
|
||||
current.mkdir("aaaaaaaaaaaaaaaaaa");
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setDirectory(current.absolutePath());
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
fd.setFileMode(QFileDialog::Directory);
|
||||
@ -860,7 +849,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting()
|
||||
QVERIFY2(tempFile->open(), qPrintable(tempFile->errorString()));
|
||||
current.cdUp();
|
||||
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setDirectory(current.absolutePath());
|
||||
fd.setViewMode(QFileDialog::Detail);
|
||||
fd.show();
|
||||
@ -880,7 +869,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting()
|
||||
#else
|
||||
QTest::qWait(500);
|
||||
#endif
|
||||
QNonNativeFileDialog fd2;
|
||||
QFileDialog fd2;
|
||||
fd2.setFileMode(QFileDialog::Directory);
|
||||
fd2.restoreState(fd.saveState());
|
||||
current.cd("aaaaaaaaaaaaaaaaaa");
|
||||
@ -907,7 +896,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting()
|
||||
#endif
|
||||
QCOMPARE(fd2.selectedFiles().first(), current.absolutePath() + QLatin1String("/g"));
|
||||
|
||||
QNonNativeFileDialog fd3(0, "This is a third file dialog", tempFile->fileName());
|
||||
QFileDialog fd3(0, "This is a third file dialog", tempFile->fileName());
|
||||
fd3.restoreState(fd.saveState());
|
||||
fd3.setFileMode(QFileDialog::Directory);
|
||||
fd3.show();
|
||||
@ -948,7 +937,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting()
|
||||
|
||||
void tst_QFileDialog2::task239706_editableFilterCombo()
|
||||
{
|
||||
QNonNativeFileDialog d;
|
||||
QFileDialog d;
|
||||
d.setNameFilter("*.cpp *.h");
|
||||
|
||||
d.show();
|
||||
@ -973,7 +962,7 @@ void tst_QFileDialog2::task218353_relativePaths()
|
||||
{
|
||||
QDir appDir = QDir::current();
|
||||
QVERIFY(appDir.cdUp() != false);
|
||||
QNonNativeFileDialog d(0, "TestDialog", "..");
|
||||
QFileDialog d(0, "TestDialog", "..");
|
||||
QCOMPARE(d.directory().absolutePath(), appDir.absolutePath());
|
||||
|
||||
d.setDirectory(appDir.absolutePath() + QLatin1String("/non-existing-directory/../another-non-existing-dir/../"));
|
||||
@ -989,7 +978,7 @@ void tst_QFileDialog2::task218353_relativePaths()
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QFileDialog2::task251321_sideBarHiddenEntries()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
|
||||
QDir current = QDir::currentPath();
|
||||
current.mkdir(".hidden");
|
||||
@ -1049,7 +1038,7 @@ public :
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QFileDialog2::task251341_sideBarRemoveEntries()
|
||||
{
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
|
||||
QDir current = QDir::currentPath();
|
||||
current.mkdir("testDir");
|
||||
@ -1118,7 +1107,7 @@ void tst_QFileDialog2::task254490_selectFileMultipleTimes()
|
||||
t = new QTemporaryFile;
|
||||
QVERIFY2(t->open(), qPrintable(t->errorString()));
|
||||
t->open();
|
||||
QNonNativeFileDialog fd(0, "TestFileDialog");
|
||||
QFileDialog fd(0, "TestFileDialog");
|
||||
|
||||
fd.setDirectory(tempPath);
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
@ -1152,7 +1141,7 @@ void tst_QFileDialog2::task257579_sideBarWithNonCleanUrls()
|
||||
dir.rmdir(dirname); //makes sure it doesn't exist any more
|
||||
QVERIFY(dir.mkdir(dirname));
|
||||
QString url = dir.absolutePath() + QLatin1Char('/') + dirname + QLatin1String("/..");
|
||||
QNonNativeFileDialog fd;
|
||||
QFileDialog fd;
|
||||
fd.setSidebarUrls(QList<QUrl>() << QUrl::fromLocalFile(url));
|
||||
QSidebar *sidebar = fd.findChild<QSidebar*>("sidebar");
|
||||
QCOMPARE(sidebar->urls().count(), 1);
|
||||
@ -1172,7 +1161,7 @@ void tst_QFileDialog2::task257579_sideBarWithNonCleanUrls()
|
||||
|
||||
void tst_QFileDialog2::task259105_filtersCornerCases()
|
||||
{
|
||||
QNonNativeFileDialog fd(0, "TestFileDialog");
|
||||
QFileDialog fd(0, "TestFileDialog");
|
||||
fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)"));
|
||||
fd.setOption(QFileDialog::HideNameFilterDetails, true);
|
||||
fd.show();
|
||||
@ -1219,7 +1208,7 @@ void tst_QFileDialog2::QTBUG4419_lineEditSelectAll()
|
||||
QString tempPath = tempDir.path();
|
||||
QTemporaryFile temporaryFile(tempPath + "/tst_qfiledialog2_lineEditSelectAll.XXXXXX");
|
||||
QVERIFY2(temporaryFile.open(), qPrintable(temporaryFile.errorString()));
|
||||
QNonNativeFileDialog fd(0, "TestFileDialog", temporaryFile.fileName());
|
||||
QFileDialog fd(0, "TestFileDialog", temporaryFile.fileName());
|
||||
|
||||
fd.setDirectory(tempPath);
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
@ -1262,7 +1251,7 @@ void tst_QFileDialog2::QTBUG6558_showDirsOnly()
|
||||
out << "The magic number is: " << 49 << "\n";
|
||||
tempFile.close();
|
||||
|
||||
QNonNativeFileDialog fd(0, "TestFileDialog");
|
||||
QFileDialog fd(0, "TestFileDialog");
|
||||
|
||||
fd.setDirectory(dir.absolutePath());
|
||||
fd.setViewMode(QFileDialog::List);
|
||||
@ -1311,7 +1300,7 @@ void tst_QFileDialog2::QTBUG4842_selectFilterWithHideNameFilterDetails()
|
||||
filtersStr << "Images (*.png *.xpm *.jpg)" << "Text files (*.txt)" << "XML files (*.xml)";
|
||||
QString chosenFilterString("Text files (*.txt)");
|
||||
|
||||
QNonNativeFileDialog fd(0, "TestFileDialog");
|
||||
QFileDialog fd(0, "TestFileDialog");
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
fd.setOption(QFileDialog::HideNameFilterDetails, true);
|
||||
fd.setNameFilters(filtersStr);
|
||||
@ -1327,7 +1316,7 @@ void tst_QFileDialog2::QTBUG4842_selectFilterWithHideNameFilterDetails()
|
||||
//We compare the current combobox text with the stripped version
|
||||
QCOMPARE(filters->currentText(), QString("Text files"));
|
||||
|
||||
QNonNativeFileDialog fd2(0, "TestFileDialog");
|
||||
QFileDialog fd2(0, "TestFileDialog");
|
||||
fd2.setAcceptMode(QFileDialog::AcceptSave);
|
||||
fd2.setOption(QFileDialog::HideNameFilterDetails, false);
|
||||
fd2.setNameFilters(filtersStr);
|
||||
@ -1347,7 +1336,7 @@ void tst_QFileDialog2::QTBUG4842_selectFilterWithHideNameFilterDetails()
|
||||
|
||||
void tst_QFileDialog2::dontShowCompleterOnRoot()
|
||||
{
|
||||
QNonNativeFileDialog fd(0, "TestFileDialog");
|
||||
QFileDialog fd(0, "TestFileDialog");
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
fd.show();
|
||||
|
||||
|
@ -280,6 +280,7 @@ void tst_QGraphicsProxyWidget::initTestCase()
|
||||
QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false);
|
||||
// Disable combo for QTBUG_43780_visibility()/Windows Vista.
|
||||
QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false);
|
||||
QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
|
||||
}
|
||||
|
||||
// This will be called after every test function.
|
||||
|
Loading…
Reference in New Issue
Block a user