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

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

Issue 2299703003: Re-land: Only allow HTTP/0.9 support on default ports. (Closed)
Patch Set: Fix test Created 4 years, 3 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
« no previous file with comments | « net/http/http_basic_state.cc ('k') | net/http/http_basic_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "net/http/http_basic_state.h" 5 #include "net/http/http_basic_state.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
9 #include "net/base/request_priority.h" 9 #include "net/base/request_priority.h"
10 #include "net/http/http_request_info.h" 10 #include "net/http/http_request_info.h"
11 #include "net/socket/client_socket_handle.h" 11 #include "net/socket/client_socket_handle.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace net { 14 namespace net {
15 namespace { 15 namespace {
16 16
17 TEST(HttpBasicStateTest, ConstructsProperly) { 17 TEST(HttpBasicStateTest, ConstructsProperly) {
18 ClientSocketHandle* const handle = new ClientSocketHandle; 18 ClientSocketHandle* const handle = new ClientSocketHandle;
19 // Ownership of |handle| is passed to |state|. 19 // Ownership of |handle| is passed to |state|.
20 const HttpBasicState state(base::WrapUnique(handle), true); 20 const HttpBasicState state(base::WrapUnique(handle), true /* using_proxy */,
21 false /* http_09_on_non_default_ports_enabled */);
21 EXPECT_EQ(handle, state.connection()); 22 EXPECT_EQ(handle, state.connection());
22 EXPECT_TRUE(state.using_proxy()); 23 EXPECT_TRUE(state.using_proxy());
24 EXPECT_FALSE(state.http_09_on_non_default_ports_enabled());
23 } 25 }
24 26
25 TEST(HttpBasicStateTest, UsingProxyCanBeFalse) { 27 TEST(HttpBasicStateTest, ConstructsProperlyWithDifferentOptions) {
26 const HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false); 28 const HttpBasicState state(base::MakeUnique<ClientSocketHandle>(),
29 false /* using_proxy */,
30 true /* http_09_on_non_default_ports_enabled */);
27 EXPECT_FALSE(state.using_proxy()); 31 EXPECT_FALSE(state.using_proxy());
32 EXPECT_TRUE(state.http_09_on_non_default_ports_enabled());
28 } 33 }
29 34
30 TEST(HttpBasicStateTest, ReleaseConnectionWorks) { 35 TEST(HttpBasicStateTest, ReleaseConnectionWorks) {
31 ClientSocketHandle* const handle = new ClientSocketHandle; 36 ClientSocketHandle* const handle = new ClientSocketHandle;
32 // Ownership of |handle| is passed to |state|. 37 // Ownership of |handle| is passed to |state|.
33 HttpBasicState state(base::WrapUnique(handle), false); 38 HttpBasicState state(base::WrapUnique(handle), false, false);
34 const std::unique_ptr<ClientSocketHandle> released_connection( 39 const std::unique_ptr<ClientSocketHandle> released_connection(
35 state.ReleaseConnection()); 40 state.ReleaseConnection());
36 EXPECT_EQ(NULL, state.connection()); 41 EXPECT_EQ(NULL, state.connection());
37 EXPECT_EQ(handle, released_connection.get()); 42 EXPECT_EQ(handle, released_connection.get());
38 } 43 }
39 44
40 TEST(HttpBasicStateTest, InitializeWorks) { 45 TEST(HttpBasicStateTest, InitializeWorks) {
41 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false); 46 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false, false);
42 const HttpRequestInfo request_info; 47 const HttpRequestInfo request_info;
43 EXPECT_EQ(OK, 48 EXPECT_EQ(OK,
44 state.Initialize( 49 state.Initialize(
45 &request_info, LOW, BoundNetLog(), CompletionCallback())); 50 &request_info, LOW, BoundNetLog(), CompletionCallback()));
46 EXPECT_TRUE(state.parser()); 51 EXPECT_TRUE(state.parser());
47 } 52 }
48 53
49 TEST(HttpBasicStateTest, DeleteParser) { 54 TEST(HttpBasicStateTest, DeleteParser) {
50 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false); 55 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false, false);
51 const HttpRequestInfo request_info; 56 const HttpRequestInfo request_info;
52 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback()); 57 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback());
53 EXPECT_TRUE(state.parser()); 58 EXPECT_TRUE(state.parser());
54 state.DeleteParser(); 59 state.DeleteParser();
55 EXPECT_EQ(NULL, state.parser()); 60 EXPECT_EQ(NULL, state.parser());
56 } 61 }
57 62
58 TEST(HttpBasicStateTest, GenerateRequestLineNoProxy) { 63 TEST(HttpBasicStateTest, GenerateRequestLineNoProxy) {
59 const bool use_proxy = false; 64 const bool use_proxy = false;
60 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), use_proxy); 65 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), use_proxy,
66 false);
61 HttpRequestInfo request_info; 67 HttpRequestInfo request_info;
62 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge"); 68 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge");
63 request_info.method = "PUT"; 69 request_info.method = "PUT";
64 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback()); 70 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback());
65 EXPECT_EQ("PUT /path?foo=bar HTTP/1.1\r\n", state.GenerateRequestLine()); 71 EXPECT_EQ("PUT /path?foo=bar HTTP/1.1\r\n", state.GenerateRequestLine());
66 } 72 }
67 73
68 TEST(HttpBasicStateTest, GenerateRequestLineWithProxy) { 74 TEST(HttpBasicStateTest, GenerateRequestLineWithProxy) {
69 const bool use_proxy = true; 75 const bool use_proxy = true;
70 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), use_proxy); 76 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), use_proxy,
77 false);
71 HttpRequestInfo request_info; 78 HttpRequestInfo request_info;
72 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge"); 79 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge");
73 request_info.method = "PUT"; 80 request_info.method = "PUT";
74 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback()); 81 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback());
75 EXPECT_EQ("PUT http://www.example.com/path?foo=bar HTTP/1.1\r\n", 82 EXPECT_EQ("PUT http://www.example.com/path?foo=bar HTTP/1.1\r\n",
76 state.GenerateRequestLine()); 83 state.GenerateRequestLine());
77 } 84 }
78 85
79 } // namespace 86 } // namespace
80 } // namespace net 87 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_basic_state.cc ('k') | net/http/http_basic_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698