Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Workspace
Commits
f4cee9b6
Commit
f4cee9b6
authored
Mar 16, 2021
by
Alexander Lohnau
💬
Browse files
bookmarksrunner: Add tests for firefox bookmarks
parent
bbfab7a0
Changes
9
Hide whitespace changes
Inline
Side-by-side
runners/bookmarks/CMakeLists.txt
View file @
f4cee9b6
...
...
@@ -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
}
)
...
...
runners/bookmarks/autotests/CMakeLists.txt
View file @
f4cee9b6
...
...
@@ -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
runners/bookmarks/autotests/firefox/firefox-config-home/atnsd8ae.testmekde/favicons.sqlite
0 → 100644
View file @
f4cee9b6
File added
runners/bookmarks/autotests/firefox/firefox-config-home/atnsd8ae.testmekde/places.sqlite
0 → 100644
View file @
f4cee9b6
File added
runners/bookmarks/autotests/firefox/firefox-config-home/profiles.ini
0 → 100644
View file @
f4cee9b6
[Install4F96D1932A9F858E]
Default
=
atnsd8ae.testmekde
Locked
=
1
[Profile1]
Name
=
testmekde
IsRelative
=
1
Path
=
atnsd8ae.testmekde
[General]
StartWithLastProfile
=
1
Version
=
2
runners/bookmarks/autotests/firefox/testfirefoxbookmarks.cpp
0 → 100644
View file @
f4cee9b6
#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"
runners/bookmarks/bookmarkmatch.h
View file @
f4cee9b6
...
...
@@ -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
);
...
...
runners/bookmarks/browsers/firefox.cpp
View file @
f4cee9b6
...
...
@@ -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
{
...
...
runners/bookmarks/browsers/firefox.h
View file @
f4cee9b6
...
...
@@ -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
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment