┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorNate Graham <[email protected]>2023-10-05 09:15:35 -0600
committerNate Graham <[email protected]>2023-10-05 09:15:35 -0600
commit30a807e44afb334dd153c8bcbdbde4f36942bee0 (patch)
treef2bb4b386ac76e257f87689e75db7364c7a12f6c /src/tests
parentb6d9cb9949111fbaf5c875e76619ca7af83c6fc3 (diff)
parentb58fead9beaf3165146d3e536b6b14ae1cc9514d (diff)
Merge branch 'master' into kf6
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/dolphinmainwindowtest.cpp37
-rw-r--r--src/tests/kitemlistcontrollerexpandtest.cpp3
-rw-r--r--src/tests/kitemlistcontrollertest.cpp3
3 files changed, 43 insertions, 0 deletions
diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp
index 009008002..e6c355a87 100644
--- a/src/tests/dolphinmainwindowtest.cpp
+++ b/src/tests/dolphinmainwindowtest.cpp
@@ -14,11 +14,14 @@
#include <KActionCollection>
+#include <QAccessible>
#include <QScopedPointer>
#include <QSignalSpy>
#include <QStandardPaths>
#include <QTest>
+#include <set>
+
class DolphinMainWindowTest : public QObject
{
Q_OBJECT
@@ -39,6 +42,7 @@ private Q_SLOTS:
void testPlacesPanelWidthResistance();
void testGoActions();
void testOpenFiles();
+ void testAccessibilityAncestorTree();
void cleanupTestCase();
private:
@@ -524,6 +528,39 @@ void DolphinMainWindowTest::testOpenFiles()
QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
}
+void DolphinMainWindowTest::testAccessibilityAncestorTree()
+{
+ m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
+ m_mainWindow->show();
+ QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+ QVERIFY(m_mainWindow->isVisible());
+
+ std::set<const QObject *> testedObjects; // Makes sure we stop testing if we arrive at an item that was already tested.
+ QAccessibleInterface *accessibleInterfaceOfMainWindow = QAccessible::queryAccessibleInterface(m_mainWindow.get());
+ Q_CHECK_PTR(accessibleInterfaceOfMainWindow);
+
+ // We will do accessibility checks for every object that gets focus. Focus will be changed using the Tab key.
+ while (qApp->focusObject() && !testedObjects.count(qApp->focusObject())) {
+ const auto currentlyFocusedObject = qApp->focusObject();
+ QAccessibleInterface *accessibleInterface = QAccessible::queryAccessibleInterface(currentlyFocusedObject);
+
+ // The accessibleInterfaces of focused objects might themselves have children.
+ // We go down that hierarchy as far as possible and then test the ancestor tree from there.
+ while (accessibleInterface->childCount() > 0) {
+ accessibleInterface = accessibleInterface->child(0);
+ }
+ while (accessibleInterface != accessibleInterfaceOfMainWindow) {
+ QVERIFY2(accessibleInterface,
+ qPrintable(QString("%1's accessibleInterface or one of its accessible children doesn't have the main window as an ancestor.")
+ .arg(currentlyFocusedObject->metaObject()->className())));
+ accessibleInterface = accessibleInterface->parent();
+ }
+
+ testedObjects.insert(currentlyFocusedObject); // Add it to testedObjects so we won't test it again later.
+ QTest::keyClick(m_mainWindow.get(), Qt::Key::Key_Tab, Qt::ShiftModifier); // ShiftModifier because the Tab cycle is currently broken going forward.
+ }
+}
+
void DolphinMainWindowTest::cleanupTestCase()
{
m_mainWindow->showNormal();
diff --git a/src/tests/kitemlistcontrollerexpandtest.cpp b/src/tests/kitemlistcontrollerexpandtest.cpp
index 368ec67ce..05708f4d2 100644
--- a/src/tests/kitemlistcontrollerexpandtest.cpp
+++ b/src/tests/kitemlistcontrollerexpandtest.cpp
@@ -48,6 +48,9 @@ void KItemListControllerExpandTest::initTestCase()
m_view = new KFileItemListView();
m_controller = new KItemListController(m_model, m_view, this);
m_container = new KItemListContainer(m_controller);
+#ifndef QT_NO_ACCESSIBILITY
+ m_view->setAccessibleParentsObject(m_container);
+#endif
m_controller = m_container->controller();
m_controller->setSelectionBehavior(KItemListController::MultiSelection);
m_selectionManager = m_controller->selectionManager();
diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp
index ac2110c0f..f462947c6 100644
--- a/src/tests/kitemlistcontrollertest.cpp
+++ b/src/tests/kitemlistcontrollertest.cpp
@@ -109,6 +109,9 @@ void KItemListControllerTest::initTestCase()
m_view = new KFileItemListView();
m_controller = new KItemListController(m_model, m_view, this);
m_container = new KItemListContainer(m_controller);
+#ifndef QT_NO_ACCESSIBILITY
+ m_view->setAccessibleParentsObject(m_container);
+#endif
m_controller = m_container->controller();
m_controller->setSelectionBehavior(KItemListController::MultiSelection);
m_selectionManager = m_controller->selectionManager();