Falkon Develop
Cross-platform Qt-based web browser
webviewtest.cpp
Go to the documentation of this file.
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
23class TestWebView : public WebView
24{
25public:
26 explicit TestWebView()
27 : WebView()
28 {
29 }
30
31 QWidget *overlayWidget() override
32 {
33 return this;
34 }
35
36 void closeView() override
37 {
38 }
39
40 void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) override
41 {
42 Q_UNUSED(req)
43 Q_UNUSED(position)
44 }
45
46 bool isFullScreen() override
47 {
48 return m_fullScreen;
49 }
50
51 void requestFullScreen(bool enable) override
52 {
53 m_fullScreen = enable;
54 }
55
56 bool m_fullScreen = false;
57};
58
59void WebViewTest::initTestCase()
60{
61}
62
63void WebViewTest::cleanupTestCase()
64{
65}
66
67void WebViewTest::loadSignalsChangePageTest()
68{
69 TestWebView view;
70 auto *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(QSL("qrc:autotests/data/basic_page.html")));
77
78 QTRY_COMPARE(loadStartedSpy.count(), 1);
79 loadStartedSpy.clear();
80
81 auto *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 auto *page3 = new WebPage;
93 view2.setPage(page3);
94
95 QSignalSpy page3LoadStart(page3, &WebPage::loadStarted);
96 page3->load(QUrl(QSL("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
#define FALKONTEST_MAIN(Test)
Definition: autotests.h:23
bool m_fullScreen
Definition: webviewtest.cpp:56
void requestFullScreen(bool enable) override
Definition: webviewtest.cpp:51
void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) override
Definition: webviewtest.cpp:40
QWidget * overlayWidget() override
Definition: webviewtest.cpp:31
bool isFullScreen() override
Definition: webviewtest.cpp:46
void closeView() override
Definition: webviewtest.cpp:36
void setPage(WebPage *page)
Definition: webview.cpp:137
void load(const QUrl &url)
Definition: webview.cpp:177
#define QSL(x)
Definition: qzcommon.h:40