diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-07-29 14:09:05 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-08-02 12:00:57 +0200 |
commit | 1a49f193afe1ba54339182a49d891917159f6719 (patch) | |
tree | 986cf277193c625c2f61015c7f29c6b403a5eb02 /tests | |
parent | 47d6b5ce11d1014548ba69df5d7b698381a8343e (diff) | |
parent | fa138d4a76e9e820f01a75771c30dbced8c4e6f3 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
src/3rdparty
src/core/resources/resources.gyp
src/webengine/doc/src/qtwebengine-overview.qdoc
src/webenginewidgets/api/qwebenginepage.cpp
src/webenginewidgets/api/qwebenginescriptcollection.cpp
src/webenginewidgets/api/qwebenginescriptcollection_p.h
tests/auto/widgets/qwebenginepage/BLACKLIST
And readded newly in 5.6 enabled tests to the BLACKLIST.
Change-Id: I4ab1fc54ebfaaf940df81b0d8d6bdd15cae8b7c4
Diffstat (limited to 'tests')
6 files changed, 150 insertions, 56 deletions
diff --git a/tests/auto/quick/qquickwebengineviewgraphics/BLACKLIST b/tests/auto/quick/qquickwebengineviewgraphics/BLACKLIST new file mode 100644 index 000000000..9ec23eb6d --- /dev/null +++ b/tests/auto/quick/qquickwebengineviewgraphics/BLACKLIST @@ -0,0 +1,2 @@ +[showHideShow] +* diff --git a/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp b/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp index 606f5af9c..2b9742b99 100644 --- a/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp +++ b/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp @@ -79,9 +79,7 @@ private Q_SLOTS: private: void setHtml(const QString &html); QScopedPointer<TestView> m_view; -#ifdef ENABLE_QML_TESTSUPPORT_API QScopedPointer<QQuickWebEngineTestSupport> m_testSupport; -#endif }; static const QString greenSquare("<div style=\"background-color: #00ff00; position:absolute; left:50px; top: 50px; width: 50px; height: 50px;\"></div>"); @@ -112,9 +110,7 @@ tst_QQuickWebEngineViewGraphics::~tst_QQuickWebEngineViewGraphics() void tst_QQuickWebEngineViewGraphics::initTestCase() { QtWebEngine::initialize(); -#ifdef ENABLE_QML_TESTSUPPORT_API m_testSupport.reset(new QQuickWebEngineTestSupport); -#endif } void tst_QQuickWebEngineViewGraphics::init() @@ -191,9 +187,7 @@ void tst_QQuickWebEngineViewGraphics::setHtml(const QString &html) QQuickWebEngineView *webEngineView = static_cast<QQuickWebEngineView *>(m_view->rootObject()); webEngineView->setProperty("url", QUrl(QStringLiteral("data:text/html,%1").arg(htmlData))); -#ifdef ENABLE_QML_TESTSUPPORT_API webEngineView->setTestSupport(m_testSupport.data()); -#endif QVERIFY(waitForViewportReady(webEngineView)); QCOMPARE(m_view->rootObject()->property("loading"), QVariant(false)); } diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index b278808f6..d220348ab 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -4,7 +4,10 @@ SUBDIRS += \ inspectorserver \ publicapi \ qquickwebenginedefaultsurfaceformat \ - qquickwebengineview \ - qquickwebengineviewgraphics + qquickwebengineview -isQMLTestSupportApiEnabled(): SUBDIRS += qmltests +isQMLTestSupportApiEnabled() { + SUBDIRS += \ + qmltests \ + qquickwebengineviewgraphics +} diff --git a/tests/auto/widgets/qwebenginepage/BLACKLIST b/tests/auto/widgets/qwebenginepage/BLACKLIST index 507fb7dbd..d435fadca 100644 --- a/tests/auto/widgets/qwebenginepage/BLACKLIST +++ b/tests/auto/widgets/qwebenginepage/BLACKLIST @@ -1,3 +1,6 @@ +[comboBoxPopupPositionAfterMove] +linux + [macCopyUnicodeToClipboard] osx diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 2f7bfb39f..a8730ce0d 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -24,10 +24,12 @@ #include <QClipboard> #include <QDir> #include <QGraphicsWidget> +#include <QHBoxLayout> #include <QLineEdit> #include <QMainWindow> #include <QMenu> #include <QMimeDatabase> +#include <QOpenGLWidget> #include <QPaintEngine> #include <QPushButton> #include <QStateMachine> @@ -114,6 +116,8 @@ private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void thirdPartyCookiePolicy(); + void comboBoxPopupPositionAfterMove(); + void comboBoxPopupPositionAfterChildMove(); void contextMenuCopy(); void contextMenuPopulatedOnce(); void acceptNavigationRequest(); @@ -144,7 +148,6 @@ private Q_SLOTS: void textEditing(); void backActionUpdate(); void protectBindingsRuntimeObjectsFromCollector(); - void localURLSchemes(); void testOptionalJSObjects(); void testLocalStorageVisibility(); void testEnablePersistentStorage(); @@ -241,6 +244,8 @@ private Q_SLOTS: void printToPdf(); private: + static QPoint elementCenter(QWebEnginePage *page, const QString &id); + QWebEngineView* m_view; QWebEnginePage* m_page; QWebEngineView* m_inputFieldsTestView; @@ -2467,34 +2472,6 @@ void tst_QWebEnginePage::protectBindingsRuntimeObjectsFromCollector() #endif } -void tst_QWebEnginePage::localURLSchemes() -{ -#if !defined(QWEBENGINESECURITYORIGIN) - QSKIP("QWEBENGINESECURITYORIGIN"); -#else - int i = QWebEngineSecurityOrigin::localSchemes().size(); - - QWebEngineSecurityOrigin::removeLocalScheme("file"); - QTRY_COMPARE(QWebEngineSecurityOrigin::localSchemes().size(), i); - QWebEngineSecurityOrigin::addLocalScheme("file"); - QTRY_COMPARE(QWebEngineSecurityOrigin::localSchemes().size(), i); - - QWebEngineSecurityOrigin::removeLocalScheme("qrc"); - QTRY_COMPARE(QWebEngineSecurityOrigin::localSchemes().size(), i - 1); - QWebEngineSecurityOrigin::addLocalScheme("qrc"); - QTRY_COMPARE(QWebEngineSecurityOrigin::localSchemes().size(), i); - - QString myscheme = "myscheme"; - QWebEngineSecurityOrigin::addLocalScheme(myscheme); - QTRY_COMPARE(QWebEngineSecurityOrigin::localSchemes().size(), i + 1); - QVERIFY(QWebEngineSecurityOrigin::localSchemes().contains(myscheme)); - QWebEngineSecurityOrigin::removeLocalScheme(myscheme); - QTRY_COMPARE(QWebEngineSecurityOrigin::localSchemes().size(), i); - QWebEngineSecurityOrigin::removeLocalScheme(myscheme); - QTRY_COMPARE(QWebEngineSecurityOrigin::localSchemes().size(), i); -#endif -} - #if defined(QWEBENGINEPAGE_SETTINGS) static inline bool testFlag(QWebEnginePage& webPage, QWebEngineSettings::WebAttribute settingAttribute, const QString& jsObjectName, bool settingValue) { @@ -2977,31 +2954,26 @@ void tst_QWebEnginePage::findText() QSignalSpy loadSpy(m_page, SIGNAL(loadFinished(bool))); m_page->setHtml(QString("<html><head></head><body><div>foo bar</div></body></html>")); QTRY_COMPARE(loadSpy.count(), 1); + + // Select whole page contents. m_page->triggerAction(QWebEnginePage::SelectAll); QTRY_COMPARE(m_page->hasSelection(), true); -#if defined(QWEBENGINEPAGE_SELECTEDHTML) - QVERIFY(!m_page->selectedHtml().isEmpty()); -#endif + + // Invoke a stopFinding() operation, which should clear the currently selected text. m_page->findText(""); - QEXPECT_FAIL("", "Unsupported: findText only highlights and doesn't update the selection.", Continue); - QVERIFY(m_page->selectedText().isEmpty()); -#if defined(QWEBENGINEPAGE_SELECTEDHTML) - QVERIFY(m_page->selectedHtml().isEmpty()); -#endif + QTRY_VERIFY(m_page->selectedText().isEmpty()); + QStringList words = (QStringList() << "foo" << "bar"); foreach (QString subString, words) { + // Invoke a find operation, which should clear the currently selected text, should + // highlight all the found ocurrences, but should not update the selected text to the + // searched for string. m_page->findText(subString); - QEXPECT_FAIL("", "Unsupported: findText only highlights and doesn't update the selection.", Continue); - QCOMPARE(m_page->selectedText(), subString); -#if defined(QWEBENGINEPAGE_SELECTEDHTML) - QVERIFY(m_page->selectedHtml().contains(subString)); -#endif + QTRY_VERIFY(m_page->selectedText().isEmpty()); + + // Search highlights should be cleared, selected text should still be empty. m_page->findText(""); - QEXPECT_FAIL("", "Unsupported: findText only highlights and doesn't update the selection.", Continue); - QVERIFY(m_page->selectedText().isEmpty()); -#if defined(QWEBENGINEPAGE_SELECTEDHTML) - QVERIFY(m_page->selectedHtml().isEmpty()); -#endif + QTRY_VERIFY(m_page->selectedText().isEmpty()); } } @@ -3154,6 +3126,96 @@ void tst_QWebEnginePage::thirdPartyCookiePolicy() #endif } +static QWindow *findNewTopLevelWindow(const QWindowList &oldTopLevelWindows) +{ + const auto tlws = QGuiApplication::topLevelWindows(); + for (auto w : tlws) { + if (!oldTopLevelWindows.contains(w)) { + return w; + } + } + return nullptr; +} + +void tst_QWebEnginePage::comboBoxPopupPositionAfterMove() +{ + QScreen *screen = QGuiApplication::primaryScreen(); + QWebEngineView view; + view.move(screen->availableGeometry().topLeft()); + view.resize(640, 480); + view.show(); + + QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool))); + view.setHtml(QLatin1String("<html><head></head><body><select id='foo'>" + "<option>fran</option><option>troz</option>" + "</select></body></html>")); + QTRY_COMPARE(loadSpy.count(), 1); + const auto oldTlws = QGuiApplication::topLevelWindows(); + QWindow *window = view.windowHandle(); + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), + elementCenter(view.page(), "foo")); + + QWindow *popup = nullptr; + QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws)); + QPoint popupPos = popup->position(); + + // Close the popup by clicking somewhere into the page. + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(1, 1)); + QTRY_VERIFY(!QGuiApplication::topLevelWindows().contains(popup)); + + // Move the top-level QWebEngineView a little and check the popup's position. + const QPoint offset(12, 13); + view.move(screen->availableGeometry().topLeft() + offset); + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), + elementCenter(view.page(), "foo")); + QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws)); + QCOMPARE(popupPos + offset, popup->position()); +} + +void tst_QWebEnginePage::comboBoxPopupPositionAfterChildMove() +{ + QWidget mainWidget; + mainWidget.setLayout(new QHBoxLayout); + + QWidget spacer; + spacer.setMinimumWidth(50); + mainWidget.layout()->addWidget(&spacer); + + QWebEngineView view; + mainWidget.layout()->addWidget(&view); + + QScreen *screen = QGuiApplication::primaryScreen(); + mainWidget.move(screen->availableGeometry().topLeft()); + mainWidget.resize(640, 480); + mainWidget.show(); + + QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool))); + view.setHtml(QLatin1String("<html><head></head><body><select autofocus id='foo'>" + "<option value=\"narf\">narf</option><option>zort</option>" + "</select></body></html>")); + QTRY_COMPARE(loadSpy.count(), 1); + const auto oldTlws = QGuiApplication::topLevelWindows(); + QWindow *window = view.window()->windowHandle(); + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), + view.mapTo(view.window(), elementCenter(view.page(), "foo"))); + + QWindow *popup = nullptr; + QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws)); + QPoint popupPos = popup->position(); + + // Close the popup by clicking somewhere into the page. + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), + view.mapTo(view.window(), QPoint(1, 1))); + QTRY_VERIFY(!QGuiApplication::topLevelWindows().contains(popup)); + + // Resize the "spacer" widget, and implicitly change the global position of the QWebEngineView. + spacer.setMinimumWidth(100); + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), + view.mapTo(view.window(), elementCenter(view.page(), "foo"))); + QTRY_VERIFY(popup = findNewTopLevelWindow(oldTlws)); + QCOMPARE(popupPos + QPoint(50, 0), popup->position()); +} + #ifdef Q_OS_MAC void tst_QWebEnginePage::macCopyUnicodeToClipboard() { @@ -4927,5 +4989,22 @@ void tst_QWebEnginePage::mouseButtonTranslation() delete view; } +QPoint tst_QWebEnginePage::elementCenter(QWebEnginePage *page, const QString &id) +{ + QVariantList rectList = evaluateJavaScriptSync(page, + "(function(){" + "var elem = document.getElementById('" + id + "');" + "var rect = elem.getBoundingClientRect();" + "return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];" + "})()").toList(); + + if (rectList.count() != 2) { + qWarning("elementCenter failed."); + return QPoint(); + } + + return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt()); +} + QTEST_MAIN(tst_QWebEnginePage) #include "tst_qwebenginepage.moc" diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index a399f5565..579a0f776 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -35,6 +35,7 @@ #include <QtWebEngineWidgets/qwebenginepage.h> #include <QtWebEngineWidgets/qwebenginesettings.h> #include <QtWebEngineWidgets/qwebengineview.h> +#include <QtWebEngineWidgets/qwebenginedownloaditem.h> class tst_QWebEngineProfile : public QObject { @@ -50,6 +51,7 @@ private Q_SLOTS: void urlSchemeHandlerFailOnRead(); void customUserAgent(); void httpAcceptLanguage(); + void downloadItem(); }; void tst_QWebEngineProfile::defaultProfile() @@ -362,5 +364,16 @@ void tst_QWebEngineProfile::httpAcceptLanguage() QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.languages")).toStringList(), QStringList(testLang)); } +void tst_QWebEngineProfile::downloadItem() +{ + qRegisterMetaType<QWebEngineDownloadItem *>(); + QWebEngineProfile testProfile; + QWebEnginePage page(&testProfile); + QSignalSpy downloadSpy(&testProfile, SIGNAL(downloadRequested(QWebEngineDownloadItem *))); + connect(&testProfile, &QWebEngineProfile::downloadRequested, this, [=] (QWebEngineDownloadItem *item) { item->accept(); }); + page.load(QUrl::fromLocalFile(QCoreApplication::applicationFilePath())); + QTRY_COMPARE(downloadSpy.count(), 1); +} + QTEST_MAIN(tst_QWebEngineProfile) #include "tst_qwebengineprofile.moc" |