Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: net/tools/quic/quic_in_memory_cache_test.cc

Issue 18655004: Add a quic_in_memory_cache_test data file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "Fix unittest error." Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "net/tools/quic/quic_in_memory_cache.h" 5 #include "net/tools/quic/quic_in_memory_cache.h"
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 "net/tools/flip_server/balsa_headers.h" 10 #include "net/tools/flip_server/balsa_headers.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace net { 13 namespace net {
14 namespace tools { 14 namespace tools {
15 namespace test { 15 namespace test {
16 namespace {
17 16
18 class QuicInMemoryCacheTest : public ::testing::Test { 17 class QuicInMemoryCacheTest : public ::testing::Test {
19 protected: 18 protected:
20 QuicInMemoryCacheTest() { 19 QuicInMemoryCacheTest() {
21 base::FilePath path; 20 base::FilePath path;
22 PathService::Get(base::DIR_SOURCE_ROOT, &path); 21 PathService::Get(base::DIR_SOURCE_ROOT, &path);
23 path = path.AppendASCII("net").AppendASCII("data") 22 path = path.AppendASCII("net").AppendASCII("data")
24 .AppendASCII("quic_in_memory_cache_data"); 23 .AppendASCII("quic_in_memory_cache_data");
25 // The file path is known to be an ascii string. 24 // The file path is known to be an ascii string.
26 FLAGS_quic_in_memory_cache_dir = path.MaybeAsASCII(); 25 FLAGS_quic_in_memory_cache_dir = path.MaybeAsASCII();
27 } 26 }
28 27
29 void CreateRequest(std::string host, 28 void CreateRequest(std::string host,
30 std::string path, 29 std::string path,
31 net::BalsaHeaders* headers) { 30 net::BalsaHeaders* headers) {
32 headers->SetRequestFirstlineFromStringPieces("GET", path, "HTTP/1.1"); 31 headers->SetRequestFirstlineFromStringPieces("GET", path, "HTTP/1.1");
33 headers->ReplaceOrAppendHeader("host", host); 32 headers->ReplaceOrAppendHeader("host", host);
34 } 33 }
34
35 void SetUp() {
36 QuicInMemoryCache::GetInstance()->ResetForTests();
37 QuicInMemoryCache::GetInstance()->Initialize();
38 }
35 }; 39 };
36 40
37 TEST_F(QuicInMemoryCacheTest, ReadsCacheDir) { 41 TEST_F(QuicInMemoryCacheTest, ReadsCacheDir) {
38 net::BalsaHeaders request_headers; 42 net::BalsaHeaders request_headers;
39 CreateRequest("quic.test.url", "/index.html", &request_headers); 43 CreateRequest("quic.test.url", "/index.html", &request_headers);
40 44
41 const QuicInMemoryCache::Response* response = 45 const QuicInMemoryCache::Response* response =
42 QuicInMemoryCache::GetInstance()->GetResponse(request_headers); 46 QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
43 ASSERT_TRUE(response); 47 ASSERT_TRUE(response);
44 std::string value; 48 std::string value;
45 response->headers().GetAllOfHeaderAsString("Connection", &value); 49 response->headers().GetAllOfHeaderAsString("Connection", &value);
46 EXPECT_EQ("200", response->headers().response_code()); 50 EXPECT_EQ("200", response->headers().response_code());
47 EXPECT_EQ("Keep-Alive", value); 51 EXPECT_EQ("Keep-Alive", value);
48 EXPECT_LT(0U, response->body().length()); 52 EXPECT_LT(0U, response->body().length());
49 } 53 }
50 54
51 TEST_F(QuicInMemoryCacheTest, ReadsCacheDirHttp) { 55 TEST_F(QuicInMemoryCacheTest, ReadsCacheDirHttp) {
52 net::BalsaHeaders request_headers; 56 net::BalsaHeaders request_headers;
53 CreateRequest("http://quic.test.url", "/index.html", &request_headers); 57 CreateRequest("", "http://quic.test.url/index.html", &request_headers);
54 58
55 const QuicInMemoryCache::Response* response = 59 const QuicInMemoryCache::Response* response =
56 QuicInMemoryCache::GetInstance()->GetResponse(request_headers); 60 QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
57 ASSERT_TRUE(response); 61 ASSERT_TRUE(response);
58 std::string value; 62 std::string value;
59 response->headers().GetAllOfHeaderAsString("Connection", &value); 63 response->headers().GetAllOfHeaderAsString("Connection", &value);
60 EXPECT_EQ("200", response->headers().response_code()); 64 EXPECT_EQ("200", response->headers().response_code());
61 EXPECT_EQ("Keep-Alive", value); 65 EXPECT_EQ("Keep-Alive", value);
62 EXPECT_LT(0U, response->body().length()); 66 EXPECT_LT(0U, response->body().length());
63 } 67 }
64 68
65 TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) { 69 TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) {
66 net::BalsaHeaders request_headers; 70 net::BalsaHeaders request_headers;
67 CreateRequest("www.google.com", "/index.html", &request_headers); 71 CreateRequest("www.google.com", "/index.html", &request_headers);
68 72
69 const QuicInMemoryCache::Response* response = 73 const QuicInMemoryCache::Response* response =
70 QuicInMemoryCache::GetInstance()->GetResponse(request_headers); 74 QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
71 ASSERT_FALSE(response); 75 ASSERT_FALSE(response);
72 } 76 }
73 77
Ryan Hamilton 2013/07/04 14:46:03 Can you add a test which pass with the new code, b
honghaiz 2013/07/04 17:34:04 Done.
74 } // namespace
75 } // namespace test 78 } // namespace test
76 } // namespace tools 79 } // namespace tools
77 } // namespace net 80 } // namespace net
OLDNEW
« net/tools/quic/quic_in_memory_cache.cc ('K') | « net/tools/quic/quic_in_memory_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698