diff --git a/autotests/autotests.h b/autotests/autotests.h index 149ee5e41..ca4d21a31 100644 --- a/autotests/autotests.h +++ b/autotests/autotests.h @@ -30,3 +30,19 @@ Test test; \ 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; +} diff --git a/autotests/autotests.qrc b/autotests/autotests.qrc index 55a721dc7..20cbc5a25 100644 --- a/autotests/autotests.qrc +++ b/autotests/autotests.qrc @@ -1,5 +1,6 @@ data/basic_page.html + data/basic_page2.html diff --git a/autotests/data/basic_page2.html b/autotests/data/basic_page2.html new file mode 100644 index 000000000..23397436e --- /dev/null +++ b/autotests/data/basic_page2.html @@ -0,0 +1,8 @@ + + + Basic Page 2 + + +

Hello World 2

+ + diff --git a/autotests/webtabtest.cpp b/autotests/webtabtest.cpp index 7845995ca..63dc1b083 100644 --- a/autotests/webtabtest.cpp +++ b/autotests/webtabtest.cpp @@ -19,9 +19,12 @@ #include "autotests.h" #include "webtab.h" #include "tabwidget.h" +#include "tabbedwebview.h" #include "mainapplication.h" #include "browserwindow.h" +#include + void WebTabTest::initTestCase() { } @@ -246,6 +249,28 @@ void WebTabTest::moveTabTest() tab4->moveTab(5); tab4->moveTab(6); 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) diff --git a/autotests/webtabtest.h b/autotests/webtabtest.h index 5054f5cbc..721945439 100644 --- a/autotests/webtabtest.h +++ b/autotests/webtabtest.h @@ -31,4 +31,5 @@ private slots: void parentChildTabsTest(); void prependChildTabsTest(); void moveTabTest(); + void loadNotRestoredTabTest(); };