Commit f4cee9b6 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

bookmarksrunner: Add tests for firefox bookmarks

parent bbfab7a0
......@@ -49,6 +49,7 @@ set(krunner_bookmarks_test_SRCS
${krunner_bookmarks_common_SRCS}
browsers/chromefindprofile.cpp
browsers/chrome.cpp
browsers/firefox.cpp
)
add_library(krunner_bookmarks_test STATIC ${krunner_bookmarks_test_SRCS})
......
......@@ -5,3 +5,7 @@ ecm_add_test(chrome/testchromebookmarks.cpp TEST_NAME testChromeBookmarks
LINK_LIBRARIES Qt::Test krunner_bookmarks_test
)
file(COPY chrome/chrome-config-home DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/chrome/)
ecm_add_test(firefox/testfirefoxbookmarks.cpp TEST_NAME testFirefoxBookmarks
LINK_LIBRARIES Qt::Test krunner_bookmarks_test
)
\ No newline at end of file
[Install4F96D1932A9F858E]
Default=atnsd8ae.testmekde
Locked=1
[Profile1]
Name=testmekde
IsRelative=1
Path=atnsd8ae.testmekde
[General]
StartWithLastProfile=1
Version=2
#include <QObject>
#include <QStandardPaths>
#include <QTest>
#include "browsers/firefox.h"
class TestFirefoxBookmarks : public QObject
{
Q_OBJECT
public:
explicit TestFirefoxBookmarks(QObject *parent = nullptr)
: QObject(parent)
{
}
private:
Firefox *m_firefox;
private Q_SLOTS:
void initTestCase();
void testAllBookmarks();
void testBookmarksQuery();
void testBookmarksQuery_data();
};
void TestFirefoxBookmarks::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
m_firefox = new Firefox(this, QFINDTESTDATA("firefox-config-home"));
}
void TestFirefoxBookmarks::testAllBookmarks()
{
m_firefox->prepare();
const QList<BookmarkMatch> matches = m_firefox->match(QStringLiteral("kde"), true);
QCOMPARE(matches.count(), 8);
m_firefox->teardown();
}
void TestFirefoxBookmarks::testBookmarksQuery_data()
{
QTest::addColumn<QString>("query");
QTest::addColumn<QStringList>("expectedUrls");
QTest::newRow("query that matches nothing") << "this does not exist" << QStringList{};
QTest::newRow("query that matches url") << "reddit.com" << QStringList{"https://www.reddit.com/"};
QTest::newRow("query that matches title") << "KDE Community" << QStringList{"https://kde.org/"};
QTest::newRow("query that matches title case insensitively") << "kde community" << QStringList{"https://kde.org/"};
QTest::newRow("query that matches multiple titles") << "ubuntu" << QStringList{"http://www.ubuntu.com/", "http://wiki.ubuntu.com/"};
}
void TestFirefoxBookmarks::testBookmarksQuery()
{
QFETCH(QString, query);
QFETCH(QStringList, expectedUrls);
m_firefox->prepare();
const QList<BookmarkMatch> matches = m_firefox->match(query, false);
QCOMPARE(matches.count(), expectedUrls.count());
for (const auto &match : matches) {
QVERIFY(expectedUrls.contains(match.bookmarkUrl()));
}
m_firefox->teardown();
}
QTEST_MAIN(TestFirefoxBookmarks)
#include "testfirefoxbookmarks.moc"
......@@ -37,6 +37,11 @@ public:
void addTo(QList<BookmarkMatch> &listOfResults, bool addEvenOnNoMatch);
Plasma::QueryMatch asQueryMatch(Plasma::AbstractRunner *runner);
Q_REQUIRED_RESULT QString bookmarkUrl() const
{
return m_bookmarkURL;
}
private:
bool matches(const QString &search, const QString &matchingField);
......
......@@ -159,7 +159,7 @@ void Firefox::init(const QString &firefoxConfigDir)
m_dbFile = grp.readEntry("dbfile", QString());
if (m_dbFile.isEmpty() || !QFile::exists(m_dbFile)) {
// Try to get the right database file, the default profile is used
KConfig firefoxProfile(firefoxConfigDir + "profiles.ini", KConfig::SimpleConfig);
KConfig firefoxProfile(firefoxConfigDir + "/profiles.ini", KConfig::SimpleConfig);
QStringList profilesList = firefoxProfile.groupList();
profilesList = profilesList.filter(QRegularExpression(QStringLiteral("^Profile\\d+$")));
......@@ -190,7 +190,7 @@ void Firefox::init(const QString &firefoxConfigDir)
qCWarning(RUNNER_BOOKMARKS) << "No default firefox profile found";
return;
}
profilePath.prepend(firefoxConfigDir);
profilePath.prepend(firefoxConfigDir + "/");
m_dbFile = profilePath + "/places.sqlite";
m_dbFile_fav = profilePath + "/favicons.sqlite";
} else {
......
......@@ -31,7 +31,7 @@ class Firefox : public QObject, public Browser
{
Q_OBJECT
public:
explicit Firefox(QObject *parent = nullptr, const QString &firefoxConfigDir = QDir::homePath() + QStringLiteral("/.mozilla/firefox/"));
explicit Firefox(QObject *parent = nullptr, const QString &firefoxConfigDir = QDir::homePath() + QStringLiteral("/.mozilla/firefox"));
~Firefox() override;
QList<BookmarkMatch> match(const QString &term, bool addEverything) override;
public Q_SLOTS:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment