summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/platform/android/tst_android.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/platform/android/tst_android.cpp')
-rw-r--r--tests/auto/corelib/platform/android/tst_android.cpp179
1 files changed, 177 insertions, 2 deletions
diff --git a/tests/auto/corelib/platform/android/tst_android.cpp b/tests/auto/corelib/platform/android/tst_android.cpp
index 2fa6ec6415..e03308a883 100644
--- a/tests/auto/corelib/platform/android/tst_android.cpp
+++ b/tests/auto/corelib/platform/android/tst_android.cpp
@@ -1,11 +1,21 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <jni.h>
#include <QTest>
+#include <QGuiApplication>
#include <QtCore/qnativeinterface.h>
#include <QtCore/qjniobject.h>
+#include <QtCore/qdiriterator.h>
+#include <QScreen>
+#include <qpa/qplatformscreen.h>
+#include <qpa/qplatformnativeinterface.h>
+#include <QtCore/qdiriterator.h>
+#include <QWidget>
+#include <QSignalSpy>
+
+using namespace Qt::StringLiterals;
class tst_Android : public QObject
{
@@ -13,9 +23,13 @@ Q_OBJECT
private slots:
void assetsRead();
void assetsNotWritable();
+ void assetsIterating();
void testAndroidSdkVersion();
void testAndroidActivity();
void testRunOnAndroidMainThread();
+ void testFullScreenDimensions();
+ void orientationChange_data();
+ void orientationChange();
};
void tst_Android::assetsRead()
@@ -41,6 +55,31 @@ void tst_Android::assetsNotWritable()
QVERIFY(!file.open(QIODevice::Append));
}
+void tst_Android::assetsIterating()
+{
+ QStringList assets = {"assets:/top_level_dir/file_in_top_dir.txt",
+ "assets:/top_level_dir/sub_dir",
+ "assets:/top_level_dir/sub_dir/file_in_sub_dir.txt",
+ "assets:/top_level_dir/sub_dir/sub_dir_2",
+ "assets:/top_level_dir/sub_dir/sub_dir_2/sub_dir_3",
+ "assets:/top_level_dir/sub_dir/sub_dir_2/sub_dir_3/file_in_sub_dir_3.txt"};
+
+ // Note that we have an "assets:/top_level_dir/sub_dir/empty_sub_dir" in the test's
+ // assets physical directory, but empty folders are not packaged in the built apk,
+ // so it's expected to not have such folder be listed in the assets on runtime
+
+ QDirIterator it("assets:/top_level_dir", QDirIterator::Subdirectories);
+ QStringList iteratorAssets;
+ while (it.hasNext())
+ iteratorAssets.append(it.next());
+
+ QVERIFY(assets == iteratorAssets);
+
+ auto entryList = QDir{"assets:/"_L1}.entryList(QStringList{"*.txt"_L1});
+ QCOMPARE(entryList.size(), 1);
+ QCOMPARE(entryList[0], "test.txt"_L1);
+}
+
void tst_Android::testAndroidSdkVersion()
{
QVERIFY(QNativeInterface::QAndroidApplication::sdkVersion() > 0);
@@ -164,6 +203,142 @@ void tst_Android::testRunOnAndroidMainThread()
}
}
+Q_DECLARE_JNI_CLASS(QtActivityDelegateBase, "org/qtproject/qt/android/QtActivityDelegateBase")
+
+void setSystemUiVisibility(int visibility)
+{
+ QNativeInterface::QAndroidApplication::runOnAndroidMainThread([visibility] {
+ auto context = QNativeInterface::QAndroidApplication::context();
+ auto activityDelegate = context.callMethod<QtJniTypes::QtActivityDelegateBase>("getActivityDelegate");
+ activityDelegate.callMethod<void>("setSystemUiVisibility", jint(visibility));
+ }).waitForFinished();
+}
+
+// QTBUG-107604
+void tst_Android::testFullScreenDimensions()
+{
+ static int SYSTEM_UI_VISIBILITY_NORMAL = 0;
+ static int SYSTEM_UI_VISIBILITY_FULLSCREEN = 1;
+ static int SYSTEM_UI_VISIBILITY_TRANSLUCENT = 2;
+
+ // this will trigger new layout updates
+ setSystemUiVisibility(SYSTEM_UI_VISIBILITY_FULLSCREEN);
+ setSystemUiVisibility(SYSTEM_UI_VISIBILITY_NORMAL);
+
+ QJniObject activity = QNativeInterface::QAndroidApplication::context();
+ QVERIFY(activity.isValid());
+
+ QJniObject windowManager =
+ activity.callObjectMethod("getWindowManager", "()Landroid/view/WindowManager;");
+ QVERIFY(windowManager.isValid());
+
+ QJniObject display = windowManager.callObjectMethod("getDefaultDisplay", "()Landroid/view/Display;");
+ QVERIFY(display.isValid());
+
+ QJniObject appSize("android/graphics/Point");
+ QVERIFY(appSize.isValid());
+
+ display.callMethod<void>("getSize", "(Landroid/graphics/Point;)V", appSize.object());
+
+ QJniObject realSize("android/graphics/Point");
+ QVERIFY(realSize.isValid());
+
+ display.callMethod<void>("getRealSize", "(Landroid/graphics/Point;)V", realSize.object());
+
+ QPlatformScreen *screen = QGuiApplication::primaryScreen()->handle();
+
+ {
+ // Normal -
+ // available geometry == app size (system bars visible and removed from available geometry)
+ QCoreApplication::processEvents();
+ QJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
+ QVERIFY(window.isValid());
+
+ QJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
+ QVERIFY(decorView.isValid());
+
+ QJniObject insets =
+ decorView.callObjectMethod("getRootWindowInsets", "()Landroid/view/WindowInsets;");
+ QVERIFY(insets.isValid());
+
+ int insetsWidth = insets.callMethod<jint>("getSystemWindowInsetRight")
+ + insets.callMethod<jint>("getSystemWindowInsetLeft");
+
+ int insetsHeight = insets.callMethod<jint>("getSystemWindowInsetTop")
+ + insets.callMethod<jint>("getSystemWindowInsetBottom");
+
+ QTRY_COMPARE(screen->availableGeometry().width(),
+ int(appSize.getField<jint>("x")) - insetsWidth);
+ QTRY_COMPARE(screen->availableGeometry().height(),
+ int(appSize.getField<jint>("y")) - insetsHeight);
+
+ QTRY_COMPARE(screen->geometry().width(), int(realSize.getField<jint>("x")));
+ QTRY_COMPARE(screen->geometry().height(), int(realSize.getField<jint>("y")));
+ }
+
+ {
+ setSystemUiVisibility(SYSTEM_UI_VISIBILITY_FULLSCREEN);
+
+ // Fullscreen
+ // available geometry == full display size (system bars hidden)
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(screen->availableGeometry().width(), int(realSize.getField<jint>("x")));
+ QTRY_COMPARE(screen->availableGeometry().height(), int(realSize.getField<jint>("y")));
+
+ QTRY_COMPARE(screen->geometry().width(), int(realSize.getField<jint>("x")));
+ QTRY_COMPARE(screen->geometry().height(), int(realSize.getField<jint>("y")));
+ }
+
+ {
+ setSystemUiVisibility(SYSTEM_UI_VISIBILITY_TRANSLUCENT);
+
+ // Translucent
+ // available geometry == full display size (system bars visible but drawable under)
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(screen->availableGeometry().width(), int(realSize.getField<jint>("x")));
+ QTRY_COMPARE(screen->availableGeometry().height(), int(realSize.getField<jint>("y")));
+
+ QTRY_COMPARE(screen->geometry().width(), int(realSize.getField<jint>("x")));
+ QTRY_COMPARE(screen->geometry().height(), int(realSize.getField<jint>("y")));
+ }
+}
+
+void tst_Android::orientationChange_data()
+{
+ QTest::addColumn<int>("nativeOrientation");
+ QTest::addColumn<Qt::ScreenOrientation>("expected");
+ QTest::addColumn<QSize>("screenSize");
+
+ const QSize portraitSize = QGuiApplication::primaryScreen()->size();
+ const QSize landscapeSize = QSize(portraitSize.height(), portraitSize.width());
+
+ QTest::newRow("InvertedLandscape") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize;
+ QTest::newRow("InvertedPortrait") << 9 << Qt::InvertedPortraitOrientation << portraitSize;
+ QTest::newRow("Landscape") << 0 << Qt::LandscapeOrientation << landscapeSize;
+ // Leave Portrait till the end
+ QTest::newRow("Portrait") << 1 << Qt::PortraitOrientation << portraitSize;
+}
+
+void tst_Android::orientationChange()
+{
+ QFETCH(int, nativeOrientation);
+ QFETCH(Qt::ScreenOrientation, expected);
+ QFETCH(QSize, screenSize);
+
+ // For QTBUG-94459 to check that the widget size are consistent after orientation changes
+ QWidget widget;
+ widget.show();
+
+ auto context = QNativeInterface::QAndroidApplication::context();
+ context.callMethod<void>("setRequestedOrientation", nativeOrientation);
+
+ QScreen *screen = QGuiApplication::primaryScreen();
+ QSignalSpy orientationSpy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
+ QTRY_COMPARE(screen->orientation(), expected);
+ QCOMPARE(orientationSpy.size(), 1);
+ QCOMPARE(screen->size(), screenSize);
+ QCOMPARE(widget.size(), screen->availableSize());
+}
+
QTEST_MAIN(tst_Android)
#include "tst_android.moc"
-