]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphinmainwindowtest.cpp
CI: Flatpak: Add ark for compression
[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 /// Test that activating a place always moves focus to the view.
461 QTest::keyClick(QApplication::focusWidget(), Qt::Key::Key_Enter);
462 QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
463 "Activating a place should move focus to the view that loads that place.");
464
465 focusPlacesPanelAction->trigger();
466 QVERIFY(placesPanel->hasFocus());
467
468 QTest::keyClick(QApplication::focusWidget(), Qt::Key::Key_Enter);
469 QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()),
470 "Activating a place should move focus to the view even if the view already has that place loaded.");
471 }
472
473 /**
474 * The places panel will resize itself if any of the other widgets requires too much horizontal space
475 * but a user never wants the size of the places panel to change unless they resized it themselves explicitly.
476 */
477 void DolphinMainWindowTest::testPlacesPanelWidthResistance()
478 {
479 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
480 m_mainWindow->show();
481 m_mainWindow->resize(800, m_mainWindow->height()); // make sure the size is sufficient so a places panel resize shouldn't be necessary.
482 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
483 QVERIFY(m_mainWindow->isVisible());
484
485 QWidget *placesPanel = reinterpret_cast<QWidget *>(m_mainWindow->m_placesPanel);
486 QVERIFY2(QTest::qWaitFor(
487 [&]() {
488 return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0;
489 },
490 5000),
491 "The test couldn't be initialised properly. The places panel should be visible.");
492 QTest::qWait(100);
493 const int initialPlacesPanelWidth = placesPanel->width();
494
495 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); // enable split view (starts animation)
496 QTest::qWait(300); // wait for animation
497 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
498
499 m_mainWindow->actionCollection()->action(QStringLiteral("show_filter_bar"))->trigger();
500 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
501
502 // Make all selection mode bars appear and test for each that this doesn't affect the places panel's width.
503 // 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.
504 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::SelectAll))->trigger();
505 for (int selectionModeStates = SelectionMode::BottomBar::CopyContents; selectionModeStates != SelectionMode::BottomBar::RenameContents;
506 selectionModeStates++) {
507 const auto contents = static_cast<SelectionMode::BottomBar::Contents>(selectionModeStates);
508 m_mainWindow->slotSetSelectionMode(true, contents);
509 QTest::qWait(20); // give time for a paint/resize
510 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
511 }
512
513 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Find))->trigger();
514 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
515
516 #if HAVE_BALOO
517 m_mainWindow->actionCollection()->action(QStringLiteral("show_information_panel"))->setChecked(true); // toggle visible
518 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
519 #endif
520
521 #if HAVE_TERMINAL
522 m_mainWindow->actionCollection()->action(QStringLiteral("show_terminal_panel"))->setChecked(true); // toggle visible
523 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
524 #endif
525
526 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); // disable split view (starts animation)
527 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
528
529 #if HAVE_BALOO
530 m_mainWindow->actionCollection()->action(QStringLiteral("show_information_panel"))->trigger(); // toggle invisible
531 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
532 #endif
533
534 #if HAVE_TERMINAL
535 m_mainWindow->actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // toggle invisible
536 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
537 #endif
538
539 m_mainWindow->showMaximized();
540 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
541
542 QTest::qWait(300); // wait for split view closing animation
543 QCOMPARE(placesPanel->width(), initialPlacesPanelWidth);
544 }
545
546 void DolphinMainWindowTest::testGoActions()
547 {
548 QScopedPointer<TestDir> testDir{new TestDir()};
549 testDir->createDir("a");
550 testDir->createDir("b");
551 testDir->createDir("b/b-1");
552 testDir->createFile("b/b-2");
553 testDir->createDir("c");
554 const QUrl childDirUrl(QDir::cleanPath(testDir->url().toString() + "/b"));
555 m_mainWindow->openDirectories({childDirUrl}, false); // Open "b" dir
556 m_mainWindow->show();
557 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
558 QVERIFY(m_mainWindow->isVisible());
559 QVERIFY(!m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->isEnabled());
560
561 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Up))->trigger();
562 /**
563 * Now, after going "up" in the file hierarchy (to "testDir"), the folder one has emerged from ("b") should have keyboard focus.
564 * This is especially important when a user wants to peek into multiple folders in quick succession.
565 */
566 QSignalSpy spyDirectoryLoadingCompleted(m_mainWindow->m_activeViewContainer->view(), &DolphinView::directoryLoadingCompleted);
567 QVERIFY(spyDirectoryLoadingCompleted.wait());
568 QVERIFY(QTest::qWaitFor([&]() {
569 return !m_mainWindow->actionCollection()->action(QStringLiteral("stop"))->isEnabled();
570 })); // "Stop" command should be disabled because it finished loading
571 QTest::qWait(500); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
572 const QUrl parentDirUrl = m_mainWindow->activeViewContainer()->url();
573 QVERIFY(parentDirUrl != childDirUrl);
574
575 auto currentItemUrl = [this]() {
576 const int currentIndex = m_mainWindow->m_activeViewContainer->view()->m_container->controller()->selectionManager()->currentItem();
577 const KFileItem currentItem = m_mainWindow->m_activeViewContainer->view()->m_model->fileItem(currentIndex);
578 return currentItem.url();
579 };
580
581 QCOMPARE(currentItemUrl(), childDirUrl); // The item we just emerged from should now have keyboard focus.
582 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0); // The item we just emerged from should not be selected. BUG: 424723
583 // Pressing arrow keys should not only move the keyboard focus but also select the item.
584 // We press "Down" to select "c" below and then "Up" so the folder "b" we just emerged from is selected for the first time.
585 m_mainWindow->actionCollection()->action(QStringLiteral("compact"))->trigger();
586 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Down, Qt::NoModifier);
587 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
588 QVERIFY2(currentItemUrl() != childDirUrl, "The current item didn't change after pressing the 'Down' key.");
589 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Up, Qt::NoModifier);
590 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
591 QCOMPARE(currentItemUrl(), childDirUrl); // After pressing 'Down' and then 'Up' we should be back where we were.
592
593 // Enter the child folder "b".
594 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Enter, Qt::NoModifier);
595 QVERIFY(spyDirectoryLoadingCompleted.wait());
596 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
597 QVERIFY(m_mainWindow->isUrlOpen(childDirUrl.toString()));
598
599 // Go back to the parent folder.
600 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger();
601 QVERIFY(spyDirectoryLoadingCompleted.wait());
602 QTest::qWait(100); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
603 QCOMPARE(m_mainWindow->activeViewContainer()->url(), parentDirUrl);
604 QVERIFY(m_mainWindow->isUrlOpen(parentDirUrl.toString()));
605 // Going 'Back' means that the view should be in the same state it was in when we left.
606 QCOMPARE(currentItemUrl(), childDirUrl); // The item we last interacted with in this location should still have keyboard focus.
607 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
608 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().constFirst().url(), childDirUrl); // It should still be selected.
609
610 // Open a new tab for the "b" child dir and verify that this doesn't interfere with anything.
611 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Enter, Qt::ControlModifier); // Open new inactive tab
612 QVERIFY(m_mainWindow->m_tabWidget->count() == 2);
613 QCOMPARE(m_mainWindow->activeViewContainer()->url(), parentDirUrl);
614 QVERIFY(m_mainWindow->isUrlOpen(parentDirUrl.toString()));
615 QVERIFY(!m_mainWindow->actionCollection()->action(QStringLiteral("undo_close_tab"))->isEnabled());
616
617 // Go forward to the child folder.
618 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->trigger();
619 QVERIFY(spyDirectoryLoadingCompleted.wait());
620 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
621 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0); // There was no action in this view yet that would warrant a selection.
622 QCOMPARE(currentItemUrl(), QUrl(QDir::cleanPath(testDir->url().toString() + "/b/b-1"))); // The first item in the view should have keyboard focus.
623
624 // Press the 'Down' key in the child folder.
625 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Down, Qt::NoModifier);
626 // The second item in the view should have keyboard focus and be selected.
627 const QUrl secondItemInChildFolderUrl{QDir::cleanPath(testDir->url().toString() + "/b/b-2")};
628 QCOMPARE(currentItemUrl(), secondItemInChildFolderUrl);
629 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
630 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().constFirst().url(), secondItemInChildFolderUrl);
631
632 // Go back to the parent folder and then re-enter the child folder.
633 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger();
634 QVERIFY(spyDirectoryLoadingCompleted.wait());
635 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->trigger();
636 QVERIFY(spyDirectoryLoadingCompleted.wait());
637 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
638 // The state of the view should be identical to how it was before we triggered "Back" and then "Forward".
639 QTRY_COMPARE(currentItemUrl(), secondItemInChildFolderUrl);
640 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
641 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().constFirst().url(), secondItemInChildFolderUrl);
642
643 // Go back to the parent folder.
644 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger();
645 QVERIFY(spyDirectoryLoadingCompleted.wait());
646 QTest::qWait(100); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second.
647 QCOMPARE(m_mainWindow->activeViewContainer()->url(), parentDirUrl);
648 QVERIFY(m_mainWindow->isUrlOpen(parentDirUrl.toString()));
649
650 // 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
651 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Close))->trigger(); // Close current tab
652 QVERIFY(m_mainWindow->m_tabWidget->count() == 1);
653 QCOMPARE(m_mainWindow->activeViewContainer()->url(), childDirUrl);
654 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0); // There was no action in this tab yet that would warrant a selection.
655 QVERIFY(!m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->isEnabled());
656 QVERIFY(!m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Forward))->isEnabled());
657 QVERIFY(m_mainWindow->actionCollection()->action(QStringLiteral("undo_close_tab"))->isEnabled());
658 }
659
660 void DolphinMainWindowTest::testOpenFiles()
661 {
662 QScopedPointer<TestDir> testDir{new TestDir()};
663 QString testDirUrl(QDir::cleanPath(testDir->url().toString()));
664 testDir->createDir("a");
665 testDir->createDir("a/b");
666 testDir->createDir("a/b/c");
667 testDir->createDir("a/b/c/d");
668 m_mainWindow->openDirectories({testDirUrl}, false);
669 m_mainWindow->show();
670
671 // We only see the unselected "a" folder in the test dir. There are no other tabs.
672 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
673 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a"));
674 QVERIFY(!m_mainWindow->isUrlOpen(testDirUrl + "/a"));
675 QVERIFY(!m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b"));
676 QCOMPARE(m_mainWindow->m_tabWidget->count(), 1);
677 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 0);
678 QCOMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0);
679
680 // "a" is already in view, so "opening" "a" should simply select it without opening a new tab.
681 m_mainWindow->openFiles({testDirUrl + "/a"}, false);
682 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
683 QCOMPARE(m_mainWindow->m_tabWidget->count(), 1);
684 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a"));
685
686 // "b" is not in view, so "opening" "b" should open a new active tab of the parent folder "a" and select "b" there.
687 m_mainWindow->openFiles({testDirUrl + "/a/b"}, false);
688 QTRY_VERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
689 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
690 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
691 QTRY_VERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b"));
692 QVERIFY2(!m_mainWindow->isUrlOpen(testDirUrl + "/a/b"), "The directory b is supposed to be visible but not open in its own tab.");
693 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
694
695 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
696 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a"));
697 // "a" is still in view in the first tab, so "opening" "a" should switch to the first tab and select "a" there.
698 m_mainWindow->openFiles({testDirUrl + "/a"}, false);
699 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
700 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 0);
701 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
702 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
703
704 // Directory "a" is already open in the second tab in which "b" is selected, so opening the directory "a" should switch to that tab.
705 m_mainWindow->openDirectories({testDirUrl + "/a"}, false);
706 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
707 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
708
709 // 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.
710 m_mainWindow->actionCollection()->action(QStringLiteral("details"))->trigger();
711 QTRY_VERIFY(m_mainWindow->activeViewContainer()->view()->itemsExpandable());
712
713 // Expand the already selected "b" with the right arrow key. This should make "c" visible.
714 QVERIFY2(!m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c"), "The parent folder wasn't expanded yet, so c shouldn't be visible.");
715 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Right);
716 QTRY_VERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c"));
717 QVERIFY2(!m_mainWindow->isUrlOpen(testDirUrl + "/a/b"), "b is supposed to be expanded, however it shouldn't be open in its own tab.");
718 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
719
720 // Switch to first tab by opening it even though it is already open.
721 m_mainWindow->openDirectories({testDirUrl}, false);
722 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
723 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 0);
724
725 // "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.
726 m_mainWindow->openFiles({testDirUrl + "/a/b/c"}, false);
727 QCOMPARE(m_mainWindow->m_tabWidget->count(), 2);
728 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
729 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
730 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl));
731 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a"));
732
733 // Opening the directory "c" on the other hand will open it in a new tab even though it is already visible in the view
734 // because openDirecories() and openFiles() serve different purposes. One opens views at urls, the other selects files within views.
735 m_mainWindow->openDirectories({testDirUrl + "/a/b/c/d", testDirUrl + "/a/b/c"}, true);
736 QCOMPARE(m_mainWindow->m_tabWidget->count(), 3);
737 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 2);
738 QVERIFY(m_mainWindow->m_tabWidget->currentTabPage()->splitViewEnabled());
739 QVERIFY(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c")); // It should still be visible in the second tab.
740 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 0);
741 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a/b/c/d"));
742 QVERIFY(m_mainWindow->isUrlOpen(testDirUrl + "/a/b/c"));
743
744 // "c" is in view in the second tab because "b" is expanded there,
745 // so "opening" "c" should switch to that tab even though "c" as a directory is open in the current tab.
746 m_mainWindow->openFiles({testDirUrl + "/a/b/c"}, false);
747 QCOMPARE(m_mainWindow->m_tabWidget->count(), 3);
748 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 1);
749 QVERIFY2(m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c/d"), "It should be visible in the secondary view of the third tab.");
750
751 // Select "b" and un-expand it with the left arrow key. This should make "c" invisible.
752 m_mainWindow->openFiles({testDirUrl + "/a/b"}, false);
753 QTest::keyClick(m_mainWindow->activeViewContainer()->view()->m_container, Qt::Key::Key_Left);
754 QTRY_VERIFY(!m_mainWindow->isItemVisibleInAnyView(testDirUrl + "/a/b/c"));
755
756 // "d" is in view in the third tab in the secondary view, so "opening" "d" should select that view.
757 m_mainWindow->openFiles({testDirUrl + "/a/b/c/d"}, false);
758 QCOMPARE(m_mainWindow->m_tabWidget->count(), 3);
759 QCOMPARE(m_mainWindow->m_tabWidget->currentIndex(), 2);
760 QVERIFY(m_mainWindow->m_tabWidget->currentTabPage()->secondaryViewContainer()->isActive());
761 QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->selectedItems().count(), 1);
762 }
763
764 void DolphinMainWindowTest::testAccessibilityTree()
765 {
766 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
767 m_mainWindow->show();
768 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
769 QVERIFY(m_mainWindow->isVisible());
770
771 QAccessibleInterface *accessibleInterfaceOfMainWindow = QAccessible::queryAccessibleInterface(m_mainWindow.get());
772 Q_CHECK_PTR(accessibleInterfaceOfMainWindow);
773
774 /// Test the accessibility of objects while traversing forwards (Tab key) and backwards (Shift+Tab).
775 int testedObjectsSizeAfterTraversingForwards = 0;
776 for (int i = 0; i < 2; i++) {
777 std::tuple<Qt::Key, Qt::KeyboardModifier> focusChainTraversalKeyCombination = {Qt::Key::Key_Tab, Qt::NoModifier};
778 if (i) {
779 focusChainTraversalKeyCombination = {Qt::Key::Key_Tab, Qt::ShiftModifier};
780 }
781
782 /// @see firstNamedAncestor below.
783 QAccessibleInterface *firstNamedAncestorOfPreviousIteration = nullptr;
784
785 /// Perform accessibility checks for every object that gets focus. Focus will be changed using the focusChainTraversalKeyCombination.
786 std::set<const QObject *> testedObjects; // Makes sure we stop testing when we arrive at an item that was already tested.
787 while (qApp->focusObject() && !testedObjects.count(qApp->focusObject())) {
788 const auto currentlyFocusedObject = qApp->focusObject();
789 const QAccessibleInterface *accessibleIntefaceOfCurrentlyFocusedObject = QAccessible::queryAccessibleInterface(currentlyFocusedObject);
790 QVERIFY(accessibleIntefaceOfCurrentlyFocusedObject);
791
792 /// Test that each object reachable by Tab or Shift+Tab has at least some accessible information. Objects without any accessible information
793 /// are even less useful to accessibility software users than unlabeled buttons are e.g. to sighted users, because unlabeled buttons at least
794 /// convey some information through their placement and icon.
795 if (currentlyFocusedObject != m_mainWindow->m_activeViewContainer->view()->m_container) { // Skip the custom container widget which has no
796 // accessible name on purpose.
797 /**
798 * The first ancestor with an accessible name is interesting because it is sometimes used to identify an object if the object itself has no
799 * 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.
800 */
801 QAccessibleInterface *firstNamedAncestor = accessibleIntefaceOfCurrentlyFocusedObject->parent();
802 while (firstNamedAncestor) {
803 if (!firstNamedAncestor->text(QAccessible::Name).isEmpty()) {
804 break;
805 }
806 firstNamedAncestor = firstNamedAncestor->parent();
807 }
808 QTRY_VERIFY2(!accessibleIntefaceOfCurrentlyFocusedObject->text(QAccessible::Name).isEmpty()
809 || (firstNamedAncestor && firstNamedAncestor != firstNamedAncestorOfPreviousIteration),
810 qPrintable(QStringLiteral("%1's accessibleInterface does not have an accessible name and can not be distinguished from the object"
811 " that had focus previously. Please fix this. You can find this %1 within its parent %2.")
812 .arg(currentlyFocusedObject->metaObject()->className())
813 .arg(currentlyFocusedObject->parent()->metaObject()->className())));
814 firstNamedAncestorOfPreviousIteration = firstNamedAncestor;
815 }
816
817 /// Test that each accessible interface has the main window as its parent.
818 QAccessibleInterface *accessibleInterface = QAccessible::queryAccessibleInterface(currentlyFocusedObject);
819 // The accessibleInterfaces of focused objects might themselves have children.
820 // We go down that hierarchy as far as possible and then test the ancestor tree from there.
821 while (accessibleInterface->childCount() > 0) {
822 accessibleInterface = accessibleInterface->child(0);
823 }
824 while (accessibleInterface != accessibleInterfaceOfMainWindow) {
825 QVERIFY2(accessibleInterface,
826 qPrintable(QStringLiteral("%1's accessibleInterface or one of its accessible children doesn't have the main window as an ancestor.")
827 .arg(currentlyFocusedObject->metaObject()->className())));
828 accessibleInterface = accessibleInterface->parent();
829 }
830
831 testedObjects.insert(currentlyFocusedObject); // Add it to testedObjects so we won't test it again later.
832 QTest::keyClick(m_mainWindow.get(), std::get<0>(focusChainTraversalKeyCombination), std::get<1>(focusChainTraversalKeyCombination));
833 QVERIFY2(currentlyFocusedObject != qApp->focusObject(),
834 "The focus chain is broken. The focused object should have changed after pressing the focusChainTraversalKeyCombination.");
835 }
836
837 if (i == 0) {
838 testedObjectsSizeAfterTraversingForwards = testedObjects.size();
839 } else {
840 QCOMPARE(testedObjects.size(), testedObjectsSizeAfterTraversingForwards); // The size after traversing backwards is different than
841 // after going forwards which is probably not intended.
842 }
843 }
844 QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 12); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the
845 // test run correctly?
846 }
847
848 void DolphinMainWindowTest::testAutoSaveSession()
849 {
850 m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false);
851 m_mainWindow->show();
852 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
853 QVERIFY(m_mainWindow->isVisible());
854
855 // Create config file
856 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
857 KConfig *config = KConfigGui::sessionConfig();
858 m_mainWindow->saveGlobalProperties(config);
859 m_mainWindow->savePropertiesInternal(config, 1);
860 config->sync();
861
862 // Setup watcher for config file changes
863 const QString configFileName = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/" + KConfigGui::sessionConfig()->name();
864 QFileSystemWatcher *configWatcher = new QFileSystemWatcher({configFileName}, this);
865 QSignalSpy spySessionSaved(configWatcher, &QFileSystemWatcher::fileChanged);
866
867 // Enable session autosave.
868 m_mainWindow->setSessionAutoSaveEnabled(true);
869 m_mainWindow->m_sessionSaveTimer->setInterval(200); // Lower the interval to speed up the testing
870
871 // Open a new tab
872 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget");
873 QVERIFY(tabWidget);
874 tabWidget->openNewActivatedTab(QUrl::fromLocalFile(QDir::tempPath()));
875 QCOMPARE(tabWidget->count(), 2);
876
877 // Wait till a session save occurs
878 QVERIFY(spySessionSaved.wait(60000));
879
880 // Disable session autosave.
881 m_mainWindow->setSessionAutoSaveEnabled(false);
882 }
883
884 void DolphinMainWindowTest::cleanupTestCase()
885 {
886 m_mainWindow->showNormal();
887 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->setChecked(false); // disable split view (starts animation)
888
889 #if HAVE_BALOO
890 m_mainWindow->actionCollection()->action(QStringLiteral("show_information_panel"))->setChecked(false); // hide panel
891 #endif
892
893 #if HAVE_TERMINAL
894 m_mainWindow->actionCollection()->action(QStringLiteral("show_terminal_panel"))->setChecked(false); // hide panel
895 #endif
896
897 // Quit Dolphin to save the hiding of panels and make sure that normal Quit doesn't crash.
898 m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Quit))->trigger();
899 }
900
901 QTEST_MAIN(DolphinMainWindowTest)
902
903 #include "dolphinmainwindowtest.moc"