Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma Mobile
Angelfish
Commits
80e3c718
Verified
Commit
80e3c718
authored
Oct 22, 2019
by
Jonah Brüchert
Browse files
Add more tests
parent
1f3e2b51
Changes
5
Hide whitespace changes
Inline
Side-by-side
autotests/CMakeLists.txt
View file @
80e3c718
...
...
@@ -6,4 +6,15 @@ include_directories(../src)
ecm_add_test
(
urlmodeltest.cpp ../src/urlmodel.cpp
TEST_NAME urlmodeltest
LINK_LIBRARIES Qt5::Test
)
LINK_LIBRARIES Qt5::Test
)
ecm_add_test
(
useragenttest.cpp ../src/useragent.cpp
TEST_NAME useragenttest
LINK_LIBRARIES Qt5::Test
)
ecm_add_test
(
browsermanagertest.cpp ../src/browsermanager.cpp ../src/urlmodel.cpp
TEST_NAME browsermanagertest
LINK_LIBRARIES Qt5::Test Qt5::Qml
)
autotests/browsermanagertest.cpp
0 → 100644
View file @
80e3c718
/*
* Copyright 2019 Jonah Brüchert <jbb@kaidan.im>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation;
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include
<QtTest/QTest>
#include
<QSignalSpy>
#include
<QUrl>
#include
"browsermanager.h"
using
namespace
AngelFish
;
class
UserAgentTest
:
public
QObject
{
Q_OBJECT
private
Q_SLOTS
:
void
initTestCase
()
{
m_browserManager
=
new
BrowserManager
();
}
void
cleanupTestCase
()
{
delete
m_browserManager
;
}
void
homepage
()
{
const
QString
newHomepage
=
QStringLiteral
(
"https://kde.org"
);
m_browserManager
->
setHomepage
(
newHomepage
);
QCOMPARE
(
m_browserManager
->
homepage
(),
newHomepage
);
}
void
searchEngine
()
{
const
QString
newSearchEngineUrl
=
QStringLiteral
(
"https://search.angelfish.kde?q="
);
m_browserManager
->
setSearchBaseUrl
(
newSearchEngineUrl
);
QCOMPARE
(
m_browserManager
->
searchBaseUrl
(),
newSearchEngineUrl
);
}
void
urlFromUserInput
()
{
const
QString
incompleteUrl
=
QStringLiteral
(
"kde.org"
);
const
QString
completeUrl
=
QStringLiteral
(
"http://kde.org"
);
QCOMPARE
(
m_browserManager
->
urlFromUserInput
(
incompleteUrl
),
completeUrl
);
}
private:
BrowserManager
*
m_browserManager
;
};
QTEST_MAIN
(
UserAgentTest
);
#include
"browsermanagertest.moc"
autotests/urlmodeltest.cpp
View file @
80e3c718
...
...
@@ -232,7 +232,7 @@ private Q_SLOTS:
QVERIFY
(
model
->
rowCount
(
QModelIndex
()));
compare
(
readFile
(
file1
),
model
);
}
;
}
void
testAdd
()
{
...
...
autotests/useragenttest.cpp
0 → 100644
View file @
80e3c718
/*
* Copyright 2019 Jonah Brüchert <jbb@kaidan.im>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation;
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include
<QtTest/QTest>
#include
<QSignalSpy>
#include
<QtWebEngine/QtWebEngineVersion>
#include
"useragent.h"
class
UserAgentTest
:
public
QObject
{
Q_OBJECT
private
Q_SLOTS
:
void
initTestCase
()
{
m_userAgent
=
new
UserAgent
();
}
void
cleanupTestCase
()
{
delete
m_userAgent
;
}
void
desktopUserAgent
()
{
m_userAgent
->
setIsMobile
(
false
);
const
QString
expectedString
=
QString
(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/%1 Chrome/75.0.3770.116 Desktop Safari/537.36"
)
.
arg
(
QTWEBENGINE_VERSION_STR
);
QCOMPARE
(
m_userAgent
->
userAgent
(),
expectedString
);
}
void
userAgentChanged
()
{
QSignalSpy
spy
(
m_userAgent
,
&
UserAgent
::
userAgentChanged
);
m_userAgent
->
setIsMobile
(
true
);
QCOMPARE
(
spy
.
count
(),
1
);
}
void
mobileUserAgent
()
{
m_userAgent
->
setIsMobile
(
true
);
const
QString
expectedString
=
QString
(
"Mozilla/5.0 (Linux; Plasma Mobile, like Android 9.0) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/%1 Chrome/75.0.3770.116 Mobile Safari/537.36"
)
.
arg
(
QTWEBENGINE_VERSION_STR
);
QCOMPARE
(
m_userAgent
->
userAgent
(),
expectedString
);
}
void
setIsMobile
()
{
QSignalSpy
spy
(
m_userAgent
,
&
UserAgent
::
isMobileChanged
);
m_userAgent
->
setIsMobile
(
false
);
QCOMPARE
(
spy
.
count
(),
1
);
m_userAgent
->
setIsMobile
(
true
);
QCOMPARE
(
spy
.
count
(),
2
);
}
void
isMobile
()
{
m_userAgent
->
setIsMobile
(
false
);
QCOMPARE
(
m_userAgent
->
isMobile
(),
false
);
m_userAgent
->
setIsMobile
(
true
);
QCOMPARE
(
m_userAgent
->
isMobile
(),
true
);
}
private:
UserAgent
*
m_userAgent
;
};
QTEST_MAIN
(
UserAgentTest
);
#include
"useragenttest.moc"
src/useragent.cpp
View file @
80e3c718
#include
"useragent.h"
#include
<QtWebEngine/
qtw
eb
e
ngine
v
ersion
.h
>
#include
<QtWebEngine/
QtW
eb
E
ngine
V
ersion>
#include
<QtWebEngine/QQuickWebEngineProfile>
UserAgent
::
UserAgent
(
QObject
*
parent
)
:
QObject
(
parent
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment