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
3 // found in the LICENSE file.
5 #include "net/http/http_basic_state.h"
7 #include "net/base/completion_callback.h"
8 #include "net/base/request_priority.h"
9 #include "net/http/http_request_info.h"
10 #include "net/socket/client_socket_handle.h"
11 #include "testing/gtest/include/gtest/gtest.h"
16 TEST(HttpBasicStateTest
, ConstructsProperly
) {
17 ClientSocketHandle
* const handle
= new ClientSocketHandle
;
18 // Ownership of handle is passed to |state|.
19 const HttpBasicState
state(handle
, true);
20 EXPECT_EQ(handle
, state
.connection());
21 EXPECT_TRUE(state
.using_proxy());
24 TEST(HttpBasicStateTest
, UsingProxyCanBeFalse
) {
25 const HttpBasicState
state(new ClientSocketHandle(), false);
26 EXPECT_FALSE(state
.using_proxy());
29 TEST(HttpBasicStateTest
, ReleaseConnectionWorks
) {
30 ClientSocketHandle
* const handle
= new ClientSocketHandle
;
31 HttpBasicState
state(handle
, false);
32 const scoped_ptr
<ClientSocketHandle
> released_connection(
33 state
.ReleaseConnection());
34 EXPECT_EQ(NULL
, state
.connection());
35 EXPECT_EQ(handle
, released_connection
.get());
38 TEST(HttpBasicStateTest
, InitializeWorks
) {
39 HttpBasicState
state(new ClientSocketHandle(), false);
40 const HttpRequestInfo request_info
;
43 &request_info
, LOW
, BoundNetLog(), CompletionCallback()));
44 EXPECT_TRUE(state
.parser());
47 TEST(HttpBasicStateTest
, DeleteParser
) {
48 HttpBasicState
state(new ClientSocketHandle(), false);
49 const HttpRequestInfo request_info
;
50 state
.Initialize(&request_info
, LOW
, BoundNetLog(), CompletionCallback());
51 EXPECT_TRUE(state
.parser());
53 EXPECT_EQ(NULL
, state
.parser());
56 TEST(HttpBasicStateTest
, GenerateRequestLineNoProxy
) {
57 const bool use_proxy
= false;
58 HttpBasicState
state(new ClientSocketHandle(), use_proxy
);
59 HttpRequestInfo request_info
;
60 request_info
.url
= GURL("http://www.example.com/path?foo=bar#hoge");
61 request_info
.method
= "PUT";
62 state
.Initialize(&request_info
, LOW
, BoundNetLog(), CompletionCallback());
63 EXPECT_EQ("PUT /path?foo=bar HTTP/1.1\r\n", state
.GenerateRequestLine());
66 TEST(HttpBasicStateTest
, GenerateRequestLineWithProxy
) {
67 const bool use_proxy
= true;
68 HttpBasicState
state(new ClientSocketHandle(), use_proxy
);
69 HttpRequestInfo request_info
;
70 request_info
.url
= GURL("http://www.example.com/path?foo=bar#hoge");
71 request_info
.method
= "PUT";
72 state
.Initialize(&request_info
, LOW
, BoundNetLog(), CompletionCallback());
73 EXPECT_EQ("PUT http://www.example.com/path?foo=bar HTTP/1.1\r\n",
74 state
.GenerateRequestLine());