File indexing completed on 2024-04-28 04:55:54
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "qmltabsapitest.h" 0019 #include "autotests.h" 0020 #include "mainapplication.h" 0021 #include "tabwidget.h" 0022 0023 void QmlTabsApiTest::initTestCase() 0024 { 0025 } 0026 0027 void QmlTabsApiTest::cleanupTestCase() 0028 { 0029 } 0030 0031 void QmlTabsApiTest::testInitWindowCount() 0032 { 0033 QCOMPARE(mApp->windowCount(), 1); 0034 QTRY_COMPARE(mApp->getWindow()->tabCount(), 1); 0035 } 0036 0037 void QmlTabsApiTest::testTabsAPI() 0038 { 0039 /* Wait until the initial tab (at index 0) in the window is created */ 0040 QTRY_COMPARE(mApp->getWindow()->tabCount(), 1); 0041 0042 // Tab Insertion 0043 QObject *qmlTabsObject = m_testHelper.evaluateQObject(QSL("Falkon.Tabs")); 0044 QVERIFY(qmlTabsObject); 0045 QSignalSpy qmlTabsInsertedSpy(qmlTabsObject, SIGNAL(tabInserted(QVariantMap))); 0046 m_testHelper.evaluate(QL1S("Falkon.Tabs.addTab({" 0047 " url: 'https://example.com/'" 0048 "})")); 0049 QCOMPARE(qmlTabsInsertedSpy.count(), 1); 0050 QVariantMap retMap1 = QVariant(qmlTabsInsertedSpy.at(0).at(0)).toMap(); 0051 int index1 = retMap1.value(QSL("index"), -1).toInt(); 0052 int windowId1 = retMap1.value(QSL("windowId"), -1).toInt(); 0053 QCOMPARE(index1, 1); 0054 QCOMPARE(windowId1, 0); 0055 0056 QObject *qmlTabObject1 = m_testHelper.evaluateQObject(QSL("Falkon.Tabs.get({index: 1})")); 0057 QVERIFY(qmlTabObject1); 0058 QCOMPARE(qmlTabObject1->property("index").toInt(), 1); 0059 QCOMPARE(qmlTabObject1->property("pinned").toBool(), false); 0060 QTRY_COMPARE(qmlTabObject1->property("url").toString(), QSL("https://example.com/")); 0061 0062 m_testHelper.evaluate(QL1S("Falkon.Tabs.addTab({" 0063 " url: 'https://another-example.com/'" 0064 "})")); 0065 QCOMPARE(qmlTabsInsertedSpy.count(), 2); 0066 QVariantMap retMap2 = QVariant(qmlTabsInsertedSpy.at(1).at(0)).toMap(); 0067 int index2 = retMap2.value(QSL("index"), -1).toInt(); 0068 int windowId2 = retMap2.value(QSL("windowId"), -1).toInt(); 0069 QCOMPARE(index2, 2); 0070 QCOMPARE(windowId2, 0); 0071 0072 bool pinnedTab = m_testHelper.evaluate(QSL("Falkon.Tabs.pinTab({index: 2})")).toBool(); 0073 QVERIFY(pinnedTab); 0074 QObject *qmlTabObject2 = m_testHelper.evaluateQObject(QSL("Falkon.Tabs.get({index: 0})")); 0075 QVERIFY(qmlTabObject2); 0076 QCOMPARE(qmlTabObject2->property("index").toInt(), 0); 0077 QCOMPARE(qmlTabObject2->property("pinned").toBool(), true); 0078 QTRY_COMPARE(qmlTabObject2->property("url").toString(), QSL("https://another-example.com/")); 0079 0080 bool unpinnedTab = m_testHelper.evaluate(QSL("Falkon.Tabs.unpinTab({index: 0})")).toBool(); 0081 QVERIFY(unpinnedTab); 0082 QObject *qmlTabObject3 = m_testHelper.evaluateQObject(QSL("Falkon.Tabs.get({index: 0})")); 0083 QVERIFY(qmlTabObject3); 0084 QCOMPARE(qmlTabObject3->property("url").toString(), QSL("https://another-example.com/")); 0085 QCOMPARE(qmlTabObject3->property("index").toInt(), 0); 0086 QCOMPARE(qmlTabObject3->property("pinned").toBool(), false); 0087 0088 // Next-Previous-Current 0089 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); 0090 m_testHelper.evaluate(QSL("Falkon.Tabs.nextTab()")); 0091 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1); 0092 m_testHelper.evaluate(QSL("Falkon.Tabs.nextTab()")); 0093 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 2); 0094 m_testHelper.evaluate(QSL("Falkon.Tabs.nextTab()")); 0095 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); 0096 m_testHelper.evaluate(QSL("Falkon.Tabs.previousTab()")); 0097 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 2); 0098 m_testHelper.evaluate(QSL("Falkon.Tabs.previousTab()")); 0099 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1); 0100 m_testHelper.evaluate(QSL("Falkon.Tabs.previousTab()")); 0101 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); 0102 m_testHelper.evaluate(QSL("Falkon.Tabs.setCurrentIndex({index: 2})")); 0103 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 2); 0104 m_testHelper.evaluate(QSL("Falkon.Tabs.setCurrentIndex({index: 1})")); 0105 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1); 0106 m_testHelper.evaluate(QSL("Falkon.Tabs.setCurrentIndex({index: 0})")); 0107 QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0); 0108 0109 // Move Tab 0110 QSignalSpy qmlTabsMovedSpy(qmlTabsObject, SIGNAL(tabMoved(QVariantMap))); 0111 m_testHelper.evaluate(QSL("Falkon.Tabs.moveTab({from: 0, to:1, windowId: 0})")); 0112 QCOMPARE(qmlTabsMovedSpy.count(), 1); 0113 0114 // Tab Removal 0115 QCOMPARE(mApp->getWindow()->tabCount(), 3); 0116 QSignalSpy qmlTabsRemovedSpy(qmlTabsObject, SIGNAL(tabRemoved(QVariantMap))); 0117 m_testHelper.evaluate(QSL("Falkon.Tabs.closeTab({index: 0})")); 0118 QCOMPARE(qmlTabsRemovedSpy.count(), 1); 0119 QCOMPARE(mApp->getWindow()->tabCount(), 2); 0120 } 0121 0122 FALKONTEST_MAIN(QmlTabsApiTest)