2 * SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "dolphinmainwindow.h"
8 #include "dolphinnewfilemenu.h"
9 #include "dolphintabpage.h"
10 #include "dolphintabwidget.h"
11 #include "dolphinviewcontainer.h"
12 #include "kitemviews/kfileitemmodel.h"
13 #include "kitemviews/kitemlistcontainer.h"
14 #include "kitemviews/kitemlistcontroller.h"
15 #include "kitemviews/kitemlistselectionmanager.h"
16 #include "kitemviews/kitemlistwidget.h"
18 #include "views/dolphinitemlistview.h"
20 #include <KActionCollection>
24 #include <QAccessible>
25 #include <QDomDocument>
26 #include <QFileSystemWatcher>
27 #include <QScopedPointer>
29 #include <QStandardPaths>
33 #include <unordered_set>
35 class DolphinMainWindowTest
: public QObject
42 void testSyncDesktopAndPhoneUi();
43 void testClosingTabsWithSearchBoxVisible();
44 void testActiveViewAfterClosingSplitView_data();
45 void testActiveViewAfterClosingSplitView();
46 void testUpdateWindowTitleAfterClosingSplitView();
47 void testUpdateWindowTitleAfterChangingSplitView();
48 void testOpenInNewTabTitle();
49 void testNewFileMenuEnabled_data();
50 void testNewFileMenuEnabled();
51 void testWindowTitle_data();
52 void testWindowTitle();
53 void testFocusLocationBar();
54 void testFocusPlacesPanel();
55 void testPlacesPanelWidthResistance();
58 void testAccessibilityTree();
59 void testAutoSaveSession();
60 void testInlineRename();
61 void cleanupTestCase();
64 QScopedPointer
<DolphinMainWindow
> m_mainWindow
;
67 void DolphinMainWindowTest::initTestCase()
69 QStandardPaths::setTestModeEnabled(true);
72 void DolphinMainWindowTest::init()
74 m_mainWindow
.reset(new DolphinMainWindow());
78 * It is too easy to forget that most changes in dolphinui.rc should be mirrored in dolphinuiforphones.rc. This test makes sure that these two files stay
79 * mostly identical. Differences between those files need to be explicitly added as exceptions to this test. So if you land here after changing either
80 * dolphinui.rc or dolphinuiforphones.rc, then resolve this test failure either by making the exact same change to the other ui.rc file, or by adding the
81 * changed object to the `exceptions` variable below.
83 void DolphinMainWindowTest::testSyncDesktopAndPhoneUi()
85 std::unordered_set
<QString
> exceptions
{{QStringLiteral("version"), QStringLiteral("ToolBar")}};
87 QDomDocument desktopUi
;
88 QFile
desktopUiXmlFile(":/kxmlgui5/dolphin/dolphinui.rc");
89 desktopUiXmlFile
.open(QIODevice::ReadOnly
);
90 desktopUi
.setContent(&desktopUiXmlFile
);
91 desktopUiXmlFile
.close();
94 QFile
phoneUiXmlFile(":/kxmlgui5/dolphin/dolphinuiforphones.rc");
95 phoneUiXmlFile
.open(QIODevice::ReadOnly
);
96 phoneUi
.setContent(&phoneUiXmlFile
);
97 phoneUiXmlFile
.close();
99 QDomElement desktopUiElement
= desktopUi
.documentElement();
100 QDomElement phoneUiElement
= phoneUi
.documentElement();
102 auto nextUiElement
= [&exceptions
](QDomElement uiElement
) -> QDomElement
{
103 QDomNode nextUiNode
{uiElement
};
105 // If the current node is an exception, we skip its children as well.
106 if (exceptions
.count(nextUiNode
.nodeName()) == 0) {
107 auto firstChild
{nextUiNode
.firstChild()};
108 if (!firstChild
.isNull()) {
109 nextUiNode
= firstChild
;
113 auto nextSibling
{nextUiNode
.nextSibling()};
114 if (!nextSibling
.isNull()) {
115 nextUiNode
= nextSibling
;
118 auto parent
{nextUiNode
.parentNode()};
120 if (parent
.isNull()) {
121 return QDomElement();
123 auto nextParentSibling
{parent
.nextSibling()};
124 if (!nextParentSibling
.isNull()) {
125 nextUiNode
= nextParentSibling
;
128 parent
= parent
.parentNode();
132 && (nextUiNode
.toElement().isNull() || exceptions
.count(nextUiNode
.nodeName()))); // We loop until we either give up finding an element or find one.
133 if (nextUiNode
.isNull()) {
134 return QDomElement();
136 return nextUiNode
.toElement();
139 int totalComparisonsCount
{0};
141 QVERIFY2(desktopUiElement
.tagName() == phoneUiElement
.tagName(),
142 qPrintable(QStringLiteral("Node mismatch: dolphinui.rc/%1::%2 and dolphinuiforphones.rc/%3::%4")
143 .arg(desktopUiElement
.parentNode().toElement().tagName())
144 .arg(desktopUiElement
.tagName())
145 .arg(phoneUiElement
.parentNode().toElement().tagName())
146 .arg(phoneUiElement
.tagName())));
147 QCOMPARE(desktopUiElement
.text(), phoneUiElement
.text());
148 const auto desktopUiElementAttributes
= desktopUiElement
.attributes();
149 const auto phoneUiElementAttributes
= phoneUiElement
.attributes();
150 for (int i
= 0; i
< desktopUiElementAttributes
.count(); i
++) {
151 QVERIFY2(phoneUiElementAttributes
.count() >= i
,
152 qPrintable(QStringLiteral("Attribute mismatch: dolphinui.rc/%1::%2 has more attributes than dolphinuiforphones.rc/%3::%4")
153 .arg(desktopUiElement
.parentNode().toElement().tagName())
154 .arg(desktopUiElement
.tagName())
155 .arg(phoneUiElement
.parentNode().toElement().tagName())
156 .arg(phoneUiElement
.tagName())));
157 if (exceptions
.count(desktopUiElementAttributes
.item(i
).nodeName())) {
160 QCOMPARE(desktopUiElementAttributes
.item(i
).nodeName(), phoneUiElementAttributes
.item(i
).nodeName());
161 QCOMPARE(desktopUiElementAttributes
.item(i
).nodeValue(), phoneUiElementAttributes
.item(i
).nodeValue());
162 totalComparisonsCount
++;
164 QVERIFY2(desktopUiElementAttributes
.count() == phoneUiElementAttributes
.count(),
165 qPrintable(QStringLiteral("Attribute mismatch: dolphinui.rc/%1::%2 has fewer attributes than dolphinuiforphones.rc/%3::%4. %5 < %6")
166 .arg(desktopUiElement
.parentNode().toElement().tagName())
167 .arg(desktopUiElement
.tagName())
168 .arg(phoneUiElement
.parentNode().toElement().tagName())
169 .arg(phoneUiElement
.tagName())
170 .arg(phoneUiElementAttributes
.count())
171 .arg(desktopUiElementAttributes
.count())));
173 desktopUiElement
= nextUiElement(desktopUiElement
);
174 phoneUiElement
= nextUiElement(phoneUiElement
);
175 totalComparisonsCount
++;
176 } while (!desktopUiElement
.isNull() || !phoneUiElement
.isNull());
177 QVERIFY2(totalComparisonsCount
> 200, qPrintable(QStringLiteral("There were only %1 comparisons. Did the test run correctly?").arg(totalComparisonsCount
)));
180 // See https://bugs.kde.org/show_bug.cgi?id=379135
181 void DolphinMainWindowTest::testClosingTabsWithSearchBoxVisible()
183 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
184 m_mainWindow
->show();
185 // Without this call the searchbox doesn't get FocusIn events.
186 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
187 QVERIFY(m_mainWindow
->isVisible());
189 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
192 // Show search box on first tab.
193 tabWidget
->currentTabPage()->activeViewContainer()->setSearchModeEnabled(true);
195 tabWidget
->openNewActivatedTab(QUrl::fromLocalFile(QDir::homePath()));
196 QCOMPARE(tabWidget
->count(), 2);
198 // Triggers the crash in bug #379135.
199 tabWidget
->closeTab();
200 QCOMPARE(tabWidget
->count(), 1);
203 void DolphinMainWindowTest::testActiveViewAfterClosingSplitView_data()
205 QTest::addColumn
<bool>("closeLeftView");
207 QTest::newRow("close left view") << true;
208 QTest::newRow("close right view") << false;
211 void DolphinMainWindowTest::testActiveViewAfterClosingSplitView()
213 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
214 m_mainWindow
->show();
215 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
216 QVERIFY(m_mainWindow
->isVisible());
218 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
220 QVERIFY(tabWidget
->currentTabPage()->primaryViewContainer());
221 QVERIFY(!tabWidget
->currentTabPage()->secondaryViewContainer());
224 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger();
225 QVERIFY(tabWidget
->currentTabPage()->splitViewEnabled());
226 QVERIFY(tabWidget
->currentTabPage()->secondaryViewContainer());
228 // Make sure the right view is the active one.
229 auto leftViewContainer
= tabWidget
->currentTabPage()->primaryViewContainer();
230 auto rightViewContainer
= tabWidget
->currentTabPage()->secondaryViewContainer();
231 QVERIFY(!leftViewContainer
->isActive());
232 QVERIFY(rightViewContainer
->isActive());
234 QFETCH(bool, closeLeftView
);
236 // Activate left view.
237 leftViewContainer
->setActive(true);
238 QVERIFY(leftViewContainer
->isActive());
239 QVERIFY(!rightViewContainer
->isActive());
241 // Close left view. The secondary view (which was on the right) will become the primary one and must be active.
242 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger();
243 QVERIFY(!leftViewContainer
->isActive());
244 QVERIFY(rightViewContainer
->isActive());
245 QCOMPARE(rightViewContainer
, tabWidget
->currentTabPage()->activeViewContainer());
247 // Close right view. The left view will become active.
248 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger();
249 QVERIFY(leftViewContainer
->isActive());
250 QVERIFY(!rightViewContainer
->isActive());
251 QCOMPARE(leftViewContainer
, tabWidget
->currentTabPage()->activeViewContainer());
255 // Test case for bug #385111
256 void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView()
258 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
259 m_mainWindow
->show();
260 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
261 QVERIFY(m_mainWindow
->isVisible());
263 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
265 QVERIFY(tabWidget
->currentTabPage()->primaryViewContainer());
266 QVERIFY(!tabWidget
->currentTabPage()->secondaryViewContainer());
269 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger();
270 QVERIFY(tabWidget
->currentTabPage()->splitViewEnabled());
271 QVERIFY(tabWidget
->currentTabPage()->secondaryViewContainer());
273 // Make sure the right view is the active one.
274 auto leftViewContainer
= tabWidget
->currentTabPage()->primaryViewContainer();
275 auto rightViewContainer
= tabWidget
->currentTabPage()->secondaryViewContainer();
276 QVERIFY(!leftViewContainer
->isActive());
277 QVERIFY(rightViewContainer
->isActive());
279 // Activate left view.
280 leftViewContainer
->setActive(true);
281 QVERIFY(leftViewContainer
->isActive());
282 QVERIFY(!rightViewContainer
->isActive());
284 // Close split view. The secondary view (which was on the right) will become the primary one and must be active.
285 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger();
286 QVERIFY(!leftViewContainer
->isActive());
287 QVERIFY(rightViewContainer
->isActive());
288 QCOMPARE(rightViewContainer
, tabWidget
->currentTabPage()->activeViewContainer());
290 // Change URL and make sure we emit the currentUrlChanged signal (which triggers the window title update).
291 QSignalSpy
currentUrlChangedSpy(tabWidget
, &DolphinTabWidget::currentUrlChanged
);
292 tabWidget
->currentTabPage()->activeViewContainer()->setUrl(QUrl::fromLocalFile(QDir::rootPath()));
293 QCOMPARE(currentUrlChangedSpy
.count(), 1);
296 // Test case for bug #402641
297 void DolphinMainWindowTest::testUpdateWindowTitleAfterChangingSplitView()
299 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
300 m_mainWindow
->show();
301 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
302 QVERIFY(m_mainWindow
->isVisible());
304 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
308 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger();
309 QVERIFY(tabWidget
->currentTabPage()->splitViewEnabled());
311 auto leftViewContainer
= tabWidget
->currentTabPage()->primaryViewContainer();
312 auto rightViewContainer
= tabWidget
->currentTabPage()->secondaryViewContainer();
314 // Store old window title.
315 const auto oldTitle
= m_mainWindow
->windowTitle();
317 // Change URL in the right view and make sure the title gets updated.
318 rightViewContainer
->setUrl(QUrl::fromLocalFile(QDir::rootPath()));
319 QVERIFY(m_mainWindow
->windowTitle() != oldTitle
);
321 // Activate back the left view and check whether the old title gets restored.
322 leftViewContainer
->setActive(true);
323 QCOMPARE(m_mainWindow
->windowTitle(), oldTitle
);
326 // Test case for bug #397910
327 void DolphinMainWindowTest::testOpenInNewTabTitle()
329 const QUrl homePathUrl
{QUrl::fromLocalFile(QDir::homePath())};
330 m_mainWindow
->openDirectories({homePathUrl
}, false);
331 m_mainWindow
->show();
332 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
333 QVERIFY(m_mainWindow
->isVisible());
335 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
338 const QUrl tempPathUrl
{QUrl::fromLocalFile(QDir::tempPath())};
339 tabWidget
->openNewTab(tempPathUrl
);
340 QCOMPARE(tabWidget
->count(), 2);
341 QVERIFY(tabWidget
->tabText(0) != tabWidget
->tabText(1));
343 QVERIFY2(!tabWidget
->tabIcon(0).isNull() && !tabWidget
->tabIcon(1).isNull(), "Tabs are supposed to have icons.");
344 QCOMPARE(KIO::iconNameForUrl(homePathUrl
), tabWidget
->tabIcon(0).name());
345 QCOMPARE(KIO::iconNameForUrl(tempPathUrl
), tabWidget
->tabIcon(1).name());
348 void DolphinMainWindowTest::testNewFileMenuEnabled_data()
350 QTest::addColumn
<QUrl
>("activeViewUrl");
351 QTest::addColumn
<bool>("expectedEnabled");
353 QTest::newRow("home") << QUrl::fromLocalFile(QDir::homePath()) << true;
354 QTest::newRow("root") << QUrl::fromLocalFile(QDir::rootPath()) << false;
355 QTest::newRow("trash") << QUrl::fromUserInput(QStringLiteral("trash:/")) << false;
358 void DolphinMainWindowTest::testNewFileMenuEnabled()
360 QFETCH(QUrl
, activeViewUrl
);
361 m_mainWindow
->openDirectories({activeViewUrl
}, false);
362 m_mainWindow
->show();
363 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
364 QVERIFY(m_mainWindow
->isVisible());
366 auto newFileMenu
= m_mainWindow
->findChild
<DolphinNewFileMenu
*>("new_menu");
367 QVERIFY(newFileMenu
);
369 QFETCH(bool, expectedEnabled
);
370 QTRY_COMPARE(newFileMenu
->isEnabled(), expectedEnabled
);
373 void DolphinMainWindowTest::testWindowTitle_data()
375 QTest::addColumn
<QUrl
>("activeViewUrl");
376 QTest::addColumn
<QString
>("expectedWindowTitle");
378 // TODO: this test should enforce the english locale.
379 QTest::newRow("home") << QUrl::fromLocalFile(QDir::homePath()) << QStringLiteral("Home");
380 QTest::newRow("home with trailing slash") << QUrl::fromLocalFile(QStringLiteral("%1/").arg(QDir::homePath())) << QStringLiteral("Home");
381 QTest::newRow("trash") << QUrl::fromUserInput(QStringLiteral("trash:/")) << QStringLiteral("Trash");
384 void DolphinMainWindowTest::testWindowTitle()
386 QFETCH(QUrl
, activeViewUrl
);
387 m_mainWindow
->openDirectories({activeViewUrl
}, false);
388 m_mainWindow
->show();
389 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
390 QVERIFY(m_mainWindow
->isVisible());
392 QFETCH(QString
, expectedWindowTitle
);
393 QCOMPARE(m_mainWindow
->windowTitle(), expectedWindowTitle
);
396 void DolphinMainWindowTest::testFocusLocationBar()
398 const QUrl homePathUrl
{QUrl::fromLocalFile(QDir::homePath())};
399 m_mainWindow
->openDirectories({homePathUrl
}, false);
400 m_mainWindow
->show();
401 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
402 QVERIFY(m_mainWindow
->isVisible());
404 QAction
*replaceLocationAction
= m_mainWindow
->actionCollection()->action(QStringLiteral("replace_location"));
405 replaceLocationAction
->trigger();
406 QVERIFY(m_mainWindow
->activeViewContainer()->urlNavigator()->isAncestorOf(QApplication::focusWidget()));
407 replaceLocationAction
->trigger();
408 QVERIFY(m_mainWindow
->activeViewContainer()->view()->hasFocus());
410 QAction
*editableLocationAction
= m_mainWindow
->actionCollection()->action(QStringLiteral("editable_location"));
411 editableLocationAction
->trigger();
412 QVERIFY(m_mainWindow
->activeViewContainer()->urlNavigator()->isAncestorOf(QApplication::focusWidget()));
413 QVERIFY(m_mainWindow
->activeViewContainer()->urlNavigator()->isUrlEditable());
414 editableLocationAction
->trigger();
415 QVERIFY(!m_mainWindow
->activeViewContainer()->urlNavigator()->isUrlEditable());
417 replaceLocationAction
->trigger();
418 QVERIFY(m_mainWindow
->activeViewContainer()->urlNavigator()->isAncestorOf(QApplication::focusWidget()));
420 // Pressing Escape multiple times should eventually move the focus back to the active view.
421 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Escape
); // Focus might not go the view yet because it toggles the editable state of the location bar.
422 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Escape
);
423 QVERIFY(m_mainWindow
->activeViewContainer()->view()->hasFocus());
426 void DolphinMainWindowTest::testFocusPlacesPanel()
428 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
429 m_mainWindow
->show();
430 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
431 QVERIFY(m_mainWindow
->isVisible());
433 QWidget
*placesPanel
= reinterpret_cast<QWidget
*>(m_mainWindow
->m_placesPanel
);
434 QVERIFY2(QTest::qWaitFor(
436 return placesPanel
&& placesPanel
->isVisible() && placesPanel
->width() > 0 && placesPanel
->height() > 0;
439 "The test couldn't be initialised properly. The places panel should be visible.");
441 QAction
*focusPlacesPanelAction
= m_mainWindow
->actionCollection()->action(QStringLiteral("focus_places_panel"));
442 QAction
*showPlacesPanelAction
= m_mainWindow
->actionCollection()->action(QStringLiteral("show_places_panel"));
444 focusPlacesPanelAction
->trigger();
445 QVERIFY(placesPanel
->hasFocus());
447 focusPlacesPanelAction
->trigger();
448 QVERIFY2(m_mainWindow
->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
449 "Triggering focus_places_panel while the panel already has focus should return the focus to the view.");
451 focusPlacesPanelAction
->trigger();
452 QVERIFY(placesPanel
->hasFocus());
454 showPlacesPanelAction
->trigger();
455 QVERIFY(!placesPanel
->isVisible());
456 QVERIFY2(m_mainWindow
->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
457 "Hiding the Places panel while it has focus should return the focus to the view.");
459 showPlacesPanelAction
->trigger();
460 QVERIFY(placesPanel
->isVisible());
461 QVERIFY2(placesPanel
->hasFocus(), "Enabling the Places panel should move keyboard focus there.");
463 /// Test that activating a place always moves focus to the view.
464 QTest::keyClick(QApplication::focusWidget(), Qt::Key::Key_Enter
);
465 QVERIFY2(m_mainWindow
->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
466 "Activating a place should move focus to the view that loads that place.");
468 focusPlacesPanelAction
->trigger();
469 QVERIFY(placesPanel
->hasFocus());
471 QTest::keyClick(QApplication::focusWidget(), Qt::Key::Key_Enter
);
472 QVERIFY2(m_mainWindow
->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
473 "Activating a place should move focus to the view even if the view already has that place loaded.");
477 * The places panel will resize itself if any of the other widgets requires too much horizontal space
478 * but a user never wants the size of the places panel to change unless they resized it themselves explicitly.
480 void DolphinMainWindowTest::testPlacesPanelWidthResistance()
482 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
483 m_mainWindow
->show();
484 m_mainWindow
->resize(800, m_mainWindow
->height()); // make sure the size is sufficient so a places panel resize shouldn't be necessary.
485 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
486 QVERIFY(m_mainWindow
->isVisible());
488 QWidget
*placesPanel
= reinterpret_cast<QWidget
*>(m_mainWindow
->m_placesPanel
);
489 QVERIFY2(QTest::qWaitFor(
491 return placesPanel
&& placesPanel
->isVisible() && placesPanel
->width() > 0;
494 "The test couldn't be initialised properly. The places panel should be visible.");
496 const int initialPlacesPanelWidth
= placesPanel
->width();
498 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger(); // enable split view (starts animation)
499 QTest::qWait(300); // wait for animation
500 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
502 m_mainWindow
->actionCollection()->action(QStringLiteral("show_filter_bar"))->trigger();
503 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
505 // Make all selection mode bars appear and test for each that this doesn't affect the places panel's width.
506 // One of the bottom bars (SelectionMode::BottomBar::GeneralContents) only shows up when at least one item is selected so we do that before we begin iterating.
507 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::SelectAll
))->trigger();
508 for (int selectionModeStates
= SelectionMode::BottomBar::CopyContents
; selectionModeStates
!= SelectionMode::BottomBar::RenameContents
;
509 selectionModeStates
++) {
510 const auto contents
= static_cast<SelectionMode::BottomBar::Contents
>(selectionModeStates
);
511 m_mainWindow
->slotSetSelectionMode(true, contents
);
512 QTest::qWait(20); // give time for a paint/resize
513 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
516 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Find
))->trigger();
517 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
520 m_mainWindow
->actionCollection()->action(QStringLiteral("show_information_panel"))->setChecked(true); // toggle visible
521 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
525 m_mainWindow
->actionCollection()->action(QStringLiteral("show_terminal_panel"))->setChecked(true); // toggle visible
526 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
529 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger(); // disable split view (starts animation)
530 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
533 m_mainWindow
->actionCollection()->action(QStringLiteral("show_information_panel"))->trigger(); // toggle invisible
534 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
538 m_mainWindow
->actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // toggle invisible
539 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
542 m_mainWindow
->showMaximized();
543 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
545 QTest::qWait(300); // wait for split view closing animation
546 QCOMPARE(placesPanel
->width(), initialPlacesPanelWidth
);
549 void DolphinMainWindowTest::testGoActions()
551 QScopedPointer
<TestDir
> testDir
{new TestDir()};
552 testDir
->createDir("a");
553 testDir
->createDir("b");
554 testDir
->createDir("b/b-1");
555 testDir
->createFile("b/b-2");
556 testDir
->createDir("c");
557 const QUrl
childDirUrl(QDir::cleanPath(testDir
->url().toString() + "/b"));
558 m_mainWindow
->openDirectories({childDirUrl
}, false); // Open "b" dir
559 m_mainWindow
->show();
560 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
561 QVERIFY(m_mainWindow
->isVisible());
562 QVERIFY(!m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))->isEnabled());
564 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Up
))->trigger();
566 * Now, after going "up" in the file hierarchy (to "testDir"), the folder one has emerged from ("b") should have keyboard focus.
567 * This is especially important when a user wants to peek into multiple folders in quick succession.
569 QSignalSpy
spyDirectoryLoadingCompleted(m_mainWindow
->m_activeViewContainer
->view(), &DolphinView::directoryLoadingCompleted
);
570 QVERIFY(spyDirectoryLoadingCompleted
.wait());
571 QVERIFY(QTest::qWaitFor([&]() {
572 return !m_mainWindow
->actionCollection()->action(QStringLiteral("stop"))->isEnabled();
573 })); // "Stop" command should be disabled because it finished loading
574 QTest::qWait(500); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
575 const QUrl parentDirUrl
= m_mainWindow
->activeViewContainer()->url();
576 QVERIFY(parentDirUrl
!= childDirUrl
);
578 auto currentItemUrl
= [this]() {
579 const int currentIndex
= m_mainWindow
->m_activeViewContainer
->view()->m_container
->controller()->selectionManager()->currentItem();
580 const KFileItem currentItem
= m_mainWindow
->m_activeViewContainer
->view()->m_model
->fileItem(currentIndex
);
581 return currentItem
.url();
584 QCOMPARE(currentItemUrl(), childDirUrl
); // The item we just emerged from should now have keyboard focus.
585 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 0); // The item we just emerged from should not be selected. BUG: 424723
586 // Pressing arrow keys should not only move the keyboard focus but also select the item.
587 // We press "Down" to select "c" below and then "Up" so the folder "b" we just emerged from is selected for the first time.
588 m_mainWindow
->actionCollection()->action(QStringLiteral("compact"))->trigger();
589 QTest::keyClick(m_mainWindow
->activeViewContainer()->view()->m_container
, Qt::Key::Key_Down
, Qt::NoModifier
);
590 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
591 QVERIFY2(currentItemUrl() != childDirUrl
, "The current item didn't change after pressing the 'Down' key.");
592 QTest::keyClick(m_mainWindow
->activeViewContainer()->view()->m_container
, Qt::Key::Key_Up
, Qt::NoModifier
);
593 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
594 QCOMPARE(currentItemUrl(), childDirUrl
); // After pressing 'Down' and then 'Up' we should be back where we were.
596 // Enter the child folder "b".
597 QTest::keyClick(m_mainWindow
->activeViewContainer()->view()->m_container
, Qt::Key::Key_Enter
, Qt::NoModifier
);
598 QVERIFY(spyDirectoryLoadingCompleted
.wait());
599 QCOMPARE(m_mainWindow
->activeViewContainer()->url(), childDirUrl
);
600 QVERIFY(m_mainWindow
->isUrlOpen(childDirUrl
.toString()));
602 // Go back to the parent folder.
603 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Back
))->trigger();
604 QVERIFY(spyDirectoryLoadingCompleted
.wait());
605 QTest::qWait(100); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
606 QCOMPARE(m_mainWindow
->activeViewContainer()->url(), parentDirUrl
);
607 QVERIFY(m_mainWindow
->isUrlOpen(parentDirUrl
.toString()));
608 // Going 'Back' means that the view should be in the same state it was in when we left.
609 QCOMPARE(currentItemUrl(), childDirUrl
); // The item we last interacted with in this location should still have keyboard focus.
610 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
611 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().constFirst().url(), childDirUrl
); // It should still be selected.
613 // Open a new tab for the "b" child dir and verify that this doesn't interfere with anything.
614 QTest::keyClick(m_mainWindow
->activeViewContainer()->view()->m_container
, Qt::Key::Key_Enter
, Qt::ControlModifier
); // Open new inactive tab
615 QVERIFY(m_mainWindow
->m_tabWidget
->count() == 2);
616 QCOMPARE(m_mainWindow
->activeViewContainer()->url(), parentDirUrl
);
617 QVERIFY(m_mainWindow
->isUrlOpen(parentDirUrl
.toString()));
618 QVERIFY(!m_mainWindow
->actionCollection()->action(QStringLiteral("undo_close_tab"))->isEnabled());
620 // Go forward to the child folder.
621 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))->trigger();
622 QVERIFY(spyDirectoryLoadingCompleted
.wait());
623 QCOMPARE(m_mainWindow
->activeViewContainer()->url(), childDirUrl
);
624 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 0); // There was no action in this view yet that would warrant a selection.
625 QCOMPARE(currentItemUrl(), QUrl(QDir::cleanPath(testDir
->url().toString() + "/b/b-1"))); // The first item in the view should have keyboard focus.
627 // Press the 'Down' key in the child folder.
628 QTest::keyClick(m_mainWindow
->activeViewContainer()->view()->m_container
, Qt::Key::Key_Down
, Qt::NoModifier
);
629 // The second item in the view should have keyboard focus and be selected.
630 const QUrl secondItemInChildFolderUrl
{QDir::cleanPath(testDir
->url().toString() + "/b/b-2")};
631 QCOMPARE(currentItemUrl(), secondItemInChildFolderUrl
);
632 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
633 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().constFirst().url(), secondItemInChildFolderUrl
);
635 // Go back to the parent folder and then re-enter the child folder.
636 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Back
))->trigger();
637 QVERIFY(spyDirectoryLoadingCompleted
.wait());
638 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))->trigger();
639 QVERIFY(spyDirectoryLoadingCompleted
.wait());
640 QCOMPARE(m_mainWindow
->activeViewContainer()->url(), childDirUrl
);
641 // The state of the view should be identical to how it was before we triggered "Back" and then "Forward".
642 QTRY_COMPARE(currentItemUrl(), secondItemInChildFolderUrl
);
643 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
644 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().constFirst().url(), secondItemInChildFolderUrl
);
646 // Go back to the parent folder.
647 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Back
))->trigger();
648 QVERIFY(spyDirectoryLoadingCompleted
.wait());
649 QTest::qWait(100); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
650 QCOMPARE(m_mainWindow
->activeViewContainer()->url(), parentDirUrl
);
651 QVERIFY(m_mainWindow
->isUrlOpen(parentDirUrl
.toString()));
653 // Close current tab and see if the "go" actions are correctly disabled in the remaining tab that was never active until now and shows the "b" dir
654 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Close
))->trigger(); // Close current tab
655 QVERIFY(m_mainWindow
->m_tabWidget
->count() == 1);
656 QCOMPARE(m_mainWindow
->activeViewContainer()->url(), childDirUrl
);
657 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 0); // There was no action in this tab yet that would warrant a selection.
658 QVERIFY(!m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Back
))->isEnabled());
659 QVERIFY(!m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))->isEnabled());
660 QVERIFY(m_mainWindow
->actionCollection()->action(QStringLiteral("undo_close_tab"))->isEnabled());
663 void DolphinMainWindowTest::testOpenFiles()
665 QScopedPointer
<TestDir
> testDir
{new TestDir()};
666 QString
testDirUrl(QDir::cleanPath(testDir
->url().toString()));
667 testDir
->createDir("a");
668 testDir
->createDir("a/b");
669 testDir
->createDir("a/b/c");
670 testDir
->createDir("a/b/c/d");
671 m_mainWindow
->openDirectories({testDirUrl
}, false);
672 m_mainWindow
->show();
674 // We only see the unselected "a" folder in the test dir. There are no other tabs.
675 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
));
676 QVERIFY(m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a"));
677 QVERIFY(!m_mainWindow
->isUrlOpen(testDirUrl
+ "/a"));
678 QVERIFY(!m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a/b"));
679 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 1);
680 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 0);
681 QCOMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 0);
683 // "a" is already in view, so "opening" "a" should simply select it without opening a new tab.
684 m_mainWindow
->openFiles({testDirUrl
+ "/a"}, false);
685 QTRY_COMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
686 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 1);
687 QVERIFY(m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a"));
689 // "b" is not in view, so "opening" "b" should open a new active tab of the parent folder "a" and select "b" there.
690 m_mainWindow
->openFiles({testDirUrl
+ "/a/b"}, false);
691 QTRY_VERIFY(m_mainWindow
->isUrlOpen(testDirUrl
+ "/a"));
692 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 2);
693 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 1);
694 QTRY_VERIFY(m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a/b"));
695 QVERIFY2(!m_mainWindow
->isUrlOpen(testDirUrl
+ "/a/b"), "The directory b is supposed to be visible but not open in its own tab.");
696 QTRY_COMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
698 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
));
699 QVERIFY(m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a"));
700 // "a" is still in view in the first tab, so "opening" "a" should switch to the first tab and select "a" there.
701 m_mainWindow
->openFiles({testDirUrl
+ "/a"}, false);
702 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 2);
703 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 0);
704 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
));
705 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
+ "/a"));
707 // Directory "a" is already open in the second tab in which "b" is selected, so opening the directory "a" should switch to that tab.
708 m_mainWindow
->openDirectories({testDirUrl
+ "/a"}, false);
709 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 2);
710 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 1);
712 // In the details view mode directories can be expanded, which changes if openFiles() needs to open a new tab or not to open a file.
713 m_mainWindow
->actionCollection()->action(QStringLiteral("details"))->trigger();
714 QTRY_VERIFY(m_mainWindow
->activeViewContainer()->view()->itemsExpandable());
716 // Expand the already selected "b" with the right arrow key. This should make "c" visible.
717 QVERIFY2(!m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a/b/c"), "The parent folder wasn't expanded yet, so c shouldn't be visible.");
718 QTest::keyClick(m_mainWindow
->activeViewContainer()->view()->m_container
, Qt::Key::Key_Right
);
719 QTRY_VERIFY(m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a/b/c"));
720 QVERIFY2(!m_mainWindow
->isUrlOpen(testDirUrl
+ "/a/b"), "b is supposed to be expanded, however it shouldn't be open in its own tab.");
721 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
+ "/a"));
723 // Switch to first tab by opening it even though it is already open.
724 m_mainWindow
->openDirectories({testDirUrl
}, false);
725 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 2);
726 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 0);
728 // "c" is in view in the second tab because "b" is expanded there, so "opening" "c" should switch to that tab and select "c" there.
729 m_mainWindow
->openFiles({testDirUrl
+ "/a/b/c"}, false);
730 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 2);
731 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 1);
732 QTRY_COMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
733 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
));
734 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
+ "/a"));
736 // Opening the directory "c" on the other hand will open it in a new tab even though it is already visible in the view
737 // because openDirecories() and openFiles() serve different purposes. One opens views at urls, the other selects files within views.
738 m_mainWindow
->openDirectories({testDirUrl
+ "/a/b/c/d", testDirUrl
+ "/a/b/c"}, true);
739 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 3);
740 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 2);
741 QVERIFY(m_mainWindow
->m_tabWidget
->currentTabPage()->splitViewEnabled());
742 QVERIFY(m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a/b/c")); // It should still be visible in the second tab.
743 QTRY_COMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 0);
744 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
+ "/a/b/c/d"));
745 QVERIFY(m_mainWindow
->isUrlOpen(testDirUrl
+ "/a/b/c"));
747 // "c" is in view in the second tab because "b" is expanded there,
748 // so "opening" "c" should switch to that tab even though "c" as a directory is open in the current tab.
749 m_mainWindow
->openFiles({testDirUrl
+ "/a/b/c"}, false);
750 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 3);
751 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 1);
752 QVERIFY2(m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a/b/c/d"), "It should be visible in the secondary view of the third tab.");
754 // Select "b" and un-expand it with the left arrow key. This should make "c" invisible.
755 m_mainWindow
->openFiles({testDirUrl
+ "/a/b"}, false);
756 QTest::keyClick(m_mainWindow
->activeViewContainer()->view()->m_container
, Qt::Key::Key_Left
);
757 QTRY_VERIFY(!m_mainWindow
->isItemVisibleInAnyView(testDirUrl
+ "/a/b/c"));
759 // "d" is in view in the third tab in the secondary view, so "opening" "d" should select that view.
760 m_mainWindow
->openFiles({testDirUrl
+ "/a/b/c/d"}, false);
761 QCOMPARE(m_mainWindow
->m_tabWidget
->count(), 3);
762 QCOMPARE(m_mainWindow
->m_tabWidget
->currentIndex(), 2);
763 QVERIFY(m_mainWindow
->m_tabWidget
->currentTabPage()->secondaryViewContainer()->isActive());
764 QTRY_COMPARE(m_mainWindow
->m_activeViewContainer
->view()->selectedItems().count(), 1);
767 void DolphinMainWindowTest::testAccessibilityTree()
769 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
770 m_mainWindow
->show();
771 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
772 QVERIFY(m_mainWindow
->isVisible());
774 QAccessibleInterface
*accessibleInterfaceOfMainWindow
= QAccessible::queryAccessibleInterface(m_mainWindow
.get());
775 Q_CHECK_PTR(accessibleInterfaceOfMainWindow
);
777 /// Test the accessibility of objects while traversing forwards (Tab key) and backwards (Shift+Tab).
778 int testedObjectsSizeAfterTraversingForwards
= 0;
779 for (int i
= 0; i
< 2; i
++) {
780 std::tuple
<Qt::Key
, Qt::KeyboardModifier
> focusChainTraversalKeyCombination
= {Qt::Key::Key_Tab
, Qt::NoModifier
};
782 focusChainTraversalKeyCombination
= {Qt::Key::Key_Tab
, Qt::ShiftModifier
};
785 /// @see firstNamedAncestor below.
786 QAccessibleInterface
*firstNamedAncestorOfPreviousIteration
= nullptr;
788 /// Perform accessibility checks for every object that gets focus. Focus will be changed using the focusChainTraversalKeyCombination.
789 std::set
<const QObject
*> testedObjects
; // Makes sure we stop testing when we arrive at an item that was already tested.
790 while (qApp
->focusObject() && !testedObjects
.count(qApp
->focusObject())) {
791 const auto currentlyFocusedObject
= qApp
->focusObject();
792 const QAccessibleInterface
*accessibleIntefaceOfCurrentlyFocusedObject
= QAccessible::queryAccessibleInterface(currentlyFocusedObject
);
793 QVERIFY(accessibleIntefaceOfCurrentlyFocusedObject
);
795 /// Test that each object reachable by Tab or Shift+Tab has at least some accessible information. Objects without any accessible information
796 /// are even less useful to accessibility software users than unlabeled buttons are e.g. to sighted users, because unlabeled buttons at least
797 /// convey some information through their placement and icon.
798 if (currentlyFocusedObject
!= m_mainWindow
->m_activeViewContainer
->view()->m_container
) { // Skip the custom container widget which has no
799 // accessible name on purpose.
801 * The first ancestor with an accessible name is interesting because it is sometimes used to identify an object if the object itself has no
802 * name. We keep it in mind to check if two subsequent objects without a name can at least be told apart by their first named ancestor.
804 QAccessibleInterface
*firstNamedAncestor
= accessibleIntefaceOfCurrentlyFocusedObject
->parent();
805 while (firstNamedAncestor
) {
806 if (!firstNamedAncestor
->text(QAccessible::Name
).isEmpty()) {
809 firstNamedAncestor
= firstNamedAncestor
->parent();
811 QTRY_VERIFY2(!accessibleIntefaceOfCurrentlyFocusedObject
->text(QAccessible::Name
).isEmpty()
812 || (firstNamedAncestor
&& firstNamedAncestor
!= firstNamedAncestorOfPreviousIteration
),
813 qPrintable(QStringLiteral("%1's accessibleInterface does not have an accessible name and can not be distinguished from the object"
814 " that had focus previously. Please fix this. You can find this %1 within its parent %2.")
815 .arg(currentlyFocusedObject
->metaObject()->className())
816 .arg(currentlyFocusedObject
->parent()->metaObject()->className())));
817 firstNamedAncestorOfPreviousIteration
= firstNamedAncestor
;
820 /// Test that each accessible interface has the main window as its parent.
821 QAccessibleInterface
*accessibleInterface
= QAccessible::queryAccessibleInterface(currentlyFocusedObject
);
822 // The accessibleInterfaces of focused objects might themselves have children.
823 // We go down that hierarchy as far as possible and then test the ancestor tree from there.
824 while (accessibleInterface
->childCount() > 0) {
825 accessibleInterface
= accessibleInterface
->child(0);
827 while (accessibleInterface
!= accessibleInterfaceOfMainWindow
) {
828 QVERIFY2(accessibleInterface
,
829 qPrintable(QStringLiteral("%1's accessibleInterface or one of its accessible children doesn't have the main window as an ancestor.")
830 .arg(currentlyFocusedObject
->metaObject()->className())));
831 accessibleInterface
= accessibleInterface
->parent();
834 testedObjects
.insert(currentlyFocusedObject
); // Add it to testedObjects so we won't test it again later.
835 QTest::keyClick(m_mainWindow
.get(), std::get
<0>(focusChainTraversalKeyCombination
), std::get
<1>(focusChainTraversalKeyCombination
));
836 QVERIFY2(currentlyFocusedObject
!= qApp
->focusObject(),
837 "The focus chain is broken. The focused object should have changed after pressing the focusChainTraversalKeyCombination.");
841 testedObjectsSizeAfterTraversingForwards
= testedObjects
.size();
843 QCOMPARE(testedObjects
.size(), testedObjectsSizeAfterTraversingForwards
); // The size after traversing backwards is different than
844 // after going forwards which is probably not intended.
847 QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards
, 12); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the
848 // test run correctly?
851 void DolphinMainWindowTest::testAutoSaveSession()
853 m_mainWindow
->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
854 m_mainWindow
->show();
855 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
856 QVERIFY(m_mainWindow
->isVisible());
858 // Create config file
859 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
860 KConfig
*config
= KConfigGui::sessionConfig();
861 m_mainWindow
->saveGlobalProperties(config
);
862 m_mainWindow
->savePropertiesInternal(config
, 1);
865 // Setup watcher for config file changes
866 const QString configFileName
= QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation
) + "/" + KConfigGui::sessionConfig()->name();
867 QFileSystemWatcher
*configWatcher
= new QFileSystemWatcher({configFileName
}, this);
868 QSignalSpy
spySessionSaved(configWatcher
, &QFileSystemWatcher::fileChanged
);
870 // Enable session autosave.
871 m_mainWindow
->setSessionAutoSaveEnabled(true);
872 m_mainWindow
->m_sessionSaveTimer
->setInterval(200); // Lower the interval to speed up the testing
875 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
877 tabWidget
->openNewActivatedTab(QUrl::fromLocalFile(QDir::tempPath()));
878 QCOMPARE(tabWidget
->count(), 2);
880 // Wait till a session save occurs
881 QVERIFY(spySessionSaved
.wait(60000));
883 // Disable session autosave.
884 m_mainWindow
->setSessionAutoSaveEnabled(false);
887 void DolphinMainWindowTest::testInlineRename()
889 QScopedPointer
<TestDir
> testDir
{new TestDir()};
890 testDir
->createFiles({"aaaa", "bbbb", "cccc", "dddd"});
891 m_mainWindow
->openDirectories({testDir
->url()}, false);
892 m_mainWindow
->show();
893 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
894 QVERIFY(m_mainWindow
->isVisible());
896 DolphinView
*view
= m_mainWindow
->activeViewContainer()->view();
897 QSignalSpy
viewDirectoryLoadingCompletedSpy(view
, &DolphinView::directoryLoadingCompleted
);
898 QSignalSpy
itemsReorderedSpy(view
->m_model
, &KFileItemModel::itemsMoved
);
899 QSignalSpy
modelDirectoryLoadingCompletedSpy(view
->m_model
, &KFileItemModel::directoryLoadingCompleted
);
901 QVERIFY(viewDirectoryLoadingCompletedSpy
.wait());
902 QTest::qWait(500); // we need to wait for the file widgets to become visible
903 view
->markUrlsAsSelected({QUrl(testDir
->url().toString() + "/aaaa")});
904 view
->updateViewState();
905 view
->renameSelectedItems();
906 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Left
);
907 QTest::keyClick(QApplication::focusWidget(), Qt::Key_E
);
908 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down
);
910 QVERIFY(itemsReorderedSpy
.wait());
911 QVERIFY(view
->m_view
->m_editingRole
);
912 KItemListWidget
*widget
= view
->m_view
->m_visibleItems
.value(view
->m_view
->firstVisibleIndex());
913 QVERIFY(!widget
->editedRole().isEmpty());
915 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Left
);
916 QTest::keyClick(QApplication::focusWidget(), Qt::Key_A
);
917 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down
);
918 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down
);
919 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Left
);
920 QTest::keyClick(QApplication::focusWidget(), Qt::Key_A
);
921 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down
);
923 QVERIFY(itemsReorderedSpy
.wait());
924 QVERIFY(view
->m_view
->m_editingRole
);
925 widget
= view
->m_view
->m_visibleItems
.value(view
->m_view
->lastVisibleIndex());
926 QVERIFY(!widget
->editedRole().isEmpty());
928 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Escape
);
929 QVERIFY(widget
->isCurrent());
930 view
->m_model
->refreshDirectory(testDir
->url());
931 QVERIFY(modelDirectoryLoadingCompletedSpy
.wait());
933 QCOMPARE(view
->m_model
->fileItem(0).name(), "abbbb");
934 QCOMPARE(view
->m_model
->fileItem(1).name(), "adddd");
935 QCOMPARE(view
->m_model
->fileItem(2).name(), "cccc");
936 QCOMPARE(view
->m_model
->fileItem(3).name(), "eaaaa");
937 QCOMPARE(view
->m_model
->count(), 4);
940 void DolphinMainWindowTest::cleanupTestCase()
942 m_mainWindow
->showNormal();
943 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->setChecked(false); // disable split view (starts animation)
946 m_mainWindow
->actionCollection()->action(QStringLiteral("show_information_panel"))->setChecked(false); // hide panel
950 m_mainWindow
->actionCollection()->action(QStringLiteral("show_terminal_panel"))->setChecked(false); // hide panel
953 // Quit Dolphin to save the hiding of panels and make sure that normal Quit doesn't crash.
954 m_mainWindow
->actionCollection()->action(KStandardAction::name(KStandardAction::Quit
))->trigger();
957 QTEST_MAIN(DolphinMainWindowTest
)
959 #include "dolphinmainwindowtest.moc"