Commit 43817a13 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

bookmarksrunner: Clean up chrome bookmarks test

The test should make sure the chrome bookmarks and profile reading
works properly and not test the conversion logic.

In the previous commit a dedicated test has been added
for the conversion and relevance logic.
parent 39d1d7af
......@@ -22,7 +22,6 @@
#include "browsers/chrome.h"
#include "browsers/chromefindprofile.h"
#include "favicon.h"
#include <QDir>
#include <QTest>
using namespace Plasma;
......@@ -48,7 +47,6 @@ void TestChromeBookmarks::bookmarkFinderShouldFindEachProfileDirectory()
void TestChromeBookmarks::bookmarkFinderShouldReportNoProfilesOnErrors()
{
FindChromeProfile findChrome("chromium", "./no-config-directory");
QList<Profile> profiles = findChrome.find();
QCOMPARE(profiles.size(), 0);
}
......@@ -67,13 +65,10 @@ void TestChromeBookmarks::itShouldGracefullyExitWhenFileIsNotFound()
QCOMPARE(chrome->match("any", true).size(), 0);
}
void verifyMatch(BookmarkMatch &match, const QString &title, const QString &url, qreal relevance, QueryMatch::Type type)
void verifyMatch(BookmarkMatch &match, const QString &title, const QString &url)
{
QueryMatch queryMatch = match.asQueryMatch(nullptr);
QCOMPARE(queryMatch.text(), title);
QCOMPARE(queryMatch.data().toString(), url);
QCOMPARE(queryMatch.relevance(), relevance);
QVERIFY2(queryMatch.type() == type, QStringLiteral("Wrong query match type: expecting %1 but was %2").arg(type, queryMatch.type()).toLatin1());
QCOMPARE(match.bookmarkTitle(), title);
QCOMPARE(match.bookmarkUrl(), url);
}
void TestChromeBookmarks::itShouldFindAllBookmarks()
......@@ -82,9 +77,9 @@ void TestChromeBookmarks::itShouldFindAllBookmarks()
chrome->prepare();
QList<BookmarkMatch> matches = chrome->match("any", true);
QCOMPARE(matches.size(), 3);
verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/", 0.18, QueryMatch::PossibleMatch);
verifyMatch(matches[1], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.18, QueryMatch::PossibleMatch);
verifyMatch(matches[2], "bookmark in somefolder", "https://somefolder.com/", 0.18, QueryMatch::PossibleMatch);
verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/");
verifyMatch(matches[1], "bookmark in other bookmarks", "https://otherbookmarks.com/");
verifyMatch(matches[2], "bookmark in somefolder", "https://somefolder.com/");
}
void TestChromeBookmarks::itShouldFindOnlyMatches()
......@@ -93,7 +88,7 @@ void TestChromeBookmarks::itShouldFindOnlyMatches()
chrome->prepare();
QList<BookmarkMatch> matches = chrome->match("other", false);
QCOMPARE(matches.size(), 1);
verifyMatch(matches[0], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.45, QueryMatch::PossibleMatch);
verifyMatch(matches[0], "bookmark in other bookmarks", "https://otherbookmarks.com/");
}
void TestChromeBookmarks::itShouldClearResultAfterCallingTeardown()
......@@ -108,16 +103,16 @@ void TestChromeBookmarks::itShouldClearResultAfterCallingTeardown()
void TestChromeBookmarks::itShouldFindBookmarksFromAllProfiles()
{
FakeFindProfile findBookmarksFromAllProfiles(
QList<Profile>() << Profile(m_configHome + "/Chrome-Bookmarks-Sample.json", "Sample", new FallbackFavicon(this))
<< Profile(m_configHome + "/Chrome-Bookmarks-SecondProfile.json", "SecondProfile", new FallbackFavicon(this)));
QList<Profile>{Profile(m_configHome + "/Chrome-Bookmarks-Sample.json", "Sample", new FallbackFavicon(this)),
Profile(m_configHome + "/Chrome-Bookmarks-SecondProfile.json", "SecondProfile", new FallbackFavicon(this))});
Chrome *chrome = new Chrome(&findBookmarksFromAllProfiles, this);
chrome->prepare();
QList<BookmarkMatch> matches = chrome->match("any", true);
QCOMPARE(matches.size(), 4);
verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/", 0.18, QueryMatch::PossibleMatch);
verifyMatch(matches[1], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.18, QueryMatch::PossibleMatch);
verifyMatch(matches[2], "bookmark in somefolder", "https://somefolder.com/", 0.18, QueryMatch::PossibleMatch);
verifyMatch(matches[3], "bookmark in secondProfile", "https://secondprofile.com/", 0.18, QueryMatch::PossibleMatch);
verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/");
verifyMatch(matches[1], "bookmark in other bookmarks", "https://otherbookmarks.com/");
verifyMatch(matches[2], "bookmark in somefolder", "https://somefolder.com/");
verifyMatch(matches[3], "bookmark in secondProfile", "https://secondprofile.com/");
}
QTEST_MAIN(TestChromeBookmarks);
......@@ -37,6 +37,11 @@ public:
void addTo(QList<BookmarkMatch> &listOfResults, bool addEvenOnNoMatch);
Plasma::QueryMatch asQueryMatch(Plasma::AbstractRunner *runner);
Q_REQUIRED_RESULT QString bookmarkTitle() const
{
return m_bookmarkTitle;
}
Q_REQUIRED_RESULT QString bookmarkUrl() const
{
return m_bookmarkURL;
......
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