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

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

Issue 2255883002: Pass ClientSocketHandle ownership around in unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« 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 "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
8 #include "net/base/request_priority.h" 9 #include "net/base/request_priority.h"
9 #include "net/http/http_request_info.h" 10 #include "net/http/http_request_info.h"
10 #include "net/socket/client_socket_handle.h" 11 #include "net/socket/client_socket_handle.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace net { 14 namespace net {
14 namespace { 15 namespace {
15 16
16 TEST(HttpBasicStateTest, ConstructsProperly) { 17 TEST(HttpBasicStateTest, ConstructsProperly) {
17 ClientSocketHandle* const handle = new ClientSocketHandle; 18 ClientSocketHandle* const handle = new ClientSocketHandle;
18 // Ownership of handle is passed to |state|. 19 // Ownership of |handle| is passed to |state|.
19 const HttpBasicState state(handle, true); 20 const HttpBasicState state(base::WrapUnique(handle), true);
20 EXPECT_EQ(handle, state.connection()); 21 EXPECT_EQ(handle, state.connection());
21 EXPECT_TRUE(state.using_proxy()); 22 EXPECT_TRUE(state.using_proxy());
22 } 23 }
23 24
24 TEST(HttpBasicStateTest, UsingProxyCanBeFalse) { 25 TEST(HttpBasicStateTest, UsingProxyCanBeFalse) {
25 const HttpBasicState state(new ClientSocketHandle(), false); 26 const HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false);
26 EXPECT_FALSE(state.using_proxy()); 27 EXPECT_FALSE(state.using_proxy());
27 } 28 }
28 29
29 TEST(HttpBasicStateTest, ReleaseConnectionWorks) { 30 TEST(HttpBasicStateTest, ReleaseConnectionWorks) {
30 ClientSocketHandle* const handle = new ClientSocketHandle; 31 ClientSocketHandle* const handle = new ClientSocketHandle;
31 HttpBasicState state(handle, false); 32 // Ownership of |handle| is passed to |state|.
33 HttpBasicState state(base::WrapUnique(handle), false);
32 const std::unique_ptr<ClientSocketHandle> released_connection( 34 const std::unique_ptr<ClientSocketHandle> released_connection(
33 state.ReleaseConnection()); 35 state.ReleaseConnection());
34 EXPECT_EQ(NULL, state.connection()); 36 EXPECT_EQ(NULL, state.connection());
35 EXPECT_EQ(handle, released_connection.get()); 37 EXPECT_EQ(handle, released_connection.get());
36 } 38 }
37 39
38 TEST(HttpBasicStateTest, InitializeWorks) { 40 TEST(HttpBasicStateTest, InitializeWorks) {
39 HttpBasicState state(new ClientSocketHandle(), false); 41 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false);
40 const HttpRequestInfo request_info; 42 const HttpRequestInfo request_info;
41 EXPECT_EQ(OK, 43 EXPECT_EQ(OK,
42 state.Initialize( 44 state.Initialize(
43 &request_info, LOW, BoundNetLog(), CompletionCallback())); 45 &request_info, LOW, BoundNetLog(), CompletionCallback()));
44 EXPECT_TRUE(state.parser()); 46 EXPECT_TRUE(state.parser());
45 } 47 }
46 48
47 TEST(HttpBasicStateTest, DeleteParser) { 49 TEST(HttpBasicStateTest, DeleteParser) {
48 HttpBasicState state(new ClientSocketHandle(), false); 50 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), false);
49 const HttpRequestInfo request_info; 51 const HttpRequestInfo request_info;
50 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback()); 52 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback());
51 EXPECT_TRUE(state.parser()); 53 EXPECT_TRUE(state.parser());
52 state.DeleteParser(); 54 state.DeleteParser();
53 EXPECT_EQ(NULL, state.parser()); 55 EXPECT_EQ(NULL, state.parser());
54 } 56 }
55 57
56 TEST(HttpBasicStateTest, GenerateRequestLineNoProxy) { 58 TEST(HttpBasicStateTest, GenerateRequestLineNoProxy) {
57 const bool use_proxy = false; 59 const bool use_proxy = false;
58 HttpBasicState state(new ClientSocketHandle(), use_proxy); 60 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), use_proxy);
59 HttpRequestInfo request_info; 61 HttpRequestInfo request_info;
60 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge"); 62 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge");
61 request_info.method = "PUT"; 63 request_info.method = "PUT";
62 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback()); 64 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback());
63 EXPECT_EQ("PUT /path?foo=bar HTTP/1.1\r\n", state.GenerateRequestLine()); 65 EXPECT_EQ("PUT /path?foo=bar HTTP/1.1\r\n", state.GenerateRequestLine());
64 } 66 }
65 67
66 TEST(HttpBasicStateTest, GenerateRequestLineWithProxy) { 68 TEST(HttpBasicStateTest, GenerateRequestLineWithProxy) {
67 const bool use_proxy = true; 69 const bool use_proxy = true;
68 HttpBasicState state(new ClientSocketHandle(), use_proxy); 70 HttpBasicState state(base::MakeUnique<ClientSocketHandle>(), use_proxy);
69 HttpRequestInfo request_info; 71 HttpRequestInfo request_info;
70 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge"); 72 request_info.url = GURL("http://www.example.com/path?foo=bar#hoge");
71 request_info.method = "PUT"; 73 request_info.method = "PUT";
72 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback()); 74 state.Initialize(&request_info, LOW, BoundNetLog(), CompletionCallback());
73 EXPECT_EQ("PUT http://www.example.com/path?foo=bar HTTP/1.1\r\n", 75 EXPECT_EQ("PUT http://www.example.com/path?foo=bar HTTP/1.1\r\n",
74 state.GenerateRequestLine()); 76 state.GenerateRequestLine());
75 } 77 }
76 78
77 } // namespace 79 } // namespace
78 } // namespace net 80 } // 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