diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-04 07:29:26 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-05 11:35:18 +0200 |
commit | 179463fd2b17343dae291ab6f7617311bcfbdb75 (patch) | |
tree | e32e298ca5d6e2b6e206dab7d42538a6ce68eba1 /tests/auto | |
parent | c8851dd1a77e730bc6a3c17b7c75b1a4c6b41f53 (diff) | |
parent | 336e706cbc839dd7b7c1d461b6b015600b5f009e (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Also blacklist tst_QWebEnginePage::comboBoxPopupPositionAfterChildMove()
and comboBoxPopupPositionAfterMove().
Conflicts:
.qmake.conf
src/3rdparty
src/core/render_widget_host_view_qt.cpp
src/core/resources/resources.gyp
src/webengine/doc/src/qtwebengine-platform-notes.qdoc
src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
tests/auto/widgets/qwebenginepage/BLACKLIST
tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
tools/qmake/mkspecs/features/functions.prf
Task-number: QTBUG-55158
Change-Id: I1d73ac9b3ca5293ad3c7e3a56f4c395da930e6f4
Diffstat (limited to 'tests/auto')
8 files changed, 180 insertions, 66 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_userScripts.qml b/tests/auto/quick/qmltests/data/tst_userScripts.qml index dbad8cd56..92ae71f0b 100644 --- a/tests/auto/quick/qmltests/data/tst_userScripts.qml +++ b/tests/auto/quick/qmltests/data/tst_userScripts.qml @@ -119,19 +119,19 @@ Item { appendDocumentTitleScript.injectionPoint = WebEngineScript.Deferred webEngineView.reload(); webEngineView.waitForLoadSucceeded(); - compare(webEngineView.title, "New title with appendix"); + tryCompare(webEngineView, "title", "New title with appendix"); appendDocumentTitleScript.injectionPoint = WebEngineScript.DocumentReady changeDocumentTitleScript.injectionPoint = WebEngineScript.Deferred webEngineView.reload(); webEngineView.waitForLoadSucceeded(); - compare(webEngineView.title, "New title"); + tryCompare(webEngineView, "title", "New title"); // Make sure we can remove scripts from the preload list. webEngineView.userScripts = [ appendDocumentTitleScript ]; webEngineView.reload(); webEngineView.waitForLoadSucceeded(); - compare(webEngineView.title, "Test page 1 with appendix"); + tryCompare(webEngineView, "title", "Test page 1 with appendix"); changeDocumentTitleScript.injectionPoint = WebEngineScript.DocumentReady } diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index d59fa92e9..904dfac26 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -549,9 +549,10 @@ void tst_QQuickWebEngineView::stopSettingFocusWhenDisabled_data() } class MouseTouchEventRecordingItem : public QQuickItem { + Q_OBJECT public: - explicit MouseTouchEventRecordingItem(QQuickItem *parent = 0) : - QQuickItem(parent), m_eventCounter(0) { + explicit MouseTouchEventRecordingItem(QQuickItem* child, QQuickItem *parent = 0) : + QQuickItem(parent), m_eventCounter(0), m_child(child) { setFlag(ItemHasContents); setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); @@ -571,9 +572,6 @@ public: case QEvent::TouchUpdate: case QEvent::TouchEnd: case QEvent::TouchCancel: - case QEvent::HoverEnter: - case QEvent::HoverMove: - case QEvent::HoverLeave: ++m_eventCounter; event->accept(); return true; @@ -593,16 +591,34 @@ public: return m_eventCounter; } +public Q_SLOTS: + void changeWidth() { + if (m_child) + setWidth(m_child->width()); + } + + void changeHeight() { + if (m_child) + setHeight(m_child->height()); + } + private: int m_eventCounter; + QQuickItem *m_child; }; void tst_QQuickWebEngineView::inputEventForwardingDisabledWhenActiveFocusOnPressDisabled() { QQuickWebEngineView *view = webEngineView(); - MouseTouchEventRecordingItem item; + MouseTouchEventRecordingItem item(view); item.setParentItem(m_window->contentItem()); - item.setSize(QSizeF(640, 480)); + + // Resize the event recorder whenever the view is resized, so that all event positions + // are contained in both of the item regions. + QObject::connect(view, &QQuickItem::widthChanged, &item, + &MouseTouchEventRecordingItem::changeWidth); + QObject::connect(view, &QQuickItem::heightChanged, &item, + &MouseTouchEventRecordingItem::changeHeight); view->setParentItem(&item); view->setSize(QSizeF(640, 480)); m_window->show(); @@ -610,6 +626,7 @@ void tst_QQuickWebEngineView::inputEventForwardingDisabledWhenActiveFocusOnPress // Simulate click and move of mouse, so that last known position in the application // is updated, thus a mouse move event is not generated when we don't expect it. QTest::mouseClick(view->window(), Qt::LeftButton); + QTRY_COMPARE(item.eventCount(), 2); item.clearEventCount(); // First disable view, so it does not receive focus on page load. 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..9900a7345 100644 --- a/tests/auto/widgets/qwebenginepage/BLACKLIST +++ b/tests/auto/widgets/qwebenginepage/BLACKLIST @@ -1,3 +1,9 @@ +[comboBoxPopupPositionAfterMove] +* + +[comboBoxPopupPositionAfterChildMove] +* + [macCopyUnicodeToClipboard] osx diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index de13019d7..d5f651384 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> @@ -115,6 +117,8 @@ private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void thirdPartyCookiePolicy(); + void comboBoxPopupPositionAfterMove(); + void comboBoxPopupPositionAfterChildMove(); void contextMenuCopy(); void contextMenuPopulatedOnce(); void acceptNavigationRequest(); @@ -145,7 +149,6 @@ private Q_SLOTS: void textEditing(); void backActionUpdate(); void protectBindingsRuntimeObjectsFromCollector(); - void localURLSchemes(); void testOptionalJSObjects(); void testLocalStorageVisibility(); void testEnablePersistentStorage(); @@ -242,6 +245,8 @@ private Q_SLOTS: void viewSource(); private: + static QPoint elementCenter(QWebEnginePage *page, const QString &id); + QWebEngineView* m_view; QWebEnginePage* m_page; QWebEngineView* m_inputFieldsTestView; @@ -2474,34 +2479,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) { @@ -2960,31 +2937,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()); } } @@ -3121,6 +3093,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() { @@ -4946,6 +5008,23 @@ 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()); +} + void tst_QWebEnginePage::viewSource() { TestPage page; 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" |