- add sources.
[platform/framework/web/crosswalk.git] / src / net / http / http_basic_state_unittest.cc
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.
4
5 #include "net/http/http_basic_state.h"
6
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"
12
13 namespace net {
14 namespace {
15
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());
22 }
23
24 TEST(HttpBasicStateTest, UsingProxyCanBeFalse) {
25   const HttpBasicState state(new ClientSocketHandle(), false);
26   EXPECT_FALSE(state.using_proxy());
27 }
28
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());
36 }
37
38 TEST(HttpBasicStateTest, InitializeWorks) {
39   HttpBasicState state(new ClientSocketHandle(), false);
40   const HttpRequestInfo request_info;
41   EXPECT_EQ(OK,
42             state.Initialize(
43                 &request_info, LOW, BoundNetLog(), CompletionCallback()));
44   EXPECT_TRUE(state.parser());
45 }
46
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());
52   state.DeleteParser();
53   EXPECT_EQ(NULL, state.parser());
54 }
55
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());
64 }
65
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());
75 }
76
77 }  // namespace
78 }  // namespace net