Title: [275050] trunk/Source/WebKit
Revision
275050
Author
[email protected]
Date
2021-03-25 11:54:45 -0700 (Thu, 25 Mar 2021)

Log Message

SendKeys on Input of type=file returns element not found in some cases
https://bugs.webkit.org/show_bug.cgi?id=223028
<rdar://problem/75526126>

Reviewed by Devin Rousso.

This bizarre behavior is triggered by removing the <input type=file> element inside an onclick() handler
for the input element. This confuses safaridriver, which expects to be able to query the file input's .value
via _javascript_ after setting the files.

As part of the fix, provide the list of selected filenames in the Automation.fileChooserDismissed event.
On the safaridriver side, just use the list of filenames provided in this event to avoid an extra JS evaluation
that may race with page content.

* UIProcess/Automation/Automation.json:
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::handleRunOpenPanel):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (275049 => 275050)


--- trunk/Source/WebKit/ChangeLog	2021-03-25 18:47:17 UTC (rev 275049)
+++ trunk/Source/WebKit/ChangeLog	2021-03-25 18:54:45 UTC (rev 275050)
@@ -1,3 +1,23 @@
+2021-03-25  BJ Burg  <[email protected]>
+
+        SendKeys on Input of type=file returns element not found in some cases
+        https://bugs.webkit.org/show_bug.cgi?id=223028
+        <rdar://problem/75526126>
+
+        Reviewed by Devin Rousso.
+
+        This bizarre behavior is triggered by removing the <input type=file> element inside an onclick() handler
+        for the input element. This confuses safaridriver, which expects to be able to query the file input's .value
+        via _javascript_ after setting the files.
+
+        As part of the fix, provide the list of selected filenames in the Automation.fileChooserDismissed event.
+        On the safaridriver side, just use the list of filenames provided in this event to avoid an extra JS evaluation
+        that may race with page content.
+
+        * UIProcess/Automation/Automation.json:
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::handleRunOpenPanel):
+
 2021-03-25  Alex Christensen  <[email protected]>
 
         REGRESSION (r272376): [iOS] ASSERTION FAILED: sessionID.isEphemeral() || !path.isEmpty() in WebKit::NetworkProcess::swServerForSession

Modified: trunk/Source/WebKit/UIProcess/Automation/Automation.json (275049 => 275050)


--- trunk/Source/WebKit/UIProcess/Automation/Automation.json	2021-03-25 18:47:17 UTC (rev 275049)
+++ trunk/Source/WebKit/UIProcess/Automation/Automation.json	2021-03-25 18:54:45 UTC (rev 275050)
@@ -721,7 +721,8 @@
             "description": "Fired when a file chooser for a file input element is dismissed by selecting files or cancelling.",
             "parameters": [
                 { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." },
-                { "name": "selectionCancelled", "type": "boolean", "description": "If true, the chooser was dismissed because file selection was cancelled." }
+                { "name": "selectionCancelled", "type": "boolean", "description": "If true, file selection was cancelled due to an error. For example, this could occur if a file's MIME type cannot be handled by WebKit." },
+                { "name": "selectedFiles", "type": "array", "items": { "type": "string" }, "optional": true, "description": "A list of file names that were successfully selected for upload." }
             ]
         },
         {

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (275049 => 275050)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2021-03-25 18:47:17 UTC (rev 275049)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2021-03-25 18:54:45 UTC (rev 275050)
@@ -900,13 +900,13 @@
     String browsingContextHandle = handleForWebPageProxy(page);
     if (!m_filesToSelectForFileUpload.size()) {
         resultListener.cancel();
-        m_domainNotifier->fileChooserDismissed(browsingContextHandle, true);
+        m_domainNotifier->fileChooserDismissed(browsingContextHandle, true, { });
         return;
     }
 
     if (m_filesToSelectForFileUpload.size() > 1 && !parameters.allowMultipleFiles()) {
         resultListener.cancel();
-        m_domainNotifier->fileChooserDismissed(browsingContextHandle, true);
+        m_domainNotifier->fileChooserDismissed(browsingContextHandle, true, { });
         return;
     }
 
@@ -925,17 +925,22 @@
     }
 
     // Per ยง14.3.10.5 in the W3C spec, if at least one file cannot be accepted, the command should fail.
-    // The REST API service can tell that this failed by checking the "files" attribute of the input element.
     for (const String& filename : m_filesToSelectForFileUpload) {
         if (!fileCanBeAcceptedForUpload(filename, allowedMIMETypes, allowedFileExtensions)) {
             resultListener.cancel();
-            m_domainNotifier->fileChooserDismissed(browsingContextHandle, true);
+            m_domainNotifier->fileChooserDismissed(browsingContextHandle, true, { });
             return;
         }
     }
 
+    // Copy the file list we used before calling out to the open panel listener.
+    Ref<JSON::ArrayOf<String>> selectedFiles = JSON::ArrayOf<String>::create();
+    for (const String& filename : m_filesToSelectForFileUpload)
+        selectedFiles->addItem(filename);
+
     resultListener.chooseFiles(m_filesToSelectForFileUpload);
-    m_domainNotifier->fileChooserDismissed(browsingContextHandle, false);
+
+    m_domainNotifier->fileChooserDismissed(browsingContextHandle, false, WTFMove(selectedFiles));
 }
 
 void WebAutomationSession::evaluateJavaScriptFunction(const Inspector::Protocol::Automation::BrowsingContextHandle& browsingContextHandle, const Inspector::Protocol::Automation::FrameHandle& frameHandle, const String& function, Ref<JSON::Array>&& arguments, Optional<bool>&& expectsImplicitCallbackArgument, Optional<double>&& callbackTimeout, Ref<EvaluateJavaScriptFunctionCallback>&& callback)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to