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

Unified Diff: net/tools/quic/quic_in_memory_cache_test.cc

Issue 1028923002: Make some changes to the QuicInMemory server to clarify the interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.cc ('k') | net/tools/quic/quic_spdy_server_stream.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_in_memory_cache_test.cc
diff --git a/net/tools/quic/quic_in_memory_cache_test.cc b/net/tools/quic/quic_in_memory_cache_test.cc
index a94285c8344dfe976ff8da69794df42e85fb13a9..e8e603eff38d93843e528803612e49858052033e 100644
--- a/net/tools/quic/quic_in_memory_cache_test.cc
+++ b/net/tools/quic/quic_in_memory_cache_test.cc
@@ -16,6 +16,7 @@
using base::IntToString;
using base::StringPiece;
+using std::string;
namespace net {
namespace tools {
@@ -32,102 +33,60 @@ class QuicInMemoryCacheTest : public ::testing::Test {
FLAGS_quic_in_memory_cache_dir = path.MaybeAsASCII();
}
- void CreateRequest(std::string host,
- std::string path,
- net::BalsaHeaders* headers) {
+ ~QuicInMemoryCacheTest() override { QuicInMemoryCachePeer::ResetForTests(); }
+
+ void CreateRequest(StringPiece host,
+ StringPiece path,
+ BalsaHeaders* headers) {
headers->SetRequestFirstlineFromStringPieces("GET", path, "HTTP/1.1");
headers->ReplaceOrAppendHeader("host", host);
}
void SetUp() override { QuicInMemoryCachePeer::ResetForTests(); }
- // This method was copied from end_to_end_test.cc in this directory.
- void AddToCache(const StringPiece& method,
- const StringPiece& path,
- const StringPiece& version,
- const StringPiece& response_code,
- const StringPiece& response_detail,
- const StringPiece& body) {
- BalsaHeaders request_headers, response_headers;
- request_headers.SetRequestFirstlineFromStringPieces(method,
- path,
- version);
- response_headers.SetRequestFirstlineFromStringPieces(version,
- response_code,
- response_detail);
- response_headers.AppendHeader("content-length",
- base::IntToString(body.length()));
-
- // Check if response already exists and matches.
- QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance();
- const QuicInMemoryCache::Response* cached_response =
- cache->GetResponse(request_headers);
- if (cached_response != nullptr) {
- std::string cached_response_headers_str, response_headers_str;
- cached_response->headers().DumpToString(&cached_response_headers_str);
- response_headers.DumpToString(&response_headers_str);
- CHECK_EQ(cached_response_headers_str, response_headers_str);
- CHECK_EQ(cached_response->body(), body);
- return;
- }
- cache->AddResponse(request_headers, response_headers, body);
- }
};
-TEST_F(QuicInMemoryCacheTest, AddResponseGetResponse) {
- std::string response_body("hello response");
- AddToCache("GET", "https://www.google.com/bar",
- "HTTP/1.1", "200", "OK", response_body);
- net::BalsaHeaders request_headers;
- CreateRequest("www.google.com", "/bar", &request_headers);
+TEST_F(QuicInMemoryCacheTest, AddSimpleResponseGetResponse) {
+ string response_body("hello response");
QuicInMemoryCache* cache = QuicInMemoryCache::GetInstance();
- const QuicInMemoryCache::Response* response =
- cache->GetResponse(request_headers);
- ASSERT_TRUE(response);
- EXPECT_EQ("200", response->headers().response_code());
- EXPECT_EQ(response_body.size(), response->body().length());
+ cache->AddSimpleResponse("www.google.com", "/", 200, "OK", response_body);
- CreateRequest("", "https://www.google.com/bar", &request_headers);
- response = cache->GetResponse(request_headers);
+ BalsaHeaders request_headers;
+ CreateRequest("www.google.com", "/", &request_headers);
+ const QuicInMemoryCache::Response* response =
+ cache->GetResponse("www.google.com", "/");
ASSERT_TRUE(response);
EXPECT_EQ("200", response->headers().response_code());
EXPECT_EQ(response_body.size(), response->body().length());
}
TEST_F(QuicInMemoryCacheTest, ReadsCacheDir) {
- net::BalsaHeaders request_headers;
- CreateRequest("quic.test.url", "/index.html", &request_headers);
-
const QuicInMemoryCache::Response* response =
- QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
+ QuicInMemoryCache::GetInstance()->GetResponse("quic.test.url",
+ "/index.html");
ASSERT_TRUE(response);
- std::string value;
+ string value;
response->headers().GetAllOfHeaderAsString("Connection", &value);
EXPECT_EQ("200", response->headers().response_code());
EXPECT_EQ("Keep-Alive", value);
EXPECT_LT(0U, response->body().length());
}
-TEST_F(QuicInMemoryCacheTest, ReadsCacheDirHttp) {
- net::BalsaHeaders request_headers;
- CreateRequest("", "http://quic.test.url/index.html", &request_headers);
-
+TEST_F(QuicInMemoryCacheTest, UsesOriginalUrl) {
const QuicInMemoryCache::Response* response =
- QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
+ QuicInMemoryCache::GetInstance()->GetResponse("quic.test.url",
+ "/index.html");
ASSERT_TRUE(response);
- std::string value;
- response->headers().GetAllOfHeaderAsString("Connection", &value);
EXPECT_EQ("200", response->headers().response_code());
- EXPECT_EQ("Keep-Alive", value);
+ string value;
+ response->headers().GetAllOfHeaderAsString("Connection", &value);
EXPECT_LT(0U, response->body().length());
}
TEST_F(QuicInMemoryCacheTest, GetResponseNoMatch) {
- net::BalsaHeaders request_headers;
- CreateRequest("www.google.com", "/index.html", &request_headers);
-
const QuicInMemoryCache::Response* response =
- QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
+ QuicInMemoryCache::GetInstance()->GetResponse("mail.google.com",
+ "/index.html");
ASSERT_FALSE(response);
}
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.cc ('k') | net/tools/quic/quic_spdy_server_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698