Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/tests/testchromebookmarks.cpp
Show All 23 Lines | |||||
24 | #include "browsers/chrome.h" | 24 | #include "browsers/chrome.h" | ||
25 | #include "browsers/chromefindprofile.h" | 25 | #include "browsers/chromefindprofile.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", new FallbackFavicon())}))); | 32 | m_findBookmarksInCurrentDirectory.reset(new FakeFindProfile(QList<Profile>({Profile("chrome-config-home/Chrome-Bookmarks-Sample.json", "Sample", new FallbackFavicon())}))); | ||
33 | } | 33 | } | ||
34 | 34 | | |||
35 | void TestChromeBookmarks::bookmarkFinderShouldFindEachProfileDirectory() | 35 | void TestChromeBookmarks::bookmarkFinderShouldFindEachProfileDirectory() | ||
36 | { | 36 | { | ||
37 | FindChromeProfile findChrome("chromium", "./chrome-config-home"); | 37 | FindChromeProfile findChrome("chromium", "./chrome-config-home"); | ||
38 | QString profileTemplate = QString("./chrome-config-home/.config/%1/%2/Bookmarks"); | 38 | QString profileTemplate = QString("./chrome-config-home/.config/%1/%2/Bookmarks"); | ||
39 | 39 | | |||
40 | QList<Profile> profiles = findChrome.find(); | 40 | QList<Profile> profiles = findChrome.find(); | ||
Show All 14 Lines | |||||
55 | void TestChromeBookmarks::itShouldFindNothingWhenPrepareIsNotCalled() | 55 | void TestChromeBookmarks::itShouldFindNothingWhenPrepareIsNotCalled() | ||
56 | { | 56 | { | ||
57 | Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); | 57 | Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); | ||
58 | QCOMPARE(chrome->match("any", true).size(), 0); | 58 | QCOMPARE(chrome->match("any", true).size(), 0); | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | void TestChromeBookmarks::itShouldGracefullyExitWhenFileIsNotFound() | 61 | void TestChromeBookmarks::itShouldGracefullyExitWhenFileIsNotFound() | ||
62 | { | 62 | { | ||
63 | FakeFindProfile finder(QList<Profile>() << Profile("FileNotExisting.json", nullptr)); | 63 | FakeFindProfile finder(QList<Profile>() << Profile("FileNotExisting.json", QString(), nullptr)); | ||
64 | Chrome *chrome = new Chrome(&finder, this); | 64 | Chrome *chrome = new Chrome(&finder, this); | ||
65 | chrome->prepare(); | 65 | chrome->prepare(); | ||
66 | QCOMPARE(chrome->match("any", true).size(), 0); | 66 | QCOMPARE(chrome->match("any", true).size(), 0); | ||
67 | } | 67 | } | ||
68 | 68 | | |||
69 | 69 | | |||
70 | void verifyMatch(BookmarkMatch &match, const QString &title, const QString &url, qreal relevance, QueryMatch::Type type) { | 70 | void verifyMatch(BookmarkMatch &match, const QString &title, const QString &url, qreal relevance, QueryMatch::Type type) { | ||
71 | QueryMatch queryMatch = match.asQueryMatch(nullptr); | 71 | QueryMatch queryMatch = match.asQueryMatch(nullptr); | ||
Show All 32 Lines | 100 | { | |||
104 | chrome->teardown(); | 104 | chrome->teardown(); | ||
105 | QCOMPARE(chrome->match("any", true).size(), 0); | 105 | QCOMPARE(chrome->match("any", true).size(), 0); | ||
106 | 106 | | |||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | void TestChromeBookmarks::itShouldFindBookmarksFromAllProfiles() | 109 | void TestChromeBookmarks::itShouldFindBookmarksFromAllProfiles() | ||
110 | { | 110 | { | ||
111 | FakeFindProfile findBookmarksFromAllProfiles(QList<Profile>() | 111 | FakeFindProfile findBookmarksFromAllProfiles(QList<Profile>() | ||
112 | << Profile("chrome-config-home/Chrome-Bookmarks-Sample.json", new FallbackFavicon(this)) | 112 | << Profile("chrome-config-home/Chrome-Bookmarks-Sample.json", "Sample", new FallbackFavicon(this)) | ||
113 | << Profile("chrome-config-home/Chrome-Bookmarks-SecondProfile.json", new FallbackFavicon(this)) ); | 113 | << Profile("chrome-config-home/Chrome-Bookmarks-SecondProfile.json", "SecondProfile", new FallbackFavicon(this)) ); | ||
114 | Chrome *chrome = new Chrome(&findBookmarksFromAllProfiles, this); | 114 | Chrome *chrome = new Chrome(&findBookmarksFromAllProfiles, this); | ||
115 | chrome->prepare(); | 115 | chrome->prepare(); | ||
116 | QList<BookmarkMatch> matches = chrome->match("any", true); | 116 | QList<BookmarkMatch> matches = chrome->match("any", true); | ||
117 | QCOMPARE(matches.size(), 4); | 117 | QCOMPARE(matches.size(), 4); | ||
118 | verifyMatch(matches[0], "some bookmark in bookmark bar", "https://somehost.com/", 0.18, QueryMatch::PossibleMatch); | 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); | 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); | 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); | 121 | verifyMatch(matches[3], "bookmark in secondProfile", "https://secondprofile.com/", 0.18, QueryMatch::PossibleMatch); | ||
122 | } | 122 | } | ||
123 | 123 | | |||
124 | 124 | | |||
125 | QTEST_MAIN(TestChromeBookmarks); | 125 | QTEST_MAIN(TestChromeBookmarks); |