1 /* ============================================================
2 * Falkon - Qt web browser
3 * Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * ============================================================ */
18 #include "autotests.h"
19 #include "webviewtest.h"
20 #include "webview.h"
21 #include "webpage.h"
22
23 class TestWebView : public WebView
24 {
25 public:
TestWebView()26 explicit TestWebView()
27 : WebView()
28 {
29 }
30
overlayWidget()31 QWidget *overlayWidget() override
32 {
33 return this;
34 }
35
closeView()36 void closeView() override
37 {
38 }
39
loadInNewTab(const LoadRequest & req,Qz::NewTabPositionFlags position)40 void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) override
41 {
42 Q_UNUSED(req)
43 Q_UNUSED(position)
44 }
45
isFullScreen()46 bool isFullScreen() override
47 {
48 return m_fullScreen;
49 }
50
requestFullScreen(bool enable)51 void requestFullScreen(bool enable) override
52 {
53 m_fullScreen = enable;
54 }
55
56 bool m_fullScreen = false;
57 };
58
initTestCase()59 void WebViewTest::initTestCase()
60 {
61 }
62
cleanupTestCase()63 void WebViewTest::cleanupTestCase()
64 {
65 }
66
loadSignalsChangePageTest()67 void WebViewTest::loadSignalsChangePageTest()
68 {
69 TestWebView view;
70 WebPage *page1 = new WebPage;
71 view.setPage(page1);
72
73 QSignalSpy loadStartedSpy(&view, &WebView::loadStarted);
74 QSignalSpy loadFinishedSpy(&view, &WebView::loadFinished);
75
76 view.load(QUrl("qrc:autotests/data/basic_page.html"));
77
78 QTRY_COMPARE(loadStartedSpy.count(), 1);
79 loadStartedSpy.clear();
80
81 WebPage *page2 = new WebPage;
82 view.setPage(page2);
83
84 // WebPage: Workaround for broken load started/finished signals in QtWebEngine 5.10
85 const int loadFinishedEmitCount = qstrncmp(qVersion(), "5.11.", 5) == 0 ? 1 : 2;
86
87 QTRY_COMPARE(loadFinishedSpy.count(), loadFinishedEmitCount);
88 QCOMPARE(loadStartedSpy.count(), 0);
89 loadFinishedSpy.clear();
90
91 QWebEngineView view2;
92 WebPage *page3 = new WebPage;
93 view2.setPage(page3);
94
95 QSignalSpy page3LoadStart(page3, &WebPage::loadStarted);
96 page3->load(QUrl("qrc:autotests/data/basic_page.html"));
97 QVERIFY(page3LoadStart.wait());
98
99 view2.setPage(new QWebEnginePage(&view2));
100 view.setPage(page3);
101
102 QTRY_COMPARE(loadStartedSpy.count(), 1);
103 QCOMPARE(loadFinishedSpy.count(), 0);
104 }
105
106 FALKONTEST_MAIN(WebViewTest)
107