summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2019-11-19 17:49:19 +0100
committerSzabolcs David <davidsz@inf.u-szeged.hu>2019-11-29 14:34:10 +0100
commit6f0173c166d6f7a2237a031808a33b0d787acd1c (patch)
treee0a8661df378661ed97e3bdf1c0e5d05582ddc84 /tests/auto
parentaca2a6df402d6454c7bbe8b0e9816645fcec8342 (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')
-rw-r--r--tests/auto/quick/qmltests/data/accepttypes.html21
-rw-r--r--tests/auto/quick/qmltests/data/tst_filePicker.qml29
-rw-r--r--tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/FilePicker.qml2
-rw-r--r--tests/auto/quick/qmltests/mock-delegates/TestParams/FilePickerParams.qml1
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro1
5 files changed, 54 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));
+ }
}
}
diff --git a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/FilePicker.qml b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/FilePicker.qml
index 5d78807df..745f533f5 100644
--- a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/FilePicker.qml
+++ b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/FilePicker.qml
@@ -33,12 +33,14 @@ QtObject {
property bool selectMultiple: false;
property bool selectExisting: false;
property bool selectFolder: false;
+ property var nameFilters: [];
signal filesSelected(var fileList);
signal rejected();
function open() {
FilePickerParams.filePickerOpened = true;
+ FilePickerParams.nameFilters = nameFilters;
if (FilePickerParams.selectFiles)
filesSelected(FilePickerParams.selectedFilesUrl)
else
diff --git a/tests/auto/quick/qmltests/mock-delegates/TestParams/FilePickerParams.qml b/tests/auto/quick/qmltests/mock-delegates/TestParams/FilePickerParams.qml
index 83ac8a66e..02b0da1d4 100644
--- a/tests/auto/quick/qmltests/mock-delegates/TestParams/FilePickerParams.qml
+++ b/tests/auto/quick/qmltests/mock-delegates/TestParams/FilePickerParams.qml
@@ -33,4 +33,5 @@ QtObject {
property var selectedFilesUrl: [];
property bool selectFiles: false;
property bool filePickerOpened: false;
+ property var nameFilters: [];
}
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 00e884e11..071795d96 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -6,6 +6,7 @@ IMPORTPATH += $$PWD/data
OTHER_FILES += \
$$PWD/data/TestWebEngineView.qml \
+ $$PWD/data/accepttypes.html \
$$PWD/data/alert.html \
$$PWD/data/append-document-title.js \
$$PWD/data/big-user-script.js \