Changeset View
Changeset View
Standalone View
Standalone View
autotests/qml/qmlhistoryapitest.cpp
- This file was added.
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 "qmltesthelper.h" | ||||
21 | #include "mainapplication.h" | ||||
22 | #include "history.h" | ||||
23 | #include "qml/api/history/qmlhistoryitem.h" | ||||
24 | #include "qml/api/history/qmlhistory.h" | ||||
25 | | ||||
26 | Q_DECLARE_METATYPE(HistoryEntry) | ||||
27 | | ||||
28 | void QmlHistoryApiTest::initTestCase() | ||||
29 | { | ||||
30 | } | ||||
31 | | ||||
32 | void QmlHistoryApiTest::cleanupTestCase() | ||||
33 | { | ||||
34 | } | ||||
35 | | ||||
36 | void QmlHistoryApiTest::testAddition() | ||||
37 | { | ||||
38 | qRegisterMetaType<HistoryEntry>(); | ||||
39 | QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded); | ||||
40 | m_testHelper.evaluate("Falkon.History.addUrl({" | ||||
41 | " url: 'https://example.com'," | ||||
42 | " title: 'Example Domain'" | ||||
43 | "})"); | ||||
44 | QTRY_COMPARE(historySpy.count(), 1); | ||||
45 | HistoryEntry entry = qvariant_cast<HistoryEntry>(historySpy.at(0).at(0)); | ||||
46 | QCOMPARE(entry.title, "Example Domain"); | ||||
47 | | ||||
48 | auto object = m_testHelper.evaluateQObject("Falkon.History"); | ||||
49 | QSignalSpy qmlHistorySpy(object, SIGNAL(visited(QmlHistoryItem*))); | ||||
50 | mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain"); | ||||
51 | QTRY_COMPARE(qmlHistorySpy.count(), 1); | ||||
52 | mApp->history()->clearHistory(); | ||||
53 | } | ||||
54 | | ||||
55 | void QmlHistoryApiTest::testSearch() | ||||
56 | { | ||||
57 | QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded); | ||||
58 | mApp->history()->addHistoryEntry(QUrl("https://example.com"), "Example Domain"); | ||||
59 | mApp->history()->addHistoryEntry(QUrl("https://another-example.com"), "Another Example Domain"); | ||||
60 | mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain"); | ||||
61 | QTRY_COMPARE(historySpy.count(), 3); | ||||
62 | auto list = m_testHelper.evaluate("Falkon.History.search('example')").toVariant().toList(); | ||||
63 | QCOMPARE(list.length(), 2); | ||||
64 | } | ||||
65 | | ||||
66 | void QmlHistoryApiTest::testVisits() | ||||
67 | { | ||||
68 | int visits = m_testHelper.evaluate("Falkon.History.getVisits('https://sample.com')").toInt(); | ||||
69 | QCOMPARE(visits, 1); | ||||
70 | QSignalSpy historySpy(mApp->history(), &History::historyEntryEdited); | ||||
71 | mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain"); | ||||
72 | QTRY_COMPARE(historySpy.count(), 1); | ||||
73 | visits = m_testHelper.evaluate("Falkon.History.getVisits('https://sample.com')").toInt(); | ||||
74 | QCOMPARE(visits, 2); | ||||
75 | } | ||||
76 | | ||||
77 | void QmlHistoryApiTest::testRemoval() | ||||
78 | { | ||||
79 | QSignalSpy historySpy(mApp->history(), &History::historyEntryDeleted); | ||||
80 | m_testHelper.evaluate("Falkon.History.deleteUrl('https://sample.com')"); | ||||
81 | QTRY_COMPARE(historySpy.count(), 1); | ||||
82 | | ||||
83 | auto object = m_testHelper.evaluateQObject("Falkon.History"); | ||||
84 | QSignalSpy qmlHistorySpy(object, SIGNAL(visitRemoved(QmlHistoryItem*))); | ||||
85 | mApp->history()->deleteHistoryEntry("https://example.com", "Example Domain"); | ||||
86 | QTRY_COMPARE(qmlHistorySpy.count(), 1); | ||||
87 | } | ||||
88 | | ||||
89 | FALKONTEST_MAIN(QmlHistoryApiTest) |