Changeset 198913 in webkit
- Timestamp:
- Mar 31, 2016, 1:52:38 PM (9 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r198911 r198913 1 2016-03-30 Timothy Hatcher <timothy@apple.com> 2 3 Web Automation: Add support for script timeouts to the evaluateJavaScriptFunction command 4 5 https://bugs.webkit.org/show_bug.cgi?id=156052 6 rdar://problem/25457151 7 8 Reviewed by Brian Burg. 9 10 * UIProcess/Automation/Automation.json: Added callbackTimeout to evaluateJavaScriptFunction. 11 Also made expectsImplicitCallbackArgument optional, since it is not required. Added JavaScriptTimeout error. 12 * UIProcess/Automation/WebAutomationSession.cpp: 13 (WebKit::WebAutomationSession::evaluateJavaScriptFunction): Added callbackTimeout. 14 * UIProcess/Automation/WebAutomationSession.h: 15 * WebProcess/Automation/WebAutomationSessionProxy.cpp: 16 (WebKit::evaluateJavaScriptCallback): Send JavaScriptTimeout error if the timeout fired. 17 (WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction): Added callbackTimeout. 18 * WebProcess/Automation/WebAutomationSessionProxy.h: 19 * WebProcess/Automation/WebAutomationSessionProxy.js: 20 (AutomationSessionProxy.prototype.evaluateJavaScriptFunction): Set a timeout to fire if the 21 callback is not called, then return an error. 22 * WebProcess/Automation/WebAutomationSessionProxy.messages.in: 23 (EvaluateJavaScriptFunction): Added callbackTimeout parameter. 24 1 25 2016-03-31 Jiewen Tan <jiewen_tan@apple.com> 2 26 -
trunk/Source/WebKit2/UIProcess/Automation/Automation.json
r198907 r198913 49 49 "InternalError", 50 50 "JavaScriptError", 51 "JavaScriptTimeout", 51 52 "WindowNotFound", 52 53 "FrameNotFound", … … 281 282 { "name": "function", "type": "string", "description": "The script to evaluate in the browsing context. It must be a function result." }, 282 283 { "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." }, 283 { "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." } 284 { "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." }, 285 { "name": "callbackTimeout", "type": "integer", "optional": true, "description": "The timeout in milliseconds that the implicit callback is expected to be called in, otherwise a <code>JavaScriptTimeout</code> error is returned." } 284 286 ], 285 287 "returns": [ -
trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp
r198907 r198913 396 396 } 397 397 398 void WebAutomationSession::evaluateJavaScriptFunction(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, bool expectsImplicitCallbackArgument, Ref<EvaluateJavaScriptFunctionCallback>&& callback)398 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) 399 399 { 400 400 WebPageProxy* page = webPageProxyForHandle(browsingContextHandle); … … 415 415 } 416 416 417 bool expectsImplicitCallbackArgument = optionalExpectsImplicitCallbackArgument ? *optionalExpectsImplicitCallbackArgument : false; 418 int callbackTimeout = optionalCallbackTimeout ? *optionalCallbackTimeout : 0; 419 417 420 uint64_t callbackID = m_nextEvaluateJavaScriptCallbackID++; 418 421 m_evaluateJavaScriptFunctionCallbacks.set(callbackID, WTFMove(callback)); 419 422 420 page->process().send(Messages::WebAutomationSessionProxy::EvaluateJavaScriptFunction(frame->frameID(), function, argumentsVector, expectsImplicitCallbackArgument, callback ID), 0);423 page->process().send(Messages::WebAutomationSessionProxy::EvaluateJavaScriptFunction(frame->frameID(), function, argumentsVector, expectsImplicitCallbackArgument, callbackTimeout, callbackID), 0); 421 424 } 422 425 -
trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
r198907 r198913 104 104 void goForwardInBrowsingContext(Inspector::ErrorString&, const String&) override; 105 105 void reloadBrowsingContext(Inspector::ErrorString&, const String&) override; 106 void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, bool expectsImplicitCallbackArgument, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;106 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; 107 107 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; 108 108 void performKeyboardInteractions(Inspector::ErrorString&, const String& handle, const Inspector::InspectorArray& interactions) override; -
trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp
r198907 r198913 127 127 static JSValueRef evaluateJavaScriptCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 128 128 { 129 ASSERT_ARG(argumentCount, argumentCount == 3);129 ASSERT_ARG(argumentCount, argumentCount == 4); 130 130 ASSERT_ARG(arguments, JSValueIsNumber(context, arguments[0])); 131 131 ASSERT_ARG(arguments, JSValueIsNumber(context, arguments[1])); 132 132 ASSERT_ARG(arguments, JSValueIsString(context, arguments[2])); 133 ASSERT_ARG(arguments, JSValueIsBoolean(context, arguments[3])); 133 134 134 135 auto automationSessionProxy = WebProcess::singleton().automationSessionProxy(); … … 140 141 JSRetainPtr<JSStringRef> result(Adopt, JSValueToStringCopy(context, arguments[2], exception)); 141 142 142 automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, result->string(), String()); 143 bool resultIsErrorName = JSValueToBoolean(context, arguments[3]); 144 145 if (resultIsErrorName) { 146 if (result->string() == "JavaScriptTimeout") { 147 String errorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::JavaScriptTimeout); 148 automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, String(), errorType); 149 } else { 150 ASSERT_NOT_REACHED(); 151 String errorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InternalError); 152 automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, String(), errorType); 153 } 154 } else 155 automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, result->string(), String()); 143 156 144 157 return JSValueMakeUndefined(context); … … 213 226 } 214 227 215 void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, uint64_t callbackID)228 void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID) 216 229 { 217 230 WebFrame* frame = WebProcess::singleton().webFrame(frameID); … … 225 238 JSValueRef exception = nullptr; 226 239 JSGlobalContextRef context = frame->jsContext(); 227 228 JSObjectRef callbackFunction = JSObjectMakeFunctionWithCallback(context, nullptr, evaluateJavaScriptCallback);229 240 230 241 if (expectsImplicitCallbackArgument) { … … 239 250 JSValueMakeNumber(context, frameID), 240 251 JSValueMakeNumber(context, callbackID), 241 callbackFunction 252 JSObjectMakeFunctionWithCallback(context, nullptr, evaluateJavaScriptCallback), 253 JSValueMakeNumber(context, callbackTimeout) 242 254 }; 243 255 -
trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h
r198907 r198913 59 59 60 60 // Called by WebAutomationSessionProxy messages 61 void evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, uint64_t callbackID);61 void evaluateJavaScriptFunction(uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID); 62 62 void resolveChildFrameWithOrdinal(uint64_t frameID, uint32_t ordinal, uint64_t callbackID); 63 63 void resolveChildFrameWithNodeHandle(uint64_t frameID, const String& nodeHandle, uint64_t callbackID); -
trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.js
r198906 r198913 40 40 // Public 41 41 42 evaluateJavaScriptFunction(functionString, argumentStrings, expectsImplicitCallbackArgument, frameID, callbackID, resultCallback )42 evaluateJavaScriptFunction(functionString, argumentStrings, expectsImplicitCallbackArgument, frameID, callbackID, resultCallback, callbackTimeout) 43 43 { 44 44 // The script is expected to be a function declaration. Evaluate it inside parenthesis to get the function value. … … 48 48 49 49 let argumentValues = argumentStrings.map(this._jsonParse, this); 50 let callback = (result) => resultCallback(frameID, callbackID, this._jsonStringify(result)); 50 51 let timeoutIdentifier = 0; 52 53 let reportResult = (result) => { clearTimeout(timeoutIdentifier); resultCallback(frameID, callbackID, this._jsonStringify(result), false); } 54 let reportTimeoutError = () => { clearTimeout(timeoutIdentifier); resultCallback(frameID, callbackID, "JavaScriptTimeout", true); } 51 55 52 56 if (expectsImplicitCallbackArgument) { 53 argumentValues.push(callback); 57 timeoutIdentifier = setTimeout(reportTimeoutError, callbackTimeout); 58 59 argumentValues.push(reportResult); 54 60 functionValue.apply(null, argumentValues); 55 61 } else 56 callback(functionValue.apply(null, argumentValues));62 reportResult(functionValue.apply(null, argumentValues)); 57 63 } 58 64 -
trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in
r198907 r198913 22 22 23 23 messages -> WebAutomationSessionProxy { 24 EvaluateJavaScriptFunction(uint64_t frameID, String function, Vector<String> arguments, bool expectsImplicitCallbackArgument, uint64_t callbackID)24 EvaluateJavaScriptFunction(uint64_t frameID, String function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID) 25 25 26 26 ResolveChildFrameWithOrdinal(uint64_t frameID, uint32_t ordinal, uint64_t callbackID)
Note:
See TracChangeset
for help on using the changeset viewer.