OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/spdy/spdy_http_utils.h" | 5 #include "net/spdy/spdy_http_utils.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "net/http/http_request_info.h" | 11 #include "net/http/http_request_info.h" |
12 #include "net/spdy/spdy_framer.h" | 12 #include "net/spdy/spdy_framer.h" |
13 #include "net/spdy/spdy_test_utils.h" | 13 #include "net/spdy/spdy_test_utils.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 bool kDirect = true; | 20 bool kDirect = true; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 TEST(SpdyHttpUtilsTest, ConvertRequestPriorityToSpdy3Priority) { | 24 TEST(SpdyHttpUtilsTest, ConvertRequestPriorityToSpdy3Priority) { |
25 EXPECT_EQ(0, ConvertRequestPriorityToSpdyPriority(HIGHEST, SPDY3)); | 25 EXPECT_EQ(0, ConvertRequestPriorityToSpdyPriority(HIGHEST, SPDY3)); |
26 EXPECT_EQ(1, ConvertRequestPriorityToSpdyPriority(MEDIUM, SPDY3)); | 26 EXPECT_EQ(1, ConvertRequestPriorityToSpdyPriority(MEDIUM, SPDY3)); |
27 EXPECT_EQ(2, ConvertRequestPriorityToSpdyPriority(LOW, SPDY3)); | 27 EXPECT_EQ(2, ConvertRequestPriorityToSpdyPriority(LOW, SPDY3)); |
28 EXPECT_EQ(3, ConvertRequestPriorityToSpdyPriority(LOWEST, SPDY3)); | 28 EXPECT_EQ(3, ConvertRequestPriorityToSpdyPriority(LOWEST, SPDY3)); |
29 EXPECT_EQ(4, ConvertRequestPriorityToSpdyPriority(IDLE, SPDY3)); | 29 EXPECT_EQ(4, ConvertRequestPriorityToSpdyPriority(IDLE, SPDY3)); |
| 30 EXPECT_EQ(5, ConvertRequestPriorityToSpdyPriority(THROTTLED, SPDY3)); |
30 } | 31 } |
31 | 32 |
32 TEST(SpdyHttpUtilsTest, ConvertSpdy3PriorityToRequestPriority) { | 33 TEST(SpdyHttpUtilsTest, ConvertSpdy3PriorityToRequestPriority) { |
33 EXPECT_EQ(HIGHEST, ConvertSpdyPriorityToRequestPriority(0, SPDY3)); | 34 EXPECT_EQ(HIGHEST, ConvertSpdyPriorityToRequestPriority(0, SPDY3)); |
34 EXPECT_EQ(MEDIUM, ConvertSpdyPriorityToRequestPriority(1, SPDY3)); | 35 EXPECT_EQ(MEDIUM, ConvertSpdyPriorityToRequestPriority(1, SPDY3)); |
35 EXPECT_EQ(LOW, ConvertSpdyPriorityToRequestPriority(2, SPDY3)); | 36 EXPECT_EQ(LOW, ConvertSpdyPriorityToRequestPriority(2, SPDY3)); |
36 EXPECT_EQ(LOWEST, ConvertSpdyPriorityToRequestPriority(3, SPDY3)); | 37 EXPECT_EQ(LOWEST, ConvertSpdyPriorityToRequestPriority(3, SPDY3)); |
37 EXPECT_EQ(IDLE, ConvertSpdyPriorityToRequestPriority(4, SPDY3)); | 38 EXPECT_EQ(IDLE, ConvertSpdyPriorityToRequestPriority(4, SPDY3)); |
| 39 EXPECT_EQ(THROTTLED, ConvertSpdyPriorityToRequestPriority(5, SPDY3)); |
38 // These are invalid values, but we should still handle them | 40 // These are invalid values, but we should still handle them |
39 // gracefully. | 41 // gracefully. |
40 for (int i = 5; i < std::numeric_limits<uint8_t>::max(); ++i) { | 42 for (int i = 6; i < std::numeric_limits<uint8_t>::max(); ++i) { |
41 EXPECT_EQ(IDLE, ConvertSpdyPriorityToRequestPriority(i, SPDY3)); | 43 EXPECT_EQ(IDLE, ConvertSpdyPriorityToRequestPriority(i, SPDY3)); |
42 } | 44 } |
43 } | 45 } |
44 | 46 |
45 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestSPDY3) { | 47 TEST(SpdyHttpUtilsTest, CreateSpdyHeadersFromHttpRequestSPDY3) { |
46 GURL url("https://www.google.com/index.html"); | 48 GURL url("https://www.google.com/index.html"); |
47 HttpRequestInfo request; | 49 HttpRequestInfo request; |
48 request.method = "GET"; | 50 request.method = "GET"; |
49 request.url = url; | 51 request.url = url; |
50 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1"); | 52 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, "Chrome/1.1"); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 EXPECT_EQ("CONNECT", headers[":method"]); | 141 EXPECT_EQ("CONNECT", headers[":method"]); |
140 EXPECT_TRUE(headers.end() == headers.find(":scheme")); | 142 EXPECT_TRUE(headers.end() == headers.find(":scheme")); |
141 EXPECT_EQ("www.google.com:443", headers[":authority"]); | 143 EXPECT_EQ("www.google.com:443", headers[":authority"]); |
142 EXPECT_EQ(headers.end(), headers.find(":path")); | 144 EXPECT_EQ(headers.end(), headers.find(":path")); |
143 EXPECT_EQ(headers.end(), headers.find(":scheme")); | 145 EXPECT_EQ(headers.end(), headers.find(":scheme")); |
144 EXPECT_TRUE(headers.end() == headers.find(":version")); | 146 EXPECT_TRUE(headers.end() == headers.find(":version")); |
145 EXPECT_EQ("Chrome/1.1", headers["user-agent"]); | 147 EXPECT_EQ("Chrome/1.1", headers["user-agent"]); |
146 } | 148 } |
147 | 149 |
148 } // namespace net | 150 } // namespace net |
OLD | NEW |