Android: fix Android filedialog and completer tests
* https://developer.android.com/training/data-storage/use-cases#opt-out- in-production-app Pick-to: 6.4 6.3 6.2 Task-number: QTQAINFRA-4748 Change-Id: If6abb48b730b9b33807f5f6648e1360defc090a6 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
1b4a792071
commit
2c6e71e562
@ -418,7 +418,18 @@ void tst_QFiledialog::completer_data()
|
||||
QTest::newRow("goto root") << QString() << rootPath << -1;
|
||||
QTest::newRow("start at root") << rootPath << QString() << -1;
|
||||
|
||||
QFileInfoList list = QDir::root().entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
QDir dir = QDir::root();
|
||||
#ifdef Q_OS_ANDROID
|
||||
// Android 11 and above doesn't allow accessing root filesystem as before,
|
||||
// so let's opt int for the app's home.
|
||||
if (QNativeInterface::QAndroidApplication::sdkVersion() >= 30) {
|
||||
const auto homePaths = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
||||
QVERIFY(!homePaths.isEmpty());
|
||||
dir = QDir(homePaths.first());
|
||||
}
|
||||
#endif
|
||||
|
||||
QFileInfoList list = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
QVERIFY(!list.isEmpty());
|
||||
const QString folder = list.first().absoluteFilePath();
|
||||
QTest::newRow("start at one below root r") << folder << "r" << -1;
|
||||
|
@ -669,6 +669,17 @@ void tst_QFileDialog2::completionOnLevelAfterRoot()
|
||||
}
|
||||
if (testDir.isEmpty())
|
||||
QSKIP("This test requires to have a unique directory of at least six ascii characters under c:/");
|
||||
#elif defined(Q_OS_ANDROID)
|
||||
// Android 11 and above doesn't allow accessing root filesystem as before,
|
||||
// so let's opt int for the app's home.
|
||||
const auto homePaths = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
||||
QVERIFY(!homePaths.isEmpty());
|
||||
fd.setFilter(QDir::Hidden | QDir::AllDirs | QDir::Files | QDir::System);
|
||||
fd.setDirectory(homePaths.first());
|
||||
QDir(homePaths.first()).mkdir("etc");
|
||||
auto cleanup = qScopeGuard([&]() {
|
||||
QDir(homePaths.first()).rmdir("etc");
|
||||
});
|
||||
#else
|
||||
fd.setFilter(QDir::Hidden | QDir::AllDirs | QDir::Files | QDir::System);
|
||||
fd.setDirectory("/");
|
||||
|
@ -151,6 +151,16 @@ tst_QCompleter::~tst_QCompleter()
|
||||
delete completer;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
static QString androidHomePath()
|
||||
{
|
||||
const auto homePaths = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
||||
QDir dir = homePaths.isEmpty() ? QDir() : homePaths.first();
|
||||
dir.cdUp();
|
||||
return dir.path();
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QCompleter::setSourceModel(ModelType type)
|
||||
{
|
||||
QTreeWidgetItem *parent, *child;
|
||||
@ -203,7 +213,13 @@ void tst_QCompleter::setSourceModel(ModelType type)
|
||||
completer->setCsvCompletion(false);
|
||||
{
|
||||
auto m = new QFileSystemModel(completer);
|
||||
#ifdef Q_OS_ANDROID
|
||||
// Android 11 and above doesn't allow accessing root filesystem as before,
|
||||
// so let's opt int for the app's home.
|
||||
m->setRootPath(androidHomePath());
|
||||
#else
|
||||
m->setRootPath("/");
|
||||
#endif
|
||||
completer->setModel(m);
|
||||
}
|
||||
completer->setCompletionColumn(0);
|
||||
@ -590,7 +606,9 @@ void tst_QCompleter::fileSystemModel_data()
|
||||
// QTest::newRow("(/d)") << "/d" << "" << "Developer" << "/Developer";
|
||||
#elif defined(Q_OS_ANDROID)
|
||||
QTest::newRow("()") << "" << "" << "/" << "/";
|
||||
QTest::newRow("(/et)") << "/et" << "" << "etc" << "/etc";
|
||||
const QString androidDir = androidHomePath();
|
||||
const QString tag = QStringLiteral("%1/fil").arg(androidDir);
|
||||
QTest::newRow(tag.toUtf8().data()) << tag << "" << "files" << androidDir + "/files";
|
||||
#else
|
||||
QTest::newRow("()") << "" << "" << "/" << "/";
|
||||
#if !defined(Q_OS_AIX) && !defined(Q_OS_HPUX) && !defined(Q_OS_QNX)
|
||||
|
Loading…
Reference in New Issue
Block a user