Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1656)

Side by Side Diff: net/tools/flip_server/http_interface_test.cc

Issue 93793004: Format and Refactor Flip Server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 MemoryCache* memory_cache, 33 MemoryCache* memory_cache,
34 FlipAcceptor* acceptor, 34 FlipAcceptor* acceptor,
35 std::string log_prefix) 35 std::string log_prefix)
36 : SMConnection(epoll_server, 36 : SMConnection(epoll_server,
37 ssl_state, 37 ssl_state,
38 memory_cache, 38 memory_cache,
39 acceptor, 39 acceptor,
40 log_prefix) {} 40 log_prefix) {}
41 41
42 MOCK_METHOD0(Cleanup, void()); 42 MOCK_METHOD0(Cleanup, void());
43 MOCK_METHOD8(InitSMConnection, void(SMConnectionPoolInterface*, 43 MOCK_METHOD8(InitSMConnection,
44 SMInterface*, 44 void(SMConnectionPoolInterface*,
45 EpollServer*, 45 SMInterface*,
46 int, 46 EpollServer*,
47 std::string, 47 int,
48 std::string, 48 std::string,
49 std::string, 49 std::string,
50 bool)); 50 std::string,
51 bool));
51 }; 52 };
52 53
53 class FlipHttpSMTest : public ::testing::Test { 54 class FlipHttpSMTest : public ::testing::Test {
54 public: 55 public:
55 explicit FlipHttpSMTest(FlipHandlerType type = FLIP_HANDLER_PROXY) { 56 explicit FlipHttpSMTest(FlipHandlerType type = FLIP_HANDLER_PROXY) {
56 SSLState* ssl_state = NULL; 57 SSLState* ssl_state = NULL;
57 mock_another_interface_.reset(new MockSMInterface); 58 mock_another_interface_.reset(new MockSMInterface);
58 memory_cache_.reset(new MemoryCache); 59 memory_cache_.reset(new MemoryCache);
59 acceptor_.reset(new FlipAcceptor(type, 60 acceptor_.reset(new FlipAcceptor(type,
60 "127.0.0.1", 61 "127.0.0.1",
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 interface_->ResetForNewConnection(); 161 interface_->ResetForNewConnection();
161 } 162 }
162 163
163 TEST_F(FlipHttpSMTest, InitSMConnection) { 164 TEST_F(FlipHttpSMTest, InitSMConnection) {
164 EXPECT_CALL(*connection_, InitSMConnection(_, _, _, _, _, _, _, _)); 165 EXPECT_CALL(*connection_, InitSMConnection(_, _, _, _, _, _, _, _));
165 166
166 interface_->InitSMConnection(NULL, NULL, NULL, 0, "", "", "", false); 167 interface_->InitSMConnection(NULL, NULL, NULL, 0, "", "", "", false);
167 } 168 }
168 169
169 TEST_F(FlipHttpSMTest, ProcessReadInput) { 170 TEST_F(FlipHttpSMTest, ProcessReadInput) {
170 std::string data = "HTTP/1.1 200 OK\r\n" 171 std::string data =
172 "HTTP/1.1 200 OK\r\n"
171 "Content-Length: 14\r\n\r\n" 173 "Content-Length: 14\r\n\r\n"
172 "hello, world\r\n"; 174 "hello, world\r\n";
173 testing::MockFunction<void(int)> checkpoint; 175 testing::MockFunction<void(int)> checkpoint; // NOLINT
174 { 176 {
175 InSequence s; 177 InSequence s;
176 EXPECT_CALL(*mock_another_interface_, SendSynReply(_, _)); 178 EXPECT_CALL(*mock_another_interface_, SendSynReply(_, _));
177 EXPECT_CALL(checkpoint, Call(0)); 179 EXPECT_CALL(checkpoint, Call(0));
178 EXPECT_CALL(*mock_another_interface_, SendDataFrame(_, _, _, _, _)); 180 EXPECT_CALL(*mock_another_interface_, SendDataFrame(_, _, _, _, _));
179 EXPECT_CALL(*mock_another_interface_, SendEOF(_)); 181 EXPECT_CALL(*mock_another_interface_, SendEOF(_));
180 } 182 }
181 183
182 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE, 184 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE,
183 interface_->spdy_framer()->ParseState()); 185 interface_->spdy_framer()->ParseState());
(...skipping 14 matching lines...) Expand all
198 200
199 ASSERT_EQ(1u, connection_->output_list()->size()); 201 ASSERT_EQ(1u, connection_->output_list()->size());
200 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); 202 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin();
201 DataFrame* df = *i++; 203 DataFrame* df = *i++;
202 ASSERT_EQ(data, StringPiece(df->data, df->size)); 204 ASSERT_EQ(data, StringPiece(df->data, df->size));
203 ASSERT_EQ(connection_->output_list()->end(), i); 205 ASSERT_EQ(connection_->output_list()->end(), i);
204 } 206 }
205 207
206 TEST_F(FlipHttpSMTest, Reset) { 208 TEST_F(FlipHttpSMTest, Reset) {
207 std::string data = "HTTP/1.1 200 OK\r\n\r\n"; 209 std::string data = "HTTP/1.1 200 OK\r\n\r\n";
208 testing::MockFunction<void(int)> checkpoint; 210 testing::MockFunction<void(int)> checkpoint; // NOLINT
209 { 211 {
210 InSequence s; 212 InSequence s;
211 EXPECT_CALL(*mock_another_interface_, SendSynReply(_, _)); 213 EXPECT_CALL(*mock_another_interface_, SendSynReply(_, _));
212 EXPECT_CALL(checkpoint, Call(0)); 214 EXPECT_CALL(checkpoint, Call(0));
213 } 215 }
214 216
215 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE, 217 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE,
216 interface_->spdy_framer()->ParseState()); 218 interface_->spdy_framer()->ParseState());
217 219
218 interface_->ProcessReadInput(data.data(), data.size()); 220 interface_->ProcessReadInput(data.data(), data.size());
219 checkpoint.Call(0); 221 checkpoint.Call(0);
220 ASSERT_FALSE(interface_->MessageFullyRead()); 222 ASSERT_FALSE(interface_->MessageFullyRead());
221 ASSERT_EQ(BalsaFrameEnums::READING_UNTIL_CLOSE, 223 ASSERT_EQ(BalsaFrameEnums::READING_UNTIL_CLOSE,
222 interface_->spdy_framer()->ParseState()); 224 interface_->spdy_framer()->ParseState());
223 225
224 interface_->Reset(); 226 interface_->Reset();
225 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE, 227 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE,
226 interface_->spdy_framer()->ParseState()); 228 interface_->spdy_framer()->ParseState());
227 } 229 }
228 230
229 TEST_F(FlipHttpSMTest, ResetForNewConnection) { 231 TEST_F(FlipHttpSMTest, ResetForNewConnection) {
230 std::string data = "HTTP/1.1 200 OK\r\n\r\n"; 232 std::string data = "HTTP/1.1 200 OK\r\n\r\n";
231 testing::MockFunction<void(int)> checkpoint; 233 testing::MockFunction<void(int)> checkpoint; // NOLINT
232 { 234 {
233 InSequence s; 235 InSequence s;
234 EXPECT_CALL(*mock_another_interface_, SendSynReply(_, _)); 236 EXPECT_CALL(*mock_another_interface_, SendSynReply(_, _));
235 EXPECT_CALL(checkpoint, Call(0)); 237 EXPECT_CALL(checkpoint, Call(0));
236 EXPECT_CALL(*mock_another_interface_, SendEOF(_)); 238 EXPECT_CALL(*mock_another_interface_, SendEOF(_));
237 EXPECT_CALL(*mock_another_interface_, ResetForNewInterface(_)); 239 EXPECT_CALL(*mock_another_interface_, ResetForNewInterface(_));
238 } 240 }
239 241
240 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE, 242 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE,
241 interface_->spdy_framer()->ParseState()); 243 interface_->spdy_framer()->ParseState());
(...skipping 15 matching lines...) Expand all
257 BalsaHeaders headers; 259 BalsaHeaders headers;
258 std::string filename = "foobar"; 260 std::string filename = "foobar";
259 memory_cache_->InsertFile(&headers, filename, ""); 261 memory_cache_->InsertFile(&headers, filename, "");
260 } 262 }
261 263
262 interface_->NewStream(stream_id, 1, "foobar"); 264 interface_->NewStream(stream_id, 1, "foobar");
263 ASSERT_TRUE(HasStream(stream_id)); 265 ASSERT_TRUE(HasStream(stream_id));
264 } 266 }
265 267
266 TEST_F(FlipHttpSMTest, NewStreamError) { 268 TEST_F(FlipHttpSMTest, NewStreamError) {
267 std::string syn_reply = "HTTP/1.1 404 Not Found\r\n" 269 std::string syn_reply =
270 "HTTP/1.1 404 Not Found\r\n"
268 "transfer-encoding: chunked\r\n\r\n"; 271 "transfer-encoding: chunked\r\n\r\n";
269 std::string body = "e\r\npage not found\r\n"; 272 std::string body = "e\r\npage not found\r\n";
270 uint32 stream_id = 4; 273 uint32 stream_id = 4;
271 274
272 ASSERT_FALSE(HasStream(stream_id)); 275 ASSERT_FALSE(HasStream(stream_id));
273 interface_->NewStream(stream_id, 1, "foobar"); 276 interface_->NewStream(stream_id, 1, "foobar");
274 277
275 ASSERT_EQ(3u, connection_->output_list()->size()); 278 ASSERT_EQ(3u, connection_->output_list()->size());
276 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); 279 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin();
277 DataFrame* df = *i++; 280 DataFrame* df = *i++;
278 ASSERT_EQ(syn_reply, StringPiece(df->data, df->size)); 281 ASSERT_EQ(syn_reply, StringPiece(df->data, df->size));
279 df = *i++; 282 df = *i++;
280 ASSERT_EQ(body, StringPiece(df->data, df->size)); 283 ASSERT_EQ(body, StringPiece(df->data, df->size));
281 df = *i++; 284 df = *i++;
282 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));
283 ASSERT_FALSE(HasStream(stream_id)); 286 ASSERT_FALSE(HasStream(stream_id));
284 } 287 }
285 288
286 TEST_F(FlipHttpSMTest, SendErrorNotFound) { 289 TEST_F(FlipHttpSMTest, SendErrorNotFound) {
287 std::string syn_reply = "HTTP/1.1 404 Not Found\r\n" 290 std::string syn_reply =
291 "HTTP/1.1 404 Not Found\r\n"
288 "transfer-encoding: chunked\r\n\r\n"; 292 "transfer-encoding: chunked\r\n\r\n";
289 std::string body = "e\r\npage not found\r\n"; 293 std::string body = "e\r\npage not found\r\n";
290 uint32 stream_id = 13; 294 uint32 stream_id = 13;
291 MemCacheIter mci; 295 MemCacheIter mci;
292 mci.stream_id = stream_id; 296 mci.stream_id = stream_id;
293 297
294 { 298 {
295 BalsaHeaders headers; 299 BalsaHeaders headers;
296 std::string filename = "foobar"; 300 std::string filename = "foobar";
297 memory_cache_->InsertFile(&headers, filename, ""); 301 memory_cache_->InsertFile(&headers, filename, "");
298 mci.file_data = memory_cache_->GetFileData(filename); 302 mci.file_data = memory_cache_->GetFileData(filename);
299 } 303 }
300 304
301 interface_->AddToOutputOrder(mci); 305 interface_->AddToOutputOrder(mci);
302 ASSERT_TRUE(HasStream(stream_id)); 306 ASSERT_TRUE(HasStream(stream_id));
303 interface_->SendErrorNotFound(stream_id); 307 interface_->SendErrorNotFound(stream_id);
304 308
305 ASSERT_EQ(3u, connection_->output_list()->size()); 309 ASSERT_EQ(3u, connection_->output_list()->size());
306 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); 310 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin();
307 DataFrame* df = *i++; 311 DataFrame* df = *i++;
308 ASSERT_EQ(syn_reply, StringPiece(df->data, df->size)); 312 ASSERT_EQ(syn_reply, StringPiece(df->data, df->size));
309 df = *i++; 313 df = *i++;
310 ASSERT_EQ(body, StringPiece(df->data, df->size)); 314 ASSERT_EQ(body, StringPiece(df->data, df->size));
311 df = *i++; 315 df = *i++;
312 ASSERT_EQ("0\r\n\r\n", StringPiece(df->data, df->size)); 316 ASSERT_EQ("0\r\n\r\n", StringPiece(df->data, df->size));
313 ASSERT_FALSE(HasStream(stream_id)); 317 ASSERT_FALSE(HasStream(stream_id));
314 } 318 }
315 319
316 TEST_F(FlipHttpSMTest, SendSynStream) { 320 TEST_F(FlipHttpSMTest, SendSynStream) {
317 std::string expected = "GET / HTTP/1.0\r\n" 321 std::string expected =
322 "GET / HTTP/1.0\r\n"
318 "key1: value1\r\n\r\n"; 323 "key1: value1\r\n\r\n";
319 BalsaHeaders headers; 324 BalsaHeaders headers;
320 headers.SetResponseFirstlineFromStringPieces("GET", "/path", "HTTP/1.0"); 325 headers.SetResponseFirstlineFromStringPieces("GET", "/path", "HTTP/1.0");
321 headers.AppendHeader("key1", "value1"); 326 headers.AppendHeader("key1", "value1");
322 interface_->SendSynStream(18, headers); 327 interface_->SendSynStream(18, headers);
323 328
324 // TODO(yhirano): Is this behavior correct? 329 // TODO(yhirano): Is this behavior correct?
325 ASSERT_EQ(0u, connection_->output_list()->size()); 330 ASSERT_EQ(0u, connection_->output_list()->size());
326 } 331 }
327 332
328 TEST_F(FlipHttpSMTest, SendSynReply) { 333 TEST_F(FlipHttpSMTest, SendSynReply) {
329 std::string expected = "HTTP/1.1 200 OK\r\n" 334 std::string expected =
335 "HTTP/1.1 200 OK\r\n"
330 "key1: value1\r\n\r\n"; 336 "key1: value1\r\n\r\n";
331 BalsaHeaders headers; 337 BalsaHeaders headers;
332 headers.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "OK"); 338 headers.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "OK");
333 headers.AppendHeader("key1", "value1"); 339 headers.AppendHeader("key1", "value1");
334 interface_->SendSynReply(18, headers); 340 interface_->SendSynReply(18, headers);
335 341
336 ASSERT_EQ(1u, connection_->output_list()->size()); 342 ASSERT_EQ(1u, connection_->output_list()->size());
337 DataFrame* df = connection_->output_list()->front(); 343 DataFrame* df = connection_->output_list()->front();
338 ASSERT_EQ(expected, StringPiece(df->data, df->size)); 344 ASSERT_EQ(expected, StringPiece(df->data, df->size));
339 } 345 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 TEST_F(FlipHttpSMHttpTest, ProcessHeaders) { 408 TEST_F(FlipHttpSMHttpTest, ProcessHeaders) {
403 BalsaVisitorInterface* visitor = interface_.get(); 409 BalsaVisitorInterface* visitor = interface_.get();
404 { 410 {
405 BalsaHeaders headers; 411 BalsaHeaders headers;
406 std::string filename = "GET_/path/file"; 412 std::string filename = "GET_/path/file";
407 memory_cache_->InsertFile(&headers, filename, ""); 413 memory_cache_->InsertFile(&headers, filename, "");
408 } 414 }
409 415
410 BalsaHeaders headers; 416 BalsaHeaders headers;
411 headers.AppendHeader("Host", "example.com"); 417 headers.AppendHeader("Host", "example.com");
412 headers.SetRequestFirstlineFromStringPieces("GET", 418 headers.SetRequestFirstlineFromStringPieces("GET", "/path/file", "HTTP/1.0");
413 "/path/file",
414 "HTTP/1.0");
415 uint32 stream_id = 133; 419 uint32 stream_id = 133;
416 interface_->SetStreamID(stream_id); 420 interface_->SetStreamID(stream_id);
417 ASSERT_FALSE(HasStream(stream_id)); 421 ASSERT_FALSE(HasStream(stream_id));
418 visitor->ProcessHeaders(headers); 422 visitor->ProcessHeaders(headers);
419 ASSERT_TRUE(HasStream(stream_id)); 423 ASSERT_TRUE(HasStream(stream_id));
420 } 424 }
421 425
422 TEST_F(FlipHttpSMHttpTest, MessageDone) { 426 TEST_F(FlipHttpSMHttpTest, MessageDone) {
423 BalsaVisitorInterface* visitor = interface_.get(); 427 BalsaVisitorInterface* visitor = interface_.get();
424 { 428 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 482 }
479 interface_->SendEOF(32); 483 interface_->SendEOF(32);
480 ASSERT_EQ(1u, connection_->output_list()->size()); 484 ASSERT_EQ(1u, connection_->output_list()->size());
481 DataFrame* df = connection_->output_list()->front(); 485 DataFrame* df = connection_->output_list()->front();
482 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));
483 } 487 }
484 488
485 } // namespace 489 } // namespace
486 490
487 } // namespace net 491 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/flip_server/http_interface.cc ('k') | net/tools/flip_server/http_message_constants.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698