Rename InputLatency::ScrollUpdate to Latency::ScrollUpdate
[chromium-blink-merge.git] / net / tools / flip_server / mem_cache_test.cc
blob87dca685bf23efbcf22b54d08ee32a692bb797ca
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.
5 #include "net/tools/flip_server/mem_cache.h"
7 #include "net/tools/balsa/balsa_headers.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace net {
12 namespace {
14 class MemoryCacheWithFakeReadToString : public MemoryCache {
15 public:
16 ~MemoryCacheWithFakeReadToString() override {}
18 void ReadToString(const char* filename, std::string* output) override {
19 *output = data_map_[filename];
22 std::map<std::string, std::string> data_map_;
25 class FlipMemoryCacheTest : public ::testing::Test {
26 public:
27 FlipMemoryCacheTest() : mem_cache_(new MemoryCacheWithFakeReadToString) {}
29 protected:
30 scoped_ptr<MemoryCacheWithFakeReadToString> mem_cache_;
33 TEST_F(FlipMemoryCacheTest, EmptyCache) {
34 MemCacheIter mci;
35 mci.stream_id = 0;
36 ASSERT_EQ(NULL, mem_cache_->GetFileData("./foo"));
37 ASSERT_EQ(NULL, mem_cache_->GetFileData("./bar"));
38 ASSERT_FALSE(mem_cache_->AssignFileData("./hello", &mci));
41 TEST_F(FlipMemoryCacheTest, ReadAndStoreFileContents) {
42 FileData* foo;
43 FileData* hello;
45 mem_cache_->data_map_["./foo"] = "bar";
46 mem_cache_->data_map_["./hello"] =
47 "HTTP/1.0 200 OK\r\n"
48 "key1: value1\r\n"
49 "key2: value2\r\n\r\n"
50 "body: body\r\n";
51 mem_cache_->ReadAndStoreFileContents("./foo");
52 mem_cache_->ReadAndStoreFileContents("./hello");
54 foo = mem_cache_->GetFileData("foo");
55 hello = mem_cache_->GetFileData("hello");
57 // "./foo" content is broken.
58 ASSERT_EQ(NULL, foo);
59 ASSERT_FALSE(NULL == hello);
60 ASSERT_EQ(hello, mem_cache_->GetFileData("hello"));
62 // "HTTP/1.0" is rewritten to "HTTP/1.1".
63 ASSERT_EQ("HTTP/1.1", hello->headers()->response_version());
64 ASSERT_EQ("200", hello->headers()->response_code());
65 ASSERT_EQ("OK", hello->headers()->response_reason_phrase());
66 ASSERT_EQ(4,
67 std::distance(hello->headers()->header_lines_begin(),
68 hello->headers()->header_lines_end()));
69 ASSERT_TRUE(hello->headers()->HasHeader("key1"));
70 ASSERT_TRUE(hello->headers()->HasHeader("key2"));
71 ASSERT_TRUE(hello->headers()->HasHeader("transfer-encoding"));
72 ASSERT_TRUE(hello->headers()->HasHeader("connection"));
73 ASSERT_EQ("value1", hello->headers()->GetHeaderPosition("key1")->second);
74 ASSERT_EQ("value2", hello->headers()->GetHeaderPosition("key2")->second);
75 ASSERT_EQ("chunked",
76 hello->headers()->GetHeaderPosition("transfer-encoding")->second);
77 ASSERT_EQ("keep-alive",
78 hello->headers()->GetHeaderPosition("connection")->second);
79 ASSERT_EQ("body: body\r\n", hello->body());
80 ASSERT_EQ("hello", hello->filename());
83 TEST_F(FlipMemoryCacheTest, GetFileDataForHtmlFile) {
84 FileData* hello_html;
86 mem_cache_->data_map_["./hello.http"] =
87 "HTTP/1.0 200 OK\r\n"
88 "key1: value1\r\n"
89 "key2: value2\r\n\r\n"
90 "body: body\r\n";
92 mem_cache_->ReadAndStoreFileContents("./hello.http");
93 hello_html = mem_cache_->GetFileData("hello.html");
94 ASSERT_FALSE(NULL == hello_html);
95 ASSERT_EQ(hello_html, mem_cache_->GetFileData("hello.http"));
98 } // namespace
100 } // namespace net