Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/tests/testchromebookmarks.cpp
Show All 16 Lines | |||||
17 | * Free Software Foundation, Inc., | 17 | * Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "testchromebookmarks.h" | 21 | #include "testchromebookmarks.h" | ||
22 | #include <QTest> | 22 | #include <QTest> | ||
23 | #include <QDir> | 23 | #include <QDir> | ||
24 | #include "browsers/chrome.h" | 24 | #include "browsers/chrome.h" | ||
25 | #include "browsers/chromefindprofile.h" | 25 | #include "browsers/chromeprofile.h" | ||
26 | #include "favicon.h" | 26 | #include "favicon.h" | ||
27 | 27 | | |||
28 | using namespace Plasma; | 28 | using namespace Plasma; | ||
29 | 29 | | |||
30 | void TestChromeBookmarks::initTestCase() | 30 | void TestChromeBookmarks::initTestCase() | ||
31 | { | 31 | { | ||
32 | m_findBookmarksInCurrentDirectory.reset(new FakeFindProfile(QList<Profile>({Profile("chrome-config-home/Chrome-Bookmarks-Sample.json", "Sample", new FallbackFavicon())}))); | 32 | QStandardPaths::setTestModeEnabled(true); | ||
33 | } | 33 | } | ||
34 | 34 | | |||
35 | void TestChromeBookmarks::bookmarkFinderShouldFindEachProfileDirectory() | 35 | void TestChromeBookmarks::bookmarkFinderShouldFindEachProfileDirectory() | ||
36 | { | 36 | { | ||
37 | FindChromeProfile findChrome("chromium", "./chrome-config-home"); | 37 | QString profileTemplate = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QString("/%2/%3/Bookmarks"); | ||
38 | QString profileTemplate = QString("./chrome-config-home/.config/%1/%2/Bookmarks"); | 38 | QList<ProfileBookmarks*> profiles = ProfileBookmarks::findAllProfiles("chromium"); | ||
39 | | ||||
40 | QList<Profile> profiles = findChrome.find(); | | |||
41 | QCOMPARE(profiles.size(), 2); | 39 | QCOMPARE(profiles.size(), 2); | ||
42 | QCOMPARE(profiles[0].path(), profileTemplate.arg("chromium").arg("Default")); | 40 | QCOMPARE(profiles[0]->path(), profileTemplate.arg("chromium", "Default")); | ||
43 | QCOMPARE(profiles[1].path(), profileTemplate.arg("chromium").arg("Profile 1")); | 41 | QCOMPARE(profiles[1]->path(), profileTemplate.arg("chromium", "Profile 1")); | ||
44 | } | | |||
45 | | ||||
46 | void TestChromeBookmarks::bookmarkFinderShouldReportNoProfilesOnErrors() | | |||
47 | { | | |||
48 | FindChromeProfile findChrome("chromium", "./no-config-directory"); | | |||
49 | | ||||
50 | QList<Profile> profiles = findChrome.find(); | | |||
51 | QCOMPARE(profiles.size(), 0); | | |||
52 | } | 42 | } | ||
53 | 43 | | |||
54 | | ||||
55 | void TestChromeBookmarks::itShouldFindNothingWhenPrepareIsNotCalled() | 44 | void TestChromeBookmarks::itShouldFindNothingWhenPrepareIsNotCalled() | ||
56 | { | 45 | { | ||
57 | Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); | 46 | Chrome chrome("chromium"); | ||
58 | QCOMPARE(chrome->match("any", true).size(), 0); | 47 | QCOMPARE(chrome.match("any", true).size(), 0); | ||
59 | } | 48 | } | ||
60 | 49 | | |||
61 | void TestChromeBookmarks::itShouldGracefullyExitWhenFileIsNotFound() | | |||
62 | { | | |||
63 | FakeFindProfile finder(QList<Profile>() << Profile("FileNotExisting.json", QString(), nullptr)); | | |||
64 | Chrome *chrome = new Chrome(&finder, this); | | |||
65 | chrome->prepare(); | | |||
66 | QCOMPARE(chrome->match("any", true).size(), 0); | | |||
67 | } | | |||
68 | | ||||
69 | | ||||
70 | void verifyMatch(BookmarkMatch &match, const QString &title, const QString &url, qreal relevance, QueryMatch::Type type) { | 50 | void verifyMatch(BookmarkMatch &match, const QString &title, const QString &url, qreal relevance, QueryMatch::Type type) { | ||
71 | QueryMatch queryMatch = match.asQueryMatch(nullptr); | 51 | QueryMatch queryMatch = match.asQueryMatch(nullptr); | ||
72 | QCOMPARE(queryMatch.text(), title); | 52 | QCOMPARE(queryMatch.text(), title); | ||
73 | QCOMPARE(queryMatch.data().toString(), url); | 53 | QCOMPARE(queryMatch.data().toString(), url); | ||
74 | QCOMPARE(queryMatch.relevance(), relevance); | 54 | QCOMPARE(queryMatch.relevance(), relevance); | ||
75 | QVERIFY2(queryMatch.type() == type, | 55 | QVERIFY2(queryMatch.type() == type, | ||
76 | QStringLiteral("Wrong query match type: expecting %1 but was %2").arg(type, queryMatch.type() ).toLatin1()); | 56 | QStringLiteral("Wrong query match type: expecting %1 but was %2").arg(type, queryMatch.type() ).toLatin1()); | ||
77 | } | 57 | } | ||
78 | 58 | | |||
79 | void TestChromeBookmarks::itShouldFindAllBookmarks() | 59 | void TestChromeBookmarks::itShouldFindAllBookmarks() | ||
80 | { | 60 | { | ||
81 | Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); | 61 | Chrome chrome("chromium"); | ||
82 | chrome->prepare(); | 62 | chrome.prepare(); | ||
83 | QList<BookmarkMatch> matches = chrome->match("any", true); | 63 | QList<BookmarkMatch> matches = chrome.match("any", true); | ||
84 | QCOMPARE(matches.size(), 3); | 64 | // The results from both profiles are displayed | ||
65 | QCOMPARE(matches.size(), 4); | ||||
85 | verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/", 0.18, QueryMatch::PossibleMatch); | 66 | verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/", 0.18, QueryMatch::PossibleMatch); | ||
86 | verifyMatch(matches[1], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.18, QueryMatch::PossibleMatch); | 67 | verifyMatch(matches[1], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.18, QueryMatch::PossibleMatch); | ||
87 | verifyMatch(matches[2], "bookmark in somefolder", "https://somefolder.com/", 0.18, QueryMatch::PossibleMatch); | 68 | verifyMatch(matches[2], "bookmark in somefolder", "https://somefolder.com/", 0.18, QueryMatch::PossibleMatch); | ||
69 | verifyMatch(matches[3], "bookmark in secondProfile", "https://secondprofile.com/", 0.18, QueryMatch::PossibleMatch); | ||||
88 | } | 70 | } | ||
89 | 71 | | |||
90 | void TestChromeBookmarks::itShouldFindOnlyMatches() | 72 | void TestChromeBookmarks::itShouldFindOnlyMatches() | ||
91 | { | 73 | { | ||
92 | Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); | 74 | Chrome chrome("chromium"); | ||
93 | chrome->prepare(); | 75 | chrome.prepare(); | ||
94 | QList<BookmarkMatch> matches = chrome->match("other", false); | 76 | QList<BookmarkMatch> matches = chrome.match("other", false); | ||
95 | QCOMPARE(matches.size(), 1); | 77 | QCOMPARE(matches.size(), 1); | ||
96 | verifyMatch(matches[0], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.45, QueryMatch::PossibleMatch); | 78 | verifyMatch(matches[0], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.45, QueryMatch::PossibleMatch); | ||
97 | } | 79 | } | ||
98 | 80 | | |||
99 | void TestChromeBookmarks::itShouldClearResultAfterCallingTeardown() | 81 | void TestChromeBookmarks::itShouldClearResultAfterCallingTeardown() | ||
100 | { | 82 | { | ||
101 | Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); | 83 | Chrome chrome("chromium"); | ||
102 | chrome->prepare(); | 84 | chrome.prepare(); | ||
103 | QCOMPARE(chrome->match("any", true).size(), 3); | 85 | QCOMPARE(chrome.match("any", true).size(), 4); | ||
104 | chrome->teardown(); | 86 | chrome.teardown(); | ||
105 | QCOMPARE(chrome->match("any", true).size(), 0); | 87 | QCOMPARE(chrome.match("any", true).size(), 0); | ||
106 | 88 | | |||
107 | } | 89 | } | ||
108 | 90 | | |||
109 | void TestChromeBookmarks::itShouldFindBookmarksFromAllProfiles() | 91 | void TestChromeBookmarks::itShouldDisplayFallbackIcon() | ||
110 | { | 92 | { | ||
111 | FakeFindProfile findBookmarksFromAllProfiles(QList<Profile>() | 93 | Chrome chrome("chromium"); | ||
112 | << Profile("chrome-config-home/Chrome-Bookmarks-Sample.json", "Sample", new FallbackFavicon(this)) | 94 | chrome.prepare(); | ||
113 | << Profile("chrome-config-home/Chrome-Bookmarks-SecondProfile.json", "SecondProfile", new FallbackFavicon(this)) ); | 95 | QList<BookmarkMatch> matches = chrome.match("any", true); | ||
114 | Chrome *chrome = new Chrome(&findBookmarksFromAllProfiles, this); | 96 | for (auto &match : matches) { | ||
115 | chrome->prepare(); | 97 | QCOMPARE(match.asQueryMatch(nullptr).icon().name(), "bookmarks"); | ||
116 | QList<BookmarkMatch> matches = chrome->match("any", true); | 98 | } | ||
117 | QCOMPARE(matches.size(), 4); | | |||
118 | verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/", 0.18, QueryMatch::PossibleMatch); | | |||
119 | verifyMatch(matches[1], "bookmark in other bookmarks", "https://otherbookmarks.com/", 0.18, QueryMatch::PossibleMatch); | | |||
120 | verifyMatch(matches[2], "bookmark in somefolder", "https://somefolder.com/", 0.18, QueryMatch::PossibleMatch); | | |||
121 | verifyMatch(matches[3], "bookmark in secondProfile", "https://secondprofile.com/", 0.18, QueryMatch::PossibleMatch); | | |||
122 | } | 99 | } | ||
123 | | ||||
124 | 100 | | |||
125 | QTEST_MAIN(TestChromeBookmarks); | 101 | QTEST_MAIN(TestChromeBookmarks); |