From e067801a0fae38c33663c9c375fef36075b59cea Mon Sep 17 00:00:00 2001 From: "mrowe@apple.com" Date: Fri, 28 Mar 2014 04:06:58 +0000 Subject: [PATCH] WebKitTestRunner needs to print history delegate information Tools: Provide an implementation of WKContextHistoryClient that logs when called for tests in the globalhistory directory. Patch by Mikhail Pozdnyakov on 2014-03-27 Reviewed by Sam Weinig. * WebKitTestRunner/TestController.cpp: (WTR::TestController::TestController): (WTR::TestController::initialize): Set the history client. (WTR::TestController::resetStateToConsistentValues): Disable logging of history client callbacks. (WTR::TestController::didNavigateWithNavigationData): Log information about the navigation. Some portions of the output are hard-coded to match WebKit1's results for now since they're fixed in our existing tests and we don't yet have API to access the data in question. (WTR::TestController::didPerformClientRedirect): (WTR::TestController::didPerformServerRedirect): (WTR::TestController::didUpdateHistoryTitle): * WebKitTestRunner/TestController.h: (WTR::TestController::setShouldLogHistoryClientCallbacks): * WebKitTestRunner/TestInvocation.cpp: (WTR::shouldLogHistoryClientCallbacks): Log history client callbacks for tests in a globalhistory directory. (WTR::TestInvocation::invoke): LayoutTests: Reviewed by Sam Weinig. * platform/wk2/TestExpectations: Enable the two layout tests that pass. One test remains disabled due to lack of testRunner API, and another due to an apparent bug in WebKit2's handling of client redirects. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166396 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 10 ++++ LayoutTests/platform/wk2/TestExpectations | 9 ++- Tools/ChangeLog | 25 ++++++++ Tools/WebKitTestRunner/TestController.cpp | 95 +++++++++++++++++++++++++++++++ Tools/WebKitTestRunner/TestController.h | 17 ++++++ Tools/WebKitTestRunner/TestInvocation.cpp | 7 +++ 6 files changed, 158 insertions(+), 5 deletions(-) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index d11592c..cb4dd3e 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,13 @@ +2014-03-27 Mark Rowe + + WebKitTestRunner needs to print history delegate information + + Reviewed by Sam Weinig. + + * platform/wk2/TestExpectations: Enable the two layout tests that pass. One test remains disabled + due to lack of testRunner API, and another due to an apparent bug in WebKit2's handling of + client redirects. + 2014-03-27 Oliver Hunt Support spread operand in |new| expressions diff --git a/LayoutTests/platform/wk2/TestExpectations b/LayoutTests/platform/wk2/TestExpectations index 23f187d..37ad824 100644 --- a/LayoutTests/platform/wk2/TestExpectations +++ b/LayoutTests/platform/wk2/TestExpectations @@ -175,13 +175,12 @@ http/tests/security/setDomainRelaxationForbiddenForURLScheme.html # fast/loader/non-deferred-substitute-load.html -# WebKitTestRunner needs to print history delegate information -# -http/tests/globalhistory/history-delegate-basic-302-redirect.html -http/tests/globalhistory/history-delegate-basic-refresh-redirect.html -http/tests/globalhistory/history-delegate-basic-title.html +# WebKitTestRunner needs testRunner.removeAllVisitedLinks http/tests/globalhistory/history-delegate-basic-visited-links.html +# WebKit2 passes the wrong source URL for client redirects +http/tests/globalhistory/history-delegate-basic-refresh-redirect.html + # transitions/default-timing-function.html failing on WebKit2 since it was added # transitions/default-timing-function.html diff --git a/Tools/ChangeLog b/Tools/ChangeLog index b2e5150..36c58fb 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,28 @@ +2014-03-27 Mikhail Pozdnyakov + + WebKitTestRunner needs to print history delegate information + + Provide an implementation of WKContextHistoryClient that logs when called for tests in + the globalhistory directory. + + Reviewed by Sam Weinig. + + * WebKitTestRunner/TestController.cpp: + (WTR::TestController::TestController): + (WTR::TestController::initialize): Set the history client. + (WTR::TestController::resetStateToConsistentValues): Disable logging of history client callbacks. + (WTR::TestController::didNavigateWithNavigationData): Log information about the navigation. Some portions + of the output are hard-coded to match WebKit1's results for now since they're fixed in our existing tests + and we don't yet have API to access the data in question. + (WTR::TestController::didPerformClientRedirect): + (WTR::TestController::didPerformServerRedirect): + (WTR::TestController::didUpdateHistoryTitle): + * WebKitTestRunner/TestController.h: + (WTR::TestController::setShouldLogHistoryClientCallbacks): + * WebKitTestRunner/TestInvocation.cpp: + (WTR::shouldLogHistoryClientCallbacks): Log history client callbacks for tests in a globalhistory directory. + (WTR::TestInvocation::invoke): + 2014-03-27 Filip Pizlo Revert http://trac.webkit.org/changeset/166386 because it broke builds. diff --git a/Tools/WebKitTestRunner/TestController.cpp b/Tools/WebKitTestRunner/TestController.cpp index d04ba40..9161cf3 100644 --- a/Tools/WebKitTestRunner/TestController.cpp +++ b/Tools/WebKitTestRunner/TestController.cpp @@ -121,6 +121,7 @@ TestController::TestController(int argc, const char* argv[]) , m_forceComplexText(false) , m_shouldUseAcceleratedDrawing(false) , m_shouldUseRemoteLayerTree(false) + , m_shouldLogHistoryClientCallbacks(false) { #if PLATFORM(IOS) @@ -369,6 +370,16 @@ void TestController::initialize(int argc, const char* argv[]) }; WKContextSetInjectedBundleClient(m_context.get(), &injectedBundleClient.base); + WKContextHistoryClientV0 historyClient = { + { 0, this }, + didNavigateWithNavigationData, + didPerformClientRedirect, + didPerformServerRedirect, + didUpdateHistoryTitle, + 0, // populateVisitedLinks + }; + WKContextSetHistoryClient(m_context.get(), &historyClient.base); + WKNotificationManagerRef notificationManager = WKContextGetNotificationManager(m_context.get()); WKNotificationProviderV0 notificationKit = m_webNotificationProvider.provider(); WKNotificationManagerSetProvider(notificationManager, ¬ificationKit.base); @@ -635,6 +646,8 @@ bool TestController::resetStateToConsistentValues() m_shouldBlockAllPlugins = false; + m_shouldLogHistoryClientCallbacks = false; + // Reset main page back to about:blank m_doneResetting = false; @@ -1293,4 +1306,86 @@ void TestController::decidePolicyForResponse(WKFrameRef frame, WKURLResponseRef WKFramePolicyListenerIgnore(listener); } +void TestController::didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef navigationData, WKFrameRef frame, const void* clientInfo) +{ + static_cast(const_cast(clientInfo))->didNavigateWithNavigationData(navigationData, frame); +} + +void TestController::didNavigateWithNavigationData(WKNavigationDataRef navigationData, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + // URL + WKRetainPtr urlWK = adoptWK(WKNavigationDataCopyURL(navigationData)); + WKRetainPtr urlStringWK = adoptWK(WKURLCopyString(urlWK.get())); + // Title + WKRetainPtr titleWK = adoptWK(WKNavigationDataCopyTitle(navigationData)); + // HTTP method + WKRetainPtr requestWK = adoptWK(WKNavigationDataCopyOriginalRequest(navigationData)); + WKRetainPtr methodWK = adoptWK(WKURLRequestCopyHTTPMethod(requestWK.get())); + + // FIXME: Determine whether the navigation was successful / a client redirect rather than hard-coding the message here. + m_currentInvocation->outputText(String::format("WebView navigated to url \"%s\" with title \"%s\" with HTTP equivalent method \"%s\". The navigation was successful and was not a client redirect.\n", + toSTD(urlStringWK).c_str(), toSTD(titleWK).c_str(), toSTD(methodWK).c_str())); +} + +void TestController::didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void* clientInfo) +{ + static_cast(const_cast(clientInfo))->didPerformClientRedirect(sourceURL, destinationURL, frame); +} + +void TestController::didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + WKRetainPtr sourceStringWK = adoptWK(WKURLCopyString(sourceURL)); + WKRetainPtr destinationStringWK = adoptWK(WKURLCopyString(destinationURL)); + + m_currentInvocation->outputText(String::format("WebView performed a client redirect from \"%s\" to \"%s\".\n", toSTD(sourceStringWK).c_str(), toSTD(destinationStringWK).c_str())); +} + +void TestController::didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void* clientInfo) +{ + static_cast(const_cast(clientInfo))->didPerformServerRedirect(sourceURL, destinationURL, frame); +} + +void TestController::didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + WKRetainPtr sourceStringWK = adoptWK(WKURLCopyString(sourceURL)); + WKRetainPtr destinationStringWK = adoptWK(WKURLCopyString(destinationURL)); + + m_currentInvocation->outputText(String::format("WebView performed a server redirect from \"%s\" to \"%s\".\n", toSTD(sourceStringWK).c_str(), toSTD(destinationStringWK).c_str())); +} + +void TestController::didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef URL, WKFrameRef frame, const void* clientInfo) +{ + static_cast(const_cast(clientInfo))->didUpdateHistoryTitle(title, URL, frame); +} + +void TestController::didUpdateHistoryTitle(WKStringRef title, WKURLRef URL, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + WKRetainPtr urlStringWK(AdoptWK, WKURLCopyString(URL)); + m_currentInvocation->outputText(String::format("WebView updated the title for history URL \"%s\" to \"%s\".\n", toSTD(urlStringWK).c_str(), toSTD(title).c_str())); +} + } // namespace WTR diff --git a/Tools/WebKitTestRunner/TestController.h b/Tools/WebKitTestRunner/TestController.h index ec26901..fe64711 100644 --- a/Tools/WebKitTestRunner/TestController.h +++ b/Tools/WebKitTestRunner/TestController.h @@ -104,6 +104,8 @@ public: void setBlockAllPlugins(bool shouldBlock) { m_shouldBlockAllPlugins = shouldBlock; } + void setShouldLogHistoryClientCallbacks(bool shouldLog) { m_shouldLogHistoryClientCallbacks = shouldLog; } + private: void initialize(int argc, const char* argv[]); void createWebViewWithOptions(WKDictionaryRef); @@ -159,6 +161,19 @@ private: static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, bool canShowMIMEType, WKFramePolicyListenerRef, WKTypeRef, const void*); void decidePolicyForResponse(WKFrameRef, WKURLResponseRef, WKFramePolicyListenerRef); + // WKContextHistoryClient + static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*); + void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef); + + static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*); + void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef); + + static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*); + void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef); + + static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*); + void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef); + static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*); static void runModal(WKPageRef, const void* clientInfo); @@ -223,6 +238,8 @@ private: bool m_shouldUseAcceleratedDrawing; bool m_shouldUseRemoteLayerTree; + bool m_shouldLogHistoryClientCallbacks; + OwnPtr m_eventSenderProxy; WorkQueueManager m_workQueueManager; diff --git a/Tools/WebKitTestRunner/TestInvocation.cpp b/Tools/WebKitTestRunner/TestInvocation.cpp index 9e491af..609a7f4 100644 --- a/Tools/WebKitTestRunner/TestInvocation.cpp +++ b/Tools/WebKitTestRunner/TestInvocation.cpp @@ -146,6 +146,11 @@ static bool shouldUseThreadedScrolling(const char* pathOrURL) } #endif +static bool shouldLogHistoryClientCallbacks(const char* pathOrURL) +{ + return strstr(pathOrURL, "globalhistory/"); +} + static void updateThreadedScrollingForCurrentTest(const char* pathOrURL) { #if PLATFORM(COCOA) @@ -200,6 +205,8 @@ void TestInvocation::invoke() m_textOutput.clear(); + TestController::shared().setShouldLogHistoryClientCallbacks(shouldLogHistoryClientCallbacks(m_pathOrURL.c_str())); + WKRetainPtr messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest")); WKRetainPtr beginTestMessageBody = adoptWK(WKMutableDictionaryCreate()); -- 1.8.3.1