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