]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/dolphinmainwindowtest.cpp
Fix failing testWindowTitle() on the KDE CI
[dolphin.git] / src / tests / dolphinmainwindowtest.cpp
index 3fdabe7b885c2358eec3132ca48ce4c8a7d5be6a..e57c79b02c6c98b0a291b6020a1126f4e1164149 100644 (file)
@@ -40,9 +40,13 @@ private slots:
     void testActiveViewAfterClosingSplitView_data();
     void testActiveViewAfterClosingSplitView();
     void testUpdateWindowTitleAfterClosingSplitView();
+    void testUpdateWindowTitleAfterChangingSplitView();
     void testOpenInNewTabTitle();
     void testNewFileMenuEnabled_data();
     void testNewFileMenuEnabled();
+    void testWindowTitle_data();
+    void testWindowTitle();
+
 
 
 private:
@@ -175,6 +179,36 @@ void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView()
     QCOMPARE(currentUrlChangedSpy.count(), 1);
 }
 
+// Test case for bug #402641
+void DolphinMainWindowTest::testUpdateWindowTitleAfterChangingSplitView()
+{
+    m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false);
+    m_mainWindow->show();
+    QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+    QVERIFY(m_mainWindow->isVisible());
+
+    auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget");
+    QVERIFY(tabWidget);
+
+    // Open split view.
+    m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger();
+    QVERIFY(tabWidget->currentTabPage()->splitViewEnabled());
+
+    auto leftViewContainer = tabWidget->currentTabPage()->primaryViewContainer();
+    auto rightViewContainer = tabWidget->currentTabPage()->secondaryViewContainer();
+
+    // Store old window title.
+    const auto oldTitle = m_mainWindow->windowTitle();
+
+    // Change URL in the right view and make sure the title gets updated.
+    rightViewContainer->setUrl(QUrl::fromLocalFile(QDir::rootPath()));
+    QVERIFY(m_mainWindow->windowTitle() != oldTitle);
+
+    // Activate back the left view and check whether the old title gets restored.
+    leftViewContainer->setActive(true);
+    QCOMPARE(m_mainWindow->windowTitle(), oldTitle);
+}
+
 // Test case for bug #397910
 void DolphinMainWindowTest::testOpenInNewTabTitle()
 {
@@ -188,9 +222,10 @@ void DolphinMainWindowTest::testOpenInNewTabTitle()
 
     tabWidget->openNewTab(QUrl::fromLocalFile(QDir::tempPath()));
     QCOMPARE(tabWidget->count(), 2);
-    qDebug() << "First tab:" << tabWidget->tabIcon(0).name() << "second tab:" << tabWidget->tabIcon(1).name();
-    QVERIFY(tabWidget->tabIcon(0).name() != tabWidget->tabIcon(1).name());
     QVERIFY(tabWidget->tabText(0) != tabWidget->tabText(1));
+    if (!tabWidget->tabIcon(0).isNull() && !tabWidget->tabIcon(1).isNull()) {
+        QVERIFY(tabWidget->tabIcon(0).name() != tabWidget->tabIcon(1).name());
+    }
 }
 
 void DolphinMainWindowTest::testNewFileMenuEnabled_data()
@@ -211,11 +246,34 @@ void DolphinMainWindowTest::testNewFileMenuEnabled()
     QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
     QVERIFY(m_mainWindow->isVisible());
 
-    auto newFileMenu = m_mainWindow->findChild<DolphinNewFileMenu*>("newFileMenu");
+    auto newFileMenu = m_mainWindow->findChild<DolphinNewFileMenu*>("new_menu");
     QVERIFY(newFileMenu);
 
     QFETCH(bool, expectedEnabled);
-    QCOMPARE(newFileMenu->isEnabled(), expectedEnabled);
+    QTRY_COMPARE(newFileMenu->isEnabled(), expectedEnabled);
+}
+
+void DolphinMainWindowTest::testWindowTitle_data()
+{
+    QTest::addColumn<QUrl>("activeViewUrl");
+    QTest::addColumn<QString>("expectedWindowTitle");
+
+    // TODO: this test should enforce the english locale.
+    QTest::newRow("home") << QUrl::fromLocalFile(QDir::homePath()) << QStringLiteral("Home");
+    QTest::newRow("home with trailing slash") << QUrl::fromLocalFile(QStringLiteral("%1/").arg(QDir::homePath())) << QStringLiteral("Home");
+    QTest::newRow("trash") << QUrl::fromUserInput(QStringLiteral("trash:/")) << QStringLiteral("Trash");
+}
+
+void DolphinMainWindowTest::testWindowTitle()
+{
+    QFETCH(QUrl, activeViewUrl);
+    m_mainWindow->openDirectories({ activeViewUrl }, false);
+    m_mainWindow->show();
+    QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+    QVERIFY(m_mainWindow->isVisible());
+
+    QFETCH(QString, expectedWindowTitle);
+    QCOMPARE(m_mainWindow->windowTitle(), expectedWindowTitle);
 }
 
 QTEST_MAIN(DolphinMainWindowTest)