diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-03 12:59:23 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-05 11:38:23 +0200 |
commit | 8f160af577e4d979954a63ab56f56e4d0c8ad0f8 (patch) | |
tree | 0c6cf366f3309c96e43e532527aff362320b7e94 /tests/auto/quick/qmltests/data | |
parent | 601003362c75283e9164e997e3835e7c36c6db00 (diff) | |
parent | fcdde728f0c4b4af5159b993e44eb6089d70aa90 (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: Ida702fd5fa05a32d6cd7fc737aa061da74b675a0
Diffstat (limited to 'tests/auto/quick/qmltests/data')
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_download.qml | 17 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_findText.qml | 58 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_loadProgress.qml | 21 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml | 60 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_newViewRequest.qml | 18 |
5 files changed, 100 insertions, 74 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_download.qml b/tests/auto/quick/qmltests/data/tst_download.qml index e4e93b993..019ebd9dc 100644 --- a/tests/auto/quick/qmltests/data/tst_download.qml +++ b/tests/auto/quick/qmltests/data/tst_download.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -28,7 +28,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtWebEngine 1.1 +import QtWebEngine 1.5 TestWebEngineView { id: webEngineView @@ -40,6 +40,7 @@ TestWebEngineView { property int receivedBytes: 0 property bool cancelDownload: false property var downloadState: [] + property var downloadInterruptReason: null SignalSpy { id: downLoadRequestedSpy @@ -55,7 +56,9 @@ TestWebEngineView { Connections { id: downloadItemConnections + ignoreUnknownSignals: true onStateChanged: downloadState.push(target.state) + onInterruptReasonChanged: downloadInterruptReason = target.interruptReason } WebEngineProfile { @@ -88,6 +91,7 @@ TestWebEngineView { cancelDownload = false downloadItemConnections.target = null downloadState = [] + downloadInterruptReason = null } function test_downloadRequest() { @@ -96,6 +100,7 @@ TestWebEngineView { downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) compare(downloadState[0], WebEngineDownloadItem.DownloadRequested) + verify(!downloadInterruptReason) } function test_totalFileLength() { @@ -104,6 +109,7 @@ TestWebEngineView { downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) compare(totalBytes, 325) + verify(!downloadInterruptReason) } function test_downloadSucceeded() { @@ -111,10 +117,12 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) - compare(downloadState[1], WebEngineDownloadItem.DownloadInProgress) + compare(downloadState[0], WebEngineDownloadItem.DownloadRequested) + tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadInProgress) downloadFinishedSpy.wait() compare(totalBytes, receivedBytes) tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted) + verify(!downloadInterruptReason) } function test_downloadCancelled() { @@ -124,7 +132,8 @@ TestWebEngineView { downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) compare(downloadFinishedSpy.count, 1) - compare(downloadState[1], WebEngineDownloadItem.DownloadCancelled) + tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadCancelled) + tryCompare(webEngineView, "downloadInterruptReason", WebEngineDownloadItem.UserCanceled) } } } diff --git a/tests/auto/quick/qmltests/data/tst_findText.qml b/tests/auto/quick/qmltests/data/tst_findText.qml index 78359bfc2..8526012c9 100644 --- a/tests/auto/quick/qmltests/data/tst_findText.qml +++ b/tests/auto/quick/qmltests/data/tst_findText.qml @@ -61,6 +61,32 @@ TestWebEngineView { return bodyInnerHTML; } + function getListItemText(index) { + var listItemText; + runJavaScript("document.getElementById('list').getElementsByTagName('li')[" + index + "].innerText;", function(result) { + listItemText = result; + }); + tryVerify(function() { return listItemText != undefined; }); + return listItemText; + } + + function appendListItem(text) { + var script = + "(function () {" + + " var list = document.getElementById('list');" + + " var item = document.createElement('li');" + + " item.appendChild(document.createTextNode('" + text + "'));" + + " list.appendChild(item);" + + " return list.getElementsByTagName('li').length - 1;" + + "})();"; + var itemIndex; + + runJavaScript(script, function(result) { itemIndex = result; }); + tryVerify(function() { return itemIndex != undefined; }); + // Make sure the DOM is up-to-date. + tryVerify(function() { return getListItemText(itemIndex).length == text.length; }); + } + function test_findText() { var findFlags = WebEngineView.FindCaseSensitively webEngineView.url = Qt.resolvedUrl("test1.html") @@ -157,5 +183,37 @@ TestWebEngineView { tryCompare(webEngineView, "matchCount", 1) verify(!findFailed) } + + function test_findTextInterruptedByLoad() { + var findFlags = 0; + + var listItemText = ''; + for (var i = 0; i < 100000; ++i) + listItemText += "bla "; + listItemText = listItemText.trim(); + + webEngineView.loadHtml( + "<html><body>" + + "<ol id='list' />" + + "</body></html>"); + verify(webEngineView.waitForLoadSucceeded()); + + // Generating a huge list is a workaround to avoid timeout while loading the test page. + for (var i = 0; i < 10; ++i) + appendListItem(listItemText); + appendListItem("hello"); + + webEngineView.clear(); + webEngineView.findText("hello", findFlags, webEngineView.findTextCallback); + + // This should not crash. + webEngineView.url = "https://www.qt.io"; + if (!webEngineView.waitForLoadSucceeded(12000)) + skip("Couldn't load page from network, skipping test."); + + // Can't be sure whether the findText succeeded before the new load. + // Thus don't check the find result just whether the callback was called. + tryVerify(function() { return webEngineView.matchCount != -1; }); + } } } diff --git a/tests/auto/quick/qmltests/data/tst_loadProgress.qml b/tests/auto/quick/qmltests/data/tst_loadProgress.qml index 32cd91418..bb85ed8e3 100644 --- a/tests/auto/quick/qmltests/data/tst_loadProgress.qml +++ b/tests/auto/quick/qmltests/data/tst_loadProgress.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -41,15 +41,31 @@ TestWebEngineView { loadProgressArray.push(webEngineView.loadProgress) } + SignalSpy { + id: spyProgress + target: webEngineView + signalName: "loadProgressChanged" + } + TestCase { name: "WebEngineViewLoadProgress" function test_loadProgress() { compare(webEngineView.loadProgress, 0) + compare(spyProgress.count, 0) loadProgressArray = [] webEngineView.url = Qt.resolvedUrl("test1.html") + // Wait for the first loadProgressChanged signal, which have to be non-negative + spyProgress.wait() + verify(loadProgressArray[0] >= 0) + verify(webEngineView.loadProgress >= 0) + + // Wait for the last loadProgressChanged signal, which have to be 100% verify(webEngineView.waitForLoadSucceeded()) + spyProgress.wait() + compare(loadProgressArray[loadProgressArray.length - 1], 100) + compare(webEngineView.loadProgress, 100) // Test whether the chromium emits progress numbers in ascending order var loadProgressMin = 0 @@ -58,9 +74,6 @@ TestWebEngineView { verify(loadProgressMin <= loadProgress) loadProgressMin = loadProgress } - - // The progress must be 100% at the end - compare(loadProgressArray[loadProgressArray.length - 1], 100) } } } diff --git a/tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml b/tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml deleted file mode 100644 index f05bb1e3d..000000000 --- a/tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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.0 -import QtTest 1.0 -import QtWebEngine 1.2 - -TestWebEngineView { - id: webEngineView - width: 400 - height: 300 - - SignalSpy { - id: spyProgress - target: webEngineView - signalName: "loadProgressChanged" - } - - TestCase { - name: "WebEngineViewLoadProgressSignal" - - function test_loadProgressSignal() { - compare(spyProgress.count, 0) - compare(webEngineView.loadProgress, 0) - webEngineView.url = Qt.resolvedUrl("test1.html") - spyProgress.wait() - verify(webEngineView.loadProgress > -1 && webEngineView.loadProgress < 101) - if (webEngineView.loadProgress > 0 && webEngineView.loadProgress < 100) { - verify(webEngineView.waitForLoadSucceeded()) - spyProgress.wait() - compare(webEngineView.loadProgress, 100) - } - } - } -} diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml index 7a04d5f5b..4becbb620 100644 --- a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml +++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml @@ -28,7 +28,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtWebEngine 1.2 +import QtWebEngine 1.5 TestWebEngineView { id: webEngineView @@ -47,7 +47,8 @@ TestWebEngineView { onNewViewRequested: { newViewRequest = { "destination": request.destination, - "userInitiated": request.userInitiated + "userInitiated": request.userInitiated, + "requestedUrl": request.requestedUrl }; dialog = Qt.createQmlObject( @@ -81,6 +82,8 @@ TestWebEngineView { } function test_jsWindowOpen() { + var url = 'data:text/html,%3Chtml%3E%3Cbody%3ETest+Page%3C%2Fbody%3E%3C%2Fhtml%3E'; + // Open an empty page in a new tab webEngineView.loadHtml( "<html><head><script>" + @@ -95,28 +98,30 @@ TestWebEngineView { verify(dialog.webEngineView.waitForLoadSucceeded()); compare(dialog.webEngineView.url, ""); + compare(newViewRequest.requestedUrl, 'about:blank'); newViewRequestedSpy.clear(); dialog.destroy(); - // Open an empty page in a new dialog + // Open a page in a new dialog webEngineView.loadHtml( "<html><head><script>" + - " function popup() { window.open('', '_blank', 'width=200,height=100'); }" + + " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" + "</script></head>" + "<body onload='popup()'></body></html>"); verify(webEngineView.waitForLoadSucceeded()); tryCompare(newViewRequestedSpy, "count", 1); compare(newViewRequest.destination, WebEngineView.NewViewInDialog); + compare(newViewRequest.requestedUrl, url); verify(!newViewRequest.userInitiated); verify(dialog.webEngineView.waitForLoadSucceeded()); newViewRequestedSpy.clear(); dialog.destroy(); - // Open an empty page in a new dialog by user + // Open a page in a new dialog by user webEngineView.loadHtml( "<html><head><script>" + - " function popup() { window.open('', '_blank', 'width=200,height=100'); }" + + " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" + "</script></head>" + "<body onload=\"document.getElementById('popupButton').focus();\">" + " <button id='popupButton' onclick='popup()'>Pop Up!</button>" + @@ -124,6 +129,7 @@ TestWebEngineView { verify(webEngineView.waitForLoadSucceeded()); verifyElementHasFocus("popupButton"); keyPress(Qt.Key_Enter); + compare(newViewRequest.requestedUrl, url); tryCompare(newViewRequestedSpy, "count", 1); compare(newViewRequest.destination, WebEngineView.NewViewInDialog); |