blob: d82f850f225e71553be36e594354309ef092a608 [file] [log] [blame]
[email protected]564b4912010-03-09 16:30:421// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4//
5// HttpAlternateProtocols is an in-memory data structure used for keeping track
6// of which HTTP HostPortPairs have an alternate protocol that can be used
7// instead of HTTP on a different port.
8
9#include "net/http/http_alternate_protocols.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12namespace net {
13namespace {
14
15TEST(HttpAlternateProtocols, Basic) {
16 HttpAlternateProtocols alternate_protocols;
17 HostPortPair test_host_port_pair;
18 test_host_port_pair.host = "foo";
19 test_host_port_pair.port = 80;
20 EXPECT_FALSE(
21 alternate_protocols.HasAlternateProtocolFor(test_host_port_pair));
[email protected]31e2c69e2010-04-15 18:06:0622 alternate_protocols.SetAlternateProtocolFor(
23 test_host_port_pair, 443, HttpAlternateProtocols::NPN_SPDY_1);
[email protected]564b4912010-03-09 16:30:4224 ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair));
25 const HttpAlternateProtocols::PortProtocolPair alternate =
26 alternate_protocols.GetAlternateProtocolFor(test_host_port_pair);
27 EXPECT_EQ(443, alternate.port);
[email protected]31e2c69e2010-04-15 18:06:0628 EXPECT_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol);
[email protected]564b4912010-03-09 16:30:4229}
30
31TEST(HttpAlternateProtocols, SetBroken) {
32 HttpAlternateProtocols alternate_protocols;
33 HostPortPair test_host_port_pair;
34 test_host_port_pair.host = "foo";
35 test_host_port_pair.port = 80;
36 alternate_protocols.MarkBrokenAlternateProtocolFor(test_host_port_pair);
37 ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair));
38 HttpAlternateProtocols::PortProtocolPair alternate =
39 alternate_protocols.GetAlternateProtocolFor(test_host_port_pair);
40 EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol);
41
42 alternate_protocols.SetAlternateProtocolFor(
43 test_host_port_pair,
44 1234,
[email protected]9f8980982010-04-29 19:30:3545 HttpAlternateProtocols::NPN_SPDY_1);
[email protected]564b4912010-03-09 16:30:4246 alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair);
47 EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol)
48 << "Second attempt should be ignored.";
49}
50
51} // namespace
52} // namespace net