diff options
Diffstat (limited to 'tests/auto/quick/qmltests/data')
-rw-r--r-- | tests/auto/quick/qmltests/data/accepttypes.html | 21 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_download.qml | 106 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_filePicker.qml | 29 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_loadUrl.qml | 2 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_navigationHistory.qml | 7 |
5 files changed, 158 insertions, 7 deletions
diff --git a/tests/auto/quick/qmltests/data/accepttypes.html b/tests/auto/quick/qmltests/data/accepttypes.html new file mode 100644 index 000000000..aff39f96e --- /dev/null +++ b/tests/auto/quick/qmltests/data/accepttypes.html @@ -0,0 +1,21 @@ +<html> +<head> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title>Default title</title> +</head> + +<body> +<input type="file" name="file" id="upfile" accept=""> + +<script> +window.onload = function() { + document.getElementById("upfile").focus(); +} + +function setAcceptType(acceptType) { + document.getElementById("upfile").accept = acceptType; + document.title = acceptType; +} +</script> +</body> +</html> diff --git a/tests/auto/quick/qmltests/data/tst_download.qml b/tests/auto/quick/qmltests/data/tst_download.qml index e049f3621..1b1750dd8 100644 --- a/tests/auto/quick/qmltests/data/tst_download.qml +++ b/tests/auto/quick/qmltests/data/tst_download.qml @@ -30,6 +30,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebEngine 1.10 import Qt.labs.platform 1.0 +import Test.util 1.0 TestWebEngineView { id: webEngineView @@ -51,6 +52,9 @@ TestWebEngineView { property int downloadDirectoryChanged: 0 property int downloadFileNameChanged: 0 property int downloadPathChanged: 0 + property bool setDirectoryFirst: false + + TempDir { id: tempDir } function urlToPath(url) { var path = url.toString() @@ -87,7 +91,7 @@ TestWebEngineView { id: testDownloadProfile onDownloadRequested: { - testDownloadProfile.downloadPath = urlToPath(StandardPaths.writableLocation(StandardPaths.TempLocation)) + testDownloadProfile.downloadPath = tempDir.path() downloadState.push(download.state) downloadItemConnections.target = download if (cancelDownload) { @@ -99,8 +103,15 @@ TestWebEngineView { download.path = testDownloadProfile.downloadPath + downloadedSetPath downloadedPath = download.path } else { - download.downloadDirectory = downloadDirectory.length != 0 ? testDownloadProfile.downloadPath + downloadDirectory : testDownloadProfile.downloadPath - download.downloadFileName = downloadFileName.length != 0 ? downloadFileName : "testfile.zip" + if (setDirectoryFirst && downloadDirectory.length != 0) + download.downloadDirectory = testDownloadProfile.downloadPath + downloadDirectory + + if (downloadFileName.length != 0) + download.downloadFileName = downloadFileName + + if (!setDirectoryFirst && downloadDirectory.length != 0) + download.downloadDirectory = testDownloadProfile.downloadPath + downloadDirectory + downloadedPath = download.downloadDirectory + download.downloadFileName } @@ -133,10 +144,12 @@ TestWebEngineView { downloadFileName = "" downloadedPath = "" downloadedSetPath = "" + setDirectoryFirst = false } function test_downloadRequest() { compare(downLoadRequestedSpy.count, 0) + downloadDirectory = "/test_downloadRequest/"; webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) @@ -148,6 +161,7 @@ TestWebEngineView { function test_totalFileLength() { compare(downLoadRequestedSpy.count, 0) + downloadDirectory = "/test_totalFileLength/"; webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) @@ -159,6 +173,7 @@ TestWebEngineView { function test_downloadSucceeded() { compare(downLoadRequestedSpy.count, 0) + downloadDirectory = "/test_downloadSucceeded/"; webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) @@ -196,11 +211,19 @@ TestWebEngineView { compare(testDownloadProfile.downloadPath, downloadPath); } - function test_downloadToDirectoryWithFileName() { + function test_downloadToDirectoryWithFileName_data() { + return [ + { tag: "setDirectoryFirst", setDirectoryFirst: true }, + { tag: "setFileNameFirst", setDirectoryFirst: false }, + ]; + } + + function test_downloadToDirectoryWithFileName(row) { compare(downLoadRequestedSpy.count, 0); compare(downloadDirectoryChanged, 0); compare(downloadFileNameChanged, 0); - downloadDirectory = "/test/"; + setDirectoryFirst = row.setDirectoryFirst; + downloadDirectory = "/test_downloadToDirectoryWithFileName/"; downloadFileName = "test.zip"; webEngineView.url = Qt.resolvedUrl("download.zip"); downLoadRequestedSpy.wait(); @@ -219,11 +242,82 @@ TestWebEngineView { verify(!downloadInterruptReason); } + function test_downloadToDirectoryWithSuggestedFileName() { + // Download file to a custom download directory with suggested file name. + compare(downLoadRequestedSpy.count, 0); + compare(downloadDirectoryChanged, 0); + compare(downloadFileNameChanged, 0); + downloadDirectory = "/test_downloadToDirectoryWithSuggestedFileName/"; + webEngineView.url = Qt.resolvedUrl("download.zip"); + downLoadRequestedSpy.wait(); + compare(downLoadRequestedSpy.count, 1); + compare(downloadUrl, webEngineView.url); + compare(suggestedFileName, "download.zip"); + compare(downloadState[0], WebEngineDownloadItem.DownloadRequested); + tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadInProgress); + compare(downloadedPath, testDownloadProfile.downloadPath + downloadDirectory + "download.zip"); + compare(downloadDirectoryChanged, 1); + compare(downloadFileNameChanged, 0); + compare(downloadPathChanged, 1); + downloadFinishedSpy.wait(); + compare(totalBytes, receivedBytes); + tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted); + verify(!downloadInterruptReason); + + // Download the same file to another directory with suggested file name. + // The downloadFileNameChanged signal should not be emitted. + downLoadRequestedSpy.clear(); + compare(downLoadRequestedSpy.count, 0); + downloadDirectoryChanged = 0; + downloadFileNameChanged = 0; + downloadPathChanged = 0; + downloadDirectory = "/test_downloadToDirectoryWithSuggestedFileName1/"; + webEngineView.url = Qt.resolvedUrl("download.zip"); + downLoadRequestedSpy.wait(); + compare(downLoadRequestedSpy.count, 1); + compare(downloadUrl, webEngineView.url); + compare(suggestedFileName, "download.zip"); + compare(downloadState[0], WebEngineDownloadItem.DownloadRequested); + tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadInProgress); + compare(downloadedPath, testDownloadProfile.downloadPath + downloadDirectory + "download.zip"); + compare(downloadDirectoryChanged, 1); + compare(downloadFileNameChanged, 0); + compare(downloadPathChanged, 1); + downloadFinishedSpy.wait(); + compare(totalBytes, receivedBytes); + tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted); + verify(!downloadInterruptReason); + + // Download same file to same directory second time -> file name should be unified. + // The downloadFileNameChanged signal should be emitted. + downLoadRequestedSpy.clear(); + compare(downLoadRequestedSpy.count, 0); + downloadDirectoryChanged = 0; + downloadFileNameChanged = 0; + downloadPathChanged = 0; + downloadDirectory = "/test_downloadToDirectoryWithSuggestedFileName1/"; + webEngineView.url = Qt.resolvedUrl("download.zip"); + downLoadRequestedSpy.wait(); + compare(downLoadRequestedSpy.count, 1); + compare(downloadUrl, webEngineView.url); + compare(suggestedFileName, "download.zip"); + compare(downloadState[0], WebEngineDownloadItem.DownloadRequested); + tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadInProgress); + compare(downloadedPath, testDownloadProfile.downloadPath + downloadDirectory + "download (1).zip"); + compare(downloadDirectoryChanged, 1); + compare(downloadFileNameChanged, 1); + compare(downloadPathChanged, 1); + downloadFinishedSpy.wait(); + compare(totalBytes, receivedBytes); + tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted); + verify(!downloadInterruptReason); +} + function test_downloadWithSetPath() { compare(downLoadRequestedSpy.count, 0); compare(downloadDirectoryChanged, 0); compare(downloadFileNameChanged, 0); - downloadedSetPath = "/test/test.zip"; + downloadedSetPath = "/test_downloadWithSetPath/test.zip"; webEngineView.url = Qt.resolvedUrl("download.zip"); downLoadRequestedSpy.wait(); compare(downLoadRequestedSpy.count, 1); diff --git a/tests/auto/quick/qmltests/data/tst_filePicker.qml b/tests/auto/quick/qmltests/data/tst_filePicker.qml index fad81273c..15eadb2a1 100644 --- a/tests/auto/quick/qmltests/data/tst_filePicker.qml +++ b/tests/auto/quick/qmltests/data/tst_filePicker.qml @@ -61,6 +61,7 @@ TestWebEngineView { FilePickerParams.filePickerOpened = false FilePickerParams.selectFiles = false FilePickerParams.selectedFilesUrl = [] + FilePickerParams.nameFilters = [] titleSpy.clear() terminationSpy.clear() } @@ -260,5 +261,33 @@ TestWebEngineView { tryCompare(webEngineView, "title", row.expected); webEngineView.fileDialogRequested.disconnect(acceptedFileHandler); } + + function test_acceptFileTypes_data() { + return [ + { tag: "CustomSuffix", input: ".pug", expected: ".pug", exactMatch: false}, + { tag: "CustomMime", input: "dog/pug", expected: "Accepted types ()", exactMatch: true}, + { tag: "CustomGlob", input: "dog/*", expected: "Accepted types ()", exactMatch: true}, + { tag: "Invalid", input: "---", expected: undefined, exactMatch: true}, + { tag: "Jpeg", input: "image/jpeg", expected: ".jpeg", exactMatch: false} + ]; + } + + function test_acceptFileTypes(row) { + var expectedFileName; + + webEngineView.url = Qt.resolvedUrl("accepttypes.html"); + verify(webEngineView.waitForLoadSucceeded()); + + webEngineView.runJavaScript("setAcceptType('" + row.input + "');"); + tryCompare(webEngineView, "title", row.input); + + keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. + tryCompare(FilePickerParams, "filePickerOpened", true); + + if (row.exactMatch) + compare(FilePickerParams.nameFilters[0], row.expected); + else + verify(FilePickerParams.nameFilters[0].includes(row.expected)); + } } } diff --git a/tests/auto/quick/qmltests/data/tst_loadUrl.qml b/tests/auto/quick/qmltests/data/tst_loadUrl.qml index ec5c965ea..7bdd0c761 100644 --- a/tests/auto/quick/qmltests/data/tst_loadUrl.qml +++ b/tests/auto/quick/qmltests/data/tst_loadUrl.qml @@ -230,7 +230,7 @@ TestWebEngineView { compare(loadRequest.activeUrl, aboutBlank); loadRequest = loadRequestArray[2]; compare(loadRequest.status, WebEngineView.LoadStartedStatus); - compare(loadRequest.activeUrl, aboutBlank); + compare(loadRequest.activeUrl, "data:text/html;charset=UTF-8,load failed"); compare(loadRequest.url, "data:text/html;charset=UTF-8,load failed") loadRequest = loadRequestArray[3]; compare(loadRequest.status, WebEngineView.LoadSucceededStatus); diff --git a/tests/auto/quick/qmltests/data/tst_navigationHistory.qml b/tests/auto/quick/qmltests/data/tst_navigationHistory.qml index 77664e645..6ed232589 100644 --- a/tests/auto/quick/qmltests/data/tst_navigationHistory.qml +++ b/tests/auto/quick/qmltests/data/tst_navigationHistory.qml @@ -134,6 +134,13 @@ TestWebEngineView { compare(forwardItemsList.count, 1) compare(backItemsList.currentItem.text, Qt.resolvedUrl("test1.html")) compare(forwardItemsList.currentItem.text, Qt.resolvedUrl("javascript.html")) + + webEngineView.navigationHistory.clear() + compare(webEngineView.url, Qt.resolvedUrl("test2.html")) + compare(webEngineView.canGoBack, false) + compare(webEngineView.canGoForward, false) + compare(backItemsList.count, 0) + compare(forwardItemsList.count, 0) } } } |