diff options
Diffstat (limited to 'WebKitTools/WebKitTestRunner/InjectedBundle')
15 files changed, 1367 insertions, 120 deletions
diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/ActivateFonts.h b/WebKitTools/WebKitTestRunner/InjectedBundle/ActivateFonts.h new file mode 100644 index 0000000..5ee1276 --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/ActivateFonts.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ActivateFonts_h +#define ActivateFonts_h + +namespace WTR { + +void activateFonts(); + +} // namespace WTR + +#endif // ActivateFonts_h diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm new file mode 100644 index 0000000..d72d4fc --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm @@ -0,0 +1,525 @@ +# Copyright (C) 2010 Apple Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +use strict; +use warnings; +use File::Spec; + +package CodeGeneratorTestRunner; + +sub new +{ + my ($class, $codeGenerator, $outputDir) = @_; + + my $reference = { + codeGenerator => $codeGenerator, + outputDir => $outputDir, + }; + + bless($reference, $class); + return $reference; +} + +sub GenerateModule +{ +} + +sub GenerateInterface +{ + my ($self, $interface, $defines) = @_; + + foreach my $file ($self->_generateHeaderFile($interface), $self->_generateImplementationFile($interface)) { + open(FILE, ">", File::Spec->catfile($$self{outputDir}, $$file{name})) or die "Failed to open $$file{name} for writing: $!"; + print FILE @{$$file{contents}}; + close(FILE) or die "Failed to close $$file{name} after writing: $!"; + } +} + +sub finish +{ +} + +sub _className +{ + my ($idlType) = @_; + + return "JS" . _implementationClassName($idlType); +} + +sub _classRefGetter +{ + my ($self, $idlType) = @_; + return $$self{codeGenerator}->WK_lcfirst(_implementationClassName($idlType)) . "Class"; +} + +sub _fileHeaderString +{ + my ($filename) = @_; + + # FIXME: We should pull header out of the IDL file to get the copyright + # year(s) right. + return <<EOF; +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +EOF +} + +sub _generateHeaderFile +{ + my ($self, $interface) = @_; + + my @contents = (); + + my $idlType = $interface->name; + my $className = _className($idlType); + my $implementationClassName = _implementationClassName($idlType); + my $filename = $className . ".h"; + + push(@contents, _fileHeaderString($filename)); + + my $parentClassName = _parentClassName($interface); + + push(@contents, <<EOF); + +#ifndef ${className}_h +#define ${className}_h + +#include "${parentClassName}.h" +EOF + push(@contents, <<EOF); + +namespace WTR { + +class ${implementationClassName}; + +class ${className} : public ${parentClassName} { +public: + static JSClassRef @{[$self->_classRefGetter($idlType)]}(); + +private: + static const JSStaticFunction* staticFunctions(); + static const JSStaticValue* staticValues(); +EOF + + if (my @functions = @{$interface->functions}) { + push(@contents, "\n // Functions\n\n"); + foreach my $function (@functions) { + push(@contents, " static JSValueRef @{[$function->signature->name]}(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef*);\n"); + } + } + + if (my @attributes = @{$interface->attributes}) { + push(@contents, "\n // Attributes\n\n"); + foreach my $attribute (@attributes) { + push(@contents, " static JSValueRef @{[$self->_getterName($attribute)]}(JSContextRef, JSObjectRef, JSStringRef, JSValueRef*);\n"); + push(@contents, " static bool @{[$self->_setterName($attribute)]}(JSContextRef, JSObjectRef, JSStringRef, JSValueRef, JSValueRef*);\n") unless $attribute->type =~ /^readonly/; + } + } + + push(@contents, <<EOF); +}; + +${implementationClassName}* to${implementationClassName}(JSContextRef, JSValueRef); + +} // namespace WTR + +#endif // ${className}_h +EOF + + return { name => $filename, contents => \@contents }; +} + +sub _generateImplementationFile +{ + my ($self, $interface) = @_; + + my @contentsPrefix = (); + my %contentsIncludes = (); + my @contents = (); + + my $idlType = $interface->name; + my $className = _className($idlType); + my $implementationClassName = _implementationClassName($idlType); + my $filename = $className . ".cpp"; + + push(@contentsPrefix, _fileHeaderString($filename)); + + my $classRefGetter = $self->_classRefGetter($idlType); + my $parentClassName = _parentClassName($interface); + + $contentsIncludes{"${className}.h"} = 1; + $contentsIncludes{"${implementationClassName}.h"} = 1; + + push(@contentsPrefix, <<EOF); + +EOF + + push(@contents, <<EOF); +#include <JavaScriptCore/JSRetainPtr.h> +#include <wtf/GetPtr.h> + +namespace WTR { + +${implementationClassName}* to${implementationClassName}(JSContextRef context, JSValueRef value) +{ + if (!context || !value || !${className}::${classRefGetter}() || !JSValueIsObjectOfClass(context, value, ${className}::${classRefGetter}())) + return 0; + return static_cast<${implementationClassName}*>(JSWrapper::unwrap(context, value)); +} + +JSClassRef ${className}::${classRefGetter}() +{ + static JSClassRef jsClass; + if (!jsClass) { + JSClassDefinition definition = kJSClassDefinitionEmpty; + definition.className = "${idlType}"; + definition.parentClass = @{[$self->_parentClassRefGetterExpression($interface)]}; + definition.staticValues = staticValues(); + definition.staticFunctions = staticFunctions(); +EOF + + push(@contents, " definition.initialize = initialize;\n") unless _parentInterface($interface); + push(@contents, " definition.finalize = finalize;\n") unless _parentInterface($interface); + + push(@contents, <<EOF); + jsClass = JSClassCreate(&definition); + } + return jsClass; +} + +EOF + + push(@contents, $self->_staticFunctionsGetterImplementation($interface), "\n"); + push(@contents, $self->_staticValuesGetterImplementation($interface)); + + if (my @functions = @{$interface->functions}) { + push(@contents, "\n// Functions\n"); + + foreach my $function (@functions) { + push(@contents, <<EOF); + +JSValueRef ${className}::@{[$function->signature->name]}(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + ${implementationClassName}* impl = to${implementationClassName}(context, thisObject); + if (!impl) + return JSValueMakeUndefined(context); +EOF + my @parameters = (); + my @specifiedParameters = @{$function->parameters}; + + push(@contents, "\n") if scalar @specifiedParameters; + + $self->_includeHeaders(\%contentsIncludes, $function->signature->type, $function->signature); + + foreach my $i (0..$#specifiedParameters) { + my $parameter = $specifiedParameters[$i]; + + $self->_includeHeaders(\%contentsIncludes, $idlType, $parameter); + + push(@contents, " " . $self->_platformTypeVariableDeclaration($parameter, $parameter->name, "arguments[$i]", "argumentCount > $i") . "\n"); + + push(@parameters, $self->_paramterExpression($parameter)); + } + + my $isVoidReturn = $function->signature->type eq "void"; + my $functionName = "impl->" . $function->signature->name; + my $functionCall = $functionName . "(" . join(", ", @parameters) . ")"; + + push(@contents, "\n") unless scalar @specifiedParameters == 1; + push(@contents, " ${functionCall};\n\n") if $isVoidReturn; + push(@contents, " return " . $self->_returnExpression($function->signature, $functionCall) . ";\n}\n"); + } + } + + if (my @attributes = @{$interface->attributes}) { + push(@contents, "\n// Attributes\n"); + foreach my $attribute (@attributes) { + $self->_includeHeaders(\%contentsIncludes, $attribute->signature->type, $attribute->signature); + + my $getterName = $self->_getterName($attribute); + my $getterExpression = "impl->${getterName}()"; + + push(@contents, <<EOF); + +JSValueRef ${className}::${getterName}(JSContextRef context, JSObjectRef object, JSStringRef, JSValueRef* exception) +{ + ${implementationClassName}* impl = to${implementationClassName}(context, object); + if (!impl) + return JSValueMakeUndefined(context); + + return @{[$self->_returnExpression($attribute->signature, $getterExpression)]}; +} +EOF + + unless ($attribute->type =~ /^readonly/) { + push(@contents, <<EOF); + +bool ${className}::@{[$self->_setterName($attribute)]}(JSContextRef context, JSObjectRef object, JSStringRef, JSValueRef value, JSValueRef* exception) +{ + ${implementationClassName}* impl = to${implementationClassName}(context, object); + if (!impl) + return false; + +EOF + + my $platformValue = $self->_platformTypeConstructor($attribute->signature, "value"); + + push(@contents, <<EOF); + impl->@{[$self->_setterName($attribute)]}(${platformValue}); + + return true; +} +EOF + } + } + } + + push(@contents, <<EOF); + +} // namespace WTR + +EOF + + unshift(@contents, map { "#include \"$_\"\n" } sort keys(%contentsIncludes)); + unshift(@contents, @contentsPrefix); + + return { name => $filename, contents => \@contents }; +} + +sub _getterName +{ + my ($self, $attribute) = @_; + + my $signature = $attribute->signature; + my $name = $signature->name; + + return $name; +} + +sub _includeHeaders +{ + my ($self, $headers, $idlType, $signature) = @_; + + return unless defined $idlType; + return if $idlType eq "boolean" or $$self{codeGenerator}->IsNonPointerType($idlType); + + $$headers{_className($idlType) . ".h"} = 1; + $$headers{_implementationClassName($idlType) . ".h"} = 1; +} + +sub _implementationClassName +{ + my ($idlType) = @_; + + return $idlType; +} + +sub _parentClassName +{ + my ($interface) = @_; + + my $parentInterface = _parentInterface($interface); + return $parentInterface ? _className($parentInterface) : "JSWrapper"; +} + +sub _parentClassRefGetterExpression +{ + my ($self, $interface) = @_; + + my $parentInterface = _parentInterface($interface); + return $parentInterface ? $self->_classRefGetter($parentInterface) . "()" : "0"; +} + +sub _parentInterface +{ + my ($interface) = @_; + return $interface->parents->[0]; +} + +sub _platformType +{ + my ($self, $idlType, $signature) = @_; + + return undef unless defined $idlType; + + return "bool" if $idlType eq "boolean"; + return "JSRetainPtr<JSStringRef>" if $$self{codeGenerator}->IsStringType($idlType); + return "double" if $$self{codeGenerator}->IsNonPointerType($idlType); + return _implementationClassName($idlType); +} + +sub _platformTypeConstructor +{ + my ($self, $signature, $argumentName) = @_; + + my $idlType = $signature->type; + + return "JSRetainPtr<JSStringRef>(Adopt, JSValueToStringCopy(context, $argumentName, 0))" if $$self{codeGenerator}->IsStringType($idlType); + return "JSValueToBoolean(context, $argumentName)" if $idlType eq "boolean"; + return "JSValueToNumber(context, $argumentName, 0)" if $$self{codeGenerator}->IsNonPointerType($idlType); + return "to" . _implementationClassName($idlType) . "(context, $argumentName)"; +} + +sub _platformTypeVariableDeclaration +{ + my ($self, $signature, $variableName, $argumentName, $condition) = @_; + + my $platformType = $self->_platformType($signature->type, $signature); + my $constructor = $self->_platformTypeConstructor($signature, $argumentName); + + my %nonPointerTypes = ( + "bool" => 1, + "double" => 1, + "JSRetainPtr<JSStringRef>" => 1, + ); + + my $nullValue = "0"; + $nullValue = "$platformType()" if defined $nonPointerTypes{$platformType} && $platformType ne "double"; + + $platformType .= "*" unless defined $nonPointerTypes{$platformType}; + + return "$platformType $variableName = $condition && $constructor;" if $condition && $platformType eq "bool"; + return "$platformType $variableName = $condition ? $constructor : $nullValue;" if $condition; + return "$platformType $variableName = $constructor;"; +} + +sub _returnExpression +{ + my ($self, $signature, $expression) = @_; + + my $convertNullStringAttribute = $signature->extendedAttributes->{"ConvertNullStringTo"}; + my $nullOrEmptyString = "NullStringAsEmptyString"; + $nullOrEmptyString = "NullStringAsNull" if defined $convertNullStringAttribute && $convertNullStringAttribute eq "Null"; + + my $returnIDLType = $signature->type; + + return "JSValueMakeUndefined(context)" if $returnIDLType eq "void"; + return "JSValueMakeBoolean(context, ${expression})" if $returnIDLType eq "boolean"; + return "JSValueMakeNumber(context, ${expression})" if $$self{codeGenerator}->IsNonPointerType($returnIDLType); + return "toJS(context, WTF::getPtr(${expression}))"; +} + +sub _paramterExpression +{ + my ($self, $parameter) = @_; + + my $idlType = $parameter->type; + my $name = $parameter->name; + + return "${name}.get()" if $$self{codeGenerator}->IsStringType($idlType); + return $name; +} + +sub _setterName +{ + my ($self, $attribute) = @_; + + my $name = $attribute->signature->name; + + return "set" . $$self{codeGenerator}->WK_ucfirst($name); +} + +sub _staticFunctionsGetterImplementation +{ + my ($self, $interface) = @_; + + my $mapFunction = sub { + my $name = $_->signature->name; + my @attributes = qw(kJSPropertyAttributeDontDelete kJSPropertyAttributeReadOnly); + push(@attributes, "kJSPropertyAttributeDontEnum") if $_->signature->extendedAttributes->{"DontEnum"}; + + return "{ \"$name\", $name, " . join(" | ", @attributes) . " }"; + }; + + return $self->_staticFunctionsOrValuesGetterImplementation($interface, "function", "{ 0, 0, 0 }", $mapFunction, $interface->functions); +} + +sub _staticFunctionsOrValuesGetterImplementation +{ + my ($self, $interface, $functionOrValue, $arrayTerminator, $mapFunction, $functionsOrAttributes) = @_; + + my $className = _className($interface->name); + my $uppercaseFunctionOrValue = $$self{codeGenerator}->WK_ucfirst($functionOrValue); + + my $result = <<EOF; +const JSStatic${uppercaseFunctionOrValue}* ${className}::static${uppercaseFunctionOrValue}s() +{ +EOF + + my @initializers = map(&$mapFunction, @{$functionsOrAttributes}); + return $result . " return 0;\n}\n" unless @initializers; + + $result .= <<EOF + static const JSStatic${uppercaseFunctionOrValue} ${functionOrValue}s[] = { + @{[join(",\n ", @initializers)]}, + ${arrayTerminator} + }; + return ${functionOrValue}s; +} +EOF +} + +sub _staticValuesGetterImplementation +{ + my ($self, $interface) = @_; + + my $mapFunction = sub { + return if $_->signature->extendedAttributes->{"NoImplementation"}; + + my $attributeName = $_->signature->name; + my $attributeIsReadonly = $_->type =~ /^readonly/; + my $getterName = $self->_getterName($_); + my $setterName = $attributeIsReadonly ? "0" : $self->_setterName($_); + my @attributes = qw(kJSPropertyAttributeDontDelete); + push(@attributes, "kJSPropertyAttributeReadOnly") if $attributeIsReadonly; + push(@attributes, "kJSPropertyAttributeDontEnum") if $_->signature->extendedAttributes->{"DontEnum"}; + + return "{ \"$attributeName\", $getterName, $setterName, " . join(" | ", @attributes) . " }"; + }; + + return $self->_staticFunctionsOrValuesGetterImplementation($interface, "value", "{ 0, 0, 0, 0 }", $mapFunction, $interface->attributes); +} + +1; diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrappable.h b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrappable.h new file mode 100644 index 0000000..cf56c5d --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrappable.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSWrappable_h +#define JSWrappable_h + +#include <JavaScriptCore/JavaScriptCore.h> +#include <wtf/RefCounted.h> + +namespace WTR { + +class JSWrappable : public RefCounted<JSWrappable> { +public: + virtual ~JSWrappable() { } + virtual JSClassRef wrapperClass() = 0; +}; + +} // namespace WTR + +#endif // JSWrappable_h diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrapper.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrapper.cpp new file mode 100644 index 0000000..a62cb2e --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrapper.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "JSWrapper.h" + +#include <JavaScriptCore/JSContextRefPrivate.h> + +namespace WTR { + +JSValueRef JSWrapper::wrap(JSContextRef context, JSWrappable* object) +{ + ASSERT_ARG(context, context); + + if (!object) + return JSValueMakeNull(context); + + JSClassRef objectClass = object->wrapperClass(); + ASSERT(objectClass); + JSObjectRef wrapperObject = JSObjectMake(context, objectClass, object); + ASSERT(wrapperObject); + + return wrapperObject; +} + +JSWrappable* JSWrapper::unwrap(JSContextRef context, JSValueRef value) +{ + ASSERT_ARG(context, context); + ASSERT_ARG(value, value); + if (!context || !value) + return 0; + return static_cast<JSWrappable*>(JSObjectGetPrivate(JSValueToObject(context, value, 0))); +} + +static JSWrappable* unwrapObject(JSObjectRef object) +{ + JSWrappable* wrappable = static_cast<JSWrappable*>(JSObjectGetPrivate(object)); + ASSERT(wrappable); + return wrappable; +} + +void JSWrapper::initialize(JSContextRef ctx, JSObjectRef object) +{ + JSWrappable* wrappable = unwrapObject(object); + if (!wrappable) + return; + wrappable->ref(); +} + +void JSWrapper::finalize(JSObjectRef object) +{ + JSWrappable* wrappable = unwrapObject(object); + if (!wrappable) + return; + wrappable->deref(); +} + +} // namespace WTR diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrapper.h b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrapper.h new file mode 100644 index 0000000..9839cb4 --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/JSWrapper.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSWrapper_h +#define JSWrapper_h + +#include "JSWrappable.h" + +namespace WTR { + +// FIXME: If necessary, we can do wrapper caching here. +class JSWrapper { +public: + static JSValueRef wrap(JSContextRef context, JSWrappable* object); + static JSWrappable* unwrap(JSContextRef context, JSValueRef value); + + static void initialize(JSContextRef, JSObjectRef); + static void finalize(JSObjectRef); +}; + +inline JSValueRef toJS(JSContextRef context, JSWrappable* impl) +{ + return JSWrapper::wrap(context, impl); +} + +} // namespace WTR + +#endif // JSWrapper_h diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl new file mode 100644 index 0000000..7da2e81 --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +module WTR { + + interface LayoutTestController { + void dumpAsText(); + void dumpStatusCallbacks(); + + void waitUntilDone(); + void notifyDone(); + + // Repaint testing + void testRepaint(); + void repaintSweepHorizontally(); + void display(); + + // Animation testing + int numberOfActiveAnimations(); + boolean pauseAnimationAtTimeOnElementWithId(in DOMString animationName, in double time, in DOMString elementId); + }; + +} diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp index 9eea3e2..d3c66fd 100644 --- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp @@ -25,6 +25,7 @@ #include "InjectedBundle.h" +#include "ActivateFonts.h" #include "InjectedBundlePage.h" #include <WebKit2/WKBundle.h> #include <WebKit2/WKBundlePage.h> @@ -73,6 +74,8 @@ void InjectedBundle::initialize(WKBundleRef bundle) _didRecieveMessage }; WKBundleSetClient(m_bundle, &client); + + activateFonts(); } void InjectedBundle::done() diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp index 27779df..b1bc89d 100644 --- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp @@ -26,7 +26,12 @@ #include "InjectedBundle.h" #include <WebKit2/WKBundleInitialize.h> -extern "C" void WKBundleInitialize(WKBundleRef bundle) +#if defined(WIN32) || defined(_WIN32) +extern "C" __declspec(dllexport) +#else +extern "C" +#endif +void WKBundleInitialize(WKBundleRef bundle) { WTR::InjectedBundle::shared().initialize(bundle); } diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp index b254405..cbba470 100644 --- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp @@ -37,6 +37,19 @@ namespace WTR { +static PassOwnPtr<Vector<char> > WKStringToUTF8(WKStringRef wkStringRef) +{ + RetainPtr<CFStringRef> cfString(AdoptCF, WKStringCopyCFString(0, wkStringRef)); + CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfString.get()), kCFStringEncodingUTF8) + 1; + OwnPtr<Vector<char> > buffer(new Vector<char>(bufferLength)); + if (!CFStringGetCString(cfString.get(), buffer->data(), bufferLength, kCFStringEncodingUTF8)) { + buffer->shrink(1); + (*buffer)[0] = 0; + } else + buffer->shrink(strlen(buffer->data()) + 1); + return buffer.release(); +} + InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page) : m_page(page) , m_isLoading(false) @@ -58,10 +71,13 @@ InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page) WKBundlePageUIClient uiClient = { 0, this, - _addMessageToConsole + _willAddMessageToConsole, + _willSetStatusbarText, + _willRunJavaScriptAlert, + _willRunJavaScriptConfirm, + _willRunJavaScriptPrompt }; WKBundlePageSetUIClient(m_page, &uiClient); - } InjectedBundlePage::~InjectedBundlePage() @@ -128,24 +144,11 @@ void InjectedBundlePage::didCommitLoadForFrame(WKBundleFrameRef frame) { } -static PassOwnPtr<Vector<char> > WKStringToUTF8(WKStringRef wkStringRef) -{ - RetainPtr<CFStringRef> cfString(AdoptCF, WKStringCopyCFString(0, wkStringRef)); - CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfString.get()), kCFStringEncodingUTF8) + 1; - OwnPtr<Vector<char> > buffer(new Vector<char>(bufferLength)); - if (!CFStringGetCString(cfString.get(), buffer->data(), bufferLength, kCFStringEncodingUTF8)) { - buffer->shrink(1); - (*buffer)[0] = 0; - } else - buffer->shrink(strlen(buffer->data()) + 1); - return buffer.release(); -} - void InjectedBundlePage::dump() { InjectedBundle::shared().layoutTestController()->invalidateWaitToDumpWatchdog(); - if (InjectedBundle::shared().layoutTestController()->dumpAsText()) { + if (InjectedBundle::shared().layoutTestController()->shouldDumpAsText()) { // FIXME: Support dumping subframes when layoutTestController()->dumpChildFramesAsText() is true. WKRetainPtr<WKStringRef> innerText(AdoptWK, WKBundleFrameCopyInnerText(WKBundlePageGetMainFrame(m_page))); OwnPtr<Vector<char> > utf8InnerText = WKStringToUTF8(innerText.get()); @@ -193,16 +196,64 @@ void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, JSContex // UI Client Callbacks -void InjectedBundlePage::_addMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo) +void InjectedBundlePage::_willAddMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willAddMessageToConsole(message, lineNumber); +} + +void InjectedBundlePage::_willSetStatusbarText(WKBundlePageRef page, WKStringRef statusbarText, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willSetStatusbarText(statusbarText); +} + +void InjectedBundlePage::_willRunJavaScriptAlert(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptAlert(message, frame); +} + +void InjectedBundlePage::_willRunJavaScriptConfirm(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void *clientInfo) +{ + return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptConfirm(message, frame); +} + +void InjectedBundlePage::_willRunJavaScriptPrompt(WKBundlePageRef page, WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef frame, const void *clientInfo) { - static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->addMessageToConsole(message, lineNumber); + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptPrompt(message, defaultValue, frame); } -void InjectedBundlePage::addMessageToConsole(WKStringRef message, uint32_t lineNumber) +void InjectedBundlePage::willAddMessageToConsole(WKStringRef message, uint32_t lineNumber) { // FIXME: Strip file: urls. OwnPtr<Vector<char> > utf8Message = WKStringToUTF8(message); InjectedBundle::shared().os() << "CONSOLE MESSAGE: line " << lineNumber << ": " << utf8Message->data() << "\n"; } +void InjectedBundlePage::willSetStatusbarText(WKStringRef statusbarText) +{ + if (!InjectedBundle::shared().layoutTestController()->shouldDumpStatusCallbacks()) + return; + + OwnPtr<Vector<char> > utf8StatusbarText = WKStringToUTF8(statusbarText); + InjectedBundle::shared().os() << "UI DELEGATE STATUS CALLBACK: setStatusText:" << utf8StatusbarText->data() << "\n"; +} + +void InjectedBundlePage::willRunJavaScriptAlert(WKStringRef message, WKBundleFrameRef) +{ + OwnPtr<Vector<char> > utf8Message = WKStringToUTF8(message); + InjectedBundle::shared().os() << "ALERT: " << utf8Message->data() << "\n"; +} + +void InjectedBundlePage::willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef) +{ + OwnPtr<Vector<char> > utf8Message = WKStringToUTF8(message); + InjectedBundle::shared().os() << "CONFIRM: " << utf8Message->data() << "\n"; +} + +void InjectedBundlePage::willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef) +{ + OwnPtr<Vector<char> > utf8Message = WKStringToUTF8(message); + OwnPtr<Vector<char> > utf8DefaultValue = WKStringToUTF8(defaultValue); + InjectedBundle::shared().os() << "PROMPT: " << utf8Message->data() << ", default text: " << utf8DefaultValue->data() << "\n"; +} + } // namespace WTR diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h index 79aebb7..bce9d2c 100644 --- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h @@ -60,8 +60,16 @@ private: void didClearWindowForFrame(WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window); // UI Client - static void _addMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo); - void addMessageToConsole(WKStringRef message, uint32_t lineNumber); + static void _willAddMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void* clientInfo); + static void _willSetStatusbarText(WKBundlePageRef page, WKStringRef statusbarText, const void* clientInfo); + static void _willRunJavaScriptAlert(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void* clientInfo); + static void _willRunJavaScriptConfirm(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void* clientInfo); + static void _willRunJavaScriptPrompt(WKBundlePageRef page, WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef frame, const void* clientInfo); + void willAddMessageToConsole(WKStringRef message, uint32_t lineNumber); + void willSetStatusbarText(WKStringRef statusbarText); + void willRunJavaScriptAlert(WKStringRef message, WKBundleFrameRef); + void willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef); + void willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef); WKBundlePageRef m_page; bool m_isLoading; diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp index cf3e0fb..fafa1e3 100644 --- a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp @@ -24,9 +24,10 @@ */ #include "LayoutTestController.h" + #include "InjectedBundle.h" #include "InjectedBundlePage.h" - +#include "JSLayoutTestController.h" #include <JavaScriptCore/JSRetainPtr.h> #include <WebKit2/WKBundleFrame.h> #include <WebKit2/WKRetainPtr.h> @@ -42,7 +43,10 @@ PassRefPtr<LayoutTestController> LayoutTestController::create(const std::string& LayoutTestController::LayoutTestController(const std::string& testPathOrURL) : m_dumpAsText(false) + , m_dumpStatusCallbacks(false) , m_waitToDump(false) + , m_testRepaint(false) + , m_testRepaintSweepHorizontally(false) , m_testPathOrURL(testPathOrURL) { } @@ -51,8 +55,19 @@ LayoutTestController::~LayoutTestController() { } -static const CFTimeInterval waitToDumpWatchdogInterval = 30.0; +JSClassRef LayoutTestController::wrapperClass() +{ + return JSLayoutTestController::layoutTestControllerClass(); +} +// This is lower than DumpRenderTree's timeout, to make it easier to work through the failures +// Eventually it should be changed to match. +static const CFTimeInterval waitToDumpWatchdogInterval = 6.0; + +void LayoutTestController::display() +{ + // FIXME: actually implement, once we want pixel tests +} void LayoutTestController::invalidateWaitToDumpWatchdog() { @@ -67,7 +82,7 @@ static void waitUntilDoneWatchdogFired(CFRunLoopTimerRef timer, void* info) InjectedBundle::shared().layoutTestController()->waitToDumpWatchdogTimerFired(); } -void LayoutTestController::setWaitToDump() +void LayoutTestController::waitUntilDone() { m_waitToDump = true; if (!m_waitToDumpWatchdog) { @@ -109,97 +124,12 @@ bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef anima return WKBundleFramePauseAnimationOnElementWithId(mainFrame, nameWK.get(), idWK.get(), time); } -static JSValueRef dumpAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); - controller->setDumpAsText(true); - return JSValueMakeUndefined(context); -} - -static JSValueRef waitUntilDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); - controller->setWaitToDump(); - return JSValueMakeUndefined(context); -} - -static JSValueRef notifyDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); - controller->notifyDone(); - return JSValueMakeUndefined(context); -} - -static JSValueRef numberOfActiveAnimationsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - if (argumentCount) - return JSValueMakeUndefined(context); - - LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); - return JSValueMakeNumber(context, controller->numberOfActiveAnimations()); -} - -static JSValueRef pauseAnimationAtTimeOnElementWithIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - if (argumentCount != 3) - return JSValueMakeUndefined(context); - - JSRetainPtr<JSStringRef> animationName(Adopt, JSValueToStringCopy(context, arguments[0], exception)); - ASSERT(!*exception); - double time = JSValueToNumber(context, arguments[1], exception); - ASSERT(!*exception); - JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[2], exception)); - ASSERT(!*exception); - - LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject)); - return JSValueMakeBoolean(context, controller->pauseAnimationAtTimeOnElementWithId(animationName.get(), time, elementId.get())); -} - -// Object Finalization - -static void layoutTestControllerObjectFinalize(JSObjectRef object) -{ - LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(object)); - controller->deref(); -} - // Object Creation void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) { JSRetainPtr<JSStringRef> layoutTestContollerStr(Adopt, JSStringCreateWithUTF8CString("layoutTestController")); - ref(); - - JSClassRef classRef = getJSClass(); - JSValueRef layoutTestContollerObject = JSObjectMake(context, classRef, this); - JSClassRelease(classRef); - - JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), layoutTestContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); -} - -JSClassRef LayoutTestController::getJSClass() -{ - static JSStaticFunction* staticFunctions = LayoutTestController::staticFunctions(); - static JSClassDefinition classDefinition = { - 0, kJSClassAttributeNone, "LayoutTestController", 0, 0, staticFunctions, - 0, layoutTestControllerObjectFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - return JSClassCreate(&classDefinition); -} - -JSStaticFunction* LayoutTestController::staticFunctions() -{ - static JSStaticFunction staticFunctions[] = { - { "dumpAsText", dumpAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "notifyDone", notifyDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "numberOfActiveAnimations", numberOfActiveAnimationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "pauseAnimationAtTimeOnElementWithId", pauseAnimationAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "waitUntilDone", waitUntilDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { 0, 0, 0 } - }; - - return staticFunctions; + JSObjectSetProperty(context, windowObject, layoutTestContollerStr.get(), JSWrapper::wrap(context, this), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); } } // namespace WTR diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h index 203f358..f9585a3 100644 --- a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h @@ -26,30 +26,40 @@ #ifndef LayoutTestController_h #define LayoutTestController_h +#include "JSWrappable.h" #include <JavaScriptCore/JavaScriptCore.h> #include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> #include <wtf/RetainPtr.h> #include <string> namespace WTR { -class LayoutTestController : public RefCounted<LayoutTestController> { +class LayoutTestController : public JSWrappable { public: static PassRefPtr<LayoutTestController> create(const std::string& testPathOrURL); ~LayoutTestController(); + // JSWrappable + JSClassRef wrapperClass(); + void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception); - bool dumpAsText() const { return m_dumpAsText; } - void setDumpAsText(bool dumpAsText) { m_dumpAsText = dumpAsText; } + bool shouldDumpAsText() const { return m_dumpAsText; } + void dumpAsText() { m_dumpAsText = true; } + + bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; } + void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; } bool waitToDump() const { return m_waitToDump; } - void setWaitToDump(); void waitToDumpWatchdogTimerFired(); void invalidateWaitToDumpWatchdog(); + void waitUntilDone(); void notifyDone(); + void testRepaint() { m_testRepaint = true; } + void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; } + void display(); + unsigned numberOfActiveAnimations() const; bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId); @@ -57,15 +67,14 @@ private: LayoutTestController(const std::string& testPathOrURL); bool m_dumpAsText; + bool m_dumpStatusCallbacks; bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called. + bool m_testRepaint; + bool m_testRepaintSweepHorizontally; std::string m_testPathOrURL; RetainPtr<CFRunLoopTimerRef> m_waitToDumpWatchdog; - - static JSClassRef getJSClass(); - static JSStaticValue* staticValues(); - static JSStaticFunction* staticFunctions(); }; } // namespace WTR diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/mac/ActivateFonts.mm b/WebKitTools/WebKitTestRunner/InjectedBundle/mac/ActivateFonts.mm new file mode 100644 index 0000000..b5bc4a1 --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/mac/ActivateFonts.mm @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ActivateFonts.h" + +#import <AppKit/AppKit.h> +#import <CoreFoundation/CoreFoundation.h> +#import <Foundation/Foundation.h> + +@interface WKTRFontActivatorDummyClass : NSObject +@end + +@implementation WKTRFontActivatorDummyClass +@end + +namespace WTR { + +void activateFonts() +{ + // Work around <rdar://problem/6698023> by activating fonts from disk + + static const char* fontFileNames[] = { + "AHEM____.TTF", + "ColorBits.ttf", + "WebKitWeightWatcher100.ttf", + "WebKitWeightWatcher200.ttf", + "WebKitWeightWatcher300.ttf", + "WebKitWeightWatcher400.ttf", + "WebKitWeightWatcher500.ttf", + "WebKitWeightWatcher600.ttf", + "WebKitWeightWatcher700.ttf", + "WebKitWeightWatcher800.ttf", + "WebKitWeightWatcher900.ttf", + 0 + }; + + NSMutableArray *fontURLs = [NSMutableArray array]; + NSURL *resourcesDirectory = [[NSBundle bundleForClass:[WKTRFontActivatorDummyClass class]] resourceURL]; + for (unsigned i = 0; fontFileNames[i]; ++i) { + NSURL *fontURL = [resourcesDirectory URLByAppendingPathComponent:[NSString stringWithUTF8String:fontFileNames[i]]]; + [fontURLs addObject:[fontURL absoluteURL]]; + } + + CFArrayRef errors = 0; + if (!CTFontManagerRegisterFontsForURLs((CFArrayRef)fontURLs, kCTFontManagerScopeProcess, &errors)) { + NSLog(@"Failed to activate fonts: %@", errors); + CFRelease(errors); + exit(1); + } +} + +} + diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/win/ActivateFonts.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/win/ActivateFonts.cpp new file mode 100644 index 0000000..c7532ce --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/win/ActivateFonts.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ActivateFonts.h" + +namespace WTR { + +void activateFonts() +{ + // FIXME: Not implemented. +} + +} diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/win/InjectedBundle.vcproj b/WebKitTools/WebKitTestRunner/InjectedBundle/win/InjectedBundle.vcproj new file mode 100644 index 0000000..601a4ac --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/win/InjectedBundle.vcproj @@ -0,0 +1,355 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="InjectedBundle"
+ ProjectGUID="{CBC3391C-F060-4BF5-A66E-81404168816B}"
+ RootNamespace="InjectedBundle"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(WebKitLibrariesDir)\tools\vsprops\common.vsprops;$(WebKitLibrariesDir)\tools\vsprops\debug.vsprops;..\..\Configurations\InjectedBundleCommon.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ ForcedIncludeFiles=""
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile=""
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine=""
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(WebKitLibrariesDir)\tools\vsprops\common.vsprops;$(WebKitLibrariesDir)\tools\vsprops\release.vsprops;..\..\Configurations\InjectedBundleCommon.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ ForcedIncludeFiles=""
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile=""
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine=""
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug_All|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(WebKitLibrariesDir)\tools\vsprops\common.vsprops;$(WebKitLibrariesDir)\tools\vsprops\debug.vsprops;$(WebKitLibrariesDir)\tools\vsprops\debug_internal.vsprops;$(WebKitLibrariesDir)\tools\vsprops\debug_all.vsprops;..\..\Configurations\InjectedBundleCommon.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ RuntimeLibrary="3"
+ ForcedIncludeFiles=""
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile=""
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine=""
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug_Internal|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(WebKitLibrariesDir)\tools\vsprops\common.vsprops;$(WebKitLibrariesDir)\tools\vsprops\debug.vsprops;$(WebKitLibrariesDir)\tools\vsprops\debug_internal.vsprops;..\..\Configurations\InjectedBundleCommon.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine=""
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ ForcedIncludeFiles=""
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile=""
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine=""
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Bindings"
+ >
+ <File
+ RelativePath="..\Bindings\CodeGeneratorTestRunner.pm"
+ >
+ </File>
+ <File
+ RelativePath="..\Bindings\JSWrappable.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Bindings\JSWrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Bindings\JSWrapper.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Derived Sources"
+ >
+ <File
+ RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSLayoutTestController.cpp"
+ >
+ </File>
+ <File
+ RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSLayoutTestController.h"
+ >
+ </File>
+ </Filter>
+ <File
+ RelativePath="ActivateFonts.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\InjectedBundle.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\InjectedBundle.h"
+ >
+ </File>
+ <File
+ RelativePath="..\InjectedBundleMain.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\InjectedBundlePage.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\InjectedBundlePage.h"
+ >
+ </File>
+ <File
+ RelativePath="..\LayoutTestController.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\LayoutTestController.h"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
|