Implement an end-to-end test for WebTransport negotiation.

PiperOrigin-RevId: 362632936
Change-Id: Ifd4a18fdb86f24bdcb7a043e3d318b4317b5dbae
diff --git a/quic/test_tools/quic_test_backend.cc b/quic/test_tools/quic_test_backend.cc
new file mode 100644
index 0000000..f33c6f1
--- /dev/null
+++ b/quic/test_tools/quic_test_backend.cc
@@ -0,0 +1,23 @@
+// Copyright (c) 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "quic/test_tools/quic_test_backend.h"
+
+namespace quic {
+namespace test {
+
+QuicSimpleServerBackend::WebTransportResponse
+QuicTestBackend::ProcessWebTransportRequest(
+    const spdy::Http2HeaderBlock& request_headers) {
+  if (!SupportsWebTransport()) {
+    return QuicSimpleServerBackend::ProcessWebTransportRequest(request_headers);
+  }
+
+  WebTransportResponse response;
+  response.response_headers[":status"] = "200";
+  return response;
+}
+
+}  // namespace test
+}  // namespace quic
diff --git a/quic/test_tools/quic_test_backend.h b/quic/test_tools/quic_test_backend.h
new file mode 100644
index 0000000..fe5b454
--- /dev/null
+++ b/quic/test_tools/quic_test_backend.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_BACKEND_H_
+#define QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_BACKEND_H_
+
+#include "quic/tools/quic_memory_cache_backend.h"
+
+namespace quic {
+namespace test {
+
+// QuicTestBackend is a QuicSimpleServer backend usable in tests.  It has extra
+// WebTransport endpoints on top of what QuicMemoryCacheBackend already
+// provides.
+class QuicTestBackend : public QuicMemoryCacheBackend {
+ public:
+  WebTransportResponse ProcessWebTransportRequest(
+      const spdy::Http2HeaderBlock& /*request_headers*/) override;
+  bool SupportsWebTransport() override { return enable_webtransport_; }
+
+  void set_enable_webtransport(bool enable_webtransport) {
+    enable_webtransport_ = enable_webtransport;
+  }
+
+ private:
+  bool enable_webtransport_ = false;
+};
+
+}  // namespace test
+}  // namespace quic
+
+#endif  // QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_BACKEND_H_