Update V8 to version 4.7.47.
[chromium-blink-merge.git] / net / spdy / spdy_http_utils_unittest.cc
blobc6464aef6b401974a3ac89444104cd4a3145f226
1 // Copyright (c) 2012 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/spdy/spdy_http_utils.h"
7 #include "base/basictypes.h"
8 #include "net/http/http_request_info.h"
9 #include "net/spdy/spdy_framer.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace net {
14 namespace {
16 bool kDirect = true;
18 } // namespace
20 TEST(SpdyHttpUtilsTest, ConvertRequestPriorityToSpdy3Priority) {
21 EXPECT_EQ(0, ConvertRequestPriorityToSpdyPriority(HIGHEST, SPDY3));
22 EXPECT_EQ(1, ConvertRequestPriorityToSpdyPriority(MEDIUM, SPDY3));
23 EXPECT_EQ(2, ConvertRequestPriorityToSpdyPriority(LOW, SPDY3));
24 EXPECT_EQ(3, ConvertRequestPriorityToSpdyPriority(LOWEST, SPDY3));
25 EXPECT_EQ(4, ConvertRequestPriorityToSpdyPriority(IDLE, SPDY3));
28 TEST(SpdyHttpUtilsTest, ConvertSpdy3PriorityToRequestPriority) {
29 EXPECT_EQ(HIGHEST, ConvertSpdyPriorityToRequestPriority(0, SPDY3));
30 EXPECT_EQ(MEDIUM, ConvertSpdyPriorityToRequestPriority(1, SPDY3));
31 EXPECT_EQ(LOW, ConvertSpdyPriorityToRequestPriority(2, SPDY3));
32 EXPECT_EQ(LOWEST, ConvertSpdyPriorityToRequestPriority(3, SPDY3));
33 EXPECT_EQ(IDLE, ConvertSpdyPriorityToRequestPriority(4, SPDY3));
34 // These are invalid values, but we should still handle them
35 // gracefully.
36 for (int i = 5; i < kuint8max; ++i) {
37 EXPECT_EQ(IDLE, ConvertSpdyPriorityToRequestPriority(i, SPDY3));
41 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestSPDY2) {
42 GURL url("https://www.google.com/index.html");
43 HttpRequestInfo request;
44 request.method = "GET";
45 request.url = url;
46 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
47 SpdyHeaderBlock headers;
48 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, SPDY2,
49 kDirect, &headers);
50 EXPECT_EQ("GET", headers["method"]);
51 EXPECT_EQ("https", headers["scheme"]);
52 EXPECT_EQ("www.google.com", headers["host"]);
53 EXPECT_EQ("/index.html", headers["url"]);
54 EXPECT_EQ("HTTP/1.1", headers["version"]);
55 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
58 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestSPDY3) {
59 GURL url("https://www.google.com/index.html");
60 HttpRequestInfo request;
61 request.method = "GET";
62 request.url = url;
63 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
64 SpdyHeaderBlock headers;
65 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, SPDY3,
66 kDirect, &headers);
67 EXPECT_EQ("GET", headers[":method"]);
68 EXPECT_EQ("https", headers[":scheme"]);
69 EXPECT_EQ("www.google.com", headers[":host"]);
70 EXPECT_EQ("/index.html", headers[":path"]);
71 EXPECT_EQ("HTTP/1.1", headers[":version"]);
72 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
75 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestHTTP2) {
76 GURL url("https://www.google.com/index.html");
77 HttpRequestInfo request;
78 request.method = "GET";
79 request.url = url;
80 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
81 SpdyHeaderBlock headers;
82 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, HTTP2,
83 kDirect, &headers);
84 EXPECT_EQ("GET", headers[":method"]);
85 EXPECT_EQ("https", headers[":scheme"]);
86 EXPECT_EQ("www.google.com", headers[":authority"]);
87 EXPECT_EQ("/index.html", headers[":path"]);
88 EXPECT_TRUE(headers.end() == headers.find(":version"));
89 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
92 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestProxySPDY2) {
93 GURL url("https://www.google.com/index.html");
94 HttpRequestInfo request;
95 request.method = "GET";
96 request.url = url;
97 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
98 SpdyHeaderBlock headers;
99 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, SPDY2,
100 !kDirect, &headers);
101 EXPECT_EQ("GET", headers["method"]);
102 EXPECT_EQ("https", headers["scheme"]);
103 EXPECT_EQ("www.google.com", headers["host"]);
104 EXPECT_EQ("https://www.google.com/index.html", headers["url"]);
105 EXPECT_EQ("HTTP/1.1", headers["version"]);
106 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
109 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestProxySPDY3) {
110 GURL url("https://www.google.com/index.html");
111 HttpRequestInfo request;
112 request.method = "GET";
113 request.url = url;
114 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
115 SpdyHeaderBlock headers;
116 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, SPDY3,
117 !kDirect, &headers);
118 EXPECT_EQ("GET", headers[":method"]);
119 EXPECT_EQ("https", headers[":scheme"]);
120 EXPECT_EQ("www.google.com", headers[":host"]);
121 EXPECT_EQ("/index.html", headers[":path"]);
122 EXPECT_EQ("HTTP/1.1", headers[":version"]);
123 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
126 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestProxyHTTP2) {
127 GURL url("https://www.google.com/index.html");
128 HttpRequestInfo request;
129 request.method = "GET";
130 request.url = url;
131 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
132 SpdyHeaderBlock headers;
133 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, HTTP2,
134 !kDirect, &headers);
135 EXPECT_EQ("GET", headers[":method"]);
136 EXPECT_EQ("https", headers[":scheme"]);
137 EXPECT_EQ("www.google.com", headers[":authority"]);
138 EXPECT_EQ("/index.html", headers[":path"]);
139 EXPECT_TRUE(headers.end() == headers.find(":version"));
140 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
143 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestConnectSPDY2) {
144 GURL url("https://www.google.com/index.html");
145 HttpRequestInfo request;
146 request.method = "CONNECT";
147 request.url = url;
148 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
149 SpdyHeaderBlock headers;
150 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, SPDY2,
151 kDirect, &headers);
152 EXPECT_EQ("CONNECT", headers["method"]);
153 EXPECT_TRUE(headers.end() == headers.find("scheme"));
154 EXPECT_EQ("www.google.com", headers["host"]);
155 EXPECT_EQ("www.google.com:443", headers["url"]);
156 EXPECT_EQ("HTTP/1.1", headers["version"]);
157 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
160 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestConnectSPDY3) {
161 GURL url("https://www.google.com/index.html");
162 HttpRequestInfo request;
163 request.method = "CONNECT";
164 request.url = url;
165 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
166 SpdyHeaderBlock headers;
167 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, SPDY3,
168 kDirect, &headers);
169 EXPECT_EQ("CONNECT", headers[":method"]);
170 EXPECT_TRUE(headers.end() == headers.find(":scheme"));
171 EXPECT_EQ("www.google.com", headers[":host"]);
172 EXPECT_EQ("www.google.com:443", headers[":path"]);
173 EXPECT_EQ("HTTP/1.1", headers[":version"]);
174 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
177 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestConnectHTTP2) {
178 GURL url("https://www.google.com/index.html");
179 HttpRequestInfo request;
180 request.method = "CONNECT";
181 request.url = url;
182 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1");
183 SpdyHeaderBlock headers;
184 CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, HTTP2,
185 kDirect, &headers);
186 EXPECT_EQ("CONNECT", headers[":method"]);
187 EXPECT_TRUE(headers.end() == headers.find(":scheme"));
188 EXPECT_EQ("www.google.com:443", headers[":authority"]);
189 EXPECT_EQ(0u, headers.count(":path"));
190 EXPECT_EQ(0u, headers.count(":scheme"));
191 EXPECT_TRUE(headers.end() == headers.find(":version"));
192 EXPECT_EQ("Chrome/1.1", headers["user-agent"]);
195 } // namespace net