diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /netwerk/test/gtest/TestSupportAlpn.cpp | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/gtest/TestSupportAlpn.cpp')
-rw-r--r-- | netwerk/test/gtest/TestSupportAlpn.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/netwerk/test/gtest/TestSupportAlpn.cpp b/netwerk/test/gtest/TestSupportAlpn.cpp new file mode 100644 index 0000000000..ee67c854e6 --- /dev/null +++ b/netwerk/test/gtest/TestSupportAlpn.cpp @@ -0,0 +1,61 @@ +#include "gtest/gtest.h" + +#include "mozilla/Preferences.h" +#include "nsIHttpProtocolHandler.h" +#include "nsHttp.h" + +namespace mozilla { +namespace net { + +TEST(TestSupportAlpn, testSvcParamKeyAlpn) +{ + Preferences::SetBool("network.http.http3.enabled", true); + // initialize gHttphandler. + nsCOMPtr<nsIHttpProtocolHandler> http = + do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http"); + + // h2 and h3 are enabled, so first appearance h3 alpn-id is returned. + nsTArray<nsCString> alpn = {"h3-28"_ns, "h3-27"_ns, "h2"_ns, "http/1.1"_ns}; + Tuple<nsCString, bool> result = SelectAlpnFromAlpnList(alpn, false, false); + ASSERT_EQ(Get<0>(result), "h3-28"_ns); + ASSERT_EQ(Get<1>(result), true); + + // We don't support h3-26, so we should choose h2. + alpn = {"h3-26"_ns, "h2"_ns, "http/1.1"_ns}; + result = SelectAlpnFromAlpnList(alpn, false, false); + ASSERT_EQ(Get<0>(result), "h2"_ns); + ASSERT_EQ(Get<1>(result), false); + + // h3 is disabled, so we will use h2. + alpn = {"h3-28"_ns, "h3-27"_ns, "h2"_ns, "http/1.1"_ns}; + result = SelectAlpnFromAlpnList(alpn, false, true); + ASSERT_EQ(Get<0>(result), "h2"_ns); + ASSERT_EQ(Get<1>(result), false); + + // h3 is disabled and h2 is not found, so we will select http/1.1. + alpn = {"h3-28"_ns, "h3-27"_ns, "http/1.1"_ns}; + result = SelectAlpnFromAlpnList(alpn, false, true); + ASSERT_EQ(Get<0>(result), "http/1.1"_ns); + ASSERT_EQ(Get<1>(result), false); + + // h3 and h2 are disabled, so we will select http/1.1. + alpn = {"h3-28"_ns, "h3-27"_ns, "h2"_ns, "http/1.1"_ns}; + result = SelectAlpnFromAlpnList(alpn, true, true); + ASSERT_EQ(Get<0>(result), "http/1.1"_ns); + ASSERT_EQ(Get<1>(result), false); + + // h3 and h2 are disabled and http1.1 is not found, we return an empty string. + alpn = {"h3-28"_ns, "h3-27"_ns, "h2"_ns}; + result = SelectAlpnFromAlpnList(alpn, true, true); + ASSERT_EQ(Get<0>(result), ""_ns); + ASSERT_EQ(Get<1>(result), false); + + // No supported alpn. + alpn = {"ftp"_ns, "h2c"_ns}; + result = SelectAlpnFromAlpnList(alpn, true, true); + ASSERT_EQ(Get<0>(result), ""_ns); + ASSERT_EQ(Get<1>(result), false); +} + +} // namespace net +} // namespace mozilla |