X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0d2aa8a1bed1cef4a2dd99493dacf40812807cf9..231200e6800a20aef5a1ba68dd3d64ecbee01000:/src/tests/dolphinmainwindowtest.cpp diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 60d46518a..f5ece564d 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -212,7 +212,8 @@ void DolphinMainWindowTest::testUpdateWindowTitleAfterChangingSplitView() // Test case for bug #397910 void DolphinMainWindowTest::testOpenInNewTabTitle() { - m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); + const QUrl homePathUrl{QUrl::fromLocalFile(QDir::homePath())}; + m_mainWindow->openDirectories({homePathUrl}, false); m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); @@ -220,13 +221,14 @@ void DolphinMainWindowTest::testOpenInNewTabTitle() auto tabWidget = m_mainWindow->findChild("tabWidget"); QVERIFY(tabWidget); - tabWidget->openNewTab(QUrl::fromLocalFile(QDir::tempPath())); + const QUrl tempPathUrl{QUrl::fromLocalFile(QDir::tempPath())}; + tabWidget->openNewTab(tempPathUrl); QCOMPARE(tabWidget->count(), 2); QVERIFY(tabWidget->tabText(0) != tabWidget->tabText(1)); - if (!tabWidget->tabIcon(0).isNull() && !tabWidget->tabIcon(1).isNull()) { - QCOMPARE(QStringLiteral("inode-directory"), tabWidget->tabIcon(0).name()); - QCOMPARE(QStringLiteral("inode-directory"), tabWidget->tabIcon(1).name()); - } + + QVERIFY2(!tabWidget->tabIcon(0).isNull() && !tabWidget->tabIcon(1).isNull(), "Tabs are supposed to have icons."); + QCOMPARE(KIO::iconNameForUrl(homePathUrl), tabWidget->tabIcon(0).name()); + QCOMPARE(KIO::iconNameForUrl(tempPathUrl), tabWidget->tabIcon(1).name()); } void DolphinMainWindowTest::testNewFileMenuEnabled_data() @@ -539,29 +541,47 @@ void DolphinMainWindowTest::testAccessibilityAncestorTree() QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - std::set 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); + // We will test the accessibility of objects traversing forwards and backwards. + int testedObjectsSizeAfterTraversingForwards = 0; + for (int i = 0; i < 2; i++) { + std::tuple focusChainTraversalKeyCombination = {Qt::Key::Key_Tab, Qt::NoModifier}; + if (i) { + focusChainTraversalKeyCombination = {Qt::Key::Key_Tab, Qt::ShiftModifier}; } - 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(); + + // We will do accessibility checks for every object that gets focus. Focus will be changed using the focusChainTraversalKeyCombination. + std::set testedObjects; // Makes sure we stop testing when we arrive at an item that was already tested. + 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(), std::get<0>(focusChainTraversalKeyCombination), std::get<1>(focusChainTraversalKeyCombination)); + QVERIFY2(currentlyFocusedObject != qApp->focusObject(), + "The focus chain is broken. The focused object should have changed after pressing the focusChainTraversalKeyCombination."); } - 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. + if (i == 0) { + testedObjectsSizeAfterTraversingForwards = testedObjects.size(); + } else { + QCOMPARE(testedObjects.size(), testedObjectsSizeAfterTraversingForwards); // The size after traversing backwards is different than + // after going forwards which is probably not intended. + } } } @@ -586,6 +606,7 @@ void DolphinMainWindowTest::testAutoSaveSession() // Enable session autosave. m_mainWindow->setSessionAutoSaveEnabled(true); + m_mainWindow->m_sessionSaveTimer->setInterval(200); // Lower the interval to speed up the testing // Open a new tab auto tabWidget = m_mainWindow->findChild("tabWidget");