mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
merging patch D14521
This commit is contained in:
parent
16accb77d8
commit
40acbff0f0
|
@ -37,29 +37,3 @@ falkon_tests(
|
||||||
databasepasswordbackendtest
|
databasepasswordbackendtest
|
||||||
databaseencryptedpasswordbackendtest
|
databaseencryptedpasswordbackendtest
|
||||||
)
|
)
|
||||||
|
|
||||||
set(falkon_autotests_SRCS
|
|
||||||
qml/qmltestitem.cpp
|
|
||||||
qml/qmltesthelper.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
macro(falkon_qml_tests)
|
|
||||||
foreach(_testname ${ARGN})
|
|
||||||
add_executable(${_testname} qml/${_testname}.cpp ${falkon_autotests_SRCS})
|
|
||||||
target_link_libraries(${_testname} Qt5::Test FalkonPrivate)
|
|
||||||
add_test(NAME falkon-qml-${_testname} COMMAND ${_testname})
|
|
||||||
ecm_mark_as_test(${_testname})
|
|
||||||
set_tests_properties(falkon-qml-${_testname} PROPERTIES RUN_SERIAL TRUE)
|
|
||||||
endforeach(_testname)
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
falkon_qml_tests(
|
|
||||||
qmlbookmarksapitest
|
|
||||||
qmltopsitesapitest
|
|
||||||
qmlhistoryapitest
|
|
||||||
qmlcookiesapitest
|
|
||||||
qmlclipboardapitest
|
|
||||||
qmltabsapitest
|
|
||||||
qmlwindowsapitest
|
|
||||||
qmluserscriptapitest
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,174 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmlbookmarksapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "bookmarks.h"
|
|
||||||
#include "bookmarkitem.h"
|
|
||||||
#include "qml/api/bookmarks/qmlbookmarktreenode.h"
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::testBookmarkTreeNodeType()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
|
|
||||||
auto type = BookmarkItem::Type(qmlTest.evaluate("Falkon.Bookmarks.rootItem().type").toInt());
|
|
||||||
QCOMPARE(mApp->bookmarks()->rootItem()->type(), type);
|
|
||||||
|
|
||||||
type = BookmarkItem::Type(qmlTest.evaluate("Falkon.Bookmarks.toolbarFolder().type").toInt());
|
|
||||||
QCOMPARE(mApp->bookmarks()->toolbarFolder()->type(), type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::testBookmarkTreeNode()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
|
|
||||||
QObject *bookmark = qmlTest.evaluateQObject("Falkon.Bookmarks.toolbarFolder()");
|
|
||||||
QVERIFY(bookmark);
|
|
||||||
auto toolbarFolder = mApp->bookmarks()->toolbarFolder();
|
|
||||||
|
|
||||||
QCOMPARE(toolbarFolder->title(), bookmark->property("title").toString());
|
|
||||||
QCOMPARE(toolbarFolder->urlString(), bookmark->property("url").toString());
|
|
||||||
QCOMPARE(toolbarFolder->description(), bookmark->property("description").toString());
|
|
||||||
QCOMPARE(!mApp->bookmarks()->canBeModified(toolbarFolder), bookmark->property("unmodifiable").toBool());
|
|
||||||
QObject* parent = qvariant_cast<QObject*>(bookmark->property("parent"));
|
|
||||||
QVERIFY(parent);
|
|
||||||
QCOMPARE(mApp->bookmarks()->rootItem()->title(), parent->property("title").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::testBookmarksCreation()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
|
|
||||||
auto item = new BookmarkItem(BookmarkItem::Url);
|
|
||||||
item->setTitle("Example Domain");
|
|
||||||
item->setUrl(QUrl("https://example.com/"));
|
|
||||||
item->setDescription("Testing bookmark description");
|
|
||||||
|
|
||||||
QObject *qmlBookmarks = qmlTest.evaluateQObject("Falkon.Bookmarks");
|
|
||||||
QVERIFY(qmlBookmarks);
|
|
||||||
|
|
||||||
QSignalSpy qmlBookmarksSpy(qmlBookmarks, SIGNAL(created(QmlBookmarkTreeNode*)));
|
|
||||||
mApp->bookmarks()->addBookmark(mApp->bookmarks()->rootItem(), item);
|
|
||||||
|
|
||||||
QCOMPARE(qmlBookmarksSpy.count(), 1);
|
|
||||||
|
|
||||||
QObject *created = qvariant_cast<QObject*>(qmlBookmarksSpy.at(0).at(0));
|
|
||||||
QVERIFY(created);
|
|
||||||
QCOMPARE(item->title(), created->property("title").toString());
|
|
||||||
|
|
||||||
qRegisterMetaType<BookmarkItem*>();
|
|
||||||
QSignalSpy bookmarksSpy(mApp->bookmarks(), &Bookmarks::bookmarkAdded);
|
|
||||||
|
|
||||||
auto out = qmlTest.evaluate("Falkon.Bookmarks.create({"
|
|
||||||
" parent: Falkon.Bookmarks.toolbarFolder(),"
|
|
||||||
" title: 'Example Plugin',"
|
|
||||||
" url: 'https://another-example.com'"
|
|
||||||
"});");
|
|
||||||
QVERIFY(out.toBool());
|
|
||||||
|
|
||||||
QCOMPARE(bookmarksSpy.count(), 1);
|
|
||||||
BookmarkItem* createdItem = qvariant_cast<BookmarkItem*>(bookmarksSpy.at(0).at(0));
|
|
||||||
QVERIFY(createdItem);
|
|
||||||
QCOMPARE(createdItem->title(), QString("Example Plugin"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::testBookmarksExistence()
|
|
||||||
{
|
|
||||||
// in continuation from testBookmarksCreation
|
|
||||||
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
auto result = qmlTest.evaluate("Falkon.Bookmarks.isBookmarked('https://example.com/')").toBool();
|
|
||||||
QVERIFY(result);
|
|
||||||
QCOMPARE(mApp->bookmarks()->isBookmarked(QUrl("https://example.com/")), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::testBookmarksModification()
|
|
||||||
{
|
|
||||||
// in continuation from testBookmarksExistence
|
|
||||||
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
|
|
||||||
QObject *qmlBookmarks = qmlTest.evaluateQObject("Falkon.Bookmarks");
|
|
||||||
QVERIFY(qmlBookmarks);
|
|
||||||
|
|
||||||
QSignalSpy qmlBookmarksSpy(qmlBookmarks, SIGNAL(changed(QmlBookmarkTreeNode*)));
|
|
||||||
BookmarkItem* item = mApp->bookmarks()->searchBookmarks("https://example.com/").at(0);
|
|
||||||
item->setTitle("Modified Example Domain");
|
|
||||||
mApp->bookmarks()->changeBookmark(item);
|
|
||||||
|
|
||||||
QCOMPARE(qmlBookmarksSpy.count(), 1);
|
|
||||||
|
|
||||||
QObject *modified = qvariant_cast<QObject*>(qmlBookmarksSpy.at(0).at(0));
|
|
||||||
QVERIFY(modified);
|
|
||||||
QCOMPARE(modified->property("title").toString(), QString("Modified Example Domain"));
|
|
||||||
|
|
||||||
qRegisterMetaType<BookmarkItem*>();
|
|
||||||
QSignalSpy bookmarksSpy(mApp->bookmarks(), &Bookmarks::bookmarkChanged);
|
|
||||||
|
|
||||||
auto out = qmlTest.evaluate("Falkon.Bookmarks.update(Falkon.Bookmarks.get('https://another-example.com'),{"
|
|
||||||
" title: 'Modified Example Plugin'"
|
|
||||||
"})");
|
|
||||||
QVERIFY(out.toBool());
|
|
||||||
|
|
||||||
QCOMPARE(bookmarksSpy.count(), 1);
|
|
||||||
BookmarkItem* modifiedItem = qvariant_cast<BookmarkItem*>(bookmarksSpy.at(0).at(0));
|
|
||||||
QVERIFY(modifiedItem);
|
|
||||||
QCOMPARE(modifiedItem->title(), QString("Modified Example Plugin"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlBookmarksApiTest::testBookmarksRemoval()
|
|
||||||
{
|
|
||||||
// in continuation from testBookmarksModification
|
|
||||||
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
|
|
||||||
QObject *qmlBookmarks = qmlTest.evaluateQObject("Falkon.Bookmarks");
|
|
||||||
QVERIFY(qmlBookmarks);
|
|
||||||
|
|
||||||
QSignalSpy qmlBookmarksSpy(qmlBookmarks, SIGNAL(removed(QmlBookmarkTreeNode*)));
|
|
||||||
BookmarkItem* item = mApp->bookmarks()->searchBookmarks("https://example.com/").at(0);
|
|
||||||
mApp->bookmarks()->removeBookmark(item);
|
|
||||||
|
|
||||||
QCOMPARE(qmlBookmarksSpy.count(), 1);
|
|
||||||
|
|
||||||
QObject *removed = qvariant_cast<QObject*>(qmlBookmarksSpy.at(0).at(0));
|
|
||||||
QVERIFY(removed);
|
|
||||||
QCOMPARE(removed->property("title").toString(), QString("Modified Example Domain"));
|
|
||||||
|
|
||||||
qRegisterMetaType<BookmarkItem*>();
|
|
||||||
QSignalSpy bookmarksSpy(mApp->bookmarks(), &Bookmarks::bookmarkRemoved);
|
|
||||||
|
|
||||||
auto out = qmlTest.evaluate("Falkon.Bookmarks.remove(Falkon.Bookmarks.get('https://another-example.com'))");
|
|
||||||
QVERIFY(out.toBool());
|
|
||||||
|
|
||||||
QCOMPARE(bookmarksSpy.count(), 1);
|
|
||||||
BookmarkItem* removedItem = qvariant_cast<BookmarkItem*>(bookmarksSpy.at(0).at(0));
|
|
||||||
QVERIFY(removedItem);
|
|
||||||
QCOMPARE(removedItem->title(), QString("Modified Example Plugin"));
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlBookmarksApiTest)
|
|
|
@ -1,41 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "bookmarkitem.h"
|
|
||||||
|
|
||||||
class QmlBookmarksApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testBookmarkTreeNodeType();
|
|
||||||
void testBookmarkTreeNode();
|
|
||||||
|
|
||||||
void testBookmarksCreation();
|
|
||||||
void testBookmarksExistence();
|
|
||||||
void testBookmarksModification();
|
|
||||||
void testBookmarksRemoval();
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BookmarkItem *)
|
|
|
@ -1,39 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmlclipboardapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include <QClipboard>
|
|
||||||
|
|
||||||
void QmlClipboardApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlClipboardApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlClipboardApiTest::testClipboard()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
qmlTest.evaluate("Falkon.Clipboard.copy('this text is copied')");
|
|
||||||
QCOMPARE(mApp->clipboard()->text(), "this text is copied");
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlClipboardApiTest)
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class QmlClipboardApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testClipboard();
|
|
||||||
};
|
|
|
@ -1,119 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmlcookiesapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "cookiejar.h"
|
|
||||||
#include "qml/api/cookies/qmlcookie.h"
|
|
||||||
#include <QWebEngineProfile>
|
|
||||||
|
|
||||||
void QmlCookiesApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlCookiesApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlCookiesApiTest::testCookieAdditionRemoval()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QSignalSpy cookieAddSpy(mApp->cookieJar(), &CookieJar::cookieAdded);
|
|
||||||
qmlTest.evaluate("Falkon.Cookies.set({"
|
|
||||||
" name: 'Example',"
|
|
||||||
" url: '.example.com',"
|
|
||||||
" expirationDate: Date.now() + 60*1000"
|
|
||||||
"})");
|
|
||||||
QTRY_COMPARE(cookieAddSpy.count(), 1);
|
|
||||||
QNetworkCookie netCookie = qvariant_cast<QNetworkCookie>(cookieAddSpy.at(0).at(0));
|
|
||||||
QCOMPARE(netCookie.name(), "Example");
|
|
||||||
QObject *object = qmlTest.evaluateQObject("Falkon.Cookies");
|
|
||||||
QVERIFY(object);
|
|
||||||
QSignalSpy qmlCookieSpy(object, SIGNAL(changed(QVariantMap)));
|
|
||||||
QNetworkCookie anotherNetCookie;
|
|
||||||
anotherNetCookie.setName(QString("Hello").toLocal8Bit());
|
|
||||||
anotherNetCookie.setDomain(".mydomain.com");
|
|
||||||
anotherNetCookie.setExpirationDate(QDateTime::currentDateTime().addSecs(60));
|
|
||||||
mApp->webProfile()->cookieStore()->setCookie(anotherNetCookie);
|
|
||||||
QTRY_COMPARE(qmlCookieSpy.count(), 1);
|
|
||||||
QVariantMap addedQmlCookieMap = QVariant(qmlCookieSpy.at(0).at(0)).toMap();
|
|
||||||
QObject *addedQmlCookie = qvariant_cast<QObject*>(addedQmlCookieMap.value("cookie"));
|
|
||||||
bool removed = addedQmlCookieMap.value("removed").toBool();
|
|
||||||
QCOMPARE(addedQmlCookie->property("name").toString(), "Hello");
|
|
||||||
QCOMPARE(removed, false);
|
|
||||||
|
|
||||||
mApp->webProfile()->cookieStore()->deleteCookie(netCookie);
|
|
||||||
QTRY_COMPARE(qmlCookieSpy.count(), 2);
|
|
||||||
QVariantMap removedQmlCookieMap = QVariant(qmlCookieSpy.at(1).at(0)).toMap();
|
|
||||||
QObject *removedQmlCookie = qvariant_cast<QObject*>(removedQmlCookieMap.value("cookie"));
|
|
||||||
removed = removedQmlCookieMap.value("removed").toBool();
|
|
||||||
QCOMPARE(removedQmlCookie->property("name").toString(), "Example");
|
|
||||||
QCOMPARE(removed, true);
|
|
||||||
|
|
||||||
QSignalSpy cookieRemoveSpy(mApp->cookieJar(), &CookieJar::cookieRemoved);
|
|
||||||
qmlTest.evaluate("Falkon.Cookies.remove({"
|
|
||||||
" name: 'Hello',"
|
|
||||||
" url: '.mydomain.com',"
|
|
||||||
"})");
|
|
||||||
QTRY_COMPARE(cookieRemoveSpy.count(), 1);
|
|
||||||
netCookie = qvariant_cast<QNetworkCookie>(cookieRemoveSpy.at(0).at(0));
|
|
||||||
QCOMPARE(netCookie.name(), "Hello");
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlCookiesApiTest::testCookieGet()
|
|
||||||
{
|
|
||||||
QDateTime current = QDateTime::currentDateTime();
|
|
||||||
QSignalSpy cookieAddSpy(mApp->cookieJar(), &CookieJar::cookieAdded);
|
|
||||||
|
|
||||||
QNetworkCookie netCookie_1;
|
|
||||||
netCookie_1.setName(QString("Apple").toLocal8Bit());
|
|
||||||
netCookie_1.setDomain(".apple-domain.com");
|
|
||||||
netCookie_1.setExpirationDate(current.addSecs(60));
|
|
||||||
mApp->webProfile()->cookieStore()->setCookie(netCookie_1);
|
|
||||||
|
|
||||||
QNetworkCookie netCookie_2;
|
|
||||||
netCookie_2.setName(QString("Mango").toLocal8Bit());
|
|
||||||
netCookie_2.setDomain(".mango-domain.com");
|
|
||||||
netCookie_2.setExpirationDate(current.addSecs(120));
|
|
||||||
mApp->webProfile()->cookieStore()->setCookie(netCookie_2);
|
|
||||||
|
|
||||||
QNetworkCookie netCookie_3;
|
|
||||||
netCookie_3.setName(QString("Mango").toLocal8Bit());
|
|
||||||
netCookie_3.setDomain(".yet-another-mango-domain.com");
|
|
||||||
netCookie_3.setExpirationDate(current.addSecs(180));
|
|
||||||
mApp->webProfile()->cookieStore()->setCookie(netCookie_3);
|
|
||||||
|
|
||||||
QTRY_COMPARE(cookieAddSpy.count(), 3);
|
|
||||||
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QObject *mangoCookie = qmlTest.evaluateQObject("Falkon.Cookies.get({"
|
|
||||||
" name: 'Mango',"
|
|
||||||
" url: '.mango-domain.com'"
|
|
||||||
"})");
|
|
||||||
QVERIFY(mangoCookie);
|
|
||||||
QCOMPARE(mangoCookie->property("name").toString(), "Mango");
|
|
||||||
// FIXME: Here current.addSecs differes from expirationDate by some ms
|
|
||||||
// a solution is to convert both to string, but this is not the best solution
|
|
||||||
QCOMPARE(mangoCookie->property("expirationDate").toDateTime().toString(), current.addSecs(120).toString());
|
|
||||||
|
|
||||||
QList<QVariant> mangoCookies = qmlTest.evaluate("Falkon.Cookies.getAll({name: 'Mango'})").toVariant().toList();
|
|
||||||
QCOMPARE(mangoCookies.length(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlCookiesApiTest)
|
|
|
@ -1,32 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class QmlCookiesApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testCookieAdditionRemoval();
|
|
||||||
void testCookieGet();
|
|
||||||
};
|
|
|
@ -1,91 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmlhistoryapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "history.h"
|
|
||||||
#include "qml/api/history/qmlhistoryitem.h"
|
|
||||||
#include "qml/api/history/qmlhistory.h"
|
|
||||||
|
|
||||||
void QmlHistoryApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistoryApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistoryApiTest::testAddition()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
qRegisterMetaType<HistoryEntry>();
|
|
||||||
QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded);
|
|
||||||
qmlTest.evaluate("Falkon.History.addUrl({"
|
|
||||||
" url: 'https://example.com',"
|
|
||||||
" title: 'Example Domain'"
|
|
||||||
"})");
|
|
||||||
QTRY_COMPARE(historySpy.count(), 1);
|
|
||||||
HistoryEntry entry = qvariant_cast<HistoryEntry>(historySpy.at(0).at(0));
|
|
||||||
QCOMPARE(entry.title, "Example Domain");
|
|
||||||
|
|
||||||
auto object = qmlTest.evaluateQObject("Falkon.History");
|
|
||||||
QSignalSpy qmlHistorySpy(object, SIGNAL(visited(QmlHistoryItem*)));
|
|
||||||
mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain");
|
|
||||||
QTRY_COMPARE(qmlHistorySpy.count(), 1);
|
|
||||||
mApp->history()->clearHistory();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistoryApiTest::testSearch()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QSignalSpy historySpy(mApp->history(), &History::historyEntryAdded);
|
|
||||||
mApp->history()->addHistoryEntry(QUrl("https://example.com"), "Example Domain");
|
|
||||||
mApp->history()->addHistoryEntry(QUrl("https://another-example.com"), "Another Example Domain");
|
|
||||||
mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain");
|
|
||||||
QTRY_COMPARE(historySpy.count(), 3);
|
|
||||||
auto list = qmlTest.evaluate("Falkon.History.search('example')").toVariant().toList();
|
|
||||||
QCOMPARE(list.length(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistoryApiTest::testVisits()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
int visits = qmlTest.evaluate("Falkon.History.getVisits('https://sample.com')").toInt();
|
|
||||||
QCOMPARE(visits, 1);
|
|
||||||
QSignalSpy historySpy(mApp->history(), &History::historyEntryEdited);
|
|
||||||
mApp->history()->addHistoryEntry(QUrl("https://sample.com"), "Sample Domain");
|
|
||||||
QTRY_COMPARE(historySpy.count(), 1);
|
|
||||||
visits = qmlTest.evaluate("Falkon.History.getVisits('https://sample.com')").toInt();
|
|
||||||
QCOMPARE(visits, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlHistoryApiTest::testRemoval()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QSignalSpy historySpy(mApp->history(), &History::historyEntryDeleted);
|
|
||||||
qmlTest.evaluate("Falkon.History.deleteUrl('https://sample.com')");
|
|
||||||
QTRY_COMPARE(historySpy.count(), 1);
|
|
||||||
|
|
||||||
auto object = qmlTest.evaluateQObject("Falkon.History");
|
|
||||||
QSignalSpy qmlHistorySpy(object, SIGNAL(visitRemoved(QmlHistoryItem*)));
|
|
||||||
mApp->history()->deleteHistoryEntry("https://example.com", "Example Domain");
|
|
||||||
QTRY_COMPARE(qmlHistorySpy.count(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlHistoryApiTest)
|
|
|
@ -1,34 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class QmlHistoryApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testAddition();
|
|
||||||
void testSearch();
|
|
||||||
void testVisits();
|
|
||||||
void testRemoval();
|
|
||||||
};
|
|
|
@ -1,129 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmltabsapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "tabwidget.h"
|
|
||||||
|
|
||||||
void QmlTabsApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTabsApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTabsApiTest::testInitWindowCount()
|
|
||||||
{
|
|
||||||
QCOMPARE(mApp->windowCount(), 1);
|
|
||||||
QCOMPARE(mApp->getWindow()->tabCount(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTabsApiTest::testTabsAPI()
|
|
||||||
{
|
|
||||||
// Tab Insertion
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QObject *qmlTabsObject = qmlTest.evaluateQObject("Falkon.Tabs");
|
|
||||||
QVERIFY(qmlTabsObject);
|
|
||||||
QSignalSpy qmlTabsInsertedSpy(qmlTabsObject, SIGNAL(tabInserted(QVariantMap)));
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.addTab({"
|
|
||||||
" url: 'https://example.com/'"
|
|
||||||
"})");
|
|
||||||
QCOMPARE(qmlTabsInsertedSpy.count(), 1);
|
|
||||||
QVariantMap retMap1 = QVariant(qmlTabsInsertedSpy.at(0).at(0)).toMap();
|
|
||||||
int index1 = retMap1.value(QSL("index"), -1).toInt();
|
|
||||||
int windowId1 = retMap1.value(QSL("windowId"), -1).toInt();
|
|
||||||
QCOMPARE(index1, 0);
|
|
||||||
QCOMPARE(windowId1, 0);
|
|
||||||
|
|
||||||
QObject *qmlTabObject1 = qmlTest.evaluateQObject("Falkon.Tabs.get({index: 0})");
|
|
||||||
QVERIFY(qmlTabObject1);
|
|
||||||
QCOMPARE(qmlTabObject1->property("url").toString(), "https://example.com/");
|
|
||||||
QCOMPARE(qmlTabObject1->property("index").toInt(), 0);
|
|
||||||
QCOMPARE(qmlTabObject1->property("pinned").toBool(), false);
|
|
||||||
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.addTab({"
|
|
||||||
" url: 'https://another-example.com/',"
|
|
||||||
"})");
|
|
||||||
QCOMPARE(qmlTabsInsertedSpy.count(), 2);
|
|
||||||
QVariantMap retMap2 = QVariant(qmlTabsInsertedSpy.at(1).at(0)).toMap();
|
|
||||||
int index2 = retMap2.value(QSL("index"), -1).toInt();
|
|
||||||
int windowId2 = retMap2.value(QSL("windowId"), -1).toInt();
|
|
||||||
QCOMPARE(index2, 1);
|
|
||||||
QCOMPARE(windowId2, 0);
|
|
||||||
|
|
||||||
bool pinnedTab = qmlTest.evaluate("Falkon.Tabs.pinTab({index: 1})").toBool();
|
|
||||||
QVERIFY(pinnedTab);
|
|
||||||
QObject *qmlTabObject2 = qmlTest.evaluateQObject("Falkon.Tabs.get({index: 0})");
|
|
||||||
QVERIFY(qmlTabObject2);
|
|
||||||
QCOMPARE(qmlTabObject2->property("url").toString(), "https://another-example.com/");
|
|
||||||
QCOMPARE(qmlTabObject2->property("index").toInt(), 0);
|
|
||||||
QCOMPARE(qmlTabObject2->property("pinned").toBool(), true);
|
|
||||||
|
|
||||||
bool unpinnedTab = qmlTest.evaluate("Falkon.Tabs.unpinTab({index: 0})").toBool();
|
|
||||||
QVERIFY(unpinnedTab);
|
|
||||||
QObject *qmlTabObject3 = qmlTest.evaluateQObject("Falkon.Tabs.get({index: 0})");
|
|
||||||
QVERIFY(qmlTabObject3);
|
|
||||||
QCOMPARE(qmlTabObject3->property("url").toString(), "https://another-example.com/");
|
|
||||||
QCOMPARE(qmlTabObject3->property("index").toInt(), 0);
|
|
||||||
QCOMPARE(qmlTabObject3->property("pinned").toBool(), false);
|
|
||||||
|
|
||||||
// Next-Previous-Current
|
|
||||||
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.nextTab()");
|
|
||||||
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1);
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.nextTab()");
|
|
||||||
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.previousTab()");
|
|
||||||
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1);
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.previousTab()");
|
|
||||||
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.setCurrentIndex({index: 1})");
|
|
||||||
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 1);
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.setCurrentIndex({index: 0})");
|
|
||||||
QCOMPARE(mApp->getWindow()->tabWidget()->currentIndex(), 0);
|
|
||||||
|
|
||||||
// Move Tab
|
|
||||||
QSignalSpy qmlTabsMovedSpy(qmlTabsObject, SIGNAL(tabMoved(QVariantMap)));
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.moveTab({from: 0, to:1, windowId: 0})");
|
|
||||||
QCOMPARE(qmlTabsMovedSpy.count(), 1);
|
|
||||||
|
|
||||||
// Tab Removal
|
|
||||||
QCOMPARE(mApp->getWindow()->tabCount(), 2);
|
|
||||||
QSignalSpy qmlTabsRemovedSpy(qmlTabsObject, SIGNAL(tabRemoved(QVariantMap)));
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.closeTab({index: 0})");
|
|
||||||
QCOMPARE(qmlTabsRemovedSpy.count(), 1);
|
|
||||||
QCOMPARE(mApp->getWindow()->tabCount(), 1);
|
|
||||||
|
|
||||||
// windowId is different from current window
|
|
||||||
BrowserWindow *otherWindow = mApp->createWindow(Qz::BW_NewWindow);
|
|
||||||
QCOMPARE(otherWindow->tabCount(), 0);
|
|
||||||
qmlTest.evaluate("Falkon.Tabs.addTab({"
|
|
||||||
" url: 'https://example.com/',"
|
|
||||||
" windowId: 1"
|
|
||||||
"})");
|
|
||||||
QCOMPARE(otherWindow->tabCount(), 1);
|
|
||||||
QObject *otherWindowTab = qmlTest.evaluateQObject("Falkon.Tabs.get({index: 0, windowId: 1})");
|
|
||||||
QVERIFY(otherWindowTab);
|
|
||||||
QObject *windowOfOtherWindowTab = qvariant_cast<QObject*>(otherWindowTab->property("browserWindow"));
|
|
||||||
QVERIFY(windowOfOtherWindowTab);
|
|
||||||
QCOMPARE(windowOfOtherWindowTab->property("id").toInt(), mApp->windowIdHash().value(otherWindow));
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlTabsApiTest)
|
|
|
@ -1,32 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class QmlTabsApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testInitWindowCount();
|
|
||||||
void testTabsAPI();
|
|
||||||
};
|
|
|
@ -1,58 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "qml/qmlplugins.h"
|
|
||||||
#include <QQmlComponent>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
QmlTestHelper::QmlTestHelper()
|
|
||||||
{
|
|
||||||
QmlPlugins::registerQmlTypes();
|
|
||||||
|
|
||||||
qmlRegisterType<QmlTestItem>("org.kde.falkon.test", 1, 0, "TestItem");
|
|
||||||
QQmlComponent component(&engine);
|
|
||||||
component.setData("import org.kde.falkon 1.0 as Falkon\n"
|
|
||||||
"import org.kde.falkon.test 1.0 as FalkonTest\n"
|
|
||||||
"import QtQuick 2.7\n"
|
|
||||||
"FalkonTest.TestItem {"
|
|
||||||
" evalFunc: function(source) {"
|
|
||||||
" return eval(source);"
|
|
||||||
" }"
|
|
||||||
"}"
|
|
||||||
, QUrl());
|
|
||||||
testItem = qobject_cast<QmlTestItem*>(component.create());
|
|
||||||
Q_ASSERT(testItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlTestHelper::evaluate(const QString &source)
|
|
||||||
{
|
|
||||||
auto out = testItem->evaluate(source);
|
|
||||||
if (out.isError()) {
|
|
||||||
qWarning() << "Error:" << out.toString();
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QObject *QmlTestHelper::evaluateQObject(const QString &source)
|
|
||||||
{
|
|
||||||
auto out = evaluate(source);
|
|
||||||
if (out.isQObject()) {
|
|
||||||
return out.toQObject();
|
|
||||||
}
|
|
||||||
return out.toVariant().value<QObject*>();
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "qmltestitem.h"
|
|
||||||
#include <QQmlEngine>
|
|
||||||
|
|
||||||
class QmlTestHelper
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit QmlTestHelper();
|
|
||||||
QJSValue evaluate(const QString &source);
|
|
||||||
QObject *evaluateQObject(const QString &source);
|
|
||||||
QQmlEngine engine;
|
|
||||||
QmlTestItem *testItem;
|
|
||||||
};
|
|
|
@ -1,39 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmltestitem.h"
|
|
||||||
|
|
||||||
QmlTestItem::QmlTestItem(QObject *parent) :
|
|
||||||
QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlTestItem::evalFunc()
|
|
||||||
{
|
|
||||||
return m_evalFunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTestItem::setEvalFunc(const QJSValue &func)
|
|
||||||
{
|
|
||||||
m_evalFunc = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJSValue QmlTestItem::evaluate(const QString &source)
|
|
||||||
{
|
|
||||||
Q_ASSERT(m_evalFunc.isCallable());
|
|
||||||
return m_evalFunc.call({source});
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QJSValue>
|
|
||||||
|
|
||||||
class QmlTestItem : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(QJSValue evalFunc READ evalFunc WRITE setEvalFunc)
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit QmlTestItem(QObject *parent = nullptr);
|
|
||||||
QJSValue evalFunc();
|
|
||||||
void setEvalFunc(const QJSValue &func);
|
|
||||||
QJSValue evaluate(const QString &source);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QJSValue m_evalFunc;
|
|
||||||
};
|
|
|
@ -1,45 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmltopsitesapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "pluginproxy.h"
|
|
||||||
#include "speeddial.h"
|
|
||||||
|
|
||||||
void QmlTopSitesApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTopSitesApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlTopSitesApiTest::testTopSites()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
mApp->plugins()->speedDial()->addPage(QUrl("https://example.com"), "Example Domain");
|
|
||||||
auto list = qmlTest.evaluate("Falkon.TopSites.get()").toVariant().toList();
|
|
||||||
QCOMPARE(list.length(), 1);
|
|
||||||
QObject* object = qvariant_cast<QObject*>(list.at(0));
|
|
||||||
QVERIFY(object);
|
|
||||||
QCOMPARE(object->property("title").toString(), "Example Domain");
|
|
||||||
QCOMPARE(object->property("url").toString(), "https://example.com");
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlTopSitesApiTest)
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class QmlTopSitesApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testTopSites();
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmluserscriptapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include <QWebEngineProfile>
|
|
||||||
#include <QWebEngineScript>
|
|
||||||
#include <QWebEngineScriptCollection>
|
|
||||||
#include "qml/api/userscript/qmluserscript.h"
|
|
||||||
#include "qml/api/userscript/qmluserscripts.h"
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::testCount()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
int count = qmlTest.evaluate("Falkon.UserScripts.count").toInt();
|
|
||||||
QCOMPARE(count, mApp->webProfile()->scripts()->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::testSize()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
int size = qmlTest.evaluate("Falkon.UserScripts.size").toInt();
|
|
||||||
QCOMPARE(size, mApp->webProfile()->scripts()->size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::testEmpty()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
bool empty = qmlTest.evaluate("Falkon.UserScripts.empty").toBool();
|
|
||||||
QCOMPARE(empty, mApp->webProfile()->scripts()->isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::testContains()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QWebEngineScript script = mApp->webProfile()->scripts()->toList().at(0);
|
|
||||||
QObject *object = qmlTest.evaluateQObject("Falkon.UserScripts");
|
|
||||||
QmlUserScripts *userScripts = dynamic_cast<QmlUserScripts*>(object);
|
|
||||||
QVERIFY(userScripts);
|
|
||||||
QmlUserScript *userScript = new QmlUserScript();
|
|
||||||
userScript->setWebEngineScript(script);
|
|
||||||
bool contains = userScripts->contains(userScript);
|
|
||||||
QCOMPARE(contains, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::testFind()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QWebEngineScript script = mApp->webProfile()->scripts()->toList().at(0);
|
|
||||||
QObject *object = qmlTest.evaluateQObject("Falkon.UserScripts");
|
|
||||||
QmlUserScripts *userScripts = dynamic_cast<QmlUserScripts*>(object);
|
|
||||||
QVERIFY(userScripts);
|
|
||||||
QObject *scriptFound = userScripts->findScript(script.name());
|
|
||||||
QVERIFY(scriptFound);
|
|
||||||
QCOMPARE(scriptFound->property("name").toString(), script.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScriptApiTest::testInsertRemove()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
int initialCount = qmlTest.evaluate("Falkon.UserScripts.count").toInt();
|
|
||||||
QObject *object = qmlTest.evaluateQObject("Falkon.UserScripts");
|
|
||||||
QmlUserScripts *userScripts = dynamic_cast<QmlUserScripts*>(object);
|
|
||||||
QVERIFY(userScripts);
|
|
||||||
QmlUserScript *userScript = new QmlUserScript();
|
|
||||||
userScript->setProperty("name", "Hello World");
|
|
||||||
userScript->setProperty("sourceCode", "(function() {"
|
|
||||||
" alert('Hello World')"
|
|
||||||
"})()");
|
|
||||||
userScripts->insert(userScript);
|
|
||||||
int finalCount = qmlTest.evaluate("Falkon.UserScripts.count").toInt();
|
|
||||||
QCOMPARE(finalCount, initialCount + 1);
|
|
||||||
|
|
||||||
userScripts->remove(userScript);
|
|
||||||
|
|
||||||
int ultimateCount = qmlTest.evaluate("Falkon.UserScripts.count").toInt();
|
|
||||||
QCOMPARE(ultimateCount, initialCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlUserScriptApiTest)
|
|
|
@ -1,36 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class QmlUserScriptApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testCount();
|
|
||||||
void testSize();
|
|
||||||
void testEmpty();
|
|
||||||
void testContains();
|
|
||||||
void testFind();
|
|
||||||
void testInsertRemove();
|
|
||||||
};
|
|
|
@ -1,69 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "qmlwindowsapitest.h"
|
|
||||||
#include "autotests.h"
|
|
||||||
#include "qmltesthelper.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "qml/api/windows/qmlwindow.h"
|
|
||||||
#include "pluginproxy.h"
|
|
||||||
#include "browserwindow.h"
|
|
||||||
|
|
||||||
void QmlWindowsApiTest::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlWindowsApiTest::cleanupTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlWindowsApiTest::testWindowsAPI()
|
|
||||||
{
|
|
||||||
QmlTestHelper qmlTest;
|
|
||||||
QObject *currentWindowObject = qmlTest.evaluateQObject("Falkon.Windows.getCurrent()");
|
|
||||||
QVERIFY(currentWindowObject);
|
|
||||||
QCOMPARE(currentWindowObject->property("id").toInt(), mApp->windowIdHash().value(mApp->getWindow()));
|
|
||||||
QCOMPARE(currentWindowObject->property("title").toString(), mApp->getWindow()->windowTitle());
|
|
||||||
QCOMPARE(currentWindowObject->property("type").toInt(), (int)mApp->getWindow()->windowType());
|
|
||||||
QCOMPARE(currentWindowObject->property("tabs").toList().length(), mApp->getWindow()->tabCount());
|
|
||||||
|
|
||||||
QObject *windowObject = qmlTest.evaluateQObject("Falkon.Windows");
|
|
||||||
QVERIFY(windowObject);
|
|
||||||
QSignalSpy qmlWindowCreatedSignal(windowObject, SIGNAL(created(QmlWindow*)));
|
|
||||||
qRegisterMetaType<BrowserWindow*>();
|
|
||||||
QSignalSpy windowCreatedSingal(mApp->plugins(), SIGNAL(mainWindowCreated(BrowserWindow*)));
|
|
||||||
QObject *newQmlWindow = qmlTest.evaluateQObject("Falkon.Windows.create({})");
|
|
||||||
QVERIFY(newQmlWindow);
|
|
||||||
QCOMPARE(mApp->windowCount(), 2);
|
|
||||||
// FIXME: signal is emitted 2 times here -
|
|
||||||
// 1st for the initial window, 2nd for the created window
|
|
||||||
QTRY_COMPARE(qmlWindowCreatedSignal.count(), 2);
|
|
||||||
QTRY_COMPARE(windowCreatedSingal.count(), 2);
|
|
||||||
QObject *newQmlSignalWindow = qvariant_cast<QObject*>(qmlWindowCreatedSignal.at(1).at(0));
|
|
||||||
QVERIFY(newQmlSignalWindow);
|
|
||||||
QCOMPARE(newQmlWindow->property("id").toInt(), newQmlSignalWindow->property("id").toInt());
|
|
||||||
|
|
||||||
int qmlWindowCount = qmlTest.evaluate("Falkon.Windows.getAll().length").toInt();
|
|
||||||
QCOMPARE(qmlWindowCount, mApp->windowCount());
|
|
||||||
|
|
||||||
QSignalSpy qmlWindowRemovedSignal(windowObject, SIGNAL(removed(QmlWindow*)));
|
|
||||||
int newQmlWindowId = newQmlSignalWindow->property("id").toInt();
|
|
||||||
qmlTest.evaluate(QString("Falkon.Windows.remove(%1)").arg(newQmlWindowId));
|
|
||||||
QTRY_COMPARE(qmlWindowRemovedSignal.count(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
FALKONTEST_MAIN(QmlWindowsApiTest)
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* Falkon - Qt web browser
|
|
||||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class QmlWindowsApiTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
void testWindowsAPI();
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user