Title: [198913] trunk/Source/WebKit2
Revision
198913
Author
[email protected]
Date
2016-03-31 13:52:38 -0700 (Thu, 31 Mar 2016)

Log Message

Web Automation: Add support for script timeouts to the evaluateJavaScriptFunction command

https://bugs.webkit.org/show_bug.cgi?id=156052
rdar://problem/25457151

Reviewed by Brian Burg.

* UIProcess/Automation/Automation.json: Added callbackTimeout to evaluateJavaScriptFunction.
Also made expectsImplicitCallbackArgument optional, since it is not required. Added _javascript_Timeout error.
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::evaluateJavaScriptFunction): Added callbackTimeout.
* UIProcess/Automation/WebAutomationSession.h:
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::evaluateJavaScriptCallback): Send _javascript_Timeout error if the timeout fired.
(WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction): Added callbackTimeout.
* WebProcess/Automation/WebAutomationSessionProxy.h:
* WebProcess/Automation/WebAutomationSessionProxy.js:
(AutomationSessionProxy.prototype.evaluateJavaScriptFunction): Set a timeout to fire if the
callback is not called, then return an error.
* WebProcess/Automation/WebAutomationSessionProxy.messages.in:
(EvaluateJavaScriptFunction): Added callbackTimeout parameter.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (198912 => 198913)


--- trunk/Source/WebKit2/ChangeLog	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-31 20:52:38 UTC (rev 198913)
@@ -1,3 +1,27 @@
+2016-03-30  Timothy Hatcher  <[email protected]>
+
+        Web Automation: Add support for script timeouts to the evaluateJavaScriptFunction command
+
+        https://bugs.webkit.org/show_bug.cgi?id=156052
+        rdar://problem/25457151
+
+        Reviewed by Brian Burg.
+
+        * UIProcess/Automation/Automation.json: Added callbackTimeout to evaluateJavaScriptFunction.
+        Also made expectsImplicitCallbackArgument optional, since it is not required. Added _javascript_Timeout error.
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::evaluateJavaScriptFunction): Added callbackTimeout.
+        * UIProcess/Automation/WebAutomationSession.h:
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::evaluateJavaScriptCallback): Send _javascript_Timeout error if the timeout fired.
+        (WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction): Added callbackTimeout.
+        * WebProcess/Automation/WebAutomationSessionProxy.h:
+        * WebProcess/Automation/WebAutomationSessionProxy.js:
+        (AutomationSessionProxy.prototype.evaluateJavaScriptFunction): Set a timeout to fire if the
+        callback is not called, then return an error.
+        * WebProcess/Automation/WebAutomationSessionProxy.messages.in:
+        (EvaluateJavaScriptFunction): Added callbackTimeout parameter.
+
 2016-03-31  Jiewen Tan  <[email protected]>
 
         WebKit should set Original URL of a download request correctly

Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (198912 => 198913)


--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-03-31 20:52:38 UTC (rev 198913)
@@ -48,6 +48,7 @@
             "enum": [
                 "InternalError",
                 "_javascript_Error",
+                "_javascript_Timeout",
                 "WindowNotFound",
                 "FrameNotFound",
                 "NodeNotFound",
@@ -280,7 +281,8 @@
                 { "name": "frameHandle", "$ref": "FrameHandle", "optional": true, "description": "The handle for the frame the script should be evaluated. The main frame is used if this parameter empty string or excluded." },
                 { "name": "function", "type": "string", "description": "The script to evaluate in the browsing context. It must be a function result." },
                 { "name": "arguments", "type": "array", "items": { "type": "string" }, "description": "The arguments to pass to the function when called. They will be parsed as JSON before calling the function." },
-                { "name": "expectsImplicitCallbackArgument", "type": "boolean", "description": "The function expects a callback function as the last argument. It is expected to call this callback with a result." }
+                { "name": "expectsImplicitCallbackArgument", "type": "boolean", "optional": true, "description": "The function expects a callback function as the last argument. It is expected to call this callback with a result." },
+                { "name": "callbackTimeout", "type": "integer", "optional": true, "description": "The timeout in milliseconds that the implicit callback is expected to be called in, otherwise a <code>_javascript_Timeout</code> error is returned." }
             ],
             "returns": [
                 { "name": "result", "type": "string", "description": "The result returned by the called function. It is JSON encoded after the function returns or calls the callback." }

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (198912 => 198913)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-31 20:52:38 UTC (rev 198913)
@@ -395,7 +395,7 @@
     page->reload(reloadFromOrigin, contentBlockersEnabled);
 }
 
-void WebAutomationSession::evaluateJavaScriptFunction(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, bool expectsImplicitCallbackArgument, Ref<EvaluateJavaScriptFunctionCallback>&& callback)
+void WebAutomationSession::evaluateJavaScriptFunction(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, const bool* optionalExpectsImplicitCallbackArgument, const int* optionalCallbackTimeout, Ref<EvaluateJavaScriptFunctionCallback>&& callback)
 {
     WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     if (!page)
@@ -414,10 +414,13 @@
         argumentsVector.uncheckedAppend(argumentString);
     }
 
+    bool expectsImplicitCallbackArgument = optionalExpectsImplicitCallbackArgument ? *optionalExpectsImplicitCallbackArgument : false;
+    int callbackTimeout = optionalCallbackTimeout ? *optionalCallbackTimeout : 0;
+
     uint64_t callbackID = m_nextEvaluateJavaScriptCallbackID++;
     m_evaluateJavaScriptFunctionCallbacks.set(callbackID, WTFMove(callback));
 
-    page->process().send(Messages::WebAutomationSessionProxy::EvaluateJavaScriptFunction(frame->frameID(), function, argumentsVector, expectsImplicitCallbackArgument, callbackID), 0);
+    page->process().send(Messages::WebAutomationSessionProxy::EvaluateJavaScriptFunction(frame->frameID(), function, argumentsVector, expectsImplicitCallbackArgument, callbackTimeout, callbackID), 0);
 }
 
 void WebAutomationSession::didEvaluateJavaScriptFunction(uint64_t callbackID, const String& result, const String& errorType)

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (198912 => 198913)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-31 20:52:38 UTC (rev 198913)
@@ -103,7 +103,7 @@
     void goBackInBrowsingContext(Inspector::ErrorString&, const String&) override;
     void goForwardInBrowsingContext(Inspector::ErrorString&, const String&) override;
     void reloadBrowsingContext(Inspector::ErrorString&, const String&) override;
-    void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, bool expectsImplicitCallbackArgument, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;
+    void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, const bool* optionalExpectsImplicitCallbackArgument, const int* optionalCallbackTimeout, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;
     void performMouseInteraction(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& requestedPosition, const String& mouseButton, const String& mouseInteraction, const Inspector::InspectorArray& keyModifiers, RefPtr<Inspector::Protocol::Automation::Point>& updatedPosition) override;
     void performKeyboardInteractions(Inspector::ErrorString&, const String& handle, const Inspector::InspectorArray& interactions) override;
     void takeScreenshot(Inspector::ErrorString&, const String& handle, Ref<Inspector::AutomationBackendDispatcherHandler::TakeScreenshotCallback>&&) override;

Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp (198912 => 198913)


--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp	2016-03-31 20:52:38 UTC (rev 198913)
@@ -126,10 +126,11 @@
 
 static JSValueRef evaluateJavaScriptCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-    ASSERT_ARG(argumentCount, argumentCount == 3);
+    ASSERT_ARG(argumentCount, argumentCount == 4);
     ASSERT_ARG(arguments, JSValueIsNumber(context, arguments[0]));
     ASSERT_ARG(arguments, JSValueIsNumber(context, arguments[1]));
     ASSERT_ARG(arguments, JSValueIsString(context, arguments[2]));
+    ASSERT_ARG(arguments, JSValueIsBoolean(context, arguments[3]));
 
     auto automationSessionProxy = WebProcess::singleton().automationSessionProxy();
     if (!automationSessionProxy)
@@ -139,8 +140,20 @@
     uint64_t callbackID = JSValueToNumber(context, arguments[1], exception);
     JSRetainPtr<JSStringRef> result(Adopt, JSValueToStringCopy(context, arguments[2], exception));
 
-    automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, result->string(), String());
+    bool resultIsErrorName = JSValueToBoolean(context, arguments[3]);
 
+    if (resultIsErrorName) {
+        if (result->string() == "_javascript_Timeout") {
+            String errorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::_javascript_Timeout);
+            automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, String(), errorType);
+        } else {
+            ASSERT_NOT_REACHED();
+            String errorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InternalError);
+            automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, String(), errorType);
+        }
+    } else
+        automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, result->string(), String());
+
     return JSValueMakeUndefined(context);
 }
 
@@ -212,7 +225,7 @@
         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidEvaluateJavaScriptFunction(callbackID, String(), errorType), 0);
 }
 
-void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, uint64_t callbackID)
+void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID)
 {
     WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     if (!frame)
@@ -225,8 +238,6 @@
     JSValueRef exception = nullptr;
     JSGlobalContextRef context = frame->jsContext();
 
-    JSObjectRef callbackFunction = JSObjectMakeFunctionWithCallback(context, nullptr, evaluateJavaScriptCallback);
-
     if (expectsImplicitCallbackArgument) {
         auto result = m_webFramePendingEvaluateJavaScriptCallbacksMap.add(frameID, Vector<uint64_t>());
         result.iterator->value.append(callbackID);
@@ -238,7 +249,8 @@
         JSValueMakeBoolean(context, expectsImplicitCallbackArgument),
         JSValueMakeNumber(context, frameID),
         JSValueMakeNumber(context, callbackID),
-        callbackFunction
+        JSObjectMakeFunctionWithCallback(context, nullptr, evaluateJavaScriptCallback),
+        JSValueMakeNumber(context, callbackTimeout)
     };
 
     callPropertyFunction(context, scriptObject, ASCIILiteral("evaluateJavaScriptFunction"), WTF_ARRAY_LENGTH(functionArguments), functionArguments, &exception);

Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h (198912 => 198913)


--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h	2016-03-31 20:52:38 UTC (rev 198913)
@@ -58,7 +58,7 @@
     void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&);
 
     // Called by WebAutomationSessionProxy messages
-    void evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, uint64_t callbackID);
+    void evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID);
     void resolveChildFrameWithOrdinal(uint64_t frameID, uint32_t ordinal, uint64_t callbackID);
     void resolveChildFrameWithNodeHandle(uint64_t frameID, const String& nodeHandle, uint64_t callbackID);
     void resolveChildFrameWithName(uint64_t frameID, const String& name, uint64_t callbackID);

Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.js (198912 => 198913)


--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.js	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.js	2016-03-31 20:52:38 UTC (rev 198913)
@@ -39,7 +39,7 @@
 
     // Public
 
-    evaluateJavaScriptFunction(functionString, argumentStrings, expectsImplicitCallbackArgument, frameID, callbackID, resultCallback)
+    evaluateJavaScriptFunction(functionString, argumentStrings, expectsImplicitCallbackArgument, frameID, callbackID, resultCallback, callbackTimeout)
     {
         // The script is expected to be a function declaration. Evaluate it inside parenthesis to get the function value.
         let functionValue = evaluate("(" + functionString + ")");
@@ -47,13 +47,19 @@
             throw new TypeError("Script did not evaluate to a function.");
 
         let argumentValues = argumentStrings.map(this._jsonParse, this);
-        let callback = (result) => resultCallback(frameID, callbackID, this._jsonStringify(result));
 
+        let timeoutIdentifier = 0;
+
+        let reportResult = (result) => { clearTimeout(timeoutIdentifier); resultCallback(frameID, callbackID, this._jsonStringify(result), false); }
+        let reportTimeoutError = () => { clearTimeout(timeoutIdentifier); resultCallback(frameID, callbackID, "_javascript_Timeout", true); }
+
         if (expectsImplicitCallbackArgument) {
-            argumentValues.push(callback);
+            timeoutIdentifier = setTimeout(reportTimeoutError, callbackTimeout);
+
+            argumentValues.push(reportResult);
             functionValue.apply(null, argumentValues);
         } else
-            callback(functionValue.apply(null, argumentValues));
+            reportResult(functionValue.apply(null, argumentValues));
     }
 
     nodeForIdentifier(identifier)

Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in (198912 => 198913)


--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in	2016-03-31 20:43:41 UTC (rev 198912)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in	2016-03-31 20:52:38 UTC (rev 198913)
@@ -21,7 +21,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebAutomationSessionProxy {
-    EvaluateJavaScriptFunction(uint64_t frameID, String function, Vector<String> arguments, bool expectsImplicitCallbackArgument, uint64_t callbackID)
+    EvaluateJavaScriptFunction(uint64_t frameID, String function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID)
 
     ResolveChildFrameWithOrdinal(uint64_t frameID, uint32_t ordinal, uint64_t callbackID)
     ResolveChildFrameWithNodeHandle(uint64_t frameID, String nodeHandle, uint64_t callbackID)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to