diff options
author | Valentin Fokin <fokinv@inf.u-szeged.hu> | 2018-05-30 14:46:15 +0200 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2018-08-02 14:17:17 +0000 |
commit | 1481e8d87fe89d9e27d9de593767b55a0e84a31f (patch) | |
tree | 7ff04c22c4c880ec8d0951255772ce8b2c49bf3a /tests/auto | |
parent | 6a5f8d69fc1d090326fa92a0b24bd494369c2d0d (diff) |
Introduce WebEngineAction in Quick API
Also implement QQuickWebEngineView::action() method similar to the Widget API
to access the WebEngineActions.
[ChangeLog][QtWebEngine] Introduce WebEngineAction in Quick API
Task-number: QTBUG-56117
Change-Id: I758cd4703db4c111c1ed9187e091d4c845486c46
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/publicapi/tst_publicapi.cpp | 10 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_action.qml | 131 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_contextMenu.qml | 5 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_viewSource.qml | 9 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/qmltests.pro | 1 |
5 files changed, 150 insertions, 6 deletions
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index aa65509c3..d8c1bd80c 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -38,6 +38,7 @@ #include <QtWebEngineCore/QWebEngineQuotaRequest> #include <QtWebEngineCore/QWebEngineRegisterProtocolHandlerRequest> #include <private/qquickwebengineview_p.h> +#include <private/qquickwebengineaction_p.h> #include <private/qquickwebenginecertificateerror_p.h> #include <private/qquickwebenginedialogrequests_p.h> #include <private/qquickwebenginedownloaditem_p.h> @@ -57,6 +58,7 @@ private Q_SLOTS: static const QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *>() << &QQuickWebEngineView::staticMetaObject + << &QQuickWebEngineAction::staticMetaObject << &QQuickWebEngineCertificateError::staticMetaObject << &QQuickWebEngineDownloadItem::staticMetaObject << &QQuickWebEngineHistory::staticMetaObject @@ -93,6 +95,13 @@ static const QStringList hardcodedTypes = QStringList() ; static const QStringList expectedAPI = QStringList() + << "QQuickWebEngineAction.text --> QString" + << "QQuickWebEngineAction.iconText --> QString" + << "QQuickWebEngineAction.enabled --> bool" + << "QQuickWebEngineAction.toggled() --> void" + << "QQuickWebEngineAction.triggered() --> void" + << "QQuickWebEngineAction.enabledChanged(bool) --> void" + << "QQuickWebEngineAction.trigger() --> void" << "QQuickWebEngineAuthenticationDialogRequest.AuthenticationTypeHTTP --> AuthenticationType" << "QQuickWebEngineAuthenticationDialogRequest.AuthenticationTypeProxy --> AuthenticationType" << "QQuickWebEngineAuthenticationDialogRequest.accepted --> bool" @@ -380,6 +389,7 @@ static const QStringList expectedAPI = QStringList() << "QQuickWebEngineSettings.webRTCPublicInterfacesOnlyChanged() --> void" << "QQuickWebEngineSingleton.defaultProfile --> QQuickWebEngineProfile*" << "QQuickWebEngineSingleton.settings --> QQuickWebEngineSettings*" + << "QQuickWebEngineView.action(WebAction) --> QQuickWebEngineAction*" << "QQuickWebEngineView.A0 --> PrintedPageSizeId" << "QQuickWebEngineView.A1 --> PrintedPageSizeId" << "QQuickWebEngineView.A10 --> PrintedPageSizeId" diff --git a/tests/auto/quick/qmltests/data/tst_action.qml b/tests/auto/quick/qmltests/data/tst_action.qml new file mode 100644 index 000000000..b27e7d821 --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_action.qml @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtWebEngine 1.8 + +TestWebEngineView { + id: webEngineView + width: 400 + height: 400 + + Component { + id: signalSpy + SignalSpy { } + } + + TestCase { + id: actionTests + name: "WebEngineAction" + when: windowShown + + function test_actions_data() { + return [ + { webAction: WebEngineView.Back, text: "Back", iconText: "go-previous", enabled: false }, + { webAction: WebEngineView.Forward, text: "Forward", iconText: "go-next", enabled: false }, + { webAction: WebEngineView.Stop, text: "Stop", iconText: "", enabled: false }, + { webAction: WebEngineView.Reload, text: "Reload", iconText: "view-refresh", enabled: true }, + { webAction: WebEngineView.Cut, text: "Cut", iconText: "Cut", enabled: true }, + { webAction: WebEngineView.Copy, text: "Copy", iconText: "", enabled: true }, + { webAction: WebEngineView.Paste, text: "Paste", iconText: "", enabled: true }, + { webAction: WebEngineView.Undo, text: "Undo", iconText: "", enabled: true }, + { webAction: WebEngineView.Redo, text: "Redo", iconText: "", enabled: true }, + { webAction: WebEngineView.SelectAll, text: "Select all", iconText: "", enabled: true }, + { webAction: WebEngineView.ReloadAndBypassCache, text: "Reload and Bypass Cache", iconText: "", enabled: true }, + { webAction: WebEngineView.PasteAndMatchStyle, text: "Paste and match style", iconText: "", enabled: true }, + { webAction: WebEngineView.OpenLinkInThisWindow, text: "Open link in this window", iconText: "", enabled: true }, + { webAction: WebEngineView.OpenLinkInNewWindow, text: "Open link in new window", iconText: "", enabled: true }, + { webAction: WebEngineView.OpenLinkInNewTab, text: "Open link in new tab", iconText: "", enabled: true }, + { webAction: WebEngineView.CopyLinkToClipboard, text: "Copy link address", iconText: "", enabled: true }, + { webAction: WebEngineView.DownloadLinkToDisk, text: "Save link", iconText: "", enabled: true }, + { webAction: WebEngineView.CopyImageToClipboard, text: "Copy image", iconText: "", enabled: true }, + { webAction: WebEngineView.CopyImageUrlToClipboard, text: "Copy image address", iconText: "", enabled: true }, + { webAction: WebEngineView.DownloadImageToDisk, text: "Save image", iconText: "", enabled: true }, + { webAction: WebEngineView.CopyMediaUrlToClipboard, text: "Copy media address", iconText: "", enabled: true }, + { webAction: WebEngineView.ToggleMediaControls, text: "Show controls", iconText: "", enabled: true }, + { webAction: WebEngineView.ToggleMediaLoop, text: "Loop", iconText: "", enabled: true }, + { webAction: WebEngineView.ToggleMediaPlayPause, text: "Toggle Play/Pause", iconText: "", enabled: true }, + { webAction: WebEngineView.ToggleMediaMute, text: "Toggle Mute", iconText: "", enabled: true }, + { webAction: WebEngineView.DownloadMediaToDisk, text: "Save media", iconText: "", enabled: true }, + { webAction: WebEngineView.InspectElement, text: "Inspect", iconText: "", enabled: true }, + { webAction: WebEngineView.ExitFullScreen, text: "Exit full screen", iconText: "", enabled: true }, + { webAction: WebEngineView.RequestClose, text: "Close Page", iconText: "", enabled: true }, + { webAction: WebEngineView.Unselect, text: "Unselect", iconText: "", enabled: true }, + { webAction: WebEngineView.SavePage, text: "Save page", iconText: "", enabled: true }, + { webAction: WebEngineView.ViewSource, text: "View page source", iconText: "view-source", enabled: true }, + { webAction: WebEngineView.ToggleBold, text: "&Bold", iconText: "", enabled: true }, + { webAction: WebEngineView.ToggleItalic, text: "&Italic", iconText: "", enabled: true }, + { webAction: WebEngineView.ToggleUnderline, text: "&Underline", iconText: "", enabled: true }, + { webAction: WebEngineView.ToggleStrikethrough, text: "&Strikethrough", iconText: "", enabled: true }, + { webAction: WebEngineView.AlignLeft, text: "Align &Left", iconText: "", enabled: true }, + { webAction: WebEngineView.AlignCenter, text: "Align &Center", iconText: "", enabled: true }, + { webAction: WebEngineView.AlignRight, text: "Align &Right", iconText: "", enabled: true }, + { webAction: WebEngineView.AlignJustified, text: "Align &Justified", iconText: "", enabled: true }, + { webAction: WebEngineView.Indent, text: "&Indent", iconText: "", enabled: true }, + { webAction: WebEngineView.Outdent, text: "&Outdent", iconText: "", enabled: true }, + { webAction: WebEngineView.InsertOrderedList, text: "Insert &Ordered List", iconText: "", enabled: true }, + { webAction: WebEngineView.InsertUnorderedList, text: "Insert &Unordered List", iconText: "", enabled: true } + ]; + } + + function test_actions(row) { + webEngineView.url = Qt.resolvedUrl("test1.html"); + verify(webEngineView.waitForLoadSucceeded()); + + var action = webEngineView.action(row.webAction); + verify(action); + + compare(action.text, row.text); + compare(action.iconText, row.iconText); + compare(action.enabled, row.enabled); + } + + function test_trigger() { + webEngineView.url = Qt.resolvedUrl("test1.html"); + verify(webEngineView.waitForLoadSucceeded()); + + var copyAction = webEngineView.action(WebEngineView.Copy); + verify(copyAction); + + var stopAction = webEngineView.action(WebEngineView.Stop); + verify(stopAction); + + var triggerSpy = createTemporaryObject(signalSpy, actionTests, {target: copyAction, signalName: "triggered"}); + var stopTriggerSpy = createTemporaryObject(signalSpy, actionTests, {target: stopAction, signalName: "triggered"}); + + verify(copyAction.enabled); + copyAction.trigger(); + compare(triggerSpy.count, 1); + + verify(!stopAction.enabled); + stopAction.trigger(); + compare(stopTriggerSpy.count, 0); + } + } +} diff --git a/tests/auto/quick/qmltests/data/tst_contextMenu.qml b/tests/auto/quick/qmltests/data/tst_contextMenu.qml index 4b6ba2bee..99450a159 100644 --- a/tests/auto/quick/qmltests/data/tst_contextMenu.qml +++ b/tests/auto/quick/qmltests/data/tst_contextMenu.qml @@ -144,6 +144,11 @@ TestWebEngineView { compare(mediaType, ContextMenuRequest.MediaTypeNone); compare(selectedText, ""); + verify(webEngineView.action(WebEngineView.OpenLinkInNewTab).enabled); + verify(webEngineView.action(WebEngineView.OpenLinkInNewWindow).enabled); + verify(webEngineView.action(WebEngineView.DownloadLinkToDisk).enabled); + verify(webEngineView.action(WebEngineView.CopyLinkToClipboard).enabled); + contextMenuRequestedSpy.clear(); // FIXME: Sometimes the keyPress(Qt.Key_Escape) event isn't caught so we keep trying tryVerify(destroyContextMenu); diff --git a/tests/auto/quick/qmltests/data/tst_viewSource.qml b/tests/auto/quick/qmltests/data/tst_viewSource.qml index b21d72eb2..4966a052a 100644 --- a/tests/auto/quick/qmltests/data/tst_viewSource.qml +++ b/tests/auto/quick/qmltests/data/tst_viewSource.qml @@ -77,8 +77,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("test1.html"); verify(webEngineView.waitForLoadSucceeded()); tryCompare(webEngineView, "title", "Test page 1"); - // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117 - //verify(webEngineView.canViewSource, true); + verify(webEngineView.action(WebEngineView.ViewSource).enabled); titleChangedSpy.clear(); webEngineView.triggerWebAction(WebEngineView.ViewSource); @@ -89,8 +88,7 @@ TestWebEngineView { compare(viewRequest.destination, WebEngineView.NewViewInTab); verify(viewRequest.userInitiated); - // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117 - //verify(!webEngineView.canViewSource); + verify(!webEngineView.action(WebEngineView.ViewSource).enabled); tryCompare(webEngineView, "title", "test1.html"); compare(webEngineView.url, "view-source:" + Qt.resolvedUrl("test1.html")); @@ -123,8 +121,7 @@ TestWebEngineView { compare(webEngineView.url, row.url); tryCompare(webEngineView, "title", row.title); - // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117 - //verify(!webEngineView.canViewSource); + verify(!webEngineView.action(WebEngineView.ViewSource).enabled); } function test_viewSourceCredentials() { diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro index 5395da0b5..a2b05e091 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -42,6 +42,7 @@ OTHER_FILES += \ $$PWD/data/keyboardModifierMapping.html \ $$PWD/data/keyboardEvents.html \ $$PWD/data/titleupdate.js \ + $$PWD/data/tst_action.qml \ $$PWD/data/tst_activeFocusOnPress.qml \ $$PWD/data/tst_contextMenu.qml \ $$PWD/data/tst_desktopBehaviorLoadHtml.qml \ |