summaryrefslogtreecommitdiffstats
path: root/WebKitTools/WebKitTestRunner
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-07-08 12:51:48 +0100
committerSteve Block <steveblock@google.com>2010-07-09 15:33:40 +0100
commitca9cb53ed1119a3fd98fafa0972ffeb56dee1c24 (patch)
treebb45155550ec013adc0ad10f4d7d354c6469b022 /WebKitTools/WebKitTestRunner
parentd4b24d9a829ed7de70381c8b99fb75a07ab40466 (diff)
downloadexternal_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')
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ASCIICType.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Assertions.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Atomics.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/FastMalloc.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashMap.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashSet.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashTraits.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Locker.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MainThread.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MathExtras.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Noncopyable.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtr.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtrCommon.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassOwnPtr.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassRefPtr.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Platform.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefCounted.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefPtr.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RetainPtr.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/StringExtras.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadSafeShared.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Threading.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadingPrimitives.h1
-rw-r--r--WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Vector.h1
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp117
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h78
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundleMain.cpp78
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp160
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h64
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp97
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h60
-rw-r--r--WebKitTools/WebKitTestRunner/TestController.cpp29
-rw-r--r--WebKitTools/WebKitTestRunner/TestController.h20
-rw-r--r--WebKitTools/WebKitTestRunner/TestInvocation.cpp145
-rw-r--r--WebKitTools/WebKitTestRunner/TestInvocation.h28
-rw-r--r--WebKitTools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj18
36 files changed, 725 insertions, 193 deletions
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ASCIICType.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ASCIICType.h
new file mode 100644
index 0000000..f2258d2
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ASCIICType.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/ASCIICType.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Assertions.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Assertions.h
new file mode 100644
index 0000000..2144410
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Assertions.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/Assertions.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Atomics.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Atomics.h
new file mode 100644
index 0000000..37b1892
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Atomics.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/Atomics.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/FastMalloc.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/FastMalloc.h
new file mode 100644
index 0000000..1701231
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/FastMalloc.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/FastMalloc.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashMap.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashMap.h
new file mode 100644
index 0000000..9f262e2
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashMap.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/HashMap.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashSet.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashSet.h
new file mode 100644
index 0000000..cfe2d80
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashSet.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/HashSet.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashTraits.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashTraits.h
new file mode 100644
index 0000000..412fa98
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/HashTraits.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/HashTraits.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Locker.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Locker.h
new file mode 100644
index 0000000..75b0acd
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Locker.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/Locker.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MainThread.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MainThread.h
new file mode 100644
index 0000000..ff75971
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MainThread.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/MainThread.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MathExtras.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MathExtras.h
new file mode 100644
index 0000000..2955786
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/MathExtras.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/MathExtras.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Noncopyable.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Noncopyable.h
new file mode 100644
index 0000000..f8484d2
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Noncopyable.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/Noncopyable.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtr.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtr.h
new file mode 100644
index 0000000..9211d38
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtr.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/OwnPtr.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtrCommon.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtrCommon.h
new file mode 100644
index 0000000..6064e88
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/OwnPtrCommon.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/PassOwnPtr.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassOwnPtr.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassOwnPtr.h
new file mode 100644
index 0000000..6064e88
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassOwnPtr.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/PassOwnPtr.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassRefPtr.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassRefPtr.h
new file mode 100644
index 0000000..aafd1a2
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/PassRefPtr.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/PassRefPtr.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Platform.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Platform.h
new file mode 100644
index 0000000..3b22955
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Platform.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/Platform.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefCounted.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefCounted.h
new file mode 100644
index 0000000..628a63b
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefCounted.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/RefCounted.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefPtr.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefPtr.h
new file mode 100644
index 0000000..0ff6213
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RefPtr.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/RefPtr.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RetainPtr.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RetainPtr.h
new file mode 100644
index 0000000..65fc27b
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/RetainPtr.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/RetainPtr.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/StringExtras.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/StringExtras.h
new file mode 100644
index 0000000..063d500
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/StringExtras.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/StringExtras.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadSafeShared.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadSafeShared.h
new file mode 100644
index 0000000..4a7a77f
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadSafeShared.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/ThreadSafeShared.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Threading.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Threading.h
new file mode 100644
index 0000000..17359e5
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Threading.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/Threading.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadingPrimitives.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadingPrimitives.h
new file mode 100644
index 0000000..a7ee117
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/ThreadingPrimitives.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/ThreadingPrimitives.h>
diff --git a/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Vector.h b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Vector.h
new file mode 100644
index 0000000..c6d15fd
--- /dev/null
+++ b/WebKitTools/WebKitTestRunner/ForwardingHeaders/wtf/Vector.h
@@ -0,0 +1 @@
+#include <JavaScriptCore/Vector.h>
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
diff --git a/WebKitTools/WebKitTestRunner/TestController.cpp b/WebKitTools/WebKitTestRunner/TestController.cpp
index 5355862..b5b15d1 100644
--- a/WebKitTools/WebKitTestRunner/TestController.cpp
+++ b/WebKitTools/WebKitTestRunner/TestController.cpp
@@ -25,6 +25,7 @@
#include "TestController.h"
+#include "PlatformWebView.h"
#include "TestInvocation.h"
#include <getopt.h>
@@ -93,12 +94,25 @@ void TestController::initialize(int argc, const char *argv[])
}
initializeInjectedBundlePath();
+
+ m_context.adopt(WKContextCreateWithInjectedBundlePath(injectedBundlePath()));
+
+ WKContextInjectedBundleClient injectedBundlePathClient = {
+ 0,
+ this,
+ _didRecieveMessageFromInjectedBundle
+ };
+ WKContextSetInjectedBundleClient(m_context.get(), &injectedBundlePathClient);
+
+ m_pageNamespace.adopt(WKPageNamespaceCreate(m_context.get()));
+ m_mainWebView = new PlatformWebView(m_pageNamespace.get());
}
void TestController::runTest(const char* test)
{
- TestInvocation invocation(test);
- invocation.invoke();
+ m_currentInvocation.set(new TestInvocation(test));
+ m_currentInvocation->invoke();
+ m_currentInvocation.clear();
}
void TestController::runTestingServerLoop()
@@ -128,5 +142,14 @@ bool TestController::run()
return true;
}
-} // namespace WTR
+void TestController::_didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void *clientInfo)
+{
+ static_cast<TestController*>(const_cast<void*>(clientInfo))->didRecieveMessageFromInjectedBundle(message);
+}
+void TestController::didRecieveMessageFromInjectedBundle(WKStringRef message)
+{
+ m_currentInvocation->didRecieveMessageFromInjectedBundle(message);
+}
+
+} // namespace WTR
diff --git a/WebKitTools/WebKitTestRunner/TestController.h b/WebKitTools/WebKitTestRunner/TestController.h
index 86eaa7c..7ad11fe 100644
--- a/WebKitTools/WebKitTestRunner/TestController.h
+++ b/WebKitTools/WebKitTestRunner/TestController.h
@@ -29,9 +29,13 @@
#include <WebKit2/WKRetainPtr.h>
#include <string>
#include <vector>
+#include <wtf/OwnPtr.h>
namespace WTR {
+class TestInvocation;
+class PlatformWebView;
+
class TestController {
public:
static TestController& shared();
@@ -46,6 +50,10 @@ public:
WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
+ PlatformWebView* mainWebView() { return m_mainWebView; }
+ WKPageNamespaceRef pageNamespace() { return m_pageNamespace.get(); }
+ WKContextRef context() { return m_context.get(); }
+
private:
TestController();
~TestController();
@@ -55,15 +63,25 @@ private:
void initializeInjectedBundlePath();
+ // WKContextInjectedBundleClient
+ static void _didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void*);
+ void didRecieveMessageFromInjectedBundle(WKStringRef message);
+
+ OwnPtr<TestInvocation> m_currentInvocation;
+
bool m_dumpTree;
bool m_dumpPixels;
bool m_threaded;
- bool m_forceComplexText;
+ bool m_forceComplexText;
bool m_verbose;
bool m_printSeparators;
bool m_usingServerMode;
std::vector<std::string> m_paths;
WKRetainPtr<WKStringRef> m_injectedBundlePath;
+
+ PlatformWebView* m_mainWebView;
+ WKRetainPtr<WKContextRef> m_context;
+ WKRetainPtr<WKPageNamespaceRef> m_pageNamespace;
};
} // namespace WTR
diff --git a/WebKitTools/WebKitTestRunner/TestInvocation.cpp b/WebKitTools/WebKitTestRunner/TestInvocation.cpp
index 80efd62..72d07ae 100644
--- a/WebKitTools/WebKitTestRunner/TestInvocation.cpp
+++ b/WebKitTools/WebKitTestRunner/TestInvocation.cpp
@@ -25,13 +25,14 @@
#include "TestInvocation.h"
+#include "PlatformWebView.h"
#include "TestController.h"
-#include <JavaScriptCore/RetainPtr.h>
#include <WebKit2/WKContextPrivate.h>
-#include <WebKit2/WKPagePrivate.h>
#include <WebKit2/WKRetainPtr.h>
#include <WebKit2/WKStringCF.h>
#include <WebKit2/WKURLCF.h>
+#include <wtf/Vector.h>
+#include <wtf/RetainPtr.h>
using namespace WebKit;
@@ -48,123 +49,85 @@ static WKURLRef createWKURL(const char* pathOrURL)
return WKURLCreateWithCFURL(cfURL.get());
}
+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;
+}
+
TestInvocation::TestInvocation(const char* pathOrURL)
: m_url(AdoptWK, createWKURL(pathOrURL))
- , m_mainWebView(0)
- , m_loadDone(false)
- , m_renderTreeFetchDone(false)
- , m_failed(false)
+ , m_gotInitialResponse(false)
+ , m_gotFinalMessage(false)
+ , m_error(false)
{
}
TestInvocation::~TestInvocation()
{
- delete m_mainWebView;
- m_mainWebView = 0;
}
void TestInvocation::invoke()
{
- initializeMainWebView();
-
- WKPageLoadURL(m_mainWebView->page(), m_url.get());
- runUntil(m_loadDone);
+ WKRetainPtr<WKStringRef> message(AdoptWK, WKStringCreateWithCFString(CFSTR("BeginTest")));
+ WKContextPostMessageToInjectedBundle(TestController::shared().context(), message.get());
- if (m_failed)
+ runUntil(m_gotInitialResponse);
+ if (m_error) {
+ dump("FAIL\n");
return;
+ }
- WKPageRenderTreeExternalRepresentation(m_mainWebView->page(), this, renderTreeExternalRepresentationFunction, renderTreeExternalRepresentationDisposeFunction);
- runUntil(m_renderTreeFetchDone);
+ WKPageLoadURL(TestController::shared().mainWebView()->page(), m_url.get());
+
+ runUntil(m_gotFinalMessage);
+ if (m_error) {
+ dump("FAIL\n");
+ return;
+ }
}
void TestInvocation::dump(const char* stringToDump)
{
printf("Content-Type: text/plain\n");
printf("%s", stringToDump);
- printf("#EOF\n");
-}
-
-void TestInvocation::initializeMainWebView()
-{
- WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreateWithInjectedBundlePath(TestController::shared().injectedBundlePath()));
- WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));
- m_mainWebView = new PlatformWebView(pageNamespace.get());
-
- WKPageLoaderClient loaderClient = {
- 0,
- this,
- didStartProvisionalLoadForFrame,
- didReceiveServerRedirectForProvisionalLoadForFrame,
- didFailProvisionalLoadWithErrorForFrame,
- didCommitLoadForFrame,
- didFinishLoadForFrame,
- didFailLoadForFrame,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0
- };
- WKPageSetPageLoaderClient(m_mainWebView->page(), &loaderClient);
-}
-
-void TestInvocation::didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
-{
-}
-
-void TestInvocation::didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
-{
-}
-void TestInvocation::didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
-{
- TestInvocation* self = reinterpret_cast<TestInvocation*>(const_cast<void*>(clientInfo));
- self->m_loadDone = true;
- self->m_failed = true;
-}
-
-void TestInvocation::didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
-{
-}
-
-void TestInvocation::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
-{
- TestInvocation* self = reinterpret_cast<TestInvocation*>(const_cast<void*>(clientInfo));
- self->m_loadDone = true;
-}
+ fputs("#EOF\n", stdout);
+ fputs("#EOF\n", stdout);
+ fputs("#EOF\n", stderr);
-void TestInvocation::didFailLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo)
-{
- TestInvocation* self = reinterpret_cast<TestInvocation*>(const_cast<void*>(clientInfo));
-
- self->m_loadDone = true;
- self->m_failed = true;
+ fflush(stdout);
+ fflush(stderr);
}
-void TestInvocation::renderTreeExternalRepresentationFunction(WKStringRef wkResult, void* context)
+void TestInvocation::didRecieveMessageFromInjectedBundle(WKStringRef message)
{
- TestInvocation* self = reinterpret_cast<TestInvocation*>(context);
-
- RetainPtr<CFStringRef> result(AdoptCF, WKStringCopyCFString(0, wkResult));
- CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(result.get()), kCFStringEncodingUTF8) + 1;
- char* buffer = (char*)malloc(bufferLength);
- CFStringGetCString(result.get(), buffer, bufferLength, kCFStringEncodingUTF8);
-
- self->dump(buffer);
- free(buffer);
+ RetainPtr<CFStringRef> cfMessage(AdoptCF, WKStringCopyCFString(0, message));
+
+ if (CFEqual(cfMessage.get(), CFSTR("Error"))) {
+ // Set all states to true to stop spinning the runloop.
+ m_gotInitialResponse = true;
+ m_gotFinalMessage = true;
+ m_error = true;
+ return;
+ }
- self->m_renderTreeFetchDone = true;
-}
+ if (CFEqual(cfMessage.get(), CFSTR("BeginTestAck"))) {
+ m_gotInitialResponse = true;
+ return;
+ }
-void TestInvocation::renderTreeExternalRepresentationDisposeFunction(void* context)
-{
- TestInvocation* self = reinterpret_cast<TestInvocation*>(context);
+ std::auto_ptr<Vector<char> > utf8Message = WKStringToUTF8(message);
- self->m_renderTreeFetchDone = true;
- self->m_failed = true;
+ dump(utf8Message->data());
+ m_gotFinalMessage = true;
}
} // namespace WTR
diff --git a/WebKitTools/WebKitTestRunner/TestInvocation.h b/WebKitTools/WebKitTestRunner/TestInvocation.h
index 4552203..fb03150 100644
--- a/WebKitTools/WebKitTestRunner/TestInvocation.h
+++ b/WebKitTools/WebKitTestRunner/TestInvocation.h
@@ -26,47 +26,31 @@
#ifndef TestInvocation_h
#define TestInvocation_h
-#include "PlatformWebView.h"
#include <WebKit2/WKRetainPtr.h>
-#include <JavaScriptCore/Noncopyable.h>
+#include <wtf/Noncopyable.h>
namespace WTR {
-class TestInvocation : Noncopyable {
+class TestInvocation : public Noncopyable {
public:
TestInvocation(const char*);
~TestInvocation();
void invoke();
+ void didRecieveMessageFromInjectedBundle(WKStringRef message);
private:
- void initializeMainWebView();
void dump(const char*);
// Helper
static void runUntil(bool& done);
- // PageLoaderClient
- static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef, const void*);
- static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef, WKFrameRef, const void*);
- static void didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef, const void*);
- static void didCommitLoadForFrame(WKPageRef, WKFrameRef, const void*);
- static void didFinishLoadForFrame(WKPageRef, WKFrameRef, const void*);
- static void didFailLoadForFrame(WKPageRef, WKFrameRef, const void*);
-
- // RenderTreeExternalRepresentation callbacks
- static void renderTreeExternalRepresentationFunction(WKStringRef, void*);
- static void renderTreeExternalRepresentationDisposeFunction(void*);
-
- WKStringRef injectedBundlePath();
-
WKRetainPtr<WKURLRef> m_url;
- PlatformWebView* m_mainWebView;
// Invocation state
- bool m_loadDone;
- bool m_renderTreeFetchDone;
- bool m_failed;
+ bool m_gotInitialResponse;
+ bool m_gotFinalMessage;
+ bool m_error;
};
} // namespace WTR
diff --git a/WebKitTools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj b/WebKitTools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj
index bef50b5..caf26a4 100644
--- a/WebKitTools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj
+++ b/WebKitTools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj
@@ -17,6 +17,9 @@
BC7934AC1190658C005EA8E2 /* WebKit2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC7934AB1190658C005EA8E2 /* WebKit2.framework */; };
BC7934E811906846005EA8E2 /* PlatformWebViewMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC7934E711906846005EA8E2 /* PlatformWebViewMac.mm */; };
BC8C795C11D2785D004535A1 /* TestControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC8C795B11D2785D004535A1 /* TestControllerMac.mm */; };
+ BCC997A411D3C8F60017BCA2 /* InjectedBundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCC997A011D3C8F60017BCA2 /* InjectedBundle.cpp */; };
+ BCC997A511D3C8F60017BCA2 /* InjectedBundlePage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCC997A211D3C8F60017BCA2 /* InjectedBundlePage.cpp */; };
+ BCC9981811D3F51E0017BCA2 /* LayoutTestController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCC9981711D3F51E0017BCA2 /* LayoutTestController.cpp */; };
BCD7D2F811921278006DB7EE /* TestInvocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCD7D2F711921278006DB7EE /* TestInvocation.cpp */; };
BCDA2ABF1190B51A00C3BC47 /* TestInvocationMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCDA2ABE1190B51A00C3BC47 /* TestInvocationMac.mm */; };
BCDA2B9A1191051F00C3BC47 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BCDA2B991191051F00C3BC47 /* JavaScriptCore.framework */; };
@@ -62,6 +65,12 @@
BC7934DD119066EC005EA8E2 /* PlatformWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformWebView.h; sourceTree = "<group>"; };
BC7934E711906846005EA8E2 /* PlatformWebViewMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformWebViewMac.mm; sourceTree = "<group>"; };
BC8C795B11D2785D004535A1 /* TestControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestControllerMac.mm; sourceTree = "<group>"; };
+ BCC997A011D3C8F60017BCA2 /* InjectedBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundle.cpp; sourceTree = "<group>"; };
+ BCC997A111D3C8F60017BCA2 /* InjectedBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundle.h; sourceTree = "<group>"; };
+ BCC997A211D3C8F60017BCA2 /* InjectedBundlePage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePage.cpp; sourceTree = "<group>"; };
+ BCC997A311D3C8F60017BCA2 /* InjectedBundlePage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundlePage.h; sourceTree = "<group>"; };
+ BCC9981611D3F51E0017BCA2 /* LayoutTestController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutTestController.h; sourceTree = "<group>"; };
+ BCC9981711D3F51E0017BCA2 /* LayoutTestController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutTestController.cpp; sourceTree = "<group>"; };
BCD7D2F611921278006DB7EE /* TestInvocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestInvocation.h; sourceTree = "<group>"; };
BCD7D2F711921278006DB7EE /* TestInvocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestInvocation.cpp; sourceTree = "<group>"; };
BCDA2ABE1190B51A00C3BC47 /* TestInvocationMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestInvocationMac.mm; sourceTree = "<group>"; };
@@ -141,7 +150,13 @@
BC25183511D1571D002EBC01 /* InjectedBundle */ = {
isa = PBXGroup;
children = (
+ BCC997A011D3C8F60017BCA2 /* InjectedBundle.cpp */,
+ BCC997A111D3C8F60017BCA2 /* InjectedBundle.h */,
BC25184611D15767002EBC01 /* InjectedBundleMain.cpp */,
+ BCC997A211D3C8F60017BCA2 /* InjectedBundlePage.cpp */,
+ BCC997A311D3C8F60017BCA2 /* InjectedBundlePage.h */,
+ BCC9981611D3F51E0017BCA2 /* LayoutTestController.h */,
+ BCC9981711D3F51E0017BCA2 /* LayoutTestController.cpp */,
);
path = InjectedBundle;
sourceTree = "<group>";
@@ -262,6 +277,9 @@
buildActionMask = 2147483647;
files = (
BC251A3E11D16831002EBC01 /* InjectedBundleMain.cpp in Sources */,
+ BCC997A411D3C8F60017BCA2 /* InjectedBundle.cpp in Sources */,
+ BCC997A511D3C8F60017BCA2 /* InjectedBundlePage.cpp in Sources */,
+ BCC9981811D3F51E0017BCA2 /* LayoutTestController.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};