Change the way SetWebSocketKeyForTesting is called

Previously SetWebSocketKeyForTesting() was called from
TestWebSocketHandshakeStreamCreateHelper::OnBasicStreamCreated(). However,
in future a WebSocketBasicHandshakeStream object will need to recreate
itself inside WebSocketBasicHandshakeStream::RenewStreamForAuth(). That
method doesn't have access to the WebSocketHandshakeStreamCreateHelper
object to call OnBasicStreamCreated().

Remove WebSocketHandshakeStreamCreateHelper::OnBasicStreamCreated() and
instead split WebSocketStreamRequest::OnHandshakeStreamCreated() into two
methods, OnBasicHandshakeStreamCreated() and
OnHttp2HandshakeStreamCreated(). During normal execution they do the same
thing, but in tests OnBasicHandshakeStreamCreated() calls
SetWebSocketKeyForTesting(). This is not needed for the Http2 variant as
the H2/WS protocol does not use this header.

Also, move OnBasicHandshakeStreamCreated(), OnHttp2HandshakeStreamCreated()
and OnFailure() methods from WebSocketStreamRequest to a new subclass,
WebSocketStreamRequestAPI. It doesn't make sense to expose these methods
to the caller of WebSocketStream::CreateAndConnectStream().
WebSocketStreamRequestAPI is used in place of the base class inside the
handshake implementation.

CreateAndConnectStreamForTesting() has to use the real
WebSocketStreamRequestImpl implementation and so cannot call
SetWebSocketKeyForTesting() directly. Instead, add a new parameter to
CreateAndConnectStreamForTesting(), |api_delegate|, providing an object
which WebSocketStreamRequestImpl calls for the methods on
WebSocketStreamRequestAPI. This is used by
WebSocketStreamCreateTestBase::CreateAndConnectStream() to inject a
TestWebSocketStreamRequestAPI object.

DummyWebSocketStreamRequest is renamed TestWebSocketStreamRequestAPI as
now that it calls SetWebSocketKeyForTesting() it is no longer just a
dummy object but actually does something.

BUG=423609

Change-Id: I5ed12ef2097f2bfc500b20f394e0da46234d4fd5
Reviewed-on: https://chromium-review.googlesource.com/1077868
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564013}
13 files changed