Falkon Develop
Cross-platform Qt-based web browser
qmlhistoryapitest.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "qmlhistoryapitest.h"
19#include "autotests.h"
20#include "mainapplication.h"
21#include "history.h"
24
26
27void QmlHistoryApiTest::initTestCase()
28{
29}
30
31void QmlHistoryApiTest::cleanupTestCase()
32{
33}
34
35void QmlHistoryApiTest::testAddition()
36{
37 qRegisterMetaType<HistoryEntry>();
38 QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded);
39 m_testHelper.evaluate(QL1S("Falkon.History.addUrl({"
40 " url: 'https://example.com',"
41 " title: 'Example Domain'"
42 "})"));
43 QTRY_COMPARE(historySpy.count(), 1);
44 HistoryEntry entry = qvariant_cast<HistoryEntry>(historySpy.at(0).at(0));
45 QCOMPARE(entry.title, QSL("Example Domain"));
46
47 auto object = m_testHelper.evaluateQObject(QSL("Falkon.History"));
48 QSignalSpy qmlHistorySpy(object, SIGNAL(visited(QmlHistoryItem*)));
49 mApp->history()->addHistoryEntry(QUrl(QSL("https://sample.com")), QSL("Sample Domain"));
50 QTRY_COMPARE(qmlHistorySpy.count(), 1);
51 mApp->history()->clearHistory();
52}
53
54void QmlHistoryApiTest::testSearch()
55{
56 QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded);
57 mApp->history()->addHistoryEntry(QUrl(QSL("https://example.com")), QSL("Example Domain"));
58 mApp->history()->addHistoryEntry(QUrl(QSL("https://another-example.com")), QSL("Another Example Domain"));
59 mApp->history()->addHistoryEntry(QUrl(QSL("https://sample.com")), QSL("Sample Domain"));
60 QTRY_COMPARE(historySpy.count(), 3);
61 auto list = m_testHelper.evaluate(QSL("Falkon.History.search('example')")).toVariant().toList();
62 QCOMPARE(list.length(), 2);
63}
64
65void QmlHistoryApiTest::testVisits()
66{
67 int visits = m_testHelper.evaluate(QSL("Falkon.History.getVisits('https://sample.com')")).toInt();
68 QCOMPARE(visits, 1);
69 QSignalSpy historySpy(mApp->history(), &History::historyEntryEdited);
70 mApp->history()->addHistoryEntry(QUrl(QSL("https://sample.com")), QSL("Sample Domain"));
71 QTRY_COMPARE(historySpy.count(), 1);
72 visits = m_testHelper.evaluate(QSL("Falkon.History.getVisits('https://sample.com')")).toInt();
73 QCOMPARE(visits, 2);
74}
75
76void QmlHistoryApiTest::testRemoval()
77{
78 QSignalSpy historySpy(mApp->history(), &History::historyEntryDeleted);
79 m_testHelper.evaluate(QSL("Falkon.History.deleteUrl('https://sample.com')"));
80 QTRY_COMPARE(historySpy.count(), 1);
81
82 auto object = m_testHelper.evaluateQObject(QSL("Falkon.History"));
83 QSignalSpy qmlHistorySpy(object, SIGNAL(visitRemoved(QmlHistoryItem*)));
84 mApp->history()->deleteHistoryEntry(QSL("https://example.com"), QSL("Example Domain"));
85 QTRY_COMPARE(qmlHistorySpy.count(), 1);
86}
87
#define FALKONTEST_MAIN(Test)
Definition: autotests.h:23
void historyEntryDeleted(const HistoryEntry &entry)
void historyEntryEdited(const HistoryEntry &before, const HistoryEntry &after)
void historyEntryAdded(const HistoryEntry &entry)
The class exposing HistoryEntry to QML.
QObject * evaluateQObject(const QString &source)
QJSValue evaluate(const QString &source)
Q_DECLARE_METATYPE(FlashCookie)
#define mApp
#define QL1S(x)
Definition: qzcommon.h:44
#define QSL(x)
Definition: qzcommon.h:40
Definition: history.h:39
QString title
Definition: history.h:45