Falkon Develop
Cross-platform Qt-based web browser
qmlwindowsapitest.cpp
Go to the documentation of this file.
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 "mainapplication.h"
22#include "pluginproxy.h"
23#include "browserwindow.h"
24
25void QmlWindowsApiTest::initTestCase()
26{
27}
28
29void QmlWindowsApiTest::cleanupTestCase()
30{
31}
32
33void QmlWindowsApiTest::testWindowsAPI()
34{
35 QObject *currentWindowObject = m_testHelper.evaluateQObject(QSL("Falkon.Windows.getCurrent()"));
36 QVERIFY(currentWindowObject);
37 QCOMPARE(currentWindowObject->property("title").toString(), mApp->getWindow()->windowTitle());
38 QCOMPARE(currentWindowObject->property("type").toInt(), (int)mApp->getWindow()->windowType());
39 QCOMPARE(currentWindowObject->property("tabs").toList().length(), mApp->getWindow()->tabCount());
40
41 QObject *windowObject = m_testHelper.evaluateQObject(QSL("Falkon.Windows"));
42 QVERIFY(windowObject);
43 QSignalSpy qmlWindowCreatedSignal(windowObject, SIGNAL(created(QmlWindow*)));
44 qRegisterMetaType<BrowserWindow*>();
45 QSignalSpy windowCreatedSingal(mApp->plugins(), SIGNAL(mainWindowCreated(BrowserWindow*)));
46
47 // for initial window
48 QTRY_COMPARE(qmlWindowCreatedSignal.count(), 1);
49 QTRY_COMPARE(windowCreatedSingal.count(), 1);
50
51 QObject *newQmlWindow = m_testHelper.evaluateQObject(QSL("Falkon.Windows.create({})"));
52 QVERIFY(newQmlWindow);
53 QCOMPARE(mApp->windowCount(), 2);
54
55 // for newly created window
56 QTRY_COMPARE(qmlWindowCreatedSignal.count(), 2);
57 QTRY_COMPARE(windowCreatedSingal.count(), 2);
58
59 auto *newQmlSignalWindow = qvariant_cast<QObject*>(qmlWindowCreatedSignal.at(1).at(0));
60 QVERIFY(newQmlSignalWindow);
61 QCOMPARE(newQmlWindow->property("id").toInt(), newQmlSignalWindow->property("id").toInt());
62
63 int qmlWindowCount = m_testHelper.evaluate(QSL("Falkon.Windows.getAll().length")).toInt();
64 QCOMPARE(qmlWindowCount, mApp->windowCount());
65
66 QSignalSpy qmlWindowRemovedSignal(windowObject, SIGNAL(removed(QmlWindow*)));
67 int newQmlWindowId = newQmlSignalWindow->property("id").toInt();
68 m_testHelper.evaluate(QString(QSL("Falkon.Windows.remove(%1)")).arg(newQmlWindowId));
69 QTRY_COMPARE(qmlWindowRemovedSignal.count(), 1);
70}
71
#define FALKONTEST_MAIN(Test)
Definition: autotests.h:23
QObject * evaluateQObject(const QString &source)
QJSValue evaluate(const QString &source)
The class exposing Browser window to QML.
Definition: qmlwindow.h:27
#define mApp
#define QSL(x)
Definition: qzcommon.h:40