| OLD | NEW |
| 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 <string> | 5 #include <string> |
| 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 "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const QuicHttpResponseCache::Response* response = | 91 const QuicHttpResponseCache::Response* response = |
| 92 cache_.GetResponse(kRequestHost, kRequestPath); | 92 cache_.GetResponse(kRequestHost, kRequestPath); |
| 93 EXPECT_EQ(response->headers(), response_headers); | 93 EXPECT_EQ(response->headers(), response_headers); |
| 94 EXPECT_EQ(response->body(), kResponseBody); | 94 EXPECT_EQ(response->body(), kResponseBody); |
| 95 EXPECT_EQ(response->trailers(), response_trailers); | 95 EXPECT_EQ(response->trailers(), response_trailers); |
| 96 } | 96 } |
| 97 | 97 |
| 98 TEST_F(QuicHttpResponseCacheTest, ReadsCacheDir) { | 98 TEST_F(QuicHttpResponseCacheTest, ReadsCacheDir) { |
| 99 cache_.InitializeFromDirectory(CacheDirectory()); | 99 cache_.InitializeFromDirectory(CacheDirectory()); |
| 100 const QuicHttpResponseCache::Response* response = | 100 const QuicHttpResponseCache::Response* response = |
| 101 cache_.GetResponse("quic.test.url", "/index.html"); | 101 cache_.GetResponse("www.example.com", "/index.html"); |
| 102 ASSERT_TRUE(response); | 102 ASSERT_TRUE(response); |
| 103 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); | 103 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
| 104 EXPECT_EQ("200", response->headers().find(":status")->second); | 104 EXPECT_EQ("200", response->headers().find(":status")->second); |
| 105 // Connection headers are not valid in HTTP/2. | 105 // Connection headers are not valid in HTTP/2. |
| 106 EXPECT_FALSE(ContainsKey(response->headers(), "connection")); | 106 EXPECT_FALSE(ContainsKey(response->headers(), "connection")); |
| 107 EXPECT_LT(0U, response->body().length()); | 107 EXPECT_LT(0U, response->body().length()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST_F(QuicHttpResponseCacheTest, ReadsCacheDirWithServerPushResource) { | 110 TEST_F(QuicHttpResponseCacheTest, ReadsCacheDirWithServerPushResource) { |
| 111 cache_.InitializeFromDirectory(CacheDirectory() + "_with_push"); | 111 cache_.InitializeFromDirectory(CacheDirectory() + "_with_push"); |
| 112 list<ServerPushInfo> resources = | 112 std::list<ServerPushInfo> resources = |
| 113 cache_.GetServerPushResources("quic.test.url/"); | 113 cache_.GetServerPushResources("www.example.com/"); |
| 114 ASSERT_EQ(1UL, resources.size()); | 114 ASSERT_EQ(1UL, resources.size()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 TEST_F(QuicHttpResponseCacheTest, ReadsCacheDirWithServerPushResources) { | 117 TEST_F(QuicHttpResponseCacheTest, ReadsCacheDirWithServerPushResources) { |
| 118 cache_.InitializeFromDirectory(CacheDirectory() + "_with_push"); | 118 cache_.InitializeFromDirectory(CacheDirectory() + "_with_push"); |
| 119 list<ServerPushInfo> resources = | 119 std::list<ServerPushInfo> resources = |
| 120 cache_.GetServerPushResources("quic.test.url/index2.html"); | 120 cache_.GetServerPushResources("www.example.com/index2.html"); |
| 121 ASSERT_EQ(2UL, resources.size()); | 121 ASSERT_EQ(2UL, resources.size()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_F(QuicHttpResponseCacheTest, UsesOriginalUrl) { | 124 TEST_F(QuicHttpResponseCacheTest, UsesOriginalUrl) { |
| 125 cache_.InitializeFromDirectory(CacheDirectory()); | 125 cache_.InitializeFromDirectory(CacheDirectory()); |
| 126 const QuicHttpResponseCache::Response* response = | 126 const QuicHttpResponseCache::Response* response = |
| 127 cache_.GetResponse("quic.test.url", "/index.html"); | 127 cache_.GetResponse("www.example.com", "/site_map.html"); |
| 128 ASSERT_TRUE(response); | 128 ASSERT_TRUE(response); |
| 129 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); | 129 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
| 130 EXPECT_EQ("200", response->headers().find(":status")->second); | 130 EXPECT_EQ("200", response->headers().find(":status")->second); |
| 131 // Connection headers are not valid in HTTP/2. | 131 // Connection headers are not valid in HTTP/2. |
| 132 EXPECT_FALSE(ContainsKey(response->headers(), "connection")); | 132 EXPECT_FALSE(ContainsKey(response->headers(), "connection")); |
| 133 EXPECT_LT(0U, response->body().length()); | 133 EXPECT_LT(0U, response->body().length()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(QuicHttpResponseCacheTest, DefaultResponse) { | 136 TEST_F(QuicHttpResponseCacheTest, DefaultResponse) { |
| 137 // Verify GetResponse returns nullptr when no default is set. | 137 // Verify GetResponse returns nullptr when no default is set. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); | 238 ASSERT_TRUE(ContainsKey(response->headers(), ":status")); |
| 239 EXPECT_EQ(push_response_status[i++], | 239 EXPECT_EQ(push_response_status[i++], |
| 240 response->headers().find(":status")->second); | 240 response->headers().find(":status")->second); |
| 241 EXPECT_EQ(push_resource.body, response->body()); | 241 EXPECT_EQ(push_resource.body, response->body()); |
| 242 resources.pop_front(); | 242 resources.pop_front(); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace test | 246 } // namespace test |
| 247 } // namespace net | 247 } // namespace net |
| OLD | NEW |