From ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 8 Jul 2010 12:51:48 +0100 Subject: Merge WebKit at r62496: Initial merge by git Change-Id: Ie3da0770eca22a70a632e3571f31cfabc80facb2 --- .../InjectedBundle/InjectedBundle.cpp | 117 +++++++++++++++ .../InjectedBundle/InjectedBundle.h | 78 ++++++++++ .../InjectedBundle/InjectedBundleMain.cpp | 78 +--------- .../InjectedBundle/InjectedBundlePage.cpp | 160 +++++++++++++++++++++ .../InjectedBundle/InjectedBundlePage.h | 64 +++++++++ .../InjectedBundle/LayoutTestController.cpp | 97 +++++++++++++ .../InjectedBundle/LayoutTestController.h | 60 ++++++++ 7 files changed, 578 insertions(+), 76 deletions(-) create mode 100644 WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp create mode 100644 WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h create mode 100644 WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp create mode 100644 WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h create mode 100644 WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp create mode 100644 WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h (limited to 'WebKitTools/WebKitTestRunner/InjectedBundle') diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp new file mode 100644 index 0000000..63013fb --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp @@ -0,0 +1,117 @@ +/* + * 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 "InjectedBundle.h" + +#include "InjectedBundlePage.h" +#include +#include +#include +#include +#include +#include + +namespace WTR { + +InjectedBundle& InjectedBundle::shared() +{ + static InjectedBundle& shared = *new InjectedBundle; + return shared; +} + +InjectedBundle::InjectedBundle() + : m_bundle(0) + , m_layoutTestController(LayoutTestController::create(std::string(""))) +{ +} + +void InjectedBundle::_didCreatePage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo) +{ + static_cast(const_cast(clientInfo))->didCreatePage(page); +} + +void InjectedBundle::_willDestroyPage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo) +{ + static_cast(const_cast(clientInfo))->willDestroyPage(page); +} + +void InjectedBundle::_didRecieveMessage(WKBundleRef bundle, WKStringRef message, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didRecieveMessage(message); +} + +void InjectedBundle::initialize(WKBundleRef bundle) +{ + m_bundle = bundle; + + WKBundleClient client = { + 0, + this, + _didCreatePage, + _willDestroyPage, + _didRecieveMessage + }; + WKBundleSetClient(m_bundle, &client); +} + +void InjectedBundle::done() +{ + std::string output = m_outputStream.str(); + RetainPtr outputCFString(AdoptCF, CFStringCreateWithCString(0, output.c_str(), kCFStringEncodingUTF8)); + WKRetainPtr doneMessage(AdoptWK, WKStringCreateWithCFString(outputCFString.get())); + WKBundlePostMessage(m_bundle, doneMessage.get()); +} + +void InjectedBundle::didCreatePage(WKBundlePageRef page) +{ + m_pages.add(page, new InjectedBundlePage(page)); +} + +void InjectedBundle::willDestroyPage(WKBundlePageRef page) +{ + delete m_pages.take(page); +} + +void InjectedBundle::didRecieveMessage(WKStringRef message) +{ + CFStringRef cfMessage = WKStringCopyCFString(0, message); + if (CFEqual(cfMessage, CFSTR("BeginTest"))) { + WKRetainPtr ackMessage(AdoptWK, WKStringCreateWithCFString(CFSTR("BeginTestAck"))); + WKBundlePostMessage(m_bundle, ackMessage.get()); + + reset(); + return; + } + + WKRetainPtr errorMessage(AdoptWK, WKStringCreateWithCFString(CFSTR("Error: Unknown."))); + WKBundlePostMessage(m_bundle, errorMessage.get()); +} + +void InjectedBundle::reset() +{ + m_outputStream.str(""); +} + +} // namespace WTR diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h new file mode 100644 index 0000000..33934cf --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h @@ -0,0 +1,78 @@ +/* + * 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 InjectedBundle_h +#define InjectedBundle_h + +#include "LayoutTestController.h" +#include +#include +#include +#include + +#include + +namespace WTR { + +class InjectedBundlePage; + +class InjectedBundle { +public: + static InjectedBundle& shared(); + + // Initialize the InjectedBundle. + void initialize(WKBundleRef); + + void done(); + + LayoutTestController* layoutTestController() { return m_layoutTestController.get(); } + + std::ostringstream& os() { return m_outputStream; } + +private: + InjectedBundle(); + ~InjectedBundle(); + + static void _didCreatePage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo); + static void _willDestroyPage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo); + static void _didRecieveMessage(WKBundleRef bundle, WKStringRef message, const void *clientInfo); + + void didCreatePage(WKBundlePageRef page); + void willDestroyPage(WKBundlePageRef page); + void didRecieveMessage(WKStringRef message); + + void reset(); + + WKBundleRef m_bundle; + HashMap m_pages; + + RefPtr m_layoutTestController; + + std::ostringstream m_outputStream; +}; + +} // namespace WTR + +#endif // InjectedBundle_h diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp index f108548..27779df 100644 --- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp @@ -23,84 +23,10 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include "InjectedBundle.h" #include -#include -#include - -static WKBundleRef globalBundle; - -// WKBundlePageClient - -void _didStartProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) -{ -} - -void _didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) -{ -} - -void _didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) -{ -} - -void _didCommitLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) -{ -} - -void _didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) -{ -} - -void _didFailLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) -{ -} - -void _didReceiveTitleForFrame(WKBundlePageRef page, WKStringRef title, WKBundleFrameRef frame, const void *clientInfo) -{ -} - -void _didClearWindow(WKBundlePageRef page, WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window, const void *clientInfo) -{ -} - -// WKBundleClient - -void _didCreatePage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo) -{ - WKBundlePageClient client = { - 0, - 0, - _didStartProvisionalLoadForFrame, - _didReceiveServerRedirectForProvisionalLoadForFrame, - _didFailProvisionalLoadWithErrorForFrame, - _didCommitLoadForFrame, - _didFinishLoadForFrame, - _didFailLoadWithErrorForFrame, - _didReceiveTitleForFrame, - _didClearWindow - }; - WKBundlePageSetClient(page, &client); -} - -void _willDestroyPage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo) -{ -} - -void _didRecieveMessage(WKBundleRef bundle, WKStringRef message, const void *clientInfo) -{ -} extern "C" void WKBundleInitialize(WKBundleRef bundle) { - globalBundle = bundle; - - WKBundleClient client = { - 0, - 0, - _didCreatePage, - _willDestroyPage, - _didRecieveMessage - }; - WKBundleSetClient(bundle, &client); + WTR::InjectedBundle::shared().initialize(bundle); } diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp new file mode 100644 index 0000000..cabb90d --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp @@ -0,0 +1,160 @@ +/* + * 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 "InjectedBundlePage.h" + +#include "InjectedBundle.h" +#include +#include +#include +#include +#include +#include +#include + +namespace WTR { + +InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page) + : m_page(page) +{ + WKBundlePageClient client = { + 0, + this, + _didStartProvisionalLoadForFrame, + _didReceiveServerRedirectForProvisionalLoadForFrame, + _didFailProvisionalLoadWithErrorForFrame, + _didCommitLoadForFrame, + _didFinishLoadForFrame, + _didFailLoadWithErrorForFrame, + _didReceiveTitleForFrame, + _didClearWindowForFrame + }; + WKBundlePageSetClient(m_page, &client); +} + +InjectedBundlePage::~InjectedBundlePage() +{ +} + +void InjectedBundlePage::_didStartProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didStartProvisionalLoadForFrame(frame); +} + +void InjectedBundlePage::_didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didReceiveServerRedirectForProvisionalLoadForFrame(frame); +} + +void InjectedBundlePage::_didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didFailProvisionalLoadWithErrorForFrame(frame); +} + +void InjectedBundlePage::_didCommitLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didCommitLoadForFrame(frame); +} + +void InjectedBundlePage::_didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didFinishLoadForFrame(frame); +} + +void InjectedBundlePage::_didFailLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didFailLoadWithErrorForFrame(frame); +} + +void InjectedBundlePage::_didReceiveTitleForFrame(WKBundlePageRef page, WKStringRef title, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didReceiveTitleForFrame(title, frame); +} + +void InjectedBundlePage::_didClearWindowForFrame(WKBundlePageRef page, WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window, const void *clientInfo) +{ + static_cast(const_cast(clientInfo))->didClearWindowForFrame(frame, ctx, window); +} + +void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundleFrameRef frame) +{ +} + +void InjectedBundlePage::didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef frame) +{ +} + +void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame) +{ +} + +void InjectedBundlePage::didCommitLoadForFrame(WKBundleFrameRef frame) +{ +} + +static std::auto_ptr > WKStringToUTF8(WKStringRef wkStringRef) +{ + RetainPtr cfString(AdoptCF, WKStringCopyCFString(0, wkStringRef)); + CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfString.get()), kCFStringEncodingUTF8) + 1; + std::auto_ptr > buffer(new Vector(bufferLength)); + if (!CFStringGetCString(cfString.get(), buffer->data(), bufferLength, kCFStringEncodingUTF8)) { + buffer->shrink(1); + (*buffer)[0] = 0; + } else + buffer->shrink(strlen(buffer->data()) + 1); + return buffer; +} + +void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame) +{ + if (!WKBundleFrameIsMainFrame(frame)) + return; + + WKRetainPtr externalRepresentation(AdoptWK, WKBundlePageCopyRenderTreeExternalRepresentation(m_page)); + std::auto_ptr > utf8String = WKStringToUTF8(externalRepresentation.get()); + + InjectedBundle::shared().os() << utf8String->data(); + InjectedBundle::shared().done(); +} + +void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame) +{ + if (!WKBundleFrameIsMainFrame(frame)) + return; + + InjectedBundle::shared().done(); +} + +void InjectedBundlePage::didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef frame) +{ +} + +void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window) +{ + JSValueRef exception = 0; + InjectedBundle::shared().layoutTestController()->makeWindowObject(ctx, window, &exception); +} + +} // namespace WTR diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h new file mode 100644 index 0000000..9782827 --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h @@ -0,0 +1,64 @@ +/* + * 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 InjectedBundlePage_h +#define InjectedBundlePage_h + +#include + +namespace WTR { + +class InjectedBundlePage { +public: + InjectedBundlePage(WKBundlePageRef); + ~InjectedBundlePage(); + + WKBundlePageRef page() const { return m_page; } + +private: + static void _didStartProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); + static void _didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); + static void _didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); + static void _didCommitLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); + static void _didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); + static void _didFailLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); + static void _didReceiveTitleForFrame(WKBundlePageRef page, WKStringRef title, WKBundleFrameRef frame, const void *clientInfo); + static void _didClearWindowForFrame(WKBundlePageRef page, WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window, const void *clientInfo); + + void didStartProvisionalLoadForFrame(WKBundleFrameRef frame); + void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef frame); + void didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame); + void didCommitLoadForFrame(WKBundleFrameRef frame); + void didFinishLoadForFrame(WKBundleFrameRef frame); + void didFailLoadWithErrorForFrame(WKBundleFrameRef frame); + void didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef frame); + void didClearWindowForFrame(WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window); + + WKBundlePageRef m_page; +}; + +} // namespace WTR + +#endif // InjectedBundlePage_h diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp new file mode 100644 index 0000000..014851c --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp @@ -0,0 +1,97 @@ +/* + * 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 "LayoutTestController.h" + +#include + +namespace WTR { + +PassRefPtr LayoutTestController::create(const std::string& testPathOrURL) +{ + return adoptRef(new LayoutTestController(testPathOrURL)); +} + +LayoutTestController::LayoutTestController(const std::string& testPathOrURL) + : m_dumpAsText(false) + , m_testPathOrURL(testPathOrURL) +{ +} + +LayoutTestController::~LayoutTestController() +{ +} + +static JSValueRef dumpAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + LayoutTestController* controller = static_cast(JSObjectGetPrivate(thisObject)); + controller->setDumpAsText(true); + return JSValueMakeUndefined(context); +} + +// Object Finalization + +static void layoutTestControllerObjectFinalize(JSObjectRef object) +{ + LayoutTestController* controller = static_cast(JSObjectGetPrivate(object)); + controller->deref(); +} + +// Object Creation + +void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) +{ + JSRetainPtr 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 }, + { 0, 0, 0 } + }; + + return staticFunctions; +} + +} // namespace WTR diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h new file mode 100644 index 0000000..56717c1 --- /dev/null +++ b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h @@ -0,0 +1,60 @@ +/* + * 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 LayoutTestController_h +#define LayoutTestController_h + +#include +#include +#include +#include + +namespace WTR { + +class LayoutTestController : public RefCounted { +public: + static PassRefPtr create(const std::string& testPathOrURL); + ~LayoutTestController(); + + void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception); + + bool dumpAsText() const { return m_dumpAsText; } + void setDumpAsText(bool dumpAsText) { m_dumpAsText = dumpAsText; } + +private: + LayoutTestController(const std::string& testPathOrURL); + + bool m_dumpAsText; + + std::string m_testPathOrURL; + + static JSClassRef getJSClass(); + static JSStaticValue* staticValues(); + static JSStaticFunction* staticFunctions(); +}; + +} // namespace WTR + +#endif // LayoutTestController_h -- cgit v1.1