summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2022-08-17 16:06:20 +0300
committerAssam Boudjelthia <assam.boudjelthia@qt.io>2022-08-18 10:51:54 +0000
commit2c6e71e562555c25e25b36d894dc42024fe35d55 (patch)
tree65c10682f7adde3d63f3c54b918b38e951b167cf
parent1b4a79207146ec378ea43de78fbf5c91d82d8355 (diff)
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>
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp13
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp11
-rw-r--r--tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp20
3 files changed, 42 insertions, 2 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index f236779eb5..e0d091c3bd 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -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;
diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
index f8dc03ac22..4ef1a0e36e 100644
--- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
@@ -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("/");
diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
index 76b12d7aea..92158190b8 100644
--- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
@@ -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)