summaryrefslogtreecommitdiffstats
path: root/WebKitTools/WebKitTestRunner/InjectedBundle
diff options
context:
space:
mode:
authorLeon Clarke <leonclarke@google.com>2010-07-15 12:03:35 +0100
committerLeon Clarke <leonclarke@google.com>2010-07-20 16:57:23 +0100
commite458d70a0d18538346f41b503114c9ebe6b2ce12 (patch)
tree86f1637deca2c524432a822e5fcedd4bef221091 /WebKitTools/WebKitTestRunner/InjectedBundle
parentf43eabc081f7ce6af24b9df4953498a3cd6ca24d (diff)
downloadexternal_webkit-e458d70a0d18538346f41b503114c9ebe6b2ce12.zip
external_webkit-e458d70a0d18538346f41b503114c9ebe6b2ce12.tar.gz
external_webkit-e458d70a0d18538346f41b503114c9ebe6b2ce12.tar.bz2
Merge WebKit at r63173 : Initial merge by git.
Change-Id: Ife5af0c7c6261fbbc8ae6bc08c390efa9ef10b44
Diffstat (limited to 'WebKitTools/WebKitTestRunner/InjectedBundle')
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp6
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h2
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp66
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h10
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp108
-rw-r--r--WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h13
6 files changed, 193 insertions, 12 deletions
diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
index 63013fb..9eea3e2 100644
--- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
+++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
@@ -43,7 +43,6 @@ InjectedBundle& InjectedBundle::shared()
InjectedBundle::InjectedBundle()
: m_bundle(0)
- , m_layoutTestController(LayoutTestController::create(std::string("")))
{
}
@@ -86,7 +85,9 @@ void InjectedBundle::done()
void InjectedBundle::didCreatePage(WKBundlePageRef page)
{
- m_pages.add(page, new InjectedBundlePage(page));
+ // FIXME: we really need the main page ref to be sent over from the ui process
+ m_mainPage = new InjectedBundlePage(page);
+ m_pages.add(page, m_mainPage);
}
void InjectedBundle::willDestroyPage(WKBundlePageRef page)
@@ -112,6 +113,7 @@ void InjectedBundle::didRecieveMessage(WKStringRef message)
void InjectedBundle::reset()
{
m_outputStream.str("");
+ m_layoutTestController = LayoutTestController::create(std::string(""));
}
} // namespace WTR
diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h
index 33934cf..1581ebc 100644
--- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h
+++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.h
@@ -48,6 +48,7 @@ public:
void done();
LayoutTestController* layoutTestController() { return m_layoutTestController.get(); }
+ InjectedBundlePage* page() { return m_mainPage; }
std::ostringstream& os() { return m_outputStream; }
@@ -67,6 +68,7 @@ private:
WKBundleRef m_bundle;
HashMap<WKBundlePageRef, InjectedBundlePage*> m_pages;
+ InjectedBundlePage* m_mainPage;
RefPtr<LayoutTestController> m_layoutTestController;
diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
index cabb90d..b254405 100644
--- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
+++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
@@ -31,6 +31,7 @@
#include <WebKit2/WKRetainPtr.h>
#include <WebKit2/WKString.h>
#include <WebKit2/WKStringCF.h>
+#include <wtf/PassOwnPtr.h>
#include <wtf/RetainPtr.h>
#include <wtf/Vector.h>
@@ -38,8 +39,9 @@ namespace WTR {
InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page)
: m_page(page)
+ , m_isLoading(false)
{
- WKBundlePageClient client = {
+ WKBundlePageLoaderClient loaderClient = {
0,
this,
_didStartProvisionalLoadForFrame,
@@ -51,13 +53,23 @@ InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page)
_didReceiveTitleForFrame,
_didClearWindowForFrame
};
- WKBundlePageSetClient(m_page, &client);
+ WKBundlePageSetLoaderClient(m_page, &loaderClient);
+
+ WKBundlePageUIClient uiClient = {
+ 0,
+ this,
+ _addMessageToConsole
+ };
+ WKBundlePageSetUIClient(m_page, &uiClient);
+
}
InjectedBundlePage::~InjectedBundlePage()
{
}
+// Loader Client Callbacks
+
void InjectedBundlePage::_didStartProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didStartProvisionalLoadForFrame(frame);
@@ -100,6 +112,8 @@ void InjectedBundlePage::_didClearWindowForFrame(WKBundlePageRef page, WKBundleF
void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundleFrameRef frame)
{
+ if (frame == WKBundlePageGetMainFrame(m_page))
+ m_isLoading = true;
}
void InjectedBundlePage::didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef frame)
@@ -114,17 +128,34 @@ void InjectedBundlePage::didCommitLoadForFrame(WKBundleFrameRef frame)
{
}
-static std::auto_ptr<Vector<char> > WKStringToUTF8(WKStringRef wkStringRef)
+static PassOwnPtr<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));
+ OwnPtr<Vector<char> > buffer(new Vector<char>(bufferLength));
if (!CFStringGetCString(cfString.get(), buffer->data(), bufferLength, kCFStringEncodingUTF8)) {
buffer->shrink(1);
(*buffer)[0] = 0;
} else
buffer->shrink(strlen(buffer->data()) + 1);
- return buffer;
+ return buffer.release();
+}
+
+void InjectedBundlePage::dump()
+{
+ InjectedBundle::shared().layoutTestController()->invalidateWaitToDumpWatchdog();
+
+ if (InjectedBundle::shared().layoutTestController()->dumpAsText()) {
+ // FIXME: Support dumping subframes when layoutTestController()->dumpChildFramesAsText() is true.
+ WKRetainPtr<WKStringRef> innerText(AdoptWK, WKBundleFrameCopyInnerText(WKBundlePageGetMainFrame(m_page)));
+ OwnPtr<Vector<char> > utf8InnerText = WKStringToUTF8(innerText.get());
+ InjectedBundle::shared().os() << utf8InnerText->data() << "\n";
+ } else {
+ WKRetainPtr<WKStringRef> externalRepresentation(AdoptWK, WKBundlePageCopyRenderTreeExternalRepresentation(m_page));
+ OwnPtr<Vector<char> > utf8externalRepresentation = WKStringToUTF8(externalRepresentation.get());
+ InjectedBundle::shared().os() << utf8externalRepresentation->data();
+ }
+ InjectedBundle::shared().done();
}
void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame)
@@ -132,11 +163,12 @@ 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());
+ m_isLoading = false;
- InjectedBundle::shared().os() << utf8String->data();
- InjectedBundle::shared().done();
+ if (InjectedBundle::shared().layoutTestController()->waitToDump())
+ return;
+
+ dump();
}
void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame)
@@ -144,6 +176,8 @@ void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame)
if (!WKBundleFrameIsMainFrame(frame))
return;
+ m_isLoading = false;
+
InjectedBundle::shared().done();
}
@@ -157,4 +191,18 @@ void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, JSContex
InjectedBundle::shared().layoutTestController()->makeWindowObject(ctx, window, &exception);
}
+// UI Client Callbacks
+
+void InjectedBundlePage::_addMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo)
+{
+ static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->addMessageToConsole(message, lineNumber);
+}
+
+void InjectedBundlePage::addMessageToConsole(WKStringRef message, uint32_t lineNumber)
+{
+ // FIXME: Strip file: urls.
+ OwnPtr<Vector<char> > utf8Message = WKStringToUTF8(message);
+ InjectedBundle::shared().os() << "CONSOLE MESSAGE: line " << lineNumber << ": " << utf8Message->data() << "\n";
+}
+
} // namespace WTR
diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h
index 9782827..79aebb7 100644
--- a/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h
+++ b/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h
@@ -36,8 +36,12 @@ public:
~InjectedBundlePage();
WKBundlePageRef page() const { return m_page; }
+ void dump();
+
+ bool isLoading() { return m_isLoading; }
private:
+ // Loader Client
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);
@@ -46,7 +50,6 @@ private:
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);
@@ -56,7 +59,12 @@ private:
void didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef frame);
void didClearWindowForFrame(WKBundleFrameRef frame, JSContextRef ctx, JSObjectRef window);
+ // UI Client
+ static void _addMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo);
+ void addMessageToConsole(WKStringRef message, uint32_t lineNumber);
+
WKBundlePageRef m_page;
+ bool m_isLoading;
};
} // namespace WTR
diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp
index 014851c..cf3e0fb 100644
--- a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp
+++ b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp
@@ -24,8 +24,14 @@
*/
#include "LayoutTestController.h"
+#include "InjectedBundle.h"
+#include "InjectedBundlePage.h"
#include <JavaScriptCore/JSRetainPtr.h>
+#include <WebKit2/WKBundleFrame.h>
+#include <WebKit2/WKRetainPtr.h>
+#include <WebKit2/WKStringCF.h>
+#include <WebKit2/WebKit2.h>
namespace WTR {
@@ -36,6 +42,7 @@ PassRefPtr<LayoutTestController> LayoutTestController::create(const std::string&
LayoutTestController::LayoutTestController(const std::string& testPathOrURL)
: m_dumpAsText(false)
+ , m_waitToDump(false)
, m_testPathOrURL(testPathOrURL)
{
}
@@ -44,6 +51,64 @@ LayoutTestController::~LayoutTestController()
{
}
+static const CFTimeInterval waitToDumpWatchdogInterval = 30.0;
+
+
+void LayoutTestController::invalidateWaitToDumpWatchdog()
+{
+ if (m_waitToDumpWatchdog) {
+ CFRunLoopTimerInvalidate(m_waitToDumpWatchdog.get());
+ m_waitToDumpWatchdog = 0;
+ }
+}
+
+static void waitUntilDoneWatchdogFired(CFRunLoopTimerRef timer, void* info)
+{
+ InjectedBundle::shared().layoutTestController()->waitToDumpWatchdogTimerFired();
+}
+
+void LayoutTestController::setWaitToDump()
+{
+ m_waitToDump = true;
+ if (!m_waitToDumpWatchdog) {
+ m_waitToDumpWatchdog.adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + waitToDumpWatchdogInterval,
+ 0, 0, 0, waitUntilDoneWatchdogFired, NULL));
+ CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_waitToDumpWatchdog.get(), kCFRunLoopCommonModes);
+ }
+}
+
+void LayoutTestController::waitToDumpWatchdogTimerFired()
+{
+ invalidateWaitToDumpWatchdog();
+ const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
+ InjectedBundle::shared().os() << message << "\n";
+ InjectedBundle::shared().done();
+}
+
+void LayoutTestController::notifyDone()
+{
+ if (m_waitToDump && !InjectedBundle::shared().page()->isLoading())
+ InjectedBundle::shared().page()->dump();
+ m_waitToDump = false;
+}
+
+unsigned LayoutTestController::numberOfActiveAnimations() const
+{
+ WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
+ return WKBundleFrameGetNumberOfActiveAnimations(mainFrame);
+}
+
+bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId)
+{
+ RetainPtr<CFStringRef> idCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, elementId));
+ WKRetainPtr<WKStringRef> idWK(AdoptWK, WKStringCreateWithCFString(idCF.get()));
+ RetainPtr<CFStringRef> nameCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, animationName));
+ WKRetainPtr<WKStringRef> nameWK(AdoptWK, WKStringCreateWithCFString(nameCF.get()));
+
+ WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
+ return WKBundleFramePauseAnimationOnElementWithId(mainFrame, nameWK.get(), idWK.get(), time);
+}
+
static JSValueRef dumpAsTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
@@ -51,6 +116,45 @@ static JSValueRef dumpAsTextCallback(JSContextRef context, JSObjectRef function,
return JSValueMakeUndefined(context);
}
+static JSValueRef waitUntilDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+ controller->setWaitToDump();
+ return JSValueMakeUndefined(context);
+}
+
+static JSValueRef notifyDoneCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+ controller->notifyDone();
+ return JSValueMakeUndefined(context);
+}
+
+static JSValueRef numberOfActiveAnimationsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ if (argumentCount)
+ return JSValueMakeUndefined(context);
+
+ LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+ return JSValueMakeNumber(context, controller->numberOfActiveAnimations());
+}
+
+static JSValueRef pauseAnimationAtTimeOnElementWithIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ if (argumentCount != 3)
+ return JSValueMakeUndefined(context);
+
+ JSRetainPtr<JSStringRef> animationName(Adopt, JSValueToStringCopy(context, arguments[0], exception));
+ ASSERT(!*exception);
+ double time = JSValueToNumber(context, arguments[1], exception);
+ ASSERT(!*exception);
+ JSRetainPtr<JSStringRef> elementId(Adopt, JSValueToStringCopy(context, arguments[2], exception));
+ ASSERT(!*exception);
+
+ LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+ return JSValueMakeBoolean(context, controller->pauseAnimationAtTimeOnElementWithId(animationName.get(), time, elementId.get()));
+}
+
// Object Finalization
static void layoutTestControllerObjectFinalize(JSObjectRef object)
@@ -88,6 +192,10 @@ JSStaticFunction* LayoutTestController::staticFunctions()
{
static JSStaticFunction staticFunctions[] = {
{ "dumpAsText", dumpAsTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "notifyDone", notifyDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "numberOfActiveAnimations", numberOfActiveAnimationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "pauseAnimationAtTimeOnElementWithId", pauseAnimationAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "waitUntilDone", waitUntilDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ 0, 0, 0 }
};
diff --git a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h
index 56717c1..203f358 100644
--- a/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h
+++ b/WebKitTools/WebKitTestRunner/InjectedBundle/LayoutTestController.h
@@ -29,6 +29,7 @@
#include <JavaScriptCore/JavaScriptCore.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
#include <string>
namespace WTR {
@@ -43,13 +44,25 @@ public:
bool dumpAsText() const { return m_dumpAsText; }
void setDumpAsText(bool dumpAsText) { m_dumpAsText = dumpAsText; }
+ bool waitToDump() const { return m_waitToDump; }
+ void setWaitToDump();
+ void waitToDumpWatchdogTimerFired();
+ void invalidateWaitToDumpWatchdog();
+ void notifyDone();
+
+ unsigned numberOfActiveAnimations() const;
+ bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
+
private:
LayoutTestController(const std::string& testPathOrURL);
bool m_dumpAsText;
+ bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
std::string m_testPathOrURL;
+ RetainPtr<CFRunLoopTimerRef> m_waitToDumpWatchdog;
+
static JSClassRef getJSClass();
static JSStaticValue* staticValues();
static JSStaticFunction* staticFunctions();