OLD | NEW |
(Empty) | |
| 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/tools/quic/quic_in_memory_cache.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/singleton.h" |
| 9 #include "base/path_service.h" |
| 10 #include "net/tools/flip_server/balsa_headers.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace net { |
| 14 namespace tools { |
| 15 namespace test { |
| 16 namespace { |
| 17 |
| 18 class QuicInMemoryCacheTest : public ::testing::Test { |
| 19 protected: |
| 20 QuicInMemoryCacheTest() { |
| 21 base::FilePath path; |
| 22 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 23 path = path.AppendASCII("net").AppendASCII("data") |
| 24 .AppendASCII("quic_in_memory_cache_data"); |
| 25 // The file path is known to be an ascii string. |
| 26 FLAGS_quic_in_memory_cache_dir = path.MaybeAsASCII(); |
| 27 } |
| 28 |
| 29 void CreateRequest(std::string host, |
| 30 std::string path, |
| 31 net::BalsaHeaders* headers) { |
| 32 headers->SetRequestFirstlineFromStringPieces("GET", path, "HTTP/1.1"); |
| 33 headers->ReplaceOrAppendHeader("host", host); |
| 34 } |
| 35 }; |
| 36 |
| 37 TEST_F(QuicInMemoryCacheTest, ReadsCacheDir) { |
| 38 net::BalsaHeaders request_headers; |
| 39 CreateRequest("quic.test.url", "/index.html", &request_headers); |
| 40 |
| 41 const QuicInMemoryCache::Response* response = |
| 42 QuicInMemoryCache::GetInstance()->GetResponse(request_headers); |
| 43 ASSERT_TRUE(response); |
| 44 std::string value; |
| 45 response->headers().GetAllOfHeaderAsString("Connection", &value); |
| 46 EXPECT_EQ("200", response->headers().response_code()); |
| 47 EXPECT_EQ("Keep-Alive", value); |
| 48 EXPECT_LT(0U, response->body().length()); |
| 49 } |
| 50 |
| 51 TEST_F(QuicInMemoryCacheTest, ReadsCacheDirHttp) { |
| 52 net::BalsaHeaders request_headers; |
| 53 CreateRequest("http://quic.test.url", "/index.html", &request_headers); |
| 54 |
| 55 const QuicInMemoryCache::Response* response = |
| 56 QuicInMemoryCache::GetInstance()->GetResponse(request_headers); |
| 57 ASSERT_TRUE(response); |
| 58 std::string value; |
| 59 response->headers().GetAllOfHeaderAsString("Connection", &value); |
| 60 EXPECT_EQ("200", response->headers().response_code()); |
| 61 EXPECT_EQ("Keep-Alive", value); |
| 62 EXPECT_LT(0U, response->body().length()); |
| 63 } |
| 64 |
| 65 TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) { |
| 66 net::BalsaHeaders request_headers; |
| 67 CreateRequest("www.google.com", "/index.html", &request_headers); |
| 68 |
| 69 const QuicInMemoryCache::Response* response = |
| 70 QuicInMemoryCache::GetInstance()->GetResponse(request_headers); |
| 71 ASSERT_FALSE(response); |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 } // namespace test |
| 76 } // namespace tools |
| 77 } // namespace net |
OLD | NEW |