From cc2397eea05eedbbcbf8a592fad13ee51f6db5cf Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 26 Jul 2019 14:28:34 +0200 Subject: Clean-up handling of selected files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplifies the code and makes sure both the two QML implementations of the file-selector are source compatible. Note, this does not address issues with test on Windows. Change-Id: Ieee84866c456d600a812683cae389d6a6980366f Reviewed-by: Michael Brüning --- tests/auto/quick/qmltests/data/tst_filePicker.qml | 52 ++++++++++------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qmltests/data/tst_filePicker.qml b/tests/auto/quick/qmltests/data/tst_filePicker.qml index 2f813b966..d2815e3a8 100644 --- a/tests/auto/quick/qmltests/data/tst_filePicker.qml +++ b/tests/auto/quick/qmltests/data/tst_filePicker.qml @@ -72,27 +72,25 @@ TestWebEngineView { function test_acceptSingleFileSelection_data() { return [ - { tag: "/test.txt)", input: "/test.txt", passDefaultDialog: false, passCustomDialog: true }, - { tag: "/tést.txt", input: "/tést.txt", passDefaultDialog: false, passCustomDialog: true }, - { tag: "file:///test.txt", input: "file:///test.txt", passDefaultDialog: true, passCustomDialog: false }, - { tag: "file:///tést.txt", input: "file:///tést.txt", passDefaultDialog: true, passCustomDialog: false }, - { tag: "file:///t%C3%A9st.txt", input: "file:///t%C3%A9st.txt", passDefaultDialog: true, passCustomDialog: false }, - { tag: "file://test.txt", input: "file://test.txt", passDefaultDialog: false, passCustomDialog: false }, - { tag: "file:/test.txt", input: "file:/test.txt", passDefaultDialog: true, passCustomDialog: false }, - { tag: "file:test//test.txt", input: "file:test//test.txt", passDefaultDialog: false, passCustomDialog: false }, - { tag: "http://test.txt", input: "http://test.txt", passDefaultDialog: false, passCustomDialog: false }, - { tag: "qrc:/test.txt", input: "qrc:/test.txt", passDefaultDialog: false, passCustomDialog: false }, + { tag: "/test.txt", input: "/test.txt", expected: "test.txt" }, + { tag: "test.txt", input: "test.txt", expected: "Failed to Upload" }, + { tag: "/tést.txt", input: "/tést.txt", expected: "tést.txt" }, + { tag: "/t%65st.txt", input: "/t%65st.txt", expected: "t%65st.txt" }, + { tag: "file:///test.txt", input: "file:///test.txt", expected: "test.txt" }, + { tag: "file:///tést.txt", input: "file:///tést.txt", expected: "tést.txt" }, + { tag: "file:///t%65st.txt", input: "file:///t%65st.txt", expected: "test.txt" }, + { tag: "file://test.txt", input: "file://test.txt", expected: "test.txt" }, + { tag: "file:/test.txt", input: "file:/test.txt", expected: "test.txt"}, + { tag: "file:test//test.txt", input: "file:test//test.txt", expected: "Failed to Upload" }, + { tag: "http://test.txt", input: "http://test.txt", expected: "Failed to Upload" }, + { tag: "qrc:/test.txt", input: "qrc:/test.txt", expected: "Failed to Upload" }, ]; } function test_acceptSingleFileSelection(row) { var expectedFileName; - // Default dialog (expects URL). - expectedFileName = "Failed to Upload"; - if (row.passDefaultDialog) - expectedFileName = row.input.slice(row.input.lastIndexOf('/') + 1); - + // Default dialog webEngineView.url = Qt.resolvedUrl("singlefileupload.html"); verify(webEngineView.waitForLoadSucceeded()); @@ -101,16 +99,12 @@ TestWebEngineView { keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. tryCompare(FilePickerParams, "filePickerOpened", true); - tryCompare(webEngineView, "title", decodeURIComponent(expectedFileName)); + tryCompare(webEngineView, "title", row.expected); - // Custom dialog (expects absolute path). + // Custom dialog var finished = false; - expectedFileName = "Failed to Upload"; - if (row.passCustomDialog) - expectedFileName = row.input.slice(row.input.lastIndexOf('/') + 1); - function acceptedFileHandler(request) { request.accepted = true; request.dialogAccept(row.input); @@ -123,7 +117,7 @@ TestWebEngineView { keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. tryVerify(function() { return finished; }); - tryCompare(webEngineView, "title", expectedFileName); + tryCompare(webEngineView, "title", row.expected); webEngineView.fileDialogRequested.disconnect(acceptedFileHandler); } @@ -165,14 +159,14 @@ TestWebEngineView { function test_acceptMultipleFilesWithCustomDialog_data() { return [ - { tag: "path", input: ["/test1.txt", "/test2.txt"], expectedValueForDefaultDialog: "Failed to Upload", expectedValueForCustomDialog: "test1.txt,test2.txt" }, - { tag: "file", input: ["file:///test1.txt", "file:///test2.txt"], expectedValueForDefaultDialog: "test1.txt,test2.txt", expectedValueForCustomDialog: "Failed to Upload" }, - { tag: "mixed", input: ["file:///test1.txt", "/test2.txt"], expectedValueForDefaultDialog: "test1.txt", expectedValueForCustomDialog: "test2.txt" }, + { tag: "path", input: ["/test1.txt", "/test2.txt"], expectedValue: "test1.txt,test2.txt" }, + { tag: "file", input: ["file:///test1.txt", "file:/test2.txt"], expectedValue: "test1.txt,test2.txt" }, + { tag: "mixed", input: ["file:///test1.txt", "/test2.txt"], expectedValue: "test1.txt,test2.txt" }, ]; } function test_acceptMultipleFilesWithCustomDialog(row) { - // Default dialog (expects URL). + // Default dialog webEngineView.url = Qt.resolvedUrl("multifileupload.html"); verify(webEngineView.waitForLoadSucceeded()); @@ -181,10 +175,10 @@ TestWebEngineView { keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. tryCompare(FilePickerParams, "filePickerOpened", true); - tryCompare(webEngineView, "title", row.expectedValueForDefaultDialog); + tryCompare(webEngineView, "title", row.expectedValue); - // Custom dialog (expects absolute path). + // Custom dialog var finished = false; function acceptedFileHandler(request) { @@ -199,7 +193,7 @@ TestWebEngineView { keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. tryVerify(function() { return finished; }); - tryCompare(webEngineView, "title", row.expectedValueForCustomDialog); + tryCompare(webEngineView, "title", row.expectedValue); webEngineView.fileDialogRequested.disconnect(acceptedFileHandler); } } -- cgit v1.2.3 From 50dc091b5ddca2fb1c80e398d2ab360a5ec5e767 Mon Sep 17 00:00:00 2001 From: Tamas Zakor Date: Mon, 29 Jul 2019 12:37:33 +0200 Subject: Fix file URI checks for FilePickerController::accepted() on Windows Extend auto tests with windows specific cases. Change-Id: I731cd520c12a38636a5df4829a79d7bd1d85a314 Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/qmltests/data/tst_filePicker.qml | 88 +++++++++++++++++++---- 1 file changed, 76 insertions(+), 12 deletions(-) (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qmltests/data/tst_filePicker.qml b/tests/auto/quick/qmltests/data/tst_filePicker.qml index d2815e3a8..fad81273c 100644 --- a/tests/auto/quick/qmltests/data/tst_filePicker.qml +++ b/tests/auto/quick/qmltests/data/tst_filePicker.qml @@ -36,6 +36,12 @@ TestWebEngineView { width: 400 height: 300 + function driveLetter() { + if (Qt.platform.os !== "windows") + return ""; + return "C:/"; + } + SignalSpy { id: titleSpy target: webEngineView @@ -72,15 +78,15 @@ TestWebEngineView { function test_acceptSingleFileSelection_data() { return [ - { tag: "/test.txt", input: "/test.txt", expected: "test.txt" }, - { tag: "test.txt", input: "test.txt", expected: "Failed to Upload" }, - { tag: "/tést.txt", input: "/tést.txt", expected: "tést.txt" }, - { tag: "/t%65st.txt", input: "/t%65st.txt", expected: "t%65st.txt" }, - { tag: "file:///test.txt", input: "file:///test.txt", expected: "test.txt" }, - { tag: "file:///tést.txt", input: "file:///tést.txt", expected: "tést.txt" }, - { tag: "file:///t%65st.txt", input: "file:///t%65st.txt", expected: "test.txt" }, - { tag: "file://test.txt", input: "file://test.txt", expected: "test.txt" }, - { tag: "file:/test.txt", input: "file:/test.txt", expected: "test.txt"}, + { tag: driveLetter() + "/test.txt", input: driveLetter() + "/test.txt", expected: "test.txt" }, + { tag: driveLetter() + "test.txt", input: driveLetter() + "test.txt", expected: "Failed to Upload" }, + { tag: driveLetter() + "/tést.txt", input: driveLetter() + "/tést.txt", expected: "tést.txt" }, + { tag: driveLetter() + "/t%65st.txt", input: driveLetter() + "/t%65st.txt", expected: "t%65st.txt" }, + { tag: "file:///" + driveLetter() + "test.txt", input: "file:///" + driveLetter() + "test.txt", expected: "test.txt" }, + { tag: "file:///" + driveLetter() + "tést.txt", input: "file:///" + driveLetter() + "tést.txt", expected: "tést.txt" }, + { tag: "file:///" + driveLetter() + "t%65st.txt", input: "file:///" + driveLetter() + "t%65st.txt", expected: "test.txt" }, + { tag: "file://" + driveLetter() + "test.txt", input: "file://" + driveLetter() + "test.txt", expected: "test.txt" }, + { tag: "file:/" + driveLetter() + "test.txt", input: "file:/" + driveLetter() + "test.txt", expected: "test.txt"}, { tag: "file:test//test.txt", input: "file:test//test.txt", expected: "Failed to Upload" }, { tag: "http://test.txt", input: "http://test.txt", expected: "Failed to Upload" }, { tag: "qrc:/test.txt", input: "qrc:/test.txt", expected: "Failed to Upload" }, @@ -159,9 +165,9 @@ TestWebEngineView { function test_acceptMultipleFilesWithCustomDialog_data() { return [ - { tag: "path", input: ["/test1.txt", "/test2.txt"], expectedValue: "test1.txt,test2.txt" }, - { tag: "file", input: ["file:///test1.txt", "file:/test2.txt"], expectedValue: "test1.txt,test2.txt" }, - { tag: "mixed", input: ["file:///test1.txt", "/test2.txt"], expectedValue: "test1.txt,test2.txt" }, + { tag: "path", input: [driveLetter() + "/test1.txt", driveLetter() + "/test2.txt"], expectedValue: "test1.txt,test2.txt" }, + { tag: "file", input: ["file:///" + driveLetter() + "test1.txt", "file:/" + driveLetter() + "test2.txt"], expectedValue: "test1.txt,test2.txt" }, + { tag: "mixed", input: ["file:///" + driveLetter() + "test1.txt", driveLetter() + "/test2.txt"], expectedValue: "test1.txt,test2.txt" }, ]; } @@ -196,5 +202,63 @@ TestWebEngineView { tryCompare(webEngineView, "title", row.expectedValue); webEngineView.fileDialogRequested.disconnect(acceptedFileHandler); } + + function test_acceptFileOnWindows_data() { + return [ + { tag: "C:test.txt", input: "C:test.txt", expected: "Failed to Upload"}, + { tag: "C:test:txt", input: "C:test:txt", expected: "Failed to Upload"}, + { tag: "C:/test.txt", input: "C:/test.txt", expected: "test.txt"}, + { tag: "C:\\test.txt", input: "C:\\test.txt", expected: "test.txt"}, + { tag: "C:\\Documents and Settings\\test\\test.txt", input: "C:\\Documents and Settings\\test\\test.txt", expected: "test.txt"}, + { tag: "\\\\applib\\products\\a%2Db\\ abc%5F9\\t.est\\test.txt", input: "file://applib/products/a%2Db/ abc%5F9/4148.920a/media/test.txt", expected: "test.txt"}, + { tag: "file://applib/products/a%2Db/ abc%5F9/t.est/test.txt", input: "file://applib/products/a%2Db/ abc%5F9/4148.920a/media/test.txt", expected: "test.txt"}, + { tag: "file://applib/products/a-b/abc_1/t.est/test.txt", input: "file://applib/products/a-b/abc_1/t.est/test.txt", expected: "test.txt"}, + { tag: "file:\\\\applib\\products\\a-b\\abc_1\\t:est\\test.txt", input: "file:\\\\applib\\products\\a-b\\abc_1\\t:est\\test.txt", expected: "test.txt"}, + { tag: "file:C:/test.txt", input: "file:C:/test.txt", expected: "Failed to Upload"}, + { tag: "file:/C:/test.txt", input: "file:/C:/test.txt", expected: "Failed to Upload"}, + { tag: "file://C:/test.txt", input: "file://C:/test.txt", expected: "Failed to Upload"}, + { tag: "file:///C:test.txt", input: "file:///C:test.txt", expected: "Failed to Upload"}, + { tag: "file:///C:/test.txt", input: "file:///C:/test.txt", expected: "test.txt"}, + { tag: "file:///C:\\test.txt", input: "file:///C:\\test.txt", expected: "test.txt"}, + { tag: "file:\\//C:/test.txt", input: "file:\\//C:/test.txt", expected: "test.txt"}, + { tag: "file:\\\\/C:\\test.txt", input: "file:\\\\/C:\\test.txt", expected: "test.txt"}, + { tag: "\\\\?\\C:/test.txt", input: "\\\\?\\C:/test.txt", expected: "Failed to Upload"}, + ]; + } + + function test_acceptFileOnWindows(row) { + if (Qt.platform.os !== "windows") + skip("Windows-only test"); + + // Default dialog + webEngineView.url = Qt.resolvedUrl("singlefileupload.html"); + verify(webEngineView.waitForLoadSucceeded()); + + FilePickerParams.selectFiles = true; + FilePickerParams.selectedFilesUrl.push(row.input); + + keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. + tryCompare(FilePickerParams, "filePickerOpened", true); + tryCompare(webEngineView, "title", row.expected); + + + // Custom dialog + var finished = false; + + function acceptedFileHandler(request) { + request.accepted = true; + request.dialogAccept(row.input); + finished = true; + } + + webEngineView.fileDialogRequested.connect(acceptedFileHandler); + webEngineView.url = Qt.resolvedUrl("singlefileupload.html"); + verify(webEngineView.waitForLoadSucceeded()); + + keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. + tryVerify(function() { return finished; }); + tryCompare(webEngineView, "title", row.expected); + webEngineView.fileDialogRequested.disconnect(acceptedFileHandler); + } } } -- cgit v1.2.3 From 20555210e74c67de028dfcca1559e9839e626c76 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 3 Sep 2019 15:08:12 +0200 Subject: Fix invalid url on profile change If adapter is initialized use always active url. Fixes: QTBUG-77977 Change-Id: Ie8d4ec7d7c703322cef50d26931cce2b130dcf34 Reviewed-by: Allan Sandfeld Jensen --- .../quick/qquickwebengineview/tst_qquickwebengineview.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index 74c04635f..5572515a1 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -91,6 +91,7 @@ private Q_SLOTS: void userScripts(); void javascriptClipboard_data(); void javascriptClipboard(); + void setProfile(); private: inline QQuickWebEngineView *newWebEngineView(); @@ -1148,5 +1149,18 @@ void tst_QQuickWebEngineView::javascriptClipboard() QTRY_COMPARE(evaluateJavaScriptSync(view, "accessPrompt").toBool(), false); } +void tst_QQuickWebEngineView::setProfile() { + QSignalSpy loadSpy(webEngineView(), SIGNAL(loadingChanged(QQuickWebEngineLoadRequest*))); + webEngineView()->setUrl(urlFromTestPath("html/basic_page.html")); + QVERIFY(waitForLoadSucceeded(webEngineView())); + QCOMPARE(loadSpy.size(), 2); + webEngineView()->setUrl(urlFromTestPath("html/basic_page2.html")); + QVERIFY(waitForLoadSucceeded(webEngineView())); + QCOMPARE(loadSpy.size(), 4); + QQuickWebEngineProfile *profile = new QQuickWebEngineProfile(); + webEngineView()->setProfile(profile); + QTRY_COMPARE(webEngineView()->url() ,urlFromTestPath("html/basic_page2.html")); +} + QTEST_MAIN(tst_QQuickWebEngineView) #include "tst_qquickwebengineview.moc" -- cgit v1.2.3