Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / net / tools / flip_server / mem_cache_test.cc
blobd5601ac14f527dc6b818c898ad93fc86c3e82b9d
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/flip_server/balsa_headers.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace net {
12 namespace {
14 class MemoryCacheWithFakeReadToString : public MemoryCache {
15 public:
16 virtual ~MemoryCacheWithFakeReadToString() {}
18 virtual void ReadToString(const char* filename, std::string* output)
19 OVERRIDE {
20 *output = data_map_[filename];
23 std::map<std::string, std::string> data_map_;
26 class FlipMemoryCacheTest : public ::testing::Test {
27 public:
28 FlipMemoryCacheTest(): mem_cache_(new MemoryCacheWithFakeReadToString) {}
30 protected:
31 scoped_ptr<MemoryCacheWithFakeReadToString> mem_cache_;
34 TEST_F(FlipMemoryCacheTest, EmptyCache) {
35 MemCacheIter mci;
36 mci.stream_id = 0;
37 ASSERT_EQ(NULL, mem_cache_->GetFileData("./foo"));
38 ASSERT_EQ(NULL, mem_cache_->GetFileData("./bar"));
39 ASSERT_FALSE(mem_cache_->AssignFileData("./hello", &mci));
42 TEST_F(FlipMemoryCacheTest, ReadAndStoreFileContents) {
43 FileData* foo;
44 FileData* hello;
46 mem_cache_->data_map_["./foo"] = "bar";
47 mem_cache_->data_map_["./hello"] = "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, std::distance(hello->headers()->header_lines_begin(),
67 hello->headers()->header_lines_end()));
68 ASSERT_TRUE(hello->headers()->HasHeader("key1"));
69 ASSERT_TRUE(hello->headers()->HasHeader("key2"));
70 ASSERT_TRUE(hello->headers()->HasHeader("transfer-encoding"));
71 ASSERT_TRUE(hello->headers()->HasHeader("connection"));
72 ASSERT_EQ("value1", hello->headers()->GetHeaderPosition("key1")->second);
73 ASSERT_EQ("value2", hello->headers()->GetHeaderPosition("key2")->second);
74 ASSERT_EQ("chunked",
75 hello->headers()->GetHeaderPosition("transfer-encoding")->second);
76 ASSERT_EQ("keep-alive",
77 hello->headers()->GetHeaderPosition("connection")->second);
78 ASSERT_EQ("body: body\r\n", hello->body());
79 ASSERT_EQ("hello", hello->filename());
82 TEST_F(FlipMemoryCacheTest, GetFileDataForHtmlFile) {
83 FileData* hello_html;
85 mem_cache_->data_map_["./hello.http"] = "HTTP/1.0 200 OK\r\n"
86 "key1: value1\r\n"
87 "key2: value2\r\n\r\n"
88 "body: body\r\n";
90 mem_cache_->ReadAndStoreFileContents("./hello.http");
91 hello_html = mem_cache_->GetFileData("hello.html");
92 ASSERT_FALSE(NULL == hello_html);
93 ASSERT_EQ(hello_html, mem_cache_->GetFileData("hello.http"));
96 } // namespace
98 } // namespace net