]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphinmainwindowtest.cpp
Test that each object has distinguishable accessible info
[dolphin.git] / src / tests / dolphinmainwindowtest.cpp
1 /*
2 * SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
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 "testdir.h"
17
18 #include <KActionCollection>
19 #include <KConfig>
20 #include <KConfigGui>
21
22 #include <QAccessible>
23 #include <QDomDocument>
24 #include <QFileSystemWatcher>
25 #include <QScopedPointer>
26 #include <QSignalSpy>
27 #include <QStandardPaths>
28 #include <QTest>
29
30 #include <set>
31 #include <unordered_set>
32
33 class DolphinMainWindowTest : public QObject
34 {
35 Q_OBJECT
36
37 private Q_SLOTS:
38 void initTestCase();
39 void init();
40 void testSyncDesktopAndPhoneUi();
41 void testClosingTabsWithSearchBoxVisible();
42 void testActiveViewAfterClosingSplitView_data();
43 void testActiveViewAfterClosingSplitView();
44 void testUpdateWindowTitleAfterClosingSplitView();
45 void testUpdateWindowTitleAfterChangingSplitView();
46 void testOpenInNewTabTitle();
47 void testNewFileMenuEnabled_data();
48 void testNewFileMenuEnabled();
49 void testWindowTitle_data();
50 void testWindowTitle();
51 void testFocusLocationBar();
52 void testFocusPlacesPanel();
53 void testPlacesPanelWidthResistance();
54 void testGoActions();
55 void testOpenFiles();
56 void testAccessibilityTree();
57 void testAutoSaveSession();
58 void cleanupTestCase();
59
60 private:
61 QScopedPointer<DolphinMainWindow> m_mainWindow;
62 };
63
64 void DolphinMainWindowTest::initTestCase()
65 {
66 QStandardPaths::setTestModeEnabled(true);
67 }
68
69 void DolphinMainWindowTest::init()
70 {
71 m_mainWindow.reset(new DolphinMainWindow());
72 }
73
74 /**
75 * 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
76 * mostly identical. Differences between those files need to be explicitly added as exceptions to this test. So if you land here after changing either
77 * 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
78 * changed object to the `exceptions` variable below.
79 */
80 void DolphinMainWindowTest::testSyncDesktopAndPhoneUi()
81 {
82 std::unordered_set<QString> exceptions{{QStringLiteral("version"), QStringLiteral("ToolBar")}};
83
84 QDomDocument desktopUi;
85 QFile desktopUiXmlFile(":/kxmlgui5/dolphin/dolphinui.rc");
86 desktopUiXmlFile.open(QIODevice::ReadOnly);
87 desktopUi.setContent(&desktopUiXmlFile);
88 desktopUiXmlFile.close();
89
90 QDomDocument phoneUi;
91 QFile phoneUiXmlFile(":/kxmlgui5/dolphin/dolphinuiforphones.rc");
92 phoneUiXmlFile.open(QIODevice::ReadOnly);
93 phoneUi.setContent(&phoneUiXmlFile);
94 phoneUiXmlFile.close();
95
96 QDomElement desktopUiElement = desktopUi.documentElement();
97 QDomElement phoneUiElement = phoneUi.documentElement();
98
99 auto nextUiElement = [&exceptions](QDomElement uiElement) -> QDomElement {
100 QDomNode nextUiNode{uiElement};
101 do {
102 // If the current node is an exception, we skip its children as well.
103 if (exceptions.count(nextUiNode.nodeName()) == 0) {
104 auto firstChild{nextUiNode.firstChild()};
105 if (!firstChild.isNull()) {
106 nextUiNode = firstChild;
107 continue;
108 }
109 }
110 auto nextSibling{nextUiNode.nextSibling()};
111 if (!nextSibling.isNull()) {
112 nextUiNode = nextSibling;
113 continue;
114 }
115 auto parent{nextUiNode.parentNode()};
116 while (true) {
117 if (parent.isNull()) {
118 return QDomElement();
119 }
120 auto nextParentSibling{parent.nextSibling()};
121 if (!nextParentSibling.isNull()) {
122 nextUiNode = nextParentSibling;
123 break;
124 }
125 parent = parent.parentNode();
126 }
127 } while (
128 !nextUiNode.isNull()
129 && (nextUiNode.toElement().isNull() || exceptions.count(nextUiNode.nodeName()))); // We loop until we either give up finding an element or find one.
130 if (nextUiNode.isNull()) {
131 return QDomElement();
132 }
133 return nextUiNode.toElement();
134 };
135
136 int totalComparisonsCount{0};
137 do {
138 QVERIFY2(desktopUiElement.tagName() == phoneUiElement.tagName(),
139 qPrintable(QStringLiteral("Node mismatch: dolphinui.rc/%1::%2 and dolphinuiforphones.rc/%3::%4")
140 .arg(desktopUiElement.parentNode().toElement().tagName())
141 .arg(desktopUiElement.tagName())
142 .arg(phoneUiElement.parentNode().toElement().tagName())
143 .arg(phoneUiElement.tagName())));
144 QCOMPARE(desktopUiElement.text(), phoneUiElement.text());
145 const auto desktopUiElementAttributes = desktopUiElement.attributes();
146 const auto phoneUiElementAttributes = phoneUiElement.attributes();
147 for (int i = 0; i < desktopUiElementAttributes.count(); i++) {
148 QVERIFY2(phoneUiElementAttributes.count() >= i,
149 qPrintable(QStringLiteral("Attribute mismatch: dolphinui.rc/%1::%2 has more attributes than dolphinuiforphones.rc/%3::%4")
150 .arg(desktopUiElement.parentNode().toElement().tagName())
151 .arg(desktopUiElement.tagName())
152 .arg(phoneUiElement.parentNode().toElement().tagName())
153 .arg(phoneUiElement.tagName())));
154 if (exceptions.count(desktopUiElementAttributes.item(i).nodeName())) {
155 continue;
156 }
157 QCOMPARE(desktopUiElementAttributes.item(i).nodeName(), phoneUiElementAttributes.item(i).nodeName());
158 QCOMPARE(desktopUiElementAttributes.item(i).nodeValue(), phoneUiElementAttributes.item(i).nodeValue());
159 totalComparisonsCount++;
160 }
161 QVERIFY2(desktopUiElementAttributes.count() == phoneUiElementAttributes.count(),
162 qPrintable(QStringLiteral("Attribute mismatch: dolphinui.rc/%1::%2 has fewer attributes than dolphinuiforphones.rc/%3::%4. %5 < %6")
163 .arg(desktopUiElement.parentNode().toElement().tagName())
164 .arg(desktopUiElement.tagName())
165 .arg(phoneUiElement.parentNode().toElement().tagName())
166 .arg(phoneUiElement.tagName())
167 .arg(phoneUiElementAttributes.count())
168 .arg(desktopUiElementAttributes.count())));
169
170 desktopUiElement = nextUiElement(desktopUiElement);
171 phoneUiElement = nextUiElement(phoneUiElement);
172 totalComparisonsCount++;
173 } while (!desktopUiElement.isNull() || !phoneUiElement.isNull());
174 QVERIFY2(totalComparisonsCount > 200, qPrintable(QStringLiteral("There were only %1 comparisons. Did the test run correctly?").arg(totalComparisonsCount)));
175 }
176
177 // See https://bugs.kde.org/show_bug.cgi?id=379135
178 void DolphinMainWindowTest::testClosingTabsWithSearchBoxVisible()
179 {
180 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
181 m_mainWindow->show();
182 // Without this call the searchbox doesn't get FocusIn events.
183 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
184 QVERIFY(m_mainWindow->isVisible());
185
186 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget");
187 QVERIFY(tabWidget);
188
189 // Show search box on first tab.
190 tabWidget->currentTabPage()->activeViewContainer()->setSearchModeEnabled(true);
191
192 tabWidget->openNewActivatedTab(QUrl::fromLocalFile(QDir::homePath()));
193 QCOMPARE(tabWidget->count(), 2);
194
195 // Triggers the crash in bug #379135.
196 tabWidget->closeTab();
197 QCOMPARE(tabWidget->count(), 1);
198 }
199
200 void DolphinMainWindowTest::testActiveViewAfterClosingSplitView_data()
201 {
202 QTest::addColumn<bool>("closeLeftView");
203
204 QTest::newRow("close left view") << true;
205 QTest::newRow("close right view") << false;
206 }
207
208 void DolphinMainWindowTest::testActiveViewAfterClosingSplitView()
209 {
210 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
211 m_mainWindow->show();
212 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
213 QVERIFY(m_mainWindow->isVisible());
214
215 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget");
216 QVERIFY(tabWidget);
217 QVERIFY(tabWidget->currentTabPage()->primaryViewContainer());
218 QVERIFY(!tabWidget->currentTabPage()->secondaryViewContainer());
219
220 // Open split view.
221 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
222 QVERIFY(tabWidget->currentTabPage()->splitViewEnabled());
223 QVERIFY(tabWidget->currentTabPage()->secondaryViewContainer());
224
225 // Make sure the right view is the active one.
226 auto leftViewContainer = tabWidget->currentTabPage()->primaryViewContainer();
227 auto rightViewContainer = tabWidget->currentTabPage()->secondaryViewContainer();
228 QVERIFY(!leftViewContainer->isActive());
229 QVERIFY(rightViewContainer->isActive());
230
231 QFETCH(bool, closeLeftView);
232 if (closeLeftView) {
233 // Activate left view.
234 leftViewContainer->setActive(true);
235 QVERIFY(leftViewContainer->isActive());
236 QVERIFY(!rightViewContainer->isActive());
237
238 // Close left view. The secondary view (which was on the right) will become the primary one and must be active.
239 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
240 QVERIFY(!leftViewContainer->isActive());
241 QVERIFY(rightViewContainer->isActive());
242 QCOMPARE(rightViewContainer, tabWidget->currentTabPage()->activeViewContainer());
243 } else {
244 // Close right view. The left view will become active.
245 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
246 QVERIFY(leftViewContainer->isActive());
247 QVERIFY(!rightViewContainer->isActive());
248 QCOMPARE(leftViewContainer, tabWidget->currentTabPage()->activeViewContainer());
249 }
250 }
251
252 // Test case for bug #385111
253 void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView()
254 {
255 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
256 m_mainWindow->show();
257 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
258 QVERIFY(m_mainWindow->isVisible());
259
260 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget");
261 QVERIFY(tabWidget);
262 QVERIFY(tabWidget->currentTabPage()->primaryViewContainer());
263 QVERIFY(!tabWidget->currentTabPage()->secondaryViewContainer());
264
265 // Open split view.
266 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
267 QVERIFY(tabWidget->currentTabPage()->splitViewEnabled());
268 QVERIFY(tabWidget->currentTabPage()->secondaryViewContainer());
269
270 // Make sure the right view is the active one.
271 auto leftViewContainer = tabWidget->currentTabPage()->primaryViewContainer();
272 auto rightViewContainer = tabWidget->currentTabPage()->secondaryViewContainer();
273 QVERIFY(!leftViewContainer->isActive());
274 QVERIFY(rightViewContainer->isActive());
275
276 // Activate left view.
277 leftViewContainer->setActive(true);
278 QVERIFY(leftViewContainer->isActive());
279 QVERIFY(!rightViewContainer->isActive());
280
281 // Close split view. The secondary view (which was on the right) will become the primary one and must be active.
282 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
283 QVERIFY(!leftViewContainer->isActive());
284 QVERIFY(rightViewContainer->isActive());
285 QCOMPARE(rightViewContainer, tabWidget->currentTabPage()->activeViewContainer());
286
287 // Change URL and make sure we emit the currentUrlChanged signal (which triggers the window title update).
288 QSignalSpy currentUrlChangedSpy(tabWidget, &DolphinTabWidget::currentUrlChanged);
289 tabWidget->currentTabPage()->activeViewContainer()->setUrl(QUrl::fromLocalFile(QDir::rootPath()));
290 QCOMPARE(currentUrlChangedSpy.count(), 1);
291 }
292
293 // Test case for bug #402641
294 void DolphinMainWindowTest::testUpdateWindowTitleAfterChangingSplitView()
295 {
296 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
297 m_mainWindow->show();
298 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
299 QVERIFY(m_mainWindow->isVisible());
300
301 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget");
302 QVERIFY(tabWidget);
303
304 // Open split view.
305 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
306 QVERIFY(tabWidget->currentTabPage()->splitViewEnabled());
307
308 auto leftViewContainer = tabWidget->currentTabPage()->primaryViewContainer();
309 auto rightViewContainer = tabWidget->currentTabPage()->secondaryViewContainer();
310
311 // Store old window title.
312 const auto oldTitle = m_mainWindow->windowTitle();
313
314 // Change URL in the right view and make sure the title gets updated.
315 rightViewContainer->setUrl(QUrl::fromLocalFile(QDir::rootPath()));
316 QVERIFY(m_mainWindow->windowTitle() != oldTitle);
317
318 // Activate back the left view and check whether the old title gets restored.
319 leftViewContainer->setActive(true);
320 QCOMPARE(m_mainWindow->windowTitle(), oldTitle);
321 }
322
323 // Test case for bug #397910
324 void DolphinMainWindowTest::testOpenInNewTabTitle()
325 {
326 const QUrl homePathUrl{QUrl::fromLocalFile(QDir::homePath())};
327 m_mainWindow->openDirectories({homePathUrl}, false);
328 m_mainWindow->show();
329 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
330 QVERIFY(m_mainWindow->isVisible());
331
332 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget");
333 QVERIFY(tabWidget);
334
335 const QUrl tempPathUrl{QUrl::fromLocalFile(QDir::tempPath())};
336 tabWidget->openNewTab(tempPathUrl);
337 QCOMPARE(tabWidget->count(), 2);
338 QVERIFY(tabWidget->tabText(0) != tabWidget->tabText(1));
339
340 QVERIFY2(!tabWidget->tabIcon(0).isNull() && !tabWidget->tabIcon(1).isNull(), "Tabs are supposed to have icons.");
341 QCOMPARE(KIO::iconNameForUrl(homePathUrl), tabWidget->tabIcon(0).name());
342 QCOMPARE(KIO::iconNameForUrl(tempPathUrl), tabWidget->tabIcon(1).name());
343 }
344
345 void DolphinMainWindowTest::testNewFileMenuEnabled_data()
346 {
347 QTest::addColumn<QUrl>("activeViewUrl");
348 QTest::addColumn<bool>("expectedEnabled");
349
350 QTest::newRow("home") << QUrl::fromLocalFile(QDir::homePath()) << true;
351 QTest::newRow("root") << QUrl::fromLocalFile(QDir::rootPath()) << false;
352 QTest::newRow("trash") << QUrl::fromUserInput(QStringLiteral("trash:/")) << false;
353 }
354
355 void DolphinMainWindowTest::testNewFileMenuEnabled()
356 {
357 QFETCH(QUrl, activeViewUrl);
358 m_mainWindow->openDirectories({activeViewUrl}, false);
359 m_mainWindow->show();
360 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
361 QVERIFY(m_mainWindow->isVisible());
362
363 auto newFileMenu = m_mainWindow->findChild<DolphinNewFileMenu *>("new_menu");
364 QVERIFY(newFileMenu);
365
366 QFETCH(bool, expectedEnabled);
367 QTRY_COMPARE(newFileMenu->isEnabled(), expectedEnabled);
368 }
369
370 void DolphinMainWindowTest::testWindowTitle_data()
371 {
372 QTest::addColumn<QUrl>("activeViewUrl");
373 QTest::addColumn<QString>("expectedWindowTitle");
374
375 // TODO: this test should enforce the english locale.
376 QTest::newRow("home") << QUrl::fromLocalFile(QDir::homePath()) << QStringLiteral("Home");
377 QTest::newRow("home with trailing slash") << QUrl::fromLocalFile(QStringLiteral("%1/").arg(QDir::homePath())) << QStringLiteral("Home");
378 QTest::newRow("trash") << QUrl::fromUserInput(QStringLiteral("trash:/")) << QStringLiteral("Trash");
379 }
380
381 void DolphinMainWindowTest::testWindowTitle()
382 {
383 QFETCH(QUrl, activeViewUrl);
384 m_mainWindow->openDirectories({activeViewUrl}, false);
385 m_mainWindow->show();
386 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
387 QVERIFY(m_mainWindow->isVisible());
388
389 QFETCH(QString, expectedWindowTitle);
390 QCOMPARE(m_mainWindow->windowTitle(), expectedWindowTitle);
391 }
392
393 void DolphinMainWindowTest::testFocusLocationBar()
394 {
395 const QUrl homePathUrl{QUrl::fromLocalFile(QDir::homePath())};
396 m_mainWindow->openDirectories({homePathUrl}, false);
397 m_mainWindow->show();
398 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
399 QVERIFY(m_mainWindow->isVisible());
400
401 QAction *replaceLocationAction = m_mainWindow->actionCollection()->action(QStringLiteral("replace_location"));
402 replaceLocationAction->trigger();
403 QVERIFY(m_mainWindow->activeViewContainer()->urlNavigator()->isAncestorOf(QApplication::focusWidget()));
404 replaceLocationAction->trigger();
405 QVERIFY(m_mainWindow->activeViewContainer()->view()->hasFocus());
406
407 QAction *editableLocationAction = m_mainWindow->actionCollection()->action(QStringLiteral("editable_location"));
408 editableLocationAction->trigger();
409 QVERIFY(m_mainWindow->activeViewContainer()->urlNavigator()->isAncestorOf(QApplication::focusWidget()));
410 QVERIFY(m_mainWindow->activeViewContainer()->urlNavigator()->isUrlEditable());
411 editableLocationAction->trigger();
412 QVERIFY(!m_mainWindow->activeViewContainer()->urlNavigator()->isUrlEditable());
413
414 replaceLocationAction->trigger();
415 QVERIFY(m_mainWindow->activeViewContainer()->urlNavigator()->isAncestorOf(QApplication::focusWidget()));
416
417 // Pressing Escape multiple times should eventually move the focus back to the active view.
418 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Escape); // Focus might not go the view yet because it toggles the editable state of the location bar.
419 QTest::keyClick(QApplication::focusWidget(), Qt::Key_Escape);
420 QVERIFY(m_mainWindow->activeViewContainer()->view()->hasFocus());
421 }
422
423 void DolphinMainWindowTest::testFocusPlacesPanel()
424 {
425 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
426 m_mainWindow->show();
427 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
428 QVERIFY(m_mainWindow->isVisible());
429
430 QWidget *placesPanel = reinterpret_cast<QWidget *>(m_mainWindow->m_placesPanel);
431 QVERIFY2(QTest::qWaitFor(
432 [&]() {
433 return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0 && placesPanel->height() > 0;
434 },
435 5000),
436 "The test couldn't be initialised properly. The places panel should be visible.");
437
438 QAction *focusPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("focus_places_panel"));
439 QAction *showPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("show_places_panel"));
440
441 focusPlacesPanelAction->trigger();
442 QVERIFY(placesPanel->hasFocus());
443
444 focusPlacesPanelAction->trigger();
445 QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
446 "Triggering focus_places_panel while the panel already has focus should return the focus to the view.");
447
448 focusPlacesPanelAction->trigger();
449 QVERIFY(placesPanel->hasFocus());
450
451 showPlacesPanelAction->trigger();
452 QVERIFY(!placesPanel->isVisible());
453 QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
454 "Hiding the Places panel while it has focus should return the focus to the view.");
455
456 showPlacesPanelAction->trigger();
457 QVERIFY(placesPanel->isVisible());
458 QVERIFY2(placesPanel->hasFocus(), "Enabling the Places panel should move keyboard focus there.");
459 }
460
461 /**
462 * The places panel will resize itself if any of the other widgets requires too much horizontal space
463 * but a user never wants the size of the places panel to change unless they resized it themselves explicitly.
464 */
465 void DolphinMainWindowTest::testPlacesPanelWidthResistance()
466 {
467 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
468 m_mainWindow->show();
469 m_mainWindow->resize(800, m_mainWindow->height()); // make sure the size is sufficient so a places panel resize shouldn't be necessary.
470 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
471 QVERIFY(m_mainWindow->isVisible());
472
473 QWidget *placesPanel = reinterpret_cast<QWidget *>(m_mainWindow->m_placesPanel);
474 QVERIFY2(QTest::qWaitFor(
475 [&]() {
476 return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0;
477 },
478 5000),
479 "The test couldn't be initialised properly. The places panel should be visible.");
480 QTest::qWait(100);
481 const int initialPlacesPanelWidth = placesPanel->width();
482
483 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); // enable split view (starts animation)
484 QTest::qWait(300); // wait for animation
485 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
486
487 m_mainWindow->actionCollection()->action(QStringLiteral("show_filter_bar"))->trigger();
488 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
489
490 // Make all selection mode bars appear and test for each that this doesn't affect the places panel's width.
491 // 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.
492 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::SelectAll))->trigger();
493 for (int selectionModeStates = SelectionMode::BottomBar::CopyContents; selectionModeStates != SelectionMode::BottomBar::RenameContents;
494 selectionModeStates++) {
495 const auto contents = static_cast<SelectionMode::BottomBar::Contents>(selectionModeStates);
496 m_mainWindow->slotSetSelectionMode(true, contents);
497 QTest::qWait(20); // give time for a paint/resize
498 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
499 }
500
501 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Find))->trigger();
502 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
503
504 #if HAVE_BALOO
505 m_mainWindow->actionCollection()->action(QStringLiteral("show_information_panel"))->setChecked(true); // toggle visible
506 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
507 #endif
508
509 #if HAVE_TERMINAL
510 m_mainWindow->actionCollection()->action(QStringLiteral("show_terminal_panel"))->setChecked(true); // toggle visible
511 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
512 #endif
513
514 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); // disable split view (starts animation)
515 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
516
517 #if HAVE_BALOO
518 m_mainWindow->actionCollection()->action(QStringLiteral("show_information_panel"))->trigger(); // toggle invisible
519 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
520 #endif
521
522 #if HAVE_TERMINAL
523 m_mainWindow->actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // toggle invisible
524 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
525 #endif
526
527 m_mainWindow->showMaximized();
528 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
529
530 QTest::qWait(300); // wait for split view closing animation
531 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
532 }
533
534 void DolphinMainWindowTest::testGoActions()
535 {
536 QScopedPointer<TestDir> testDir{new TestDir()};
537 testDir->createDir("a");
538 testDir->createDir("b");
539 testDir->createDir("b/b-1");
540 testDir->createFile("b/b-2");
541 testDir->createDir("c");
542 const QUrl childDirUrl(QDir::cleanPath(testDir->url().toString() + "/b"));
543 m_mainWindow->openDirectories({childDirUrl}, false); // Open "b" dir
544 m_mainWindow->show();
545 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
546 QVERIFY(m_mainWindow->isVisible());
547 QVERIFY(!m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->isEnabled());
548
549 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Up))->trigger();
550 /**
551 * Now, after going "up" in the file hierarchy (to "testDir"), the folder one has emerged from ("b") should have keyboard focus.
552 * This is especially important when a user wants to peek into multiple folders in quick succession.
553 */
554 QSignalSpy spyDirectoryLoadingCompleted(m_mainWindow->m_activeViewContainer->view(), &DolphinView::directoryLoadingCompleted);
555 QVERIFY(spyDirectoryLoadingCompleted.wait());
556 QVERIFY(QTest::qWaitFor([&]() {
557 return !m_mainWindow->actionCollection()->action(QStringLiteral("stop"))->isEnabled();
558 })); // "Stop" command should be disabled because it finished loading
559 QTest::qWait(500); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
560 const QUrl parentDirUrl = m_mainWindow->activeViewContainer()->url();
561 QVERIFY(parentDirUrl != childDirUrl);
562
563 auto currentItemUrl = [this]() {
564 const int currentIndex = m_mainWindow->m_activeViewContainer->view()->m_container->controller()->selectionManager()->currentItem();
565 const KFileItem currentItem = m_mainWindow->m_activeViewContainer->view()->m_model->fileItem(currentIndex);
566 return currentItem.url();
567 };
568
569 QCOMPARE(currentItemUrl(), childDirUrl); // The item we just emerged from should now have keyboard focus.
570 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0); // The item we just emerged from should not be selected. BUG: 424723
571 // Pressing arrow keys should not only move the keyboard focus but also select the item.
572 // We press "Down" to select "c" below and then "Up" so the folder "b" we just emerged from is selected for the first time.
573 m_mainWindow->actionCollection()->action(QStringLiteral("compact"))->trigger();
574 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Down, Qt::NoModifier);
575 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
576 QVERIFY2(currentItemUrl() != childDirUrl, "The current item didn't change after pressing the 'Down' key.");
577 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Up, Qt::NoModifier);
578 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
579 QCOMPARE(currentItemUrl(), childDirUrl); // After pressing 'Down' and then 'Up' we should be back where we were.
580
581 // Enter the child folder "b".
582 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Enter, Qt::NoModifier);
583 QVERIFY(spyDirectoryLoadingCompleted.wait());
584 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
585 QVERIFY(m_mainWindow->isUrlOpen(childDirUrl.toString()));
586
587 // Go back to the parent folder.
588 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger();
589 QVERIFY(spyDirectoryLoadingCompleted.wait());
590 QTest::qWait(100); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
591 QCOMPARE(m_mainWindow->activeViewContainer()->url(), parentDirUrl);
592 QVERIFY(m_mainWindow->isUrlOpen(parentDirUrl.toString()));
593 // Going 'Back' means that the view should be in the same state it was in when we left.
594 QCOMPARE(currentItemUrl(), childDirUrl); // The item we last interacted with in this location should still have keyboard focus.
595 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
596 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().constFirst().url(), childDirUrl); // It should still be selected.
597
598 // Open a new tab for the "b" child dir and verify that this doesn't interfere with anything.
599 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Enter, Qt::ControlModifier); // Open new inactive tab
600 QVERIFY(m_mainWindow->m_tabWidget->count() == 2);
601 QCOMPARE(m_mainWindow->activeViewContainer()->url(), parentDirUrl);
602 QVERIFY(m_mainWindow->isUrlOpen(parentDirUrl.toString()));
603 QVERIFY(!m_mainWindow->actionCollection()->action(QStringLiteral("undo_close_tab"))->isEnabled());
604
605 // Go forward to the child folder.
606 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->trigger();
607 QVERIFY(spyDirectoryLoadingCompleted.wait());
608 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
609 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0); // There was no action in this view yet that would warrant a selection.
610 QCOMPARE(currentItemUrl(), QUrl(QDir::cleanPath(testDir->url().toString() + "/b/b-1"))); // The first item in the view should have keyboard focus.
611
612 // Press the 'Down' key in the child folder.
613 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Down, Qt::NoModifier);
614 // The second item in the view should have keyboard focus and be selected.
615 const QUrl secondItemInChildFolderUrl{QDir::cleanPath(testDir->url().toString() + "/b/b-2")};
616 QCOMPARE(currentItemUrl(), secondItemInChildFolderUrl);
617 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
618 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().constFirst().url(), secondItemInChildFolderUrl);
619
620 // Go back to the parent folder and then re-enter the child folder.
621 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger();
622 QVERIFY(spyDirectoryLoadingCompleted.wait());
623 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->trigger();
624 QVERIFY(spyDirectoryLoadingCompleted.wait());
625 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
626 // The state of the view should be identical to how it was before we triggered "Back" and then "Forward".
627 QTRY_COMPARE(currentItemUrl(), secondItemInChildFolderUrl);
628 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
629 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().constFirst().url(), secondItemInChildFolderUrl);
630
631 // Go back to the parent folder.
632 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger();
633 QVERIFY(spyDirectoryLoadingCompleted.wait());
634 QTest::qWait(100); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
635 QCOMPARE(m_mainWindow->activeViewContainer()->url(), parentDirUrl);
636 QVERIFY(m_mainWindow->isUrlOpen(parentDirUrl.toString()));
637
638 // 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
639 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Close))->trigger(); // Close current tab
640 QVERIFY(m_mainWindow->m_tabWidget->count() == 1);
641 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
642 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0); // There was no action in this tab yet that would warrant a selection.
643 QVERIFY(!m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->isEnabled());
644 QVERIFY(!m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->isEnabled());
645 QVERIFY(m_mainWindow->actionCollection()->action(QStringLiteral("undo_close_tab"))->isEnabled());
646 }
647
648 void DolphinMainWindowTest::testOpenFiles()
649 {
650 QScopedPointer<TestDir> testDir{new TestDir()};
651 QString testDirUrl(QDir::cleanPath(testDir->url().toString()));
652 testDir->createDir("a");
653 testDir->createDir("a/b");
654 testDir->createDir("a/b/c");
655 testDir->createDir("a/b/c/d");
656 m_mainWindow->openDirectories({testDirUrl}, false);
657 m_mainWindow->show();
658
659 // We only see the unselected "a" folder in the test dir. There are no other tabs.
660 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
661 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a"));
662 QVERIFY(!m_mainWindow->isUrlOpen(testDirUrl + "/a"));
663 QVERIFY(!m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b"));
664 QCOMPARE(m_mainWindow->m_tabWidget->count(), 1);
665 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 0);
666 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0);
667
668 // "a" is already in view, so "opening" "a" should simply select it without opening a new tab.
669 m_mainWindow->openFiles({testDirUrl + "/a"}, false);
670 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
671 QCOMPARE(m_mainWindow->m_tabWidget->count(), 1);
672 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a"));
673
674 // "b" is not in view, so "opening" "b" should open a new active tab of the parent folder "a" and select "b" there.
675 m_mainWindow->openFiles({testDirUrl + "/a/b"}, false);
676 QTRY_VERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
677 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
678 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
679 QTRY_VERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b"));
680 QVERIFY2(!m_mainWindow->isUrlOpen(testDirUrl + "/a/b"), "The directory b is supposed to be visible but not open in its own tab.");
681 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
682
683 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
684 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a"));
685 // "a" is still in view in the first tab, so "opening" "a" should switch to the first tab and select "a" there.
686 m_mainWindow->openFiles({testDirUrl + "/a"}, false);
687 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
688 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 0);
689 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
690 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
691
692 // Directory "a" is already open in the second tab in which "b" is selected, so opening the directory "a" should switch to that tab.
693 m_mainWindow->openDirectories({testDirUrl + "/a"}, false);
694 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
695 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
696
697 // 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.
698 m_mainWindow->actionCollection()->action(QStringLiteral("details"))->trigger();
699 QTRY_VERIFY(m_mainWindow->activeViewContainer()->view()->itemsExpandable());
700
701 // Expand the already selected "b" with the right arrow key. This should make "c" visible.
702 QVERIFY2(!m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c"), "The parent folder wasn't expanded yet, so c shouldn't be visible.");
703 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Right);
704 QTRY_VERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c"));
705 QVERIFY2(!m_mainWindow->isUrlOpen(testDirUrl + "/a/b"), "b is supposed to be expanded, however it shouldn't be open in its own tab.");
706 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
707
708 // Switch to first tab by opening it even though it is already open.
709 m_mainWindow->openDirectories({testDirUrl}, false);
710 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
711 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 0);
712
713 // "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.
714 m_mainWindow->openFiles({testDirUrl + "/a/b/c"}, false);
715 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
716 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
717 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
718 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
719 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
720
721 // Opening the directory "c" on the other hand will open it in a new tab even though it is already visible in the view
722 // because openDirecories() and openFiles() serve different purposes. One opens views at urls, the other selects files within views.
723 m_mainWindow->openDirectories({testDirUrl + "/a/b/c/d", testDirUrl + "/a/b/c"}, true);
724 QCOMPARE(m_mainWindow->m_tabWidget->count(), 3);
725 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 2);
726 QVERIFY(m_mainWindow->m_tabWidget->currentTabPage()->splitViewEnabled());
727 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c")); // It should still be visible in the second tab.
728 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0);
729 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a/b/c/d"));
730 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a/b/c"));
731
732 // "c" is in view in the second tab because "b" is expanded there,
733 // so "opening" "c" should switch to that tab even though "c" as a directory is open in the current tab.
734 m_mainWindow->openFiles({testDirUrl + "/a/b/c"}, false);
735 QCOMPARE(m_mainWindow->m_tabWidget->count(), 3);
736 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
737 QVERIFY2(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c/d"), "It should be visible in the secondary view of the third tab.");
738
739 // Select "b" and un-expand it with the left arrow key. This should make "c" invisible.
740 m_mainWindow->openFiles({testDirUrl + "/a/b"}, false);
741 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Left);
742 QTRY_VERIFY(!m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c"));
743
744 // "d" is in view in the third tab in the secondary view, so "opening" "d" should select that view.
745 m_mainWindow->openFiles({testDirUrl + "/a/b/c/d"}, false);
746 QCOMPARE(m_mainWindow->m_tabWidget->count(), 3);
747 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 2);
748 QVERIFY(m_mainWindow->m_tabWidget->currentTabPage()->secondaryViewContainer()->isActive());
749 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
750 }
751
752 void DolphinMainWindowTest::testAccessibilityTree()
753 {
754 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
755 m_mainWindow->show();
756 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
757 QVERIFY(m_mainWindow->isVisible());
758
759 QAccessibleInterface *accessibleInterfaceOfMainWindow = QAccessible::queryAccessibleInterface(m_mainWindow.get());
760 Q_CHECK_PTR(accessibleInterfaceOfMainWindow);
761
762 /// Test the accessibility of objects while traversing forwards (Tab key) and backwards (Shift+Tab).
763 int testedObjectsSizeAfterTraversingForwards = 0;
764 for (int i = 0; i < 2; i++) {
765 std::tuple<Qt::Key, Qt::KeyboardModifier> focusChainTraversalKeyCombination = {Qt::Key::Key_Tab, Qt::NoModifier};
766 if (i) {
767 focusChainTraversalKeyCombination = {Qt::Key::Key_Tab, Qt::ShiftModifier};
768 }
769
770 /// @see firstNamedAncestor below.
771 QAccessibleInterface *firstNamedAncestorOfPreviousIteration = nullptr;
772
773 /// Perform accessibility checks for every object that gets focus. Focus will be changed using the focusChainTraversalKeyCombination.
774 std::set<const QObject *> testedObjects; // Makes sure we stop testing when we arrive at an item that was already tested.
775 while (qApp->focusObject() && !testedObjects.count(qApp->focusObject())) {
776 const auto currentlyFocusedObject = qApp->focusObject();
777 const QAccessibleInterface *accessibleIntefaceOfCurrentlyFocusedObject = QAccessible::queryAccessibleInterface(currentlyFocusedObject);
778 QVERIFY(accessibleIntefaceOfCurrentlyFocusedObject);
779
780 /// Test that each object reachable by Tab or Shift+Tab has at least some accessible information. Objects without any accessible information
781 /// are even less useful to accessibility software users than unlabeled buttons are e.g. to sighted users, because unlabeled buttons at least
782 /// convey some information through their placement and icon.
783 if (currentlyFocusedObject != m_mainWindow->m_activeViewContainer->view()->m_container) { // Skip the custom container widget which has no
784 // accessible name on purpose.
785 /**
786 * The first ancestor with an accessible name is interesting because it is sometimes used to identify an object if the object itself has no
787 * 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.
788 */
789 QAccessibleInterface *firstNamedAncestor = accessibleIntefaceOfCurrentlyFocusedObject->parent();
790 while (firstNamedAncestor) {
791 if (!firstNamedAncestor->text(QAccessible::Name).isEmpty()) {
792 break;
793 }
794 firstNamedAncestor = firstNamedAncestor->parent();
795 }
796 QTRY_VERIFY2(!accessibleIntefaceOfCurrentlyFocusedObject->text(QAccessible::Name).isEmpty()
797 || (firstNamedAncestor && firstNamedAncestor != firstNamedAncestorOfPreviousIteration),
798 qPrintable(QStringLiteral("%1's accessibleInterface does not have an accessible name and can not be distinguished from the object"
799 " that had focus previously. Please fix this. You can find this %1 within its parent %2.")
800 .arg(currentlyFocusedObject->metaObject()->className())
801 .arg(currentlyFocusedObject->parent()->metaObject()->className())));
802 firstNamedAncestorOfPreviousIteration = firstNamedAncestor;
803 }
804
805 /// Test that each accessible interface has the main window as its parent.
806 QAccessibleInterface *accessibleInterface = QAccessible::queryAccessibleInterface(currentlyFocusedObject);
807 // The accessibleInterfaces of focused objects might themselves have children.
808 // We go down that hierarchy as far as possible and then test the ancestor tree from there.
809 while (accessibleInterface->childCount() > 0) {
810 accessibleInterface = accessibleInterface->child(0);
811 }
812 while (accessibleInterface != accessibleInterfaceOfMainWindow) {
813 QVERIFY2(accessibleInterface,
814 qPrintable(QStringLiteral("%1's accessibleInterface or one of its accessible children doesn't have the main window as an ancestor.")
815 .arg(currentlyFocusedObject->metaObject()->className())));
816 accessibleInterface = accessibleInterface->parent();
817 }
818
819 testedObjects.insert(currentlyFocusedObject); // Add it to testedObjects so we won't test it again later.
820 QTest::keyClick(m_mainWindow.get(), std::get<0>(focusChainTraversalKeyCombination), std::get<1>(focusChainTraversalKeyCombination));
821 QVERIFY2(currentlyFocusedObject != qApp->focusObject(),
822 "The focus chain is broken. The focused object should have changed after pressing the focusChainTraversalKeyCombination.");
823 }
824
825 if (i == 0) {
826 testedObjectsSizeAfterTraversingForwards = testedObjects.size();
827 } else {
828 QCOMPARE(testedObjects.size(), testedObjectsSizeAfterTraversingForwards); // The size after traversing backwards is different than
829 // after going forwards which is probably not intended.
830 }
831 }
832 QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 12); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the
833 // test run correctly?
834 }
835
836 void DolphinMainWindowTest::testAutoSaveSession()
837 {
838 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
839 m_mainWindow->show();
840 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
841 QVERIFY(m_mainWindow->isVisible());
842
843 // Create config file
844 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
845 KConfig *config = KConfigGui::sessionConfig();
846 m_mainWindow->saveGlobalProperties(config);
847 m_mainWindow->savePropertiesInternal(config, 1);
848 config->sync();
849
850 // Setup watcher for config file changes
851 const QString configFileName = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/" + KConfigGui::sessionConfig()->name();
852 QFileSystemWatcher *configWatcher = new QFileSystemWatcher({configFileName}, this);
853 QSignalSpy spySessionSaved(configWatcher, &QFileSystemWatcher::fileChanged);
854
855 // Enable session autosave.
856 m_mainWindow->setSessionAutoSaveEnabled(true);
857 m_mainWindow->m_sessionSaveTimer->setInterval(200); // Lower the interval to speed up the testing
858
859 // Open a new tab
860 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget");
861 QVERIFY(tabWidget);
862 tabWidget->openNewActivatedTab(QUrl::fromLocalFile(QDir::tempPath()));
863 QCOMPARE(tabWidget->count(), 2);
864
865 // Wait till a session save occurs
866 QVERIFY(spySessionSaved.wait(60000));
867
868 // Disable session autosave.
869 m_mainWindow->setSessionAutoSaveEnabled(false);
870 }
871
872 void DolphinMainWindowTest::cleanupTestCase()
873 {
874 m_mainWindow->showNormal();
875 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->setChecked(false); // disable split view (starts animation)
876
877 #if HAVE_BALOO
878 m_mainWindow->actionCollection()->action(QStringLiteral("show_information_panel"))->setChecked(false); // hide panel
879 #endif
880
881 #if HAVE_TERMINAL
882 m_mainWindow->actionCollection()->action(QStringLiteral("show_terminal_panel"))->setChecked(false); // hide panel
883 #endif
884
885 // Quit Dolphin to save the hiding of panels and make sure that normal Quit doesn't crash.
886 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Quit))->trigger();
887 }
888
889 QTEST_MAIN(DolphinMainWindowTest)
890
891 #include "dolphinmainwindowtest.moc"