Changeset View
Changeset View
Standalone View
Standalone View
autotests/qml/qmlwindowsapitest.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 "qmlwindowsapitest.h" | ||||
19 | #include "autotests.h" | ||||
20 | #include "qmltesthelper.h" | ||||
21 | #include "mainapplication.h" | ||||
22 | #include "qml/api/windows/qmlwindow.h" | ||||
23 | #include "pluginproxy.h" | ||||
24 | #include "browserwindow.h" | ||||
25 | | ||||
26 | void QmlWindowsApiTest::initTestCase() | ||||
27 | { | ||||
28 | } | ||||
29 | | ||||
30 | void QmlWindowsApiTest::cleanupTestCase() | ||||
31 | { | ||||
32 | } | ||||
33 | | ||||
34 | void QmlWindowsApiTest::testWindowsAPI() | ||||
35 | { | ||||
36 | QObject *currentWindowObject = m_testHelper.evaluateQObject("Falkon.Windows.getCurrent()"); | ||||
37 | QVERIFY(currentWindowObject); | ||||
38 | QCOMPARE(currentWindowObject->property("title").toString(), mApp->getWindow()->windowTitle()); | ||||
39 | QCOMPARE(currentWindowObject->property("type").toInt(), (int)mApp->getWindow()->windowType()); | ||||
40 | QCOMPARE(currentWindowObject->property("tabs").toList().length(), mApp->getWindow()->tabCount()); | ||||
41 | | ||||
42 | QObject *windowObject = m_testHelper.evaluateQObject("Falkon.Windows"); | ||||
43 | QVERIFY(windowObject); | ||||
44 | QSignalSpy qmlWindowCreatedSignal(windowObject, SIGNAL(created(QmlWindow*))); | ||||
45 | qRegisterMetaType<BrowserWindow*>(); | ||||
46 | QSignalSpy windowCreatedSingal(mApp->plugins(), SIGNAL(mainWindowCreated(BrowserWindow*))); | ||||
47 | QObject *newQmlWindow = m_testHelper.evaluateQObject("Falkon.Windows.create({})"); | ||||
48 | QVERIFY(newQmlWindow); | ||||
49 | QCOMPARE(mApp->windowCount(), 2); | ||||
50 | // FIXME: signal is emitted 2 times here - | ||||
51 | // 1st for the initial window, 2nd for the created window | ||||
52 | QTRY_COMPARE(qmlWindowCreatedSignal.count(), 2); | ||||
53 | QTRY_COMPARE(windowCreatedSingal.count(), 2); | ||||
54 | QObject *newQmlSignalWindow = qvariant_cast<QObject*>(qmlWindowCreatedSignal.at(1).at(0)); | ||||
55 | QVERIFY(newQmlSignalWindow); | ||||
56 | QCOMPARE(newQmlWindow->property("id").toInt(), newQmlSignalWindow->property("id").toInt()); | ||||
57 | | ||||
58 | int qmlWindowCount = m_testHelper.evaluate("Falkon.Windows.getAll().length").toInt(); | ||||
59 | QCOMPARE(qmlWindowCount, mApp->windowCount()); | ||||
60 | | ||||
61 | QSignalSpy qmlWindowRemovedSignal(windowObject, SIGNAL(removed(QmlWindow*))); | ||||
62 | int newQmlWindowId = newQmlSignalWindow->property("id").toInt(); | ||||
63 | m_testHelper.evaluate(QString("Falkon.Windows.remove(%1)").arg(newQmlWindowId)); | ||||
64 | QTRY_COMPARE(qmlWindowRemovedSignal.count(), 1); | ||||
65 | } | ||||
66 | | ||||
67 | FALKONTEST_MAIN(QmlWindowsApiTest) |