1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42:10 +02:00

WebTabTest: Add loadNotRestoredTabTest

This commit is contained in:
David Rosca 2018-02-12 22:43:24 +01:00
parent c67a32a845
commit 1ef1455957
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
5 changed files with 51 additions and 0 deletions

View File

@ -30,3 +30,19 @@
Test test; \ Test test; \
return QTest::qExec(&test, argc, argv); \ return QTest::qExec(&test, argc, argv); \
} }
bool waitForLoadfinished(QObject *object)
{
if (qstrcmp(object->metaObject()->className(), "WebTab") == 0) {
QSignalSpy spy(object, SIGNAL(loadingChanged(bool)));
while (spy.wait()) {
if (spy.count() > 0 && spy.at(0).at(0).toBool()) {
return true;
}
spy.clear();
}
return false;
}
qDebug() << "Unsupported object" << object;
return false;
}

View File

@ -1,5 +1,6 @@
<RCC> <RCC>
<qresource prefix="/autotests"> <qresource prefix="/autotests">
<file>data/basic_page.html</file> <file>data/basic_page.html</file>
<file>data/basic_page2.html</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -0,0 +1,8 @@
<html>
<head>
<title> Basic Page 2 </title>
</head>
<body>
<h1>Hello World 2</h1>
</body>
</html>

View File

@ -19,9 +19,12 @@
#include "autotests.h" #include "autotests.h"
#include "webtab.h" #include "webtab.h"
#include "tabwidget.h" #include "tabwidget.h"
#include "tabbedwebview.h"
#include "mainapplication.h" #include "mainapplication.h"
#include "browserwindow.h" #include "browserwindow.h"
#include <QWebEngineHistory>
void WebTabTest::initTestCase() void WebTabTest::initTestCase()
{ {
} }
@ -246,6 +249,28 @@ void WebTabTest::moveTabTest()
tab4->moveTab(5); tab4->moveTab(5);
tab4->moveTab(6); tab4->moveTab(6);
QCOMPARE(movedSpy.count(), 0); QCOMPARE(movedSpy.count(), 0);
delete w;
}
void WebTabTest::loadNotRestoredTabTest()
{
WebTab tab;
tab.load(QUrl("qrc:autotests/data/basic_page.html"));
QVERIFY(waitForLoadfinished(&tab));
QTRY_COMPARE(tab.webView()->history()->count(), 1);
tab.unload();
QVERIFY(!tab.isRestored());
tab.load(QUrl("qrc:autotests/data/basic_page2.html"));
QVERIFY(waitForLoadfinished(&tab));
QTRY_COMPARE(tab.webView()->history()->count(), 2);
QCOMPARE(tab.url(), QUrl("qrc:autotests/data/basic_page2.html"));
QCOMPARE(tab.webView()->history()->currentItem().url(), QUrl("qrc:autotests/data/basic_page2.html"));
QCOMPARE(tab.webView()->history()->backItem().url(), QUrl("qrc:autotests/data/basic_page.html"));
} }
FALKONTEST_MAIN(WebTabTest) FALKONTEST_MAIN(WebTabTest)

View File

@ -31,4 +31,5 @@ private slots:
void parentChildTabsTest(); void parentChildTabsTest();
void prependChildTabsTest(); void prependChildTabsTest();
void moveTabTest(); void moveTabTest();
void loadNotRestoredTabTest();
}; };