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 "net/tools/flip_server/http_interface.h" | 5 #include "net/tools/flip_server/http_interface.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 void TearDown() override { | 89 void TearDown() override { |
90 if (acceptor_->listen_fd_ >= 0) { | 90 if (acceptor_->listen_fd_ >= 0) { |
91 epoll_server_->UnregisterFD(acceptor_->listen_fd_); | 91 epoll_server_->UnregisterFD(acceptor_->listen_fd_); |
92 close(acceptor_->listen_fd_); | 92 close(acceptor_->listen_fd_); |
93 acceptor_->listen_fd_ = -1; | 93 acceptor_->listen_fd_ = -1; |
94 } | 94 } |
95 STLDeleteElements(connection_->output_list()); | 95 STLDeleteElements(connection_->output_list()); |
96 } | 96 } |
97 | 97 |
98 bool HasStream(uint32 stream_id) { | 98 bool HasStream(uint32_t stream_id) { |
99 return interface_->output_ordering().ExistsInPriorityMaps(stream_id); | 99 return interface_->output_ordering().ExistsInPriorityMaps(stream_id); |
100 } | 100 } |
101 | 101 |
102 protected: | 102 protected: |
103 scoped_ptr<MockSMInterface> mock_another_interface_; | 103 scoped_ptr<MockSMInterface> mock_another_interface_; |
104 scoped_ptr<MemoryCache> memory_cache_; | 104 scoped_ptr<MemoryCache> memory_cache_; |
105 scoped_ptr<FlipAcceptor> acceptor_; | 105 scoped_ptr<FlipAcceptor> acceptor_; |
106 scoped_ptr<EpollServer> epoll_server_; | 106 scoped_ptr<EpollServer> epoll_server_; |
107 scoped_ptr<MockSMConnection> connection_; | 107 scoped_ptr<MockSMConnection> connection_; |
108 scoped_ptr<HttpSM> interface_; | 108 scoped_ptr<HttpSM> interface_; |
(...skipping 15 matching lines...) Expand all Loading... |
124 public: | 124 public: |
125 FlipHttpSMSpdyTest() : FlipHttpSMTest(FLIP_HANDLER_SPDY_SERVER) {} | 125 FlipHttpSMSpdyTest() : FlipHttpSMTest(FLIP_HANDLER_SPDY_SERVER) {} |
126 ~FlipHttpSMSpdyTest() override {} | 126 ~FlipHttpSMSpdyTest() override {} |
127 }; | 127 }; |
128 | 128 |
129 TEST_F(FlipHttpSMTest, Construct) { | 129 TEST_F(FlipHttpSMTest, Construct) { |
130 ASSERT_FALSE(interface_->spdy_framer()->is_request()); | 130 ASSERT_FALSE(interface_->spdy_framer()->is_request()); |
131 } | 131 } |
132 | 132 |
133 TEST_F(FlipHttpSMTest, AddToOutputOrder) { | 133 TEST_F(FlipHttpSMTest, AddToOutputOrder) { |
134 uint32 stream_id = 13; | 134 uint32_t stream_id = 13; |
135 MemCacheIter mci; | 135 MemCacheIter mci; |
136 mci.stream_id = stream_id; | 136 mci.stream_id = stream_id; |
137 | 137 |
138 { | 138 { |
139 BalsaHeaders headers; | 139 BalsaHeaders headers; |
140 std::string filename = "foobar"; | 140 std::string filename = "foobar"; |
141 memory_cache_->InsertFile(&headers, filename, ""); | 141 memory_cache_->InsertFile(&headers, filename, ""); |
142 mci.file_data = memory_cache_->GetFileData(filename); | 142 mci.file_data = memory_cache_->GetFileData(filename); |
143 } | 143 } |
144 | 144 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 ASSERT_FALSE(interface_->MessageFullyRead()); | 247 ASSERT_FALSE(interface_->MessageFullyRead()); |
248 ASSERT_EQ(BalsaFrameEnums::READING_UNTIL_CLOSE, | 248 ASSERT_EQ(BalsaFrameEnums::READING_UNTIL_CLOSE, |
249 interface_->spdy_framer()->ParseState()); | 249 interface_->spdy_framer()->ParseState()); |
250 | 250 |
251 interface_->ResetForNewConnection(); | 251 interface_->ResetForNewConnection(); |
252 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE, | 252 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE, |
253 interface_->spdy_framer()->ParseState()); | 253 interface_->spdy_framer()->ParseState()); |
254 } | 254 } |
255 | 255 |
256 TEST_F(FlipHttpSMTest, NewStream) { | 256 TEST_F(FlipHttpSMTest, NewStream) { |
257 uint32 stream_id = 4; | 257 uint32_t stream_id = 4; |
258 { | 258 { |
259 BalsaHeaders headers; | 259 BalsaHeaders headers; |
260 std::string filename = "foobar"; | 260 std::string filename = "foobar"; |
261 memory_cache_->InsertFile(&headers, filename, ""); | 261 memory_cache_->InsertFile(&headers, filename, ""); |
262 } | 262 } |
263 | 263 |
264 interface_->NewStream(stream_id, 1, "foobar"); | 264 interface_->NewStream(stream_id, 1, "foobar"); |
265 ASSERT_TRUE(HasStream(stream_id)); | 265 ASSERT_TRUE(HasStream(stream_id)); |
266 } | 266 } |
267 | 267 |
268 TEST_F(FlipHttpSMTest, NewStreamError) { | 268 TEST_F(FlipHttpSMTest, NewStreamError) { |
269 std::string syn_reply = | 269 std::string syn_reply = |
270 "HTTP/1.1 404 Not Found\r\n" | 270 "HTTP/1.1 404 Not Found\r\n" |
271 "transfer-encoding: chunked\r\n\r\n"; | 271 "transfer-encoding: chunked\r\n\r\n"; |
272 std::string body = "e\r\npage not found\r\n"; | 272 std::string body = "e\r\npage not found\r\n"; |
273 uint32 stream_id = 4; | 273 uint32_t stream_id = 4; |
274 | 274 |
275 ASSERT_FALSE(HasStream(stream_id)); | 275 ASSERT_FALSE(HasStream(stream_id)); |
276 interface_->NewStream(stream_id, 1, "foobar"); | 276 interface_->NewStream(stream_id, 1, "foobar"); |
277 | 277 |
278 ASSERT_EQ(3u, connection_->output_list()->size()); | 278 ASSERT_EQ(3u, connection_->output_list()->size()); |
279 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | 279 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); |
280 DataFrame* df = *i++; | 280 DataFrame* df = *i++; |
281 ASSERT_EQ(syn_reply, StringPiece(df->data, df->size)); | 281 ASSERT_EQ(syn_reply, StringPiece(df->data, df->size)); |
282 df = *i++; | 282 df = *i++; |
283 ASSERT_EQ(body, StringPiece(df->data, df->size)); | 283 ASSERT_EQ(body, StringPiece(df->data, df->size)); |
284 df = *i++; | 284 df = *i++; |
285 ASSERT_EQ("0\r\n\r\n", StringPiece(df->data, df->size)); | 285 ASSERT_EQ("0\r\n\r\n", StringPiece(df->data, df->size)); |
286 ASSERT_FALSE(HasStream(stream_id)); | 286 ASSERT_FALSE(HasStream(stream_id)); |
287 } | 287 } |
288 | 288 |
289 TEST_F(FlipHttpSMTest, SendErrorNotFound) { | 289 TEST_F(FlipHttpSMTest, SendErrorNotFound) { |
290 std::string syn_reply = | 290 std::string syn_reply = |
291 "HTTP/1.1 404 Not Found\r\n" | 291 "HTTP/1.1 404 Not Found\r\n" |
292 "transfer-encoding: chunked\r\n\r\n"; | 292 "transfer-encoding: chunked\r\n\r\n"; |
293 std::string body = "e\r\npage not found\r\n"; | 293 std::string body = "e\r\npage not found\r\n"; |
294 uint32 stream_id = 13; | 294 uint32_t stream_id = 13; |
295 MemCacheIter mci; | 295 MemCacheIter mci; |
296 mci.stream_id = stream_id; | 296 mci.stream_id = stream_id; |
297 | 297 |
298 { | 298 { |
299 BalsaHeaders headers; | 299 BalsaHeaders headers; |
300 std::string filename = "foobar"; | 300 std::string filename = "foobar"; |
301 memory_cache_->InsertFile(&headers, filename, ""); | 301 memory_cache_->InsertFile(&headers, filename, ""); |
302 mci.file_data = memory_cache_->GetFileData(filename); | 302 mci.file_data = memory_cache_->GetFileData(filename); |
303 } | 303 } |
304 | 304 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 BalsaVisitorInterface* visitor = interface_.get(); | 409 BalsaVisitorInterface* visitor = interface_.get(); |
410 { | 410 { |
411 BalsaHeaders headers; | 411 BalsaHeaders headers; |
412 std::string filename = "GET_/path/file"; | 412 std::string filename = "GET_/path/file"; |
413 memory_cache_->InsertFile(&headers, filename, ""); | 413 memory_cache_->InsertFile(&headers, filename, ""); |
414 } | 414 } |
415 | 415 |
416 BalsaHeaders headers; | 416 BalsaHeaders headers; |
417 headers.AppendHeader("Host", "example.com"); | 417 headers.AppendHeader("Host", "example.com"); |
418 headers.SetRequestFirstlineFromStringPieces("GET", "/path/file", "HTTP/1.0"); | 418 headers.SetRequestFirstlineFromStringPieces("GET", "/path/file", "HTTP/1.0"); |
419 uint32 stream_id = 133; | 419 uint32_t stream_id = 133; |
420 interface_->SetStreamID(stream_id); | 420 interface_->SetStreamID(stream_id); |
421 ASSERT_FALSE(HasStream(stream_id)); | 421 ASSERT_FALSE(HasStream(stream_id)); |
422 visitor->ProcessHeaders(headers); | 422 visitor->ProcessHeaders(headers); |
423 ASSERT_TRUE(HasStream(stream_id)); | 423 ASSERT_TRUE(HasStream(stream_id)); |
424 } | 424 } |
425 | 425 |
426 TEST_F(FlipHttpSMHttpTest, MessageDone) { | 426 TEST_F(FlipHttpSMHttpTest, MessageDone) { |
427 BalsaVisitorInterface* visitor = interface_.get(); | 427 BalsaVisitorInterface* visitor = interface_.get(); |
428 { | 428 { |
429 InSequence s; | 429 InSequence s; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 482 } |
483 interface_->SendEOF(32); | 483 interface_->SendEOF(32); |
484 ASSERT_EQ(1u, connection_->output_list()->size()); | 484 ASSERT_EQ(1u, connection_->output_list()->size()); |
485 DataFrame* df = connection_->output_list()->front(); | 485 DataFrame* df = connection_->output_list()->front(); |
486 ASSERT_EQ("0\r\n\r\n", StringPiece(df->data, df->size)); | 486 ASSERT_EQ("0\r\n\r\n", StringPiece(df->data, df->size)); |
487 } | 487 } |
488 | 488 |
489 } // namespace | 489 } // namespace |
490 | 490 |
491 } // namespace net | 491 } // namespace net |
OLD | NEW |