WebKitTestRunner needs support for setHandlesAuthenticationChallenges
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jan 2013 01:41:17 +0000 (01:41 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jan 2013 01:41:17 +0000 (01:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103653

Reviewed by Anders Carlsson.

Tools:

Implement setHandlesAuthenticationChallenges in the UIProcess by sending credentials
and the enabled boolean to the UIProcess and then implementing the didReceiveAuthenticationChallengeInFrame
client callback.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: Exposed the new TestRunner
methods to the JavaScript API.
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setHandlesAuthenticationChallenges): Added this callback for the JavaScript API.
(WTR::TestRunner::setAuthenticationUsername): Ditto.
(WTR::TestRunner::setAuthenticationPassword): Ditto.
* WebKitTestRunner/InjectedBundle/TestRunner.h:
(TestRunner): Added new declarations for the above.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::createWebViewWithOptions): Hook up the new didReceiveSynchronousMessageFromInjectedBundle
callback.
(WTR::TestController::resetStateToConsistentValues): Reset the credentials and enabled boolean between tests.
(WTR::TestController::didReceiveAuthenticationChallengeInFrame): Handle the callback by using
the authentication information passed from the InjectedBundle.
* WebKitTestRunner/TestController.h:
(WTR::TestController::setHandlesAuthenticationChallenges): Added setter to allow TestInvocation
to communicate with the TestController.
(WTR::TestController::setAuthenticationUsername): Ditto.
(WTR::TestController::setAuthenticationPassword): Ditto.
(TestController):
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Handle the messages sending authentication
information from the InjectedBundle.
(WTR::TestInvocation::outputText): Added this method so that the TestController can output
text to the TestInvocation text output.
* WebKitTestRunner/TestInvocation.h:
(TestInvocation): Added declaration for new method.

LayoutTests:

Unskip authentication tests which are now passing.

* platform/wk2/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139140 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/wk2/TestExpectations
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp
Tools/WebKitTestRunner/TestInvocation.h

index 5b4a946..962274c 100644 (file)
@@ -1,3 +1,14 @@
+2013-01-08  Martin Robinson  <mrobinson@igalia.com>
+
+        WebKitTestRunner needs support for setHandlesAuthenticationChallenges
+        https://bugs.webkit.org/show_bug.cgi?id=103653
+
+        Reviewed by Anders Carlsson.
+
+        Unskip authentication tests which are now passing.
+
+        * platform/wk2/TestExpectations:
+
 2013-01-08  Justin Novosad  <junov@google.com>
 
         Color bleeding with rounded rectangles on high dpi displays
index 0d72b87..9747ba7 100644 (file)
@@ -388,21 +388,6 @@ http/tests/misc/link-rel-icon-beforeload.html
 # WebKitTestRunner should dump text/plain content as text
 http/tests/incremental/slow-utf8-text.pl
 
-# WebKitTestRunner needs layoutTestController.setHandlesAuthenticationChallenges
-http/tests/misc/authentication-redirect-1/authentication-sent-to-redirect-cross-origin.html
-http/tests/misc/authentication-redirect-2/authentication-sent-to-redirect-same-origin.html
-http/tests/misc/authentication-redirect-3/authentication-sent-to-redirect-same-origin-with-location-credentials.html
-http/tests/misc/authentication-redirect-4/authentication-sent-to-redirect-same-origin-url.html
-http/tests/loading/authentication-after-redirect-stores-wrong-credentials/authentication-after-redirect-stores-wrong-credentials.html
-http/tests/loading/basic-auth-resend-wrong-credentials.html
-http/tests/loading/basic-credentials-sent-automatically.html
-http/tests/security/401-logout/401-logout.php
-http/tests/xmlhttprequest/basic-auth-nopassword.html
-http/tests/xmlhttprequest/basic-auth-nouser.html
-http/tests/xmlhttprequest/remember-bad-password.html
-http/tests/xmlhttprequest/failed-auth.html
-http/tests/misc/401-alternative-content.php
-
 # WebKitTestRunner needs layoutTestController.setSmartInsertDeleteEnabled
 editing/deleting/smart-editing-disabled.html
 
index 55b6041..a04e2ba 100644 (file)
@@ -1,3 +1,42 @@
+2013-01-08  Martin Robinson  <mrobinson@igalia.com>
+
+        WebKitTestRunner needs support for setHandlesAuthenticationChallenges
+        https://bugs.webkit.org/show_bug.cgi?id=103653
+
+        Reviewed by Anders Carlsson.
+
+        Implement setHandlesAuthenticationChallenges in the UIProcess by sending credentials
+        and the enabled boolean to the UIProcess and then implementing the didReceiveAuthenticationChallengeInFrame
+        client callback.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: Exposed the new TestRunner
+        methods to the JavaScript API.
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::setHandlesAuthenticationChallenges): Added this callback for the JavaScript API.
+        (WTR::TestRunner::setAuthenticationUsername): Ditto.
+        (WTR::TestRunner::setAuthenticationPassword): Ditto.
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        (TestRunner): Added new declarations for the above.
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::createWebViewWithOptions): Hook up the new didReceiveSynchronousMessageFromInjectedBundle
+        callback.
+        (WTR::TestController::resetStateToConsistentValues): Reset the credentials and enabled boolean between tests.
+        (WTR::TestController::didReceiveAuthenticationChallengeInFrame): Handle the callback by using
+        the authentication information passed from the InjectedBundle.
+        * WebKitTestRunner/TestController.h:
+        (WTR::TestController::setHandlesAuthenticationChallenges): Added setter to allow TestInvocation
+        to communicate with the TestController.
+        (WTR::TestController::setAuthenticationUsername): Ditto.
+        (WTR::TestController::setAuthenticationPassword): Ditto.
+        (TestController):
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Handle the messages sending authentication
+        information from the InjectedBundle.
+        (WTR::TestInvocation::outputText): Added this method so that the TestController can output
+        text to the TestInvocation text output.
+        * WebKitTestRunner/TestInvocation.h:
+        (TestInvocation): Added declaration for new method.
+
 2013-01-08  Benjamin Poulain  <benjamin@webkit.org>
 
         Add myself as a watcher for Web Geolocation
index 47b0180..f2713c7 100644 (file)
@@ -195,5 +195,10 @@ interface TestRunner {
     void queueReload();
     void queueLoadingScript(in DOMString script);
     void queueNonLoadingScript(in DOMString script);
+
+    // Authentication
+    void setHandlesAuthenticationChallenges(in boolean value);
+    void setAuthenticationUsername(in DOMString username);
+    void setAuthenticationPassword(in DOMString password);
 };
 
index de06c51..771e7d5 100644 (file)
@@ -33,6 +33,7 @@
 #include "StringFunctions.h"
 #include "TestController.h"
 #include <WebCore/PageVisibilityState.h>
+#include <WebKit2/WKBundle.h>
 #include <WebKit2/WKBundleBackForwardList.h>
 #include <WebKit2/WKBundleFrame.h>
 #include <WebKit2/WKBundleFramePrivate.h>
@@ -896,4 +897,25 @@ void TestRunner::setViewModeMediaFeature(JSStringRef mode)
     WKBundlePageSetViewMode(InjectedBundle::shared().page()->page(), modeWK.get());
 }
 
+void TestRunner::setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges)
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetHandlesAuthenticationChallenge"));
+    WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(handlesAuthenticationChallenges));
+    WKBundlePostMessage(InjectedBundle::shared().bundle(), messageName.get(), messageBody.get());
+}
+
+void TestRunner::setAuthenticationUsername(JSStringRef username)
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetAuthenticationUsername"));
+    WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(username));
+    WKBundlePostMessage(InjectedBundle::shared().bundle(), messageName.get(), messageBody.get());
+}
+
+void TestRunner::setAuthenticationPassword(JSStringRef password)
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetAuthenticationPassword"));
+    WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(password));
+    WKBundlePostMessage(InjectedBundle::shared().bundle(), messageName.get(), messageBody.get());
+}
+
 } // namespace WTR
index 7329270..c095b95 100644 (file)
@@ -162,6 +162,11 @@ public:
     // Printing
     bool isPageBoxVisible(int pageIndex);
 
+    // Authentication
+    void setHandlesAuthenticationChallenges(bool);
+    void setAuthenticationUsername(JSStringRef);
+    void setAuthenticationPassword(JSStringRef);
+
     void setValueForUser(JSContextRef, JSValueRef element, JSStringRef value);
 
     // Audio testing.
index 3c4c86c..a56a0ed 100644 (file)
 #include "PlatformWebView.h"
 #include "StringFunctions.h"
 #include "TestInvocation.h"
+#include <WebKit2/WKAuthenticationChallenge.h>
+#include <WebKit2/WKAuthenticationDecisionListener.h>
 #include <WebKit2/WKContextPrivate.h>
+#include <WebKit2/WKCredential.h>
 #include <WebKit2/WKNotification.h>
 #include <WebKit2/WKNotificationManager.h>
 #include <WebKit2/WKNotificationPermissionRequest.h>
@@ -44,6 +47,7 @@
 #include <stdlib.h>
 #include <string>
 #include <wtf/PassOwnPtr.h>
+#include <wtf/text/CString.h>
 
 #if PLATFORM(MAC)
 #include <WebKit2/WKPagePrivateMac.h>
@@ -436,7 +440,7 @@ void TestController::createWebViewWithOptions(WKDictionaryRef options)
         0, // didFailToInitializePlugin
         0, // didDisplayInsecureContentForFrame
         0, // canAuthenticateAgainstProtectionSpaceInFrame
-        0, // didReceiveAuthenticationChallengeInFrame
+        didReceiveAuthenticationChallengeInFrame, // didReceiveAuthenticationChallengeInFrame
         0, // didStartProgress
         0, // didChangeProgress
         0, // didFinishProgress
@@ -584,6 +588,10 @@ bool TestController::resetStateToConsistentValues()
 
     m_workQueueManager.clearWorkQueue();
 
+    m_handlesAuthenticationChallenges = false;
+    m_authenticationUsername = String();
+    m_authenticationPassword = String();
+
     // Reset main page back to about:blank
     m_doneResetting = false;
 
@@ -1002,6 +1010,11 @@ void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKT
     static_cast<TestController*>(const_cast<void*>(clientInfo))->didFinishLoadForFrame(page, frame);
 }
 
+void TestController::didReceiveAuthenticationChallengeInFrame(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo)
+{
+    static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveAuthenticationChallengeInFrame(page, frame, authenticationChallenge);
+}
+
 void TestController::processDidCrash(WKPageRef page, const void* clientInfo)
 {
     static_cast<TestController*>(const_cast<void*>(clientInfo))->processDidCrash();
@@ -1031,6 +1044,26 @@ void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame)
     shared().notifyDone();
 }
 
+void TestController::didReceiveAuthenticationChallengeInFrame(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge)
+{
+    String message;
+    if (!m_handlesAuthenticationChallenges)
+        message = "<unknown> - didReceiveAuthenticationChallenge - Simulating cancelled authentication sheet\n";
+    else
+        message = String::format("<unknown> - didReceiveAuthenticationChallenge - Responding with %s:%s\n", m_authenticationUsername.utf8().data(), m_authenticationPassword.utf8().data());
+    m_currentInvocation->outputText(message);
+
+    WKAuthenticationDecisionListenerRef decisionListener = WKAuthenticationChallengeGetDecisionListener(authenticationChallenge);
+    if (!m_handlesAuthenticationChallenges) {
+        WKAuthenticationDecisionListenerUseCredential(decisionListener, 0);
+        return;
+    }
+    WKRetainPtr<WKStringRef> username(AdoptWK, WKStringCreateWithUTF8CString(m_authenticationUsername.utf8().data()));
+    WKRetainPtr<WKStringRef> password(AdoptWK, WKStringCreateWithUTF8CString(m_authenticationPassword.utf8().data()));
+    WKRetainPtr<WKCredentialRef> credential(AdoptWK, WKCredentialCreate(username.get(), password.get(), kWKCredentialPersistenceForSession));
+    WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get());
+}
+
 void TestController::processDidCrash()
 {
     // This function can be called multiple times when crash logs are being saved on Windows, so
index 092c9cb..9d4e287 100644 (file)
@@ -83,6 +83,10 @@ public:
 
     WorkQueueManager& workQueueManager() { return m_workQueueManager; }
 
+    void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
+    void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
+    void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
+
 private:
     void initialize(int argc, const char* argv[]);
     void createWebViewWithOptions(WKDictionaryRef);
@@ -122,6 +126,9 @@ private:
 
     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKStringRef, WKStringRef, WKStringRef, const void*);
 
+    static void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef, const void *clientInfo);
+    void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef);
+
     // WKPagePolicyClient
     static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
@@ -181,6 +188,10 @@ private:
     bool m_policyDelegateEnabled;
     bool m_policyDelegatePermissive;
 
+    bool m_handlesAuthenticationChallenges;
+    String m_authenticationUsername;
+    String m_authenticationPassword;
+
 #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
     OwnPtr<EventSenderProxy> m_eventSenderProxy;
 #endif
index cd9f7be..ce8ad9c 100644 (file)
@@ -590,6 +590,27 @@ void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName
         return;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "SetHandlesAuthenticationChallenge")) {
+        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
+        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
+        TestController::shared().setHandlesAuthenticationChallenges(WKBooleanGetValue(value));
+        return;
+    }
+
+    if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationUsername")) {
+        ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
+        WKStringRef username = static_cast<WKStringRef>(messageBody);
+        TestController::shared().setAuthenticationUsername(toWTFString(username));
+        return;
+    }
+
+    if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationPassword")) {
+        ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
+        WKStringRef password = static_cast<WKStringRef>(messageBody);
+        TestController::shared().setAuthenticationPassword(toWTFString(password));
+        return;
+    }
+
     ASSERT_NOT_REACHED();
 }
 
@@ -612,4 +633,9 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB
     return 0;
 }
 
+void TestInvocation::outputText(const WTF::String& text)
+{
+    m_textOutput.append(text);
+}
+
 } // namespace WTR
index 272c1f7..6a1631e 100644 (file)
@@ -47,6 +47,7 @@ public:
     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
 
     void dumpWebProcessUnresponsiveness();
+    void outputText(const WTF::String&);
 private:
     void dumpResults();
     static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false);