OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "net/spdy/spdy_framer.h" | 14 #include "net/spdy/spdy_framer.h" |
15 #include "net/tools/balsa/balsa_headers.h" | |
16 #include "net/tools/quic/quic_in_memory_cache.h" | 15 #include "net/tools/quic/quic_in_memory_cache.h" |
17 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 16 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
19 | 18 |
20 using base::ContainsKey; | 19 using base::ContainsKey; |
21 using base::IntToString; | 20 using base::IntToString; |
22 using base::StringPiece; | 21 using base::StringPiece; |
23 using net::SpdyHeaderBlock; | 22 using net::SpdyHeaderBlock; |
24 using std::list; | 23 using std::list; |
25 using std::string; | 24 using std::string; |
26 | 25 |
27 namespace net { | 26 namespace net { |
28 namespace test { | 27 namespace test { |
29 | 28 |
30 namespace { | 29 namespace { |
31 typedef QuicInMemoryCache::Response Response; | 30 typedef QuicInMemoryCache::Response Response; |
32 typedef QuicInMemoryCache::ServerPushInfo ServerPushInfo; | 31 typedef QuicInMemoryCache::ServerPushInfo ServerPushInfo; |
33 }; // namespace | 32 }; // namespace |
34 | 33 |
35 class QuicInMemoryCacheTest : public ::testing::Test { | 34 class QuicInMemoryCacheTest : public ::testing::Test { |
36 protected: | 35 protected: |
37 QuicInMemoryCacheTest() { QuicInMemoryCachePeer::ResetForTests(); } | 36 QuicInMemoryCacheTest() { QuicInMemoryCachePeer::ResetForTests(); } |
38 | 37 |
39 ~QuicInMemoryCacheTest() override { QuicInMemoryCachePeer::ResetForTests(); } | 38 ~QuicInMemoryCacheTest() override { QuicInMemoryCachePeer::ResetForTests(); } |
40 | 39 |
41 void CreateRequest(string host, string path, BalsaHeaders* headers) { | 40 void CreateRequest(string host, string path, SpdyHeaderBlock* headers) { |
42 headers->SetRequestFirstlineFromStringPieces("GET", path, "HTTP/1.1"); | 41 (*headers)[":method"] = "GET"; |
43 headers->ReplaceOrAppendHeader("host", host); | 42 (*headers)[":path"] = path; |
| 43 (*headers)[":authority"] = host; |
| 44 (*headers)[":scheme"] = "https"; |
44 } | 45 } |
45 | 46 |
46 string CacheDirectory() { | 47 string CacheDirectory() { |
47 base::FilePath path; | 48 base::FilePath path; |
48 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 49 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
49 path = path.AppendASCII("net").AppendASCII("data").AppendASCII( | 50 path = path.AppendASCII("net").AppendASCII("data").AppendASCII( |
50 "quic_in_memory_cache_data"); | 51 "quic_in_memory_cache_data"); |
51 // The file path is known to be an ascii string. | 52 // The file path is known to be an ascii string. |
52 return path.MaybeAsASCII(); | 53 return path.MaybeAsASCII(); |
53 } | 54 } |
54 }; | 55 }; |
55 | 56 |
56 TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) { | 57 TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) { |
57 const QuicInMemoryCache::Response* response = | 58 const QuicInMemoryCache::Response* response = |
58 QuicInMemoryCache::GetInstance()->GetResponse("mail.google.com", | 59 QuicInMemoryCache::GetInstance()->GetResponse("mail.google.com", |
59 "/index.html"); | 60 "/index.html"); |
60 ASSERT_FALSE(response); | 61 ASSERT_FALSE(response); |
61 } | 62 } |
62 | 63 |
63 TEST_F(QuicInMemoryCacheTest, AddSimpleResponseGetResponse) { | 64 TEST_F(QuicInMemoryCacheTest, AddSimpleResponseGetResponse) { |
64 string response_body("hello response"); | 65 string response_body("hello response"); |
65 QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance(); | 66 QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance(); |
66 cache->AddSimpleResponse("www.google.com", "/", 200, response_body); | 67 cache->AddSimpleResponse("www.google.com", "/", 200, response_body); |
67 | 68 |
68 BalsaHeaders request_headers; | 69 SpdyHeaderBlock request_headers; |
69 CreateRequest("www.google.com", "/", &request_headers); | 70 CreateRequest("www.google.com", "/", &request_headers); |
70 const QuicInMemoryCache::Response* response = | 71 const QuicInMemoryCache::Response* response = |
71 cache->GetResponse("www.google.com", "/"); | 72 cache->GetResponse("www.google.com", "/"); |
72 ASSERT_TRUE(response); | 73 ASSERT_TRUE(response); |
73 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); | 74 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
74 EXPECT_EQ("200", response->headers().find(":status")->second); | 75 EXPECT_EQ("200", response->headers().find(":status")->second); |
75 EXPECT_EQ(response_body.size(), response->body().length()); | 76 EXPECT_EQ(response_body.size(), response->body().length()); |
76 } | 77 } |
77 | 78 |
78 TEST_F(QuicInMemoryCacheTest, AddResponse) { | 79 TEST_F(QuicInMemoryCacheTest, AddResponse) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); | 252 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
252 EXPECT_EQ(push_response_status[i++], | 253 EXPECT_EQ(push_response_status[i++], |
253 response->headers().find(":status")->second); | 254 response->headers().find(":status")->second); |
254 EXPECT_EQ(push_resource.body, response->body()); | 255 EXPECT_EQ(push_resource.body, response->body()); |
255 resources.pop_front(); | 256 resources.pop_front(); |
256 } | 257 } |
257 } | 258 } |
258 | 259 |
259 } // namespace test | 260 } // namespace test |
260 } // namespace net | 261 } // namespace net |
OLD | NEW |