diff options
author | Szabolcs David <davidsz@inf.u-szeged.hu> | 2019-11-19 17:49:19 +0100 |
---|---|---|
committer | Szabolcs David <davidsz@inf.u-szeged.hu> | 2019-11-29 14:34:10 +0100 |
commit | 6f0173c166d6f7a2237a031808a33b0d787acd1c (patch) | |
tree | e0a8661df378661ed97e3bdf1c0e5d05582ddc84 /tests/auto/quick/qmltests/data | |
parent | aca2a6df402d6454c7bbe8b0e9816645fcec8342 (diff) |
Support accept attribute of file input
Set name filters of QFileDialog and QML FileDialog to avoid presenting
all file types.
Task-number: QTBUG-76564
Change-Id: I321214a30bc7e875ad132b015c63282f4eb482bf
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
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_filePicker.qml | 29 |
2 files changed, 50 insertions, 0 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_filePicker.qml b/tests/auto/quick/qmltests/data/tst_filePicker.qml index fad81273c..c9572224e 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: "Accepted types ()", 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)); + } } } |