File indexing completed on 2024-04-28 04:55:55
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 "qmlwindowsapitest.h" 0019 #include "autotests.h" 0020 #include "mainapplication.h" 0021 #include "qml/api/windows/qmlwindow.h" 0022 #include "pluginproxy.h" 0023 #include "browserwindow.h" 0024 0025 void QmlWindowsApiTest::initTestCase() 0026 { 0027 } 0028 0029 void QmlWindowsApiTest::cleanupTestCase() 0030 { 0031 } 0032 0033 void QmlWindowsApiTest::testWindowsAPI() 0034 { 0035 QObject *currentWindowObject = m_testHelper.evaluateQObject(QSL("Falkon.Windows.getCurrent()")); 0036 QVERIFY(currentWindowObject); 0037 QCOMPARE(currentWindowObject->property("title").toString(), mApp->getWindow()->windowTitle()); 0038 QCOMPARE(currentWindowObject->property("type").toInt(), (int)mApp->getWindow()->windowType()); 0039 QCOMPARE(currentWindowObject->property("tabs").toList().length(), mApp->getWindow()->tabCount()); 0040 0041 QObject *windowObject = m_testHelper.evaluateQObject(QSL("Falkon.Windows")); 0042 QVERIFY(windowObject); 0043 QSignalSpy qmlWindowCreatedSignal(windowObject, SIGNAL(created(QmlWindow*))); 0044 qRegisterMetaType<BrowserWindow*>(); 0045 QSignalSpy windowCreatedSingal(mApp->plugins(), SIGNAL(mainWindowCreated(BrowserWindow*))); 0046 0047 // for initial window 0048 QTRY_COMPARE(qmlWindowCreatedSignal.count(), 1); 0049 QTRY_COMPARE(windowCreatedSingal.count(), 1); 0050 0051 QObject *newQmlWindow = m_testHelper.evaluateQObject(QSL("Falkon.Windows.create({})")); 0052 QVERIFY(newQmlWindow); 0053 QCOMPARE(mApp->windowCount(), 2); 0054 0055 // for newly created window 0056 QTRY_COMPARE(qmlWindowCreatedSignal.count(), 2); 0057 QTRY_COMPARE(windowCreatedSingal.count(), 2); 0058 0059 auto *newQmlSignalWindow = qvariant_cast<QObject*>(qmlWindowCreatedSignal.at(1).at(0)); 0060 QVERIFY(newQmlSignalWindow); 0061 QCOMPARE(newQmlWindow->property("id").toInt(), newQmlSignalWindow->property("id").toInt()); 0062 0063 int qmlWindowCount = m_testHelper.evaluate(QSL("Falkon.Windows.getAll().length")).toInt(); 0064 QCOMPARE(qmlWindowCount, mApp->windowCount()); 0065 0066 QSignalSpy qmlWindowRemovedSignal(windowObject, SIGNAL(removed(QmlWindow*))); 0067 int newQmlWindowId = newQmlSignalWindow->property("id").toInt(); 0068 m_testHelper.evaluate(QString(QSL("Falkon.Windows.remove(%1)")).arg(newQmlWindowId)); 0069 QTRY_COMPARE(qmlWindowRemovedSignal.count(), 1); 0070 } 0071 0072 FALKONTEST_MAIN(QmlWindowsApiTest)