Index: net/websockets/websocket_channel_test.cc |
diff --git a/net/websockets/websocket_channel_test.cc b/net/websockets/websocket_channel_test.cc |
index 464c30e161957aa83ed35e446209d65fc7f89176..4a8f119a65b52a9b0da34d67e972ab0ae0c44a80 100644 |
--- a/net/websockets/websocket_channel_test.cc |
+++ b/net/websockets/websocket_channel_test.cc |
@@ -97,6 +97,7 @@ using ::testing::AnyNumber; |
using ::testing::DefaultValue; |
using ::testing::InSequence; |
using ::testing::MockFunction; |
+using ::testing::NotNull; |
using ::testing::Return; |
using ::testing::SaveArg; |
using ::testing::StrictMock; |
@@ -171,9 +172,21 @@ class MockWebSocketEventInterface : public WebSocketEventInterface { |
OnFinishOpeningHandshakeCalled(); |
return CHANNEL_ALIVE; |
} |
+ virtual ChannelState OnSSLCertificateError( |
+ scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
+ const GURL& url, |
+ const SSLInfo& ssl_info, |
+ bool fatal) OVERRIDE { |
+ OnSSLCertificateErrorCalled( |
+ ssl_error_callbacks.get(), url, ssl_info, fatal); |
+ return CHANNEL_ALIVE; |
+ } |
MOCK_METHOD0(OnStartOpeningHandshakeCalled, void()); // NOLINT |
MOCK_METHOD0(OnFinishOpeningHandshakeCalled, void()); // NOLINT |
+ MOCK_METHOD4( |
+ OnSSLCertificateErrorCalled, |
+ void(SSLErrorCallbacks*, const GURL&, const SSLInfo&, bool)); // NOLINT |
}; |
// This fake EventInterface is for tests which need a WebSocketEventInterface |
@@ -210,6 +223,13 @@ class FakeWebSocketEventInterface : public WebSocketEventInterface { |
scoped_ptr<WebSocketHandshakeResponseInfo> response) OVERRIDE { |
return CHANNEL_ALIVE; |
} |
+ virtual ChannelState OnSSLCertificateError( |
+ scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
+ const GURL& url, |
+ const SSLInfo& ssl_info, |
+ bool fatal) OVERRIDE { |
+ return CHANNEL_ALIVE; |
+ } |
}; |
// This fake WebSocketStream is for tests that require a WebSocketStream but are |
@@ -713,6 +733,13 @@ std::vector<char> AsVector(const std::string& s) { |
return std::vector<char>(s.begin(), s.end()); |
} |
+class FakeSSLErrorCallbacks |
+ : public WebSocketEventInterface::SSLErrorCallbacks { |
+ public: |
+ virtual void CancelSSLRequest(int error, const SSLInfo* ssl_info) OVERRIDE {} |
+ virtual void ContinueSSLRequest() OVERRIDE {} |
+}; |
+ |
// Base class for all test fixtures. |
class WebSocketChannelTest : public ::testing::Test { |
protected: |
@@ -797,6 +824,7 @@ enum EventInterfaceCall { |
EVENT_ON_DROP_CHANNEL = 0x20, |
EVENT_ON_START_OPENING_HANDSHAKE = 0x40, |
EVENT_ON_FINISH_OPENING_HANDSHAKE = 0x80, |
+ EVENT_ON_SSL_CERTIFICATE_ERROR = 0x100, |
}; |
class WebSocketChannelDeletingTest : public WebSocketChannelTest { |
@@ -818,7 +846,8 @@ class WebSocketChannelDeletingTest : public WebSocketChannelTest { |
EVENT_ON_FAIL_CHANNEL | |
EVENT_ON_DROP_CHANNEL | |
EVENT_ON_START_OPENING_HANDSHAKE | |
- EVENT_ON_FINISH_OPENING_HANDSHAKE) {} |
+ EVENT_ON_FINISH_OPENING_HANDSHAKE | |
+ EVENT_ON_SSL_CERTIFICATE_ERROR) {} |
// Create a ChannelDeletingFakeWebSocketEventInterface. Defined out-of-line to |
// avoid circular dependency. |
virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() OVERRIDE; |
@@ -877,6 +906,13 @@ class ChannelDeletingFakeWebSocketEventInterface |
scoped_ptr<WebSocketHandshakeResponseInfo> response) OVERRIDE { |
return fixture_->DeleteIfDeleting(EVENT_ON_FINISH_OPENING_HANDSHAKE); |
} |
+ virtual ChannelState OnSSLCertificateError( |
+ scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
+ const GURL& url, |
+ const SSLInfo& ssl_info, |
+ bool fatal) OVERRIDE { |
+ return fixture_->DeleteIfDeleting(EVENT_ON_SSL_CERTIFICATE_ERROR); |
+ } |
private: |
// A pointer to the test fixture. Owned by the test harness; this object will |
@@ -3209,6 +3245,24 @@ TEST_F(WebSocketChannelEventInterfaceTest, DataFramesNonEmptyOrFinal) { |
CreateChannelAndConnectSuccessfully(); |
} |
+// Calls to OnSSLCertificateError() must be passed through to the event |
+// interface with the correct URL attached. |
+TEST_F(WebSocketChannelEventInterfaceTest, OnSSLCertificateErrorCalled) { |
+ const GURL wss_url("wss://example.com/sslerror"); |
+ connect_data_.socket_url = wss_url; |
+ const SSLInfo ssl_info; |
+ const bool fatal = true; |
+ scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> fake_callbacks( |
+ new FakeSSLErrorCallbacks); |
+ |
+ EXPECT_CALL(*event_interface_, |
+ OnSSLCertificateErrorCalled(NotNull(), wss_url, _, fatal)); |
+ |
+ CreateChannelAndConnect(); |
+ connect_data_.creator.connect_delegate->OnSSLCertificateError( |
+ fake_callbacks.Pass(), ssl_info, fatal); |
+} |
+ |
// If we receive another frame after Close, it is not valid. It is not |
// completely clear what behaviour is required from the standard in this case, |
// but the current implementation fails the connection. Since a Close has |