]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphinmainwindowtest.cpp
Add failing test case for bug #385111
[dolphin.git] / src / tests / dolphinmainwindowtest.cpp
1 /***************************************************************************
2 * Copyright (C) 2017 by Elvis Angelaccio <elvis.angelaccio@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "dolphinmainwindow.h"
21 #include "dolphintabpage.h"
22 #include "dolphintabwidget.h"
23 #include "dolphinviewcontainer.h"
24
25 #include <KActionCollection>
26
27 #include <QSignalSpy>
28 #include <QTest>
29
30 class DolphinMainWindowTest : public QObject
31 {
32 Q_OBJECT
33
34 private slots:
35 void init();
36 void testClosingTabsWithSearchBoxVisible();
37 void testUpdateWindowTitleAfterClosingSplitView();
38
39 private:
40 QScopedPointer<DolphinMainWindow> m_mainWindow;
41 };
42
43 void DolphinMainWindowTest::init()
44 {
45 m_mainWindow.reset(new DolphinMainWindow());
46 }
47
48 // See https://bugs.kde.org/show_bug.cgi?id=379135
49 void DolphinMainWindowTest::testClosingTabsWithSearchBoxVisible()
50 {
51 m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false);
52 m_mainWindow->show();
53 // Without this call the searchbox doesn't get FocusIn events.
54 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
55 QVERIFY(m_mainWindow->isVisible());
56
57 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget");
58 QVERIFY(tabWidget);
59
60 // Show search box on first tab.
61 tabWidget->currentTabPage()->activeViewContainer()->setSearchModeEnabled(true);
62
63 tabWidget->openNewActivatedTab(QUrl::fromLocalFile(QDir::homePath()));
64 QCOMPARE(tabWidget->count(), 2);
65
66 // Triggers the crash in bug #379135.
67 tabWidget->closeTab();
68 QCOMPARE(tabWidget->count(), 1);
69 }
70
71 // Test case for bug #385111
72 void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView()
73 {
74 m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false);
75 m_mainWindow->show();
76 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
77 QVERIFY(m_mainWindow->isVisible());
78
79 auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget");
80 QVERIFY(tabWidget);
81 QVERIFY(tabWidget->currentTabPage()->primaryViewContainer());
82 QVERIFY(!tabWidget->currentTabPage()->secondaryViewContainer());
83
84 // Open split view.
85 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
86 QVERIFY(tabWidget->currentTabPage()->splitViewEnabled());
87 QVERIFY(tabWidget->currentTabPage()->secondaryViewContainer());
88
89 // Make sure the right view is the active one.
90 auto leftViewContainer = tabWidget->currentTabPage()->primaryViewContainer();
91 auto rightViewContainer = tabWidget->currentTabPage()->secondaryViewContainer();
92 QVERIFY(!leftViewContainer->isActive());
93 QVERIFY(rightViewContainer->isActive());
94
95 // Activate left view.
96 leftViewContainer->setActive(true);
97 QVERIFY(leftViewContainer->isActive());
98 QVERIFY(!rightViewContainer->isActive());
99
100 // Close split view. The secondary view (which was on the right) will become the primary one and must be active.
101 m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
102 QVERIFY(rightViewContainer->isActive());
103 QCOMPARE(rightViewContainer, tabWidget->currentTabPage()->activeViewContainer());
104
105 // Change URL and make sure we emit the currentUrlChanged signal (which triggers the window title update).
106 QSignalSpy currentUrlChangedSpy(tabWidget, &DolphinTabWidget::currentUrlChanged);
107 tabWidget->currentTabPage()->activeViewContainer()->setUrl(QUrl::fromLocalFile(QDir::rootPath()));
108 QCOMPARE(currentUrlChangedSpy.count(), 1);
109 }
110
111 QTEST_MAIN(DolphinMainWindowTest)
112
113 #include "dolphinmainwindowtest.moc"