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

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

Issue 16354006: Fix a bug in quic_in_memory_cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quic_clientserver2
Patch Set: Add unittest. Created 7 years, 6 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') | no next file » | 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
new file mode 100644
index 0000000000000000000000000000000000000000..438f24c4d9e0c543628bd5e17f83ec42f0e3280e
--- /dev/null
+++ b/net/tools/quic/quic_in_memory_cache_test.cc
@@ -0,0 +1,77 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/tools/quic/quic_in_memory_cache.h"
+
+#include "base/files/file_path.h"
+#include "base/memory/singleton.h"
+#include "base/path_service.h"
+#include "net/tools/flip_server/balsa_headers.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+namespace tools {
+namespace test {
+namespace {
+
+class QuicInMemoryCacheTest : public ::testing::Test {
+ protected:
+ QuicInMemoryCacheTest() {
+ base::FilePath path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &path);
+ path = path.AppendASCII("net").AppendASCII("data")
+ .AppendASCII("quic_in_memory_cache_data");
+ // The file path is known to be an ascii string.
+ FLAGS_quic_in_memory_cache_dir = path.MaybeAsASCII();
+ }
+
+ void CreateRequest(std::string host,
+ std::string path,
+ net::BalsaHeaders* headers) {
+ headers->SetRequestFirstlineFromStringPieces("GET", path, "HTTP/1.1");
+ headers->ReplaceOrAppendHeader("host", host);
+ }
+};
+
+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);
+ ASSERT_TRUE(response);
+ std::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);
+
+ const QuicInMemoryCache::Response* response =
+ QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
+ ASSERT_TRUE(response);
+ std::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, GetResponseNoMatch) {
+ net::BalsaHeaders request_headers;
+ CreateRequest("www.google.com", "/index.html", &request_headers);
+
+ const QuicInMemoryCache::Response* response =
+ QuicInMemoryCache::GetInstance()->GetResponse(request_headers);
+ ASSERT_FALSE(response);
+}
+
+} // namespace
+} // namespace test
+} // namespace tools
+} // namespace net
« no previous file with comments | « 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