[webkit-dev] Calling JavaScript function from within DumpRenderTree
Sam Weinig
sam.weinig at gmail.com
Fri Jan 1 21:25:06 PST 2010
On Fri, Jan 1, 2010 at 7:13 PM, Chris Fleizach <cfleizach at apple.com> wrote:
> I need to have a layout test register a callback with DRT, then have that
> callback be called at the appropriate time (in order to test accessibility
> notifications)
>
> I can't figure out the right incantations to do so.
>
> I'd like to do something like this in the LayoutTest
>
> var addedNotification = liveRegion.addNotificationListener("ariaCallback");
>
> then have a function in the test like
>
> function ariaCallback(notification) {
> // do stuff with notification
> }
>
> DRT knows when to call this method, but I'm not sure how.. This is what I
> have so far, which does not work.
>
> // The JavaScript callback we'll use when we get a notification
> static JSStringRef AXNotificationFunctionCallback = 0;
>
> static void _accessibilityNotificationCallback(id element, NSString*
> notification)
> {
> if (!AXNotificationFunctionCallback)
> return;
>
>
> JSObjectRef function = JSObjectMakeFunction([mainFrame globalContext],
> NULL, 0, NULL, AXNotificationFunctionCallback, NULL, 1, NULL);
> JSValueRef argument = JSValueMakeString([mainFrame globalContext],
> JSStringCreateWithCFString((CFStringRef)notification));
>
>
>
>
> JSObjectCallAsFunction([mainFrame globalContext], function, NULL, 1,
> &argument, NULL);
> }
>
What you need to do is lookup the function object on the global object. Your
function would look more like:
static void _accessibilityNotificationCallback(id element, NSString*
notification)
{
if (!AXNotificationFunctionCallback)
return;
JSValueRef functionValue = JSObjectGetProperty([mainFrame
globalContext], JSContextGetGlobalObject([mainFrame globalContext]),
AXNotificationFunctionCallback, NULL);
if (!JSValueIsObject(functionValue))
return;
JSObjectRef functionObject = static_cast<JSObjectRef>(functionValue);
JSValueRef argument = JSValueMakeString([mainFrame globalContext],
JSStringCreateWithCFString((CFStringRef)notification));
JSObjectCallAsFunction([mainFrame globalContext], function, NULL, 1,
&argument, NULL);
}
(You probably would want to add some more exception checks).
That said, a more javascripty way to do this would be to pass the function
object to liveRegion.addNotificationListener itself. That way, in the test
file, you would have,
liveRegion.addNotificationListener(function(notification) {
// do stuff with notification
});
In the implementation of addNotificationListener, you would save the
function object off instead of saving off the string, and then call it in
_accessibilityNotificationCallback.
-Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20100101/f362c0fe/attachment.html>
More information about the webkit-dev
mailing list