]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphinmainwindowtest.cpp
1 /***************************************************************************
2 * Copyright (C) 2017 by Elvis Angelaccio <elvis.angelaccio@kde.org> *
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. *
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. *
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 ***************************************************************************/
20 #include "dolphinmainwindow.h"
21 #include "dolphintabpage.h"
22 #include "dolphintabwidget.h"
23 #include "dolphinviewcontainer.h"
25 #include <KActionCollection>
30 class DolphinMainWindowTest
: public QObject
36 void testClosingTabsWithSearchBoxVisible();
37 void testUpdateWindowTitleAfterClosingSplitView();
40 QScopedPointer
<DolphinMainWindow
> m_mainWindow
;
43 void DolphinMainWindowTest::init()
45 m_mainWindow
.reset(new DolphinMainWindow());
48 // See https://bugs.kde.org/show_bug.cgi?id=379135
49 void DolphinMainWindowTest::testClosingTabsWithSearchBoxVisible()
51 m_mainWindow
->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false);
53 // Without this call the searchbox doesn't get FocusIn events.
54 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
55 QVERIFY(m_mainWindow
->isVisible());
57 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
60 // Show search box on first tab.
61 tabWidget
->currentTabPage()->activeViewContainer()->setSearchModeEnabled(true);
63 tabWidget
->openNewActivatedTab(QUrl::fromLocalFile(QDir::homePath()));
64 QCOMPARE(tabWidget
->count(), 2);
66 // Triggers the crash in bug #379135.
67 tabWidget
->closeTab();
68 QCOMPARE(tabWidget
->count(), 1);
71 // Test case for bug #385111
72 void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView()
74 m_mainWindow
->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false);
76 QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow
.data()));
77 QVERIFY(m_mainWindow
->isVisible());
79 auto tabWidget
= m_mainWindow
->findChild
<DolphinTabWidget
*>("tabWidget");
81 QVERIFY(tabWidget
->currentTabPage()->primaryViewContainer());
82 QVERIFY(!tabWidget
->currentTabPage()->secondaryViewContainer());
85 m_mainWindow
->actionCollection()->action(QStringLiteral("split_view"))->trigger();
86 QVERIFY(tabWidget
->currentTabPage()->splitViewEnabled());
87 QVERIFY(tabWidget
->currentTabPage()->secondaryViewContainer());
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());
95 // Activate left view.
96 leftViewContainer
->setActive(true);
97 QVERIFY(leftViewContainer
->isActive());
98 QVERIFY(!rightViewContainer
->isActive());
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());
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);
111 QTEST_MAIN(DolphinMainWindowTest
)
113 #include "dolphinmainwindowtest.moc"