| 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/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 12 #include "net/tools/balsa/balsa_headers.h" | 13 #include "net/tools/balsa/balsa_headers.h" |
| 13 #include "net/tools/quic/quic_in_memory_cache.h" | 14 #include "net/tools/quic/quic_in_memory_cache.h" |
| 14 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 15 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using base::IntToString; | 18 using base::IntToString; |
| 18 using base::StringPiece; | 19 using base::StringPiece; |
| 19 using std::string; | 20 using std::string; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 49 TEST_F(QuicInMemoryCacheTest, AddSimpleResponseGetResponse) { | 50 TEST_F(QuicInMemoryCacheTest, AddSimpleResponseGetResponse) { |
| 50 string response_body("hello response"); | 51 string response_body("hello response"); |
| 51 QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance(); | 52 QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance(); |
| 52 cache->AddSimpleResponse("www.google.com", "/", 200, "OK", response_body); | 53 cache->AddSimpleResponse("www.google.com", "/", 200, "OK", response_body); |
| 53 | 54 |
| 54 BalsaHeaders request_headers; | 55 BalsaHeaders request_headers; |
| 55 CreateRequest("www.google.com", "/", &request_headers); | 56 CreateRequest("www.google.com", "/", &request_headers); |
| 56 const QuicInMemoryCache::Response* response = | 57 const QuicInMemoryCache::Response* response = |
| 57 cache->GetResponse("www.google.com", "/"); | 58 cache->GetResponse("www.google.com", "/"); |
| 58 ASSERT_TRUE(response); | 59 ASSERT_TRUE(response); |
| 59 EXPECT_EQ("200", response->headers().response_code()); | 60 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
| 61 EXPECT_EQ("200 OK", response->headers().find(":status")->second); |
| 60 EXPECT_EQ(response_body.size(), response->body().length()); | 62 EXPECT_EQ(response_body.size(), response->body().length()); |
| 61 } | 63 } |
| 62 | 64 |
| 63 TEST_F(QuicInMemoryCacheTest, ReadsCacheDir) { | 65 TEST_F(QuicInMemoryCacheTest, ReadsCacheDir) { |
| 64 const QuicInMemoryCache::Response* response = | 66 const QuicInMemoryCache::Response* response = |
| 65 QuicInMemoryCache::GetInstance()->GetResponse("quic.test.url", | 67 QuicInMemoryCache::GetInstance()->GetResponse("quic.test.url", |
| 66 "/index.html"); | 68 "/index.html"); |
| 67 ASSERT_TRUE(response); | 69 ASSERT_TRUE(response); |
| 68 string value; | 70 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
| 69 response->headers().GetAllOfHeaderAsString("Connection", &value); | 71 EXPECT_EQ("200 OK", response->headers().find(":status")->second); |
| 70 EXPECT_EQ("200", response->headers().response_code()); | 72 ASSERT_TRUE(ContainsKey(response->headers(), "connection")); |
| 71 EXPECT_EQ("Keep-Alive", value); | 73 EXPECT_EQ("close", response->headers().find("connection")->second); |
| 72 EXPECT_LT(0U, response->body().length()); | 74 EXPECT_LT(0U, response->body().length()); |
| 73 } | 75 } |
| 74 | 76 |
| 75 TEST_F(QuicInMemoryCacheTest, UsesOriginalUrl) { | 77 TEST_F(QuicInMemoryCacheTest, UsesOriginalUrl) { |
| 76 const QuicInMemoryCache::Response* response = | 78 const QuicInMemoryCache::Response* response = |
| 77 QuicInMemoryCache::GetInstance()->GetResponse("quic.test.url", | 79 QuicInMemoryCache::GetInstance()->GetResponse("quic.test.url", |
| 78 "/index.html"); | 80 "/index.html"); |
| 79 ASSERT_TRUE(response); | 81 ASSERT_TRUE(response); |
| 80 EXPECT_EQ("200", response->headers().response_code()); | 82 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
| 81 string value; | 83 EXPECT_EQ("200 OK", response->headers().find(":status")->second); |
| 82 response->headers().GetAllOfHeaderAsString("Connection", &value); | 84 ASSERT_TRUE(ContainsKey(response->headers(), "connection")); |
| 85 EXPECT_EQ("close", response->headers().find("connection")->second); |
| 83 EXPECT_LT(0U, response->body().length()); | 86 EXPECT_LT(0U, response->body().length()); |
| 84 } | 87 } |
| 85 | 88 |
| 86 TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) { | 89 TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) { |
| 87 const QuicInMemoryCache::Response* response = | 90 const QuicInMemoryCache::Response* response = |
| 88 QuicInMemoryCache::GetInstance()->GetResponse("mail.google.com", | 91 QuicInMemoryCache::GetInstance()->GetResponse("mail.google.com", |
| 89 "/index.html"); | 92 "/index.html"); |
| 90 ASSERT_FALSE(response); | 93 ASSERT_FALSE(response); |
| 91 } | 94 } |
| 92 | 95 |
| 93 } // namespace test | 96 } // namespace test |
| 94 } // namespace tools | 97 } // namespace tools |
| 95 } // namespace net | 98 } // namespace net |
| OLD | NEW |