File indexing completed on 2024-04-21 04:55:39
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "autotests.h" 0019 #include "webviewtest.h" 0020 #include "webview.h" 0021 #include "webpage.h" 0022 0023 class TestWebView : public WebView 0024 { 0025 public: 0026 explicit TestWebView() 0027 : WebView() 0028 { 0029 } 0030 0031 QWidget *overlayWidget() override 0032 { 0033 return this; 0034 } 0035 0036 void closeView() override 0037 { 0038 } 0039 0040 void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) override 0041 { 0042 Q_UNUSED(req) 0043 Q_UNUSED(position) 0044 } 0045 0046 bool isFullScreen() override 0047 { 0048 return m_fullScreen; 0049 } 0050 0051 void requestFullScreen(bool enable) override 0052 { 0053 m_fullScreen = enable; 0054 } 0055 0056 bool m_fullScreen = false; 0057 }; 0058 0059 void WebViewTest::initTestCase() 0060 { 0061 } 0062 0063 void WebViewTest::cleanupTestCase() 0064 { 0065 } 0066 0067 void WebViewTest::loadSignalsChangePageTest() 0068 { 0069 TestWebView view; 0070 auto *page1 = new WebPage; 0071 view.setPage(page1); 0072 0073 QSignalSpy loadStartedSpy(&view, &WebView::loadStarted); 0074 QSignalSpy loadFinishedSpy(&view, &WebView::loadFinished); 0075 0076 view.load(QUrl(QSL("qrc:autotests/data/basic_page.html"))); 0077 0078 QTRY_COMPARE(loadStartedSpy.count(), 1); 0079 loadStartedSpy.clear(); 0080 0081 auto *page2 = new WebPage; 0082 view.setPage(page2); 0083 0084 // WebPage: Workaround for broken load started/finished signals in QtWebEngine 5.10 0085 const int loadFinishedEmitCount = qstrncmp(qVersion(), "5.11.", 5) == 0 ? 1 : 2; 0086 0087 QTRY_COMPARE(loadFinishedSpy.count(), loadFinishedEmitCount); 0088 QCOMPARE(loadStartedSpy.count(), 0); 0089 loadFinishedSpy.clear(); 0090 0091 QWebEngineView view2; 0092 auto *page3 = new WebPage; 0093 view2.setPage(page3); 0094 0095 QSignalSpy page3LoadStart(page3, &WebPage::loadStarted); 0096 page3->load(QUrl(QSL("qrc:autotests/data/basic_page.html"))); 0097 QVERIFY(page3LoadStart.wait()); 0098 0099 view2.setPage(new QWebEnginePage(&view2)); 0100 view.setPage(page3); 0101 0102 QTRY_COMPARE(loadStartedSpy.count(), 1); 0103 QCOMPARE(loadFinishedSpy.count(), 0); 0104 } 0105 0106 FALKONTEST_MAIN(WebViewTest)