Changeset View
Changeset View
Standalone View
Standalone View
autotests/qml/qmltabsapitest.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 "qmltabsapitest.h" | ||||
19 | #include "autotests.h" | ||||
20 | #include "qmltesthelper.h" | ||||
21 | #include "mainapplication.h" | ||||
22 | #include "tabwidget.h" | ||||
23 | | ||||
24 | void QmlTabsApiTest::initTestCase() | ||||
25 | { | ||||
26 | } | ||||
27 | | ||||
28 | void QmlTabsApiTest::cleanupTestCase() | ||||
29 | { | ||||
30 | } | ||||
31 | | ||||
32 | void QmlTabsApiTest::testInitWindowCount() | ||||
33 | { | ||||
34 | QCOMPARE(mApp->windowCount(), 1); | ||||
35 | QCOMPARE(mApp->getWindow()->tabCount(), 0); | ||||
36 | } | ||||
37 | | ||||
38 | void QmlTabsApiTest::testTabsAPI() | ||||
39 | { | ||||
40 | // Tab Insertion | ||||
41 | QObject *qmlTabsObject = m_testHelper.evaluateQObject("Falkon.Tabs"); | ||||
42 | QVERIFY(qmlTabsObject); | ||||
43 | QSignalSpy qmlTabsInsertedSpy(qmlTabsObject, SIGNAL(tabInserted(QVariantMap))); | ||||
44 | m_testHelper.evaluate("Falkon.Tabs.addTab({" | ||||
45 | " url: 'https://example.com/'" | ||||
46 | "})"); | ||||
47 | QCOMPARE(qmlTabsInsertedSpy.count(), 1); | ||||
48 | QVariantMap retMap1 = QVariant(qmlTabsInsertedSpy.at(0).at(0)).toMap(); | ||||
49 | int index1 = retMap1.value(QSL("index"), -1).toInt(); | ||||
50 | int windowId1 = retMap1.value(QSL("windowId"), -1).toInt(); | ||||
51 | QCOMPARE(index1, 0); | ||||
52 | QCOMPARE(windowId1, 0); | ||||
53 | | ||||
54 | QObject *qmlTabObject1 = m_testHelper.evaluateQObject("Falkon.Tabs.get({index: 0})"); | ||||
55 | QVERIFY(qmlTabObject1); | ||||
56 | QCOMPARE(qmlTabObject1->property("url").toString(), "https://example.com/"); | ||||
57 | QCOMPARE(qmlTabObject1->property("index").toInt(), 0); | ||||
58 | QCOMPARE(qmlTabObject1->property("pinned").toBool(), false); | ||||
59 | | ||||
60 | m_testHelper.evaluate("Falkon.Tabs.addTab({" | ||||
61 | " url: 'https://another-example.com/'," | ||||
62 | "})"); | ||||
63 | QCOMPARE(qmlTabsInsertedSpy.count(), 2); | ||||
64 | QVariantMap retMap2 = QVariant(qmlTabsInsertedSpy.at(1).at(0)).toMap(); | ||||
65 | int index2 = retMap2.value(QSL("index"), -1).toInt(); | ||||
66 | int windowId2 = retMap2.value(QSL("windowId"), -1).toInt(); | ||||
67 | QCOMPARE(index2, 1); | ||||
68 | QCOMPARE(windowId2, 0); | ||||
69 | | ||||
70 | bool pinnedTab = m_testHelper.evaluate("Falkon.Tabs.pinTab({index: 1})").toBool(); | ||||
71 | QVERIFY(pinnedTab); | ||||
72 | QObject *qmlTabObject2 = m_testHelper.evaluateQObject("Falkon.Tabs.get({index: 0})"); | ||||
73 | QVERIFY(qmlTabObject2); | ||||
74 | QCOMPARE(qmlTabObject2->property("url").toString(), "https://another-example.com/"); | ||||
75 | QCOMPARE(qmlTabObject2->property("index").toInt(), 0); | ||||
76 | QCOMPARE(qmlTabObject2->property("pinned").toBool(), true); | ||||
77 | | ||||
78 | bool unpinnedTab = m_testHelper.evaluate("Falkon.Tabs.unpinTab({index: 0})").toBool(); | ||||
79 | QVERIFY(unpinnedTab); | ||||
80 | QObject *qmlTabObject3 = m_testHelper.evaluateQObject("Falkon.Tabs.get({index: 0})"); | ||||
81 | QVERIFY(qmlTabObject3); | ||||
82 | QCOMPARE(qmlTabObject3->property("url").toString(), "https://another-example.com/"); | ||||
83 | QCOMPARE(qmlTabObject3->property("index").toInt(), 0); | ||||
84 | QCOMPARE(qmlTabObject3->property("pinned").toBool(), false); | ||||
85 | | ||||
86 | // Next-Previous-Current | ||||
87 | QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); | ||||
88 | m_testHelper.evaluate("Falkon.Tabs.nextTab()"); | ||||
89 | QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1); | ||||
90 | m_testHelper.evaluate("Falkon.Tabs.nextTab()"); | ||||
91 | QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); | ||||
92 | m_testHelper.evaluate("Falkon.Tabs.previousTab()"); | ||||
93 | QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1); | ||||
94 | m_testHelper.evaluate("Falkon.Tabs.previousTab()"); | ||||
95 | QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); | ||||
96 | m_testHelper.evaluate("Falkon.Tabs.setCurrentIndex({index: 1})"); | ||||
97 | QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1); | ||||
98 | m_testHelper.evaluate("Falkon.Tabs.setCurrentIndex({index: 0})"); | ||||
99 | QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); | ||||
100 | | ||||
101 | // Move Tab | ||||
102 | QSignalSpy qmlTabsMovedSpy(qmlTabsObject, SIGNAL(tabMoved(QVariantMap))); | ||||
103 | m_testHelper.evaluate("Falkon.Tabs.moveTab({from: 0, to:1, windowId: 0})"); | ||||
104 | QCOMPARE(qmlTabsMovedSpy.count(), 1); | ||||
105 | | ||||
106 | // Tab Removal | ||||
107 | QCOMPARE(mApp->getWindow()->tabCount(), 2); | ||||
108 | QSignalSpy qmlTabsRemovedSpy(qmlTabsObject, SIGNAL(tabRemoved(QVariantMap))); | ||||
109 | m_testHelper.evaluate("Falkon.Tabs.closeTab({index: 0})"); | ||||
110 | QCOMPARE(qmlTabsRemovedSpy.count(), 1); | ||||
111 | QCOMPARE(mApp->getWindow()->tabCount(), 1); | ||||
112 | } | ||||
113 | | ||||
114 | FALKONTEST_MAIN(QmlTabsApiTest) |