From 3395426ab651a631aca8ee6b0a694a71df19100f Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Thu, 3 Oct 2019 22:48:16 +0300 Subject: Import QtWebKit commit 49b749171e786df3adcd7a755df428c1846acd69 Change-Id: I4c82d8030969d941bb78b1cc4e77c0a66db8da2c Reviewed-by: Konstantin Tokarev --- Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp | 1599 -------------------- 1 file changed, 1599 deletions(-) delete mode 100644 Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp (limited to 'Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp') diff --git a/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp b/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp deleted file mode 100644 index 2068eec3f..000000000 --- a/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp +++ /dev/null @@ -1,1599 +0,0 @@ -/* - Copyright (C) 2008,2009 Nokia Corporation and/or its subsidiary(-ies) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef QT_NO_OPENSSL -#include -#endif -#include "../util.h" - -class tst_QWebFrame : public QObject -{ - Q_OBJECT - -public: - bool eventFilter(QObject* watched, QEvent* event); - -public Q_SLOTS: - void init(); - void cleanup(); - -private Q_SLOTS: - void horizontalScrollAfterBack(); - void symmetricUrl(); - void progressSignal(); - void urlChange(); - void requestedUrl(); - void requestedUrlAfterSetAndLoadFailures(); - void javaScriptWindowObjectCleared_data(); - void javaScriptWindowObjectCleared(); - void javaScriptWindowObjectClearedOnEvaluate(); - void setHtml(); - void setHtmlWithImageResource(); - void setHtmlWithStylesheetResource(); - void setHtmlWithBaseURL(); - void setHtmlWithJSAlert(); - void ipv6HostEncoding(); - void metaData(); -#if !defined(QT_NO_COMBOBOX) - void popupFocus(); -#endif - void inputFieldFocus(); - void hitTestContent(); - void baseUrl_data(); - void baseUrl(); - void hasSetFocus(); - void renderGeometry(); - void renderHints(); - void scrollPosition(); - void scrollToAnchor(); - void scrollbarsOff(); - void evaluateWillCauseRepaint(); - void setContent_data(); - void setContent(); - void setCacheLoadControlAttribute(); - void setUrlWithPendingLoads(); - void setUrlWithFragment_data(); - void setUrlWithFragment(); - void setUrlToEmpty(); - void setUrlToInvalid(); - void setUrlHistory(); - void setUrlUsingStateObject(); - void setUrlSameUrl(); - void setUrlThenLoads_data(); - void setUrlThenLoads(); - void loadFinishedAfterNotFoundError(); - void signalsDuringErrorHandling(); - void loadInSignalHandlers_data(); - void loadInSignalHandlers(); - -private: - QWebView* m_view { nullptr }; - QWebPage* m_page { nullptr }; - QWebView* m_inputFieldsTestView { nullptr }; - int m_inputFieldTestPaintCount { 0 }; -}; - -bool tst_QWebFrame::eventFilter(QObject* watched, QEvent* event) -{ - // used on the inputFieldFocus test - if (watched == m_inputFieldsTestView) { - if (event->type() == QEvent::Paint) - m_inputFieldTestPaintCount++; - } - return QObject::eventFilter(watched, event); -} - -void tst_QWebFrame::init() -{ - m_view = new QWebView(); - m_page = m_view->page(); -} - -void tst_QWebFrame::cleanup() -{ - delete m_view; -} - -void tst_QWebFrame::symmetricUrl() -{ - QVERIFY(m_view->url().isEmpty()); - - QCOMPARE(m_view->history()->count(), 0); - - QUrl dataUrl("data:text/html,

Test"); - - m_view->setUrl(dataUrl); - QCOMPARE(m_view->url(), dataUrl); - QCOMPARE(m_view->history()->count(), 0); - - // loading is _not_ immediate, so the text isn't set just yet. - QVERIFY(m_view->page()->mainFrame()->toPlainText().isEmpty()); - - ::waitForSignal(m_view, SIGNAL(loadFinished(bool))); - - QCOMPARE(m_view->history()->count(), 1); - QCOMPARE(m_view->page()->mainFrame()->toPlainText(), QString("Test")); - - QUrl dataUrl2("data:text/html,

Test2"); - QUrl dataUrl3("data:text/html,

Test3"); - - m_view->setUrl(dataUrl2); - m_view->setUrl(dataUrl3); - - QCOMPARE(m_view->url(), dataUrl3); - - ::waitForSignal(m_view, SIGNAL(loadFinished(bool))); - - QCOMPARE(m_view->history()->count(), 2); - - QCOMPARE(m_view->page()->mainFrame()->toPlainText(), QString("Test3")); -} - -void tst_QWebFrame::progressSignal() -{ - QSignalSpy progressSpy(m_view, SIGNAL(loadProgress(int))); - - QUrl dataUrl("data:text/html,

Test"); - m_view->setUrl(dataUrl); - - ::waitForSignal(m_view, SIGNAL(loadFinished(bool))); - - QVERIFY(progressSpy.size() >= 1); - QCOMPARE(progressSpy.last().first().toInt(), 100); -} - -void tst_QWebFrame::urlChange() -{ - QSignalSpy urlSpy(m_page->mainFrame(), SIGNAL(urlChanged(QUrl))); - - QUrl dataUrl("data:text/html,

Test"); - m_view->setUrl(dataUrl); - - ::waitForSignal(m_page->mainFrame(), SIGNAL(urlChanged(QUrl))); - - QCOMPARE(urlSpy.size(), 1); - - QUrl dataUrl2("data:text/html,title

Test"); - m_view->setUrl(dataUrl2); - - ::waitForSignal(m_page->mainFrame(), SIGNAL(urlChanged(QUrl))); - - QCOMPARE(urlSpy.size(), 2); -} - -class FakeReply : public QNetworkReply { - Q_OBJECT - -public: - static const QUrl urlFor404ErrorWithoutContents; - - FakeReply(const QNetworkRequest& request, QObject* parent = 0) - : QNetworkReply(parent) - { - setOperation(QNetworkAccessManager::GetOperation); - setRequest(request); - setUrl(request.url()); - if (request.url() == QUrl("qrc:/test1.html")) { - setHeader(QNetworkRequest::LocationHeader, QString("qrc:/test2.html")); - setAttribute(QNetworkRequest::RedirectionTargetAttribute, QUrl("qrc:/test2.html")); - QTimer::singleShot(0, this, SLOT(continueRedirect())); - } -#ifndef QT_NO_OPENSSL - else if (request.url() == QUrl("qrc:/fake-ssl-error.html")) { - setError(QNetworkReply::SslHandshakeFailedError, tr("Fake error!")); - QTimer::singleShot(0, this, SLOT(continueError())); - } -#endif - else if (request.url().host() == QLatin1String("abcdef.abcdef")) { - setError(QNetworkReply::HostNotFoundError, tr("Invalid URL")); - QTimer::singleShot(0, this, SLOT(continueError())); - } else if (request.url() == FakeReply::urlFor404ErrorWithoutContents) { - setError(QNetworkReply::ContentNotFoundError, "Not found"); - setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 404); - QTimer::singleShot(0, this, SLOT(continueError())); - } - - open(QIODevice::ReadOnly); - } - ~FakeReply() - { - close(); - } - virtual void abort() {} - virtual void close() {} - -protected: - qint64 readData(char*, qint64) - { - return 0; - } - -private Q_SLOTS: - void continueRedirect() - { - emit metaDataChanged(); - emit finished(); - } - - void continueError() - { - emit error(this->error()); - emit finished(); - } -}; - -const QUrl FakeReply::urlFor404ErrorWithoutContents = QUrl("http://this.will/return-http-404-error-without-contents.html"); - -class FakeNetworkManager : public QNetworkAccessManager { - Q_OBJECT - -public: - FakeNetworkManager(QObject* parent) : QNetworkAccessManager(parent) { } - -protected: - virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest& request, QIODevice* outgoingData) - { - QString url = request.url().toString(); - if (op == QNetworkAccessManager::GetOperation) { -#ifndef QT_NO_OPENSSL - if (url == "qrc:/fake-ssl-error.html") { - FakeReply* reply = new FakeReply(request, this); - QList errors; - emit sslErrors(reply, errors << QSslError(QSslError::UnspecifiedError)); - return reply; - } -#endif - if (url == "qrc:/test1.html" || url == "http://abcdef.abcdef/" || request.url() == FakeReply::urlFor404ErrorWithoutContents) - return new FakeReply(request, this); - } - - return QNetworkAccessManager::createRequest(op, request, outgoingData); - } -}; - -void tst_QWebFrame::requestedUrl() -{ - QWebPage page; - QWebFrame* frame = page.mainFrame(); - - // in few seconds, the image should be completely loaded - QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); - FakeNetworkManager* networkManager = new FakeNetworkManager(&page); - page.setNetworkAccessManager(networkManager); - - frame->setUrl(QUrl("qrc:/test1.html")); - waitForSignal(frame, SIGNAL(loadFinished(bool)), 200); - QCOMPARE(spy.count(), 1); - QCOMPARE(frame->requestedUrl(), QUrl("qrc:/test1.html")); - QCOMPARE(frame->url(), QUrl("qrc:/test2.html")); - - frame->setUrl(QUrl("qrc:/non-existent.html")); - waitForSignal(frame, SIGNAL(loadFinished(bool)), 200); - QCOMPARE(spy.count(), 2); - QCOMPARE(frame->requestedUrl(), QUrl("qrc:/non-existent.html")); - QCOMPARE(frame->url(), QUrl("qrc:/non-existent.html")); - - frame->setUrl(QUrl("http://abcdef.abcdef")); - waitForSignal(frame, SIGNAL(loadFinished(bool)), 200); - QCOMPARE(spy.count(), 3); - QCOMPARE(frame->requestedUrl(), QUrl("http://abcdef.abcdef/")); - QCOMPARE(frame->url(), QUrl("http://abcdef.abcdef/")); - -#ifndef QT_NO_OPENSSL - qRegisterMetaType >("QList"); - qRegisterMetaType("QNetworkReply*"); - - QSignalSpy spy2(page.networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*,QList))); - frame->setUrl(QUrl("qrc:/fake-ssl-error.html")); - waitForSignal(frame, SIGNAL(loadFinished(bool)), 200); - QCOMPARE(spy2.count(), 1); - QCOMPARE(frame->requestedUrl(), QUrl("qrc:/fake-ssl-error.html")); - QCOMPARE(frame->url(), QUrl("qrc:/fake-ssl-error.html")); -#endif -} - -void tst_QWebFrame::requestedUrlAfterSetAndLoadFailures() -{ - QWebPage page; - QWebFrame* frame = page.mainFrame(); - - QSignalSpy spy(frame, SIGNAL(loadFinished(bool))); - - const QUrl first("http://abcdef.abcdef/"); - frame->setUrl(first); - ::waitForSignal(frame, SIGNAL(loadFinished(bool))); - QCOMPARE(frame->url(), first); - QCOMPARE(frame->requestedUrl(), first); - QVERIFY(!spy.at(0).first().toBool()); - - const QUrl second("http://abcdef.abcdef/another_page.html"); - QVERIFY(first != second); - - page.settings()->setAttribute(QWebSettings::ErrorPageEnabled, false); - - frame->load(second); - ::waitForSignal(frame, SIGNAL(loadFinished(bool))); - QCOMPARE(frame->url(), first); - QCOMPARE(frame->requestedUrl(), second); - QVERIFY(!spy.at(1).first().toBool()); - - page.settings()->setAttribute(QWebSettings::ErrorPageEnabled, true); - - frame->load(second); - ::waitForSignal(frame, SIGNAL(loadFinished(bool))); - QCOMPARE(frame->url(), second); - QCOMPARE(frame->requestedUrl(), second); - QVERIFY(!spy.at(2).first().toBool()); -} - -void tst_QWebFrame::javaScriptWindowObjectCleared_data() -{ - QTest::addColumn("html"); - QTest::addColumn("signalCount"); - QTest::newRow("with

hello world

" << 1; - // NOTE: Empty scripts no longer cause this signal to be emitted. - QTest::newRow("with empty

hello world

" << 0; - QTest::newRow("without

hello world

"); - MyPage page; - m_view->setPage(&page); - page.mainFrame()->setHtml(html); - QCOMPARE(page.alerts, 1); - QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=118663", Continue); - QCOMPARE(m_view->page()->mainFrame()->toHtml(), html); -} - -class TestNetworkManager : public QNetworkAccessManager -{ -public: - TestNetworkManager(QObject* parent) : QNetworkAccessManager(parent) {} - - QList requestedUrls; - -protected: - virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest &request, QIODevice* outgoingData) { - requestedUrls.append(request.url()); - QNetworkRequest redirectedRequest = request; - redirectedRequest.setUrl(QUrl("data:text/html,

hello")); - return QNetworkAccessManager::createRequest(op, redirectedRequest, outgoingData); - } -}; - -void tst_QWebFrame::ipv6HostEncoding() -{ - TestNetworkManager* networkManager = new TestNetworkManager(m_page); - m_page->setNetworkAccessManager(networkManager); - networkManager->requestedUrls.clear(); - - QUrl baseUrl = QUrl::fromEncoded("http://[::1]/index.html"); - m_view->setHtml("

Hi", baseUrl); - m_view->page()->mainFrame()->evaluateJavaScript("var r = new XMLHttpRequest();" - "r.open('GET', 'http://[::1]/test.xml', false);" - "r.send(null);" - ); - QCOMPARE(networkManager->requestedUrls.count(), 1); - QCOMPARE(networkManager->requestedUrls.at(0), QUrl::fromEncoded("http://[::1]/test.xml")); -} - -void tst_QWebFrame::metaData() -{ - m_view->setHtml("" - " " - " " - " " - " " - ""); - - QMultiMap metaData = m_view->page()->mainFrame()->metaData(); - - QCOMPARE(metaData.count(), 2); - - QCOMPARE(metaData.value("description"), QString("Test description")); - QCOMPARE(metaData.value("keywords"), QString("HTML, JavaScript, Css")); - QCOMPARE(metaData.value("nonexistant"), QString()); - - m_view->setHtml("" - " " - " " - " " - " " - ""); - - metaData = m_view->page()->mainFrame()->metaData(); - - QCOMPARE(metaData.count(), 2); - - QStringList values = metaData.values("samekey"); - QCOMPARE(values.count(), 2); - - QVERIFY(values.contains("FirstValue")); - QVERIFY(values.contains("SecondValue")); - - QCOMPARE(metaData.value("nonexistant"), QString()); -} - -#if !defined(QT_NO_COMBOBOX) -void tst_QWebFrame::popupFocus() -{ - QWebView view; - view.setHtml("" - " " - " " - " " - " " - " " - ""); - view.resize(400, 100); - // Call setFocus before show to work around http://bugreports.qt.nokia.com/browse/QTBUG-14762 - view.setFocus(); - view.show(); - QTest::qWaitForWindowExposed(&view); - view.activateWindow(); - QTRY_VERIFY(view.hasFocus()); - - // open the popup by clicking. check if focus is on the popup - const QWebElement webCombo = view.page()->mainFrame()->documentElement().findFirst(QLatin1String("select[name=select]")); - QTest::mouseClick(&view, Qt::LeftButton, 0, webCombo.geometry().center()); - - QComboBox* combo = view.findChild(); - QVERIFY(combo != 0); - QTRY_VERIFY(!view.hasFocus() && combo->view()->hasFocus()); // Focus should be on the popup - - // hide the popup and check if focus is on the page - combo->hidePopup(); - QTRY_VERIFY(view.hasFocus()); // Focus should be back on the WebView -} -#endif - -void tst_QWebFrame::inputFieldFocus() -{ - QWebView view; - view.setHtml(""); - view.resize(400, 100); - view.show(); - QTest::qWaitForWindowExposed(&view); - view.activateWindow(); - view.setFocus(); - QTRY_VERIFY(view.hasFocus()); - - // double the flashing time, should at least blink once already - int delay = qApp->cursorFlashTime() * 2; - - // focus the lineedit and check if it blinks - bool autoSipEnabled = qApp->autoSipEnabled(); - qApp->setAutoSipEnabled(false); - const QWebElement inputElement = view.page()->mainFrame()->documentElement().findFirst(QLatin1String("input[type=text]")); - QTest::mouseClick(&view, Qt::LeftButton, 0, inputElement.geometry().center()); - m_inputFieldsTestView = &view; - view.installEventFilter( this ); - QTest::qWait(delay); - QVERIFY2(m_inputFieldTestPaintCount >= 3, - "The input field should have a blinking caret"); - qApp->setAutoSipEnabled(autoSipEnabled); -} - -void tst_QWebFrame::hitTestContent() -{ - QString html("

A paragraph




link text"); - - QWebPage page; - QWebFrame* frame = page.mainFrame(); - frame->setHtml(html); - page.setViewportSize(QSize(200, 0)); //no height so link is not visible - const QWebElement linkElement = frame->documentElement().findFirst(QLatin1String("a#link")); - QWebHitTestResult result = frame->hitTestContent(linkElement.geometry().center()); - QCOMPARE(result.linkText(), QString("link text")); - QWebElement link = result.linkElement(); - QCOMPARE(link.attribute("target"), QString("_foo")); - QCOMPARE(result.element().tagName(), QString("A")); -} - -void tst_QWebFrame::baseUrl_data() -{ - QTest::addColumn("html"); - QTest::addColumn("loadUrl"); - QTest::addColumn("url"); - QTest::addColumn("baseUrl"); - - QTest::newRow("null") << QString() << QUrl() - << QUrl("about:blank") << QUrl("about:blank"); - - QTest::newRow("foo") << QString() << QUrl("http://foobar.baz/") - << QUrl("http://foobar.baz/") << QUrl("http://foobar.baz/"); - - QString html = "" - "" - "" - "" - ""; - QTest::newRow("customBaseUrl") << html << QUrl("http://foobar.baz/") - << QUrl("http://foobar.baz/") << QUrl("http://foobaz.bar/"); -} - -void tst_QWebFrame::baseUrl() -{ - QFETCH(QString, html); - QFETCH(QUrl, loadUrl); - QFETCH(QUrl, url); - QFETCH(QUrl, baseUrl); - - m_page->mainFrame()->setHtml(html, loadUrl); - QCOMPARE(m_page->mainFrame()->url(), url); - QCOMPARE(m_page->mainFrame()->baseUrl(), baseUrl); -} - -void tst_QWebFrame::hasSetFocus() -{ - QString html("

top

" \ - "