Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: net/http/http_alternate_protocols_unittest.cc

Issue 3195015: Add option to simulate alternate protocol always being present.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // HttpAlternateProtocols is an in-memory data structure used for keeping track 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 6 // of which HTTP HostPortPairs have an alternate protocol that can be used
7 // instead of HTTP on a different port. 7 // instead of HTTP on a different port.
8 8
9 #include "net/http/http_alternate_protocols.h" 9 #include "net/http/http_alternate_protocols.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 26 matching lines...) Expand all
37 37
38 alternate_protocols.SetAlternateProtocolFor( 38 alternate_protocols.SetAlternateProtocolFor(
39 test_host_port_pair, 39 test_host_port_pair,
40 1234, 40 1234,
41 HttpAlternateProtocols::NPN_SPDY_1); 41 HttpAlternateProtocols::NPN_SPDY_1);
42 alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair); 42 alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair);
43 EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol) 43 EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol)
44 << "Second attempt should be ignored."; 44 << "Second attempt should be ignored.";
45 } 45 }
46 46
47 TEST(HttpAlternateProtocols, Forced) {
48 // Test forced alternate protocols.
49
50 HttpAlternateProtocols::PortProtocolPair default_protocol;
51 default_protocol.port = 1234;
52 default_protocol.protocol = HttpAlternateProtocols::NPN_SPDY_2;
53 HttpAlternateProtocols::ForceAlternateProtocol(default_protocol);
54
55 HttpAlternateProtocols alternate_protocols;
56
57 // Verify the forced protocol.
58 HostPortPair test_host_port_pair("foo", 80);
59 EXPECT_TRUE(
60 alternate_protocols.HasAlternateProtocolFor(test_host_port_pair));
61 HttpAlternateProtocols::PortProtocolPair alternate =
62 alternate_protocols.GetAlternateProtocolFor(test_host_port_pair);
63 EXPECT_EQ(default_protocol.port, alternate.port);
64 EXPECT_EQ(default_protocol.protocol, alternate.protocol);
65
66 // Verify the real protocol overrides the forced protocol.
67 alternate_protocols.SetAlternateProtocolFor(
68 test_host_port_pair, 443, HttpAlternateProtocols::NPN_SPDY_1);
69 ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(test_host_port_pair));
70 alternate = alternate_protocols.GetAlternateProtocolFor(test_host_port_pair);
71 EXPECT_EQ(443, alternate.port);
72 EXPECT_EQ(HttpAlternateProtocols::NPN_SPDY_1, alternate.protocol);
73
74 // Turn off the static, forced alternate protocol so that tests don't
75 // have this state.
76 HttpAlternateProtocols::DisableForcedAlternateProtocol();
77
78 // Verify the forced protocol is off.
79 HostPortPair test_host_port_pair2("bar", 80);
80 EXPECT_FALSE(
81 alternate_protocols.HasAlternateProtocolFor(test_host_port_pair2));
82 }
83
47 } // namespace 84 } // namespace
48 } // namespace net 85 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698