diff options
author | Steve Block <steveblock@google.com> | 2010-07-08 12:51:48 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-07-09 15:33:40 +0100 |
commit | ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24 (patch) | |
tree | bb45155550ec013adc0ad10f4d7d354c6469b022 /WebKitTools/WebKitTestRunner/InjectedBundle | |
parent | d4b24d9a829ed7de70381c8b99fb75a07ab40466 (diff) | |
download | external_webkit-ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24.zip external_webkit-ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24.tar.gz external_webkit-ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24.tar.bz2 |
Merge WebKit at r62496: Initial merge by git
Change-Id: Ie3da0770eca22a70a632e3571f31cfabc80facb2
Diffstat (limited to 'WebKitTools/WebKitTestRunner/InjectedBundle')
7 files changed, 578 insertions, 76 deletions
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 <WebKit2/WKBundle.h> +#include <WebKit2/WKBundlePage.h> +#include <WebKit2/WKRetainPtr.h> +#include <WebKit2/WKStringCF.h> +#include <WebKit2/WebKit2.h> +#include <wtf/RetainPtr.h> + +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<InjectedBundle*>(const_cast<void*>(clientInfo))->didCreatePage(page); +} + +void InjectedBundle::_willDestroyPage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo) +{ + static_cast<InjectedBundle*>(const_cast<void*>(clientInfo))->willDestroyPage(page); +} + +void InjectedBundle::_didRecieveMessage(WKBundleRef bundle, WKStringRef message, const void *clientInfo) +{ + static_cast<InjectedBundle*>(const_cast<void*>(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<CFStringRef> outputCFString(AdoptCF, CFStringCreateWithCString(0, output.c_str(), kCFStringEncodingUTF8)); + WKRetainPtr<WKStringRef> 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<WKStringRef> ackMessage(AdoptWK, WKStringCreateWithCFString(CFSTR("BeginTestAck"))); + WKBundlePostMessage(m_bundle, ackMessage.get()); + + reset(); + return; + } + + WKRetainPtr<WKStringRef> 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 <WebKit2/WKBase.h> +#include <WebKit2/WKBundleBase.h> +#include <wtf/HashMap.h> +#include <wtf/RefPtr.h> + +#include <sstream> + +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<WKBundlePageRef, InjectedBundlePage*> m_pages; + + RefPtr<LayoutTestController> 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 <WebKit2/WKBundle.h> +#include "InjectedBundle.h" #include <WebKit2/WKBundleInitialize.h> -#include <WebKit2/WKBundlePage.h> -#include <WebKit2/WebKit2.h> - -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 <WebKit2/WKBundleFrame.h> +#include <WebKit2/WKBundlePagePrivate.h> +#include <WebKit2/WKRetainPtr.h> +#include <WebKit2/WKString.h> +#include <WebKit2/WKStringCF.h> +#include <wtf/RetainPtr.h> +#include <wtf/Vector.h> + +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<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didStartProvisionalLoadForFrame(frame); +} + +void InjectedBundlePage::_didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveServerRedirectForProvisionalLoadForFrame(frame); +} + +void InjectedBundlePage::_didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFailProvisionalLoadWithErrorForFrame(frame); +} + +void InjectedBundlePage::_didCommitLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didCommitLoadForFrame(frame); +} + +void InjectedBundlePage::_didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFinishLoadForFrame(frame); +} + +void InjectedBundlePage::_didFailLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFailLoadWithErrorForFrame(frame); +} + +void InjectedBundlePage::_didReceiveTitleForFrame(WKBundlePageRef page, WKStringRef title, WKBundleFrameRef frame, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveTitleForFrame(title, frame); +} + +void InjectedBundlePage::_didClearWindowForFrame(WKBundlePageRef page, WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window, const void *clientInfo) +{ + static_cast<InjectedBundlePage*>(const_cast<void*>(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<Vector<char> > WKStringToUTF8(WKStringRef wkStringRef) +{ + RetainPtr<CFStringRef> cfString(AdoptCF, WKStringCopyCFString(0, wkStringRef)); + CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfString.get()), kCFStringEncodingUTF8) + 1; + std::auto_ptr<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; +} + +void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame) +{ + if (!WKBundleFrameIsMainFrame(frame)) + return; + + WKRetainPtr<WKStringRef> externalRepresentation(AdoptWK, WKBundlePageCopyRenderTreeExternalRepresentation(m_page)); + std::auto_ptr<Vector<char> > 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 <WebKit2/WKBundlePage.h> + +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 <JavaScriptCore/JSRetainPtr.h> + +namespace WTR { + +PassRefPtr<LayoutTestController> 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<LayoutTestController*>(JSObjectGetPrivate(thisObject)); + controller->setDumpAsText(true); + return JSValueMakeUndefined(context); +} + +// 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 }, + { 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 <JavaScriptCore/JavaScriptCore.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <string> + +namespace WTR { + +class LayoutTestController : public RefCounted<LayoutTestController> { +public: + static PassRefPtr<LayoutTestController> 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 |