diff options
Diffstat (limited to 'WebKitTools/WebKitTestRunner/TestController.cpp')
-rw-r--r-- | WebKitTools/WebKitTestRunner/TestController.cpp | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/WebKitTools/WebKitTestRunner/TestController.cpp b/WebKitTools/WebKitTestRunner/TestController.cpp index 93857a7..c8a78d5 100644 --- a/WebKitTools/WebKitTestRunner/TestController.cpp +++ b/WebKitTools/WebKitTestRunner/TestController.cpp @@ -26,8 +26,10 @@ #include "TestController.h" #include "PlatformWebView.h" +#include "StringFunctions.h" #include "TestInvocation.h" #include <WebKit2/WKContextPrivate.h> +#include <WebKit2/WKPreferencesPrivate.h> #include <wtf/PassOwnPtr.h> namespace WTR { @@ -45,6 +47,8 @@ TestController::TestController(int argc, const char* argv[]) , m_verbose(false) , m_printSeparators(false) , m_usingServerMode(false) + , m_state(Initial) + , m_doneResetting(false) { initialize(argc, argv); controller = this; @@ -78,6 +82,7 @@ static WKPageRef createOtherPage(WKPageRef oldPage, const void*) closeOtherPage, 0, 0, + 0, 0 }; WKPageSetPageUIClient(newPage, &otherPageUIClient); @@ -119,6 +124,7 @@ void TestController::initialize(int argc, const char* argv[]) initializeTestPluginDirectory(); m_context.adopt(WKContextCreateWithInjectedBundlePath(injectedBundlePath())); + platformInitializeContext(); WKContextInjectedBundleClient injectedBundleClient = { 0, @@ -128,7 +134,7 @@ void TestController::initialize(int argc, const char* argv[]) WKContextSetInjectedBundleClient(m_context.get(), &injectedBundleClient); _WKContextSetAdditionalPluginsDirectory(m_context.get(), testPluginDirectory()); - + m_pageNamespace.adopt(WKPageNamespaceCreate(m_context.get())); m_mainWebView = adoptPtr(new PlatformWebView(m_pageNamespace.get())); @@ -140,13 +146,60 @@ void TestController::initialize(int argc, const char* argv[]) 0, 0, 0, + 0, 0 }; WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient); + + WKPageLoaderClient pageLoaderClient = { + 0, + this, + 0, + 0, + 0, + 0, + didFinishLoadForFrame, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }; + WKPageSetPageLoaderClient(m_mainWebView->page(), &pageLoaderClient); +} + +void TestController::resetStateToConsistentValues() +{ + m_state = Resetting; + + // FIXME: This function should also ensure that there is only one page open. + + // Reset preferences + WKPreferencesRef preferences = WKContextGetPreferences(m_context.get()); + WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true); + WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing); + + m_mainWebView->focus(); + + // Reset main page back to about:blank + m_doneResetting = false; + + WKRetainPtr<WKURLRef> url(AdoptWK, createWKURL("about:blank")); + WKPageLoadURL(m_mainWebView->page(), url.get()); + TestController::runUntil(m_doneResetting); } void TestController::runTest(const char* test) { + resetStateToConsistentValues(); + + m_state = RunningTest; m_currentInvocation.set(new TestInvocation(test)); m_currentInvocation->invoke(); m_currentInvocation.clear(); @@ -177,6 +230,8 @@ void TestController::run() } } +// WKContextInjectedBundleClient + void TestController::didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo) { static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveMessageFromInjectedBundle(messageName, messageBody); @@ -187,4 +242,28 @@ void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName m_currentInvocation->didReceiveMessageFromInjectedBundle(messageName, messageBody); } +// WKPageLoaderClient + +void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didFinishLoadForFrame(page, frame); +} + +void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame) +{ + if (m_state != Resetting) + return; + + if (!WKFrameIsMainFrame(frame)) + return; + + WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKFrameCopyURL(frame)); + RetainPtr<CFURLRef> cfURL= toCF(wkURL); + CFStringRef cfURLString = CFURLGetString(cfURL.get()); + if (!CFEqual(cfURLString, CFSTR("about:blank"))) + return; + + m_doneResetting = true; +} + } // namespace WTR |