summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2014-10-17 16:01:40 +0200
committerAndras Becsi <andras.becsi@digia.com>2014-10-20 10:21:04 +0200
commitacce17434876082ba46c631109b48e641185ca17 (patch)
tree08520f64ec4a8ce2841a0ceb4d6e6c3851eb5b46 /tests/auto
parent181d8fdf4cb45f31dd1692c5c6ea677eaa697929 (diff)
Implement acceptNavigationRequest for the widgets API.
This is the equivalent API for navigationRequested in QtQuick. This patch also enables and updates tests that depended on this API, and removes the ones that we will not support. Change-Id: I28970c11225420a9680fbd767880130492664179 Reviewed-by: Michael Bruning <michael.bruning@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp166
1 files changed, 48 insertions, 118 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index b6d3f14c5..f0a89d9aa 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -107,11 +107,11 @@ private Q_SLOTS:
void contextMenuCopy();
void contextMenuPopulatedOnce();
void acceptNavigationRequest();
+ void acceptNavigationRequestNavigationType();
void geolocationRequestJS();
void loadFinished();
void actionStates();
void popupFormSubmission();
- void acceptNavigationRequestWithNewWindow();
void userStyleSheet();
void userStyleSheetFromLocalFileUrl();
void userStyleSheetFromQrcUrl();
@@ -133,8 +133,6 @@ private Q_SLOTS:
void textEditing();
void backActionUpdate();
void frameAt();
- void requestCache();
- void loadCachedPage();
void protectBindingsRuntimeObjectsFromCollector();
void localURLSchemes();
void testOptionalJSObjects();
@@ -238,7 +236,6 @@ void tst_QWebEnginePage::cleanupTestCase()
cleanupFiles(); // Be nice
}
-#if defined(QWEBENGINEPAGE_ACCEPTNAVIGATIONREQUEST)
class NavigationRequestOverride : public QWebEnginePage
{
public:
@@ -246,21 +243,18 @@ public:
bool m_acceptNavigationRequest;
protected:
- virtual bool acceptNavigationRequest(QWebEngineFrame* frame, const QNetworkRequest &request, QWebEnginePage::NavigationType type) {
- Q_UNUSED(frame);
- Q_UNUSED(request);
+ virtual bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
+ {
+ Q_UNUSED(url);
Q_UNUSED(type);
+ Q_UNUSED(isMainFrame);
return m_acceptNavigationRequest;
}
};
-#endif
void tst_QWebEnginePage::acceptNavigationRequest()
{
-#if !defined(QWEBENGINEPAGE_ACCEPTNAVIGATIONREQUEST)
- QSKIP("QWEBENGINEPAGE_ACCEPTNAVIGATIONREQUEST");
-#else
QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
NavigationRequestOverride* newPage = new NavigationRequestOverride(m_view, false);
@@ -276,11 +270,10 @@ void tst_QWebEnginePage::acceptNavigationRequest()
evaluateJavaScriptSync(m_view->page(), "tstform.submit();");
QTRY_COMPARE(loadSpy.count(), 2);
- QCOMPARE(m_view->page()->toPlainText(), QString("foo?"));
+ QCOMPARE(toPlainTextSync(m_view->page()), QString("foo?"));
// Restore default page
m_view->setPage(0);
-#endif
}
#if defined(QWEBENGINEPAGE_SETFEATUREPERMISSION)
@@ -437,23 +430,22 @@ public:
connect(this, SIGNAL(geometryChangeRequested(QRect)), this, SLOT(slotGeometryChangeRequested(QRect)));
}
-#if defined(QWEBENGINEPAGE_ACCEPTNAVIGATIONREQUEST)
struct Navigation {
- QWebEngineFrame *frame;
- QNetworkRequest request;
NavigationType type;
+ QUrl url;
+ bool isMainFrame;
};
QList<Navigation> navigations;
- virtual bool acceptNavigationRequest(QWebEngineFrame* frame, const QNetworkRequest &request, NavigationType type) {
+ virtual bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
+ {
Navigation n;
- n.frame = frame;
- n.request = request;
+ n.url = url;
n.type = type;
+ n.isMainFrame = isMainFrame;
navigations.append(n);
return true;
}
-#endif
QList<TestPage*> createdWindows;
virtual QWebEnginePage* createWindow(WebWindowType) {
@@ -469,6 +461,42 @@ private Q_SLOTS:
}
};
+void tst_QWebEnginePage::acceptNavigationRequestNavigationType()
+{
+
+ TestPage page;
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+
+ page.load(QUrl("qrc:///resources/script.html"));
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QTRY_COMPARE(page.navigations.count(), 1);
+
+ page.load(QUrl("qrc:///resources/content.html"));
+ QTRY_COMPARE(loadSpy.count(), 2);
+ QTRY_COMPARE(page.navigations.count(), 2);
+
+ page.triggerAction(QWebEnginePage::Stop);
+ QVERIFY(page.history()->canGoBack());
+ page.triggerAction(QWebEnginePage::Back);
+
+ QTRY_COMPARE(loadSpy.count(), 3);
+ QTRY_COMPARE(page.navigations.count(), 3);
+
+ page.triggerAction(QWebEnginePage::Reload);
+ QTRY_COMPARE(loadSpy.count(), 4);
+ QTRY_COMPARE(page.navigations.count(), 4);
+
+ QList<QWebEnginePage::NavigationType> expectedList;
+ expectedList << QWebEnginePage::NavigationTypeTyped
+ << QWebEnginePage::NavigationTypeTyped
+ << QWebEnginePage::NavigationTypeBackForward
+ << QWebEnginePage::NavigationTypeReload;
+ QVERIFY(expectedList.count() == page.navigations.count());
+ for (int i = 0; i < expectedList.count(); ++i) {
+ QCOMPARE(page.navigations[i].type, expectedList[i]);
+ }
+}
+
void tst_QWebEnginePage::popupFormSubmission()
{
TestPage page;
@@ -489,38 +517,6 @@ void tst_QWebEnginePage::popupFormSubmission()
QVERIFY(url.contains("?foo=bar"));
}
-void tst_QWebEnginePage::acceptNavigationRequestWithNewWindow()
-{
-#if !defined(QWEBENGINESETTINGS)
- QSKIP("QWEBENGINESETTINGS");
-#else
- TestPage* page = new TestPage(m_view);
- page->settings()->setAttribute(QWebEngineSettings::LinksIncludedInFocusChain, true);
- m_page = page;
- m_view->setPage(m_page);
-
- m_view->setUrl(QString("data:text/html,<a href=\"data:text/html,Reached\" target=\"_blank\">Click me</a>"));
- QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
-
- QFocusEvent fe(QEvent::FocusIn);
- m_page->event(&fe);
-
- QVERIFY(m_page->focusNextPrevChild(/*next*/ true));
-
- QKeyEvent keyEnter(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
- m_page->event(&keyEnter);
-
- QCOMPARE(page->navigations.count(), 2);
-
- TestPage::Navigation n = page->navigations.at(1);
- QVERIFY(!n.frame);
- QCOMPARE(n.request.url().toString(), QString("data:text/html,Reached"));
- QVERIFY(n.type == QWebEnginePage::NavigationTypeLinkClicked);
-
- QCOMPARE(page->createdWindows.count(), 1);
-#endif
-}
-
class TestNetworkManager : public QNetworkAccessManager
{
public:
@@ -1604,72 +1600,6 @@ void tst_QWebEnginePage::textEditing()
#endif
}
-void tst_QWebEnginePage::requestCache()
-{
-#if !defined(ACCEPTNAVIGATIONREQUEST)
- QSKIP("ACCEPTNAVIGATIONREQUEST");
-#else
- TestPage page;
- QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
-
- page.setUrl(QString("data:text/html,<a href=\"data:text/html,Reached\" target=\"_blank\">Click me</a>"));
- QTRY_COMPARE(loadSpy.count(), 1);
- QTRY_COMPARE(page.navigations.count(), 1);
-
- page.setUrl(QString("data:text/html,<a href=\"data:text/html,Reached\" target=\"_blank\">Click me2</a>"));
- QTRY_COMPARE(loadSpy.count(), 2);
- QTRY_COMPARE(page.navigations.count(), 2);
-
- page.triggerAction(QWebEnginePage::Stop);
- QVERIFY(page.history()->canGoBack());
- page.triggerAction(QWebEnginePage::Back);
-
- QTRY_COMPARE(loadSpy.count(), 3);
- QTRY_COMPARE(page.navigations.count(), 3);
- QCOMPARE(page.navigations.at(0).request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(),
- (int)QNetworkRequest::PreferNetwork);
- QCOMPARE(page.navigations.at(1).request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(),
- (int)QNetworkRequest::PreferNetwork);
- QCOMPARE(page.navigations.at(2).request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(),
- (int)QNetworkRequest::PreferCache);
-#endif
-}
-
-void tst_QWebEnginePage::loadCachedPage()
-{
-#if !defined(QWEBENGINESETTINGS)
- QSKIP("QWEBENGINESETTINGS");
-#else
- TestPage page;
- QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
- page.settings()->setMaximumPagesInCache(3);
-
- page.load(QUrl("data:text/html,This is first page"));
-
- QTRY_COMPARE(loadSpy.count(), 1);
- QTRY_COMPARE(page.navigations.count(), 1);
-
- QUrl firstPageUrl = page.url();
- page.load(QUrl("data:text/html,This is second page"));
-
- QTRY_COMPARE(loadSpy.count(), 2);
- QTRY_COMPARE(page.navigations.count(), 2);
-
- page.triggerAction(QWebEnginePage::Stop);
- QVERIFY(page.history()->canGoBack());
-
- QSignalSpy urlSpy(&page, SIGNAL(urlChanged(QUrl)));
- QVERIFY(urlSpy.isValid());
-
- page.triggerAction(QWebEnginePage::Back);
- ::waitForSignal(&page, SIGNAL(urlChanged(QUrl)));
- QCOMPARE(urlSpy.size(), 1);
-
- QList<QVariant> arguments1 = urlSpy.takeFirst();
- QCOMPARE(arguments1.at(0).toUrl(), firstPageUrl);
-#endif
-}
-
void tst_QWebEnginePage::backActionUpdate()
{
QWebEngineView view;