| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fetch/MultipartImageResourceParser.h" | 5 #include "core/fetch/MultipartImageResourceParser.h" |
| 6 | 6 |
| 7 #include "platform/network/ResourceResponse.h" | 7 #include "platform/network/ResourceResponse.h" |
| 8 #include "public/platform/Platform.h" | 8 #include "public/platform/Platform.h" |
| 9 #include "public/platform/WebURL.h" | 9 #include "public/platform/WebURL.h" |
| 10 #include "public/platform/WebURLResponse.h" | 10 #include "public/platform/WebURLResponse.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 { | 22 { |
| 23 if (data.isEmpty()) | 23 if (data.isEmpty()) |
| 24 return String(""); | 24 return String(""); |
| 25 return String(data.data(), data.size()); | 25 return String(data.data(), data.size()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 class MockClient final : public NoBaseWillBeGarbageCollectedFinalized<MockClient
>, public MultipartImageResourceParser::Client { | 28 class MockClient final : public NoBaseWillBeGarbageCollectedFinalized<MockClient
>, public MultipartImageResourceParser::Client { |
| 29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockClient); | 29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockClient); |
| 30 | 30 |
| 31 public: | 31 public: |
| 32 void onePartInMultipartReceived(const ResourceResponse& response, bool isFir
stPart) override | 32 void onePartInMultipartReceived(const ResourceResponse& response) override |
| 33 { | 33 { |
| 34 if (isFirstPart != m_responses.isEmpty()) | |
| 35 FAIL() << "m_responses.size() = " << m_responses.size() << ", isFirs
tPart = " << isFirstPart; | |
| 36 | |
| 37 m_responses.append(response); | 34 m_responses.append(response); |
| 38 m_data.append(Vector<char>()); | 35 m_data.append(Vector<char>()); |
| 39 } | 36 } |
| 40 void multipartDataReceived(const char* bytes, size_t size) override | 37 void multipartDataReceived(const char* bytes, size_t size) override |
| 41 { | 38 { |
| 42 m_data.last().append(bytes, size); | 39 m_data.last().append(bytes, size); |
| 43 } | 40 } |
| 44 | 41 |
| 45 Vector<ResourceResponse> m_responses; | 42 Vector<ResourceResponse> m_responses; |
| 46 Vector<Vector<char>> m_data; | 43 Vector<Vector<char>> m_data; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 MultipartImageResourceParser* parser = new MultipartImageResourceParser(resp
onse, boundary, client); | 435 MultipartImageResourceParser* parser = new MultipartImageResourceParser(resp
onse, boundary, client); |
| 439 | 436 |
| 440 const char data[] = "--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"; | 437 const char data[] = "--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"; |
| 441 parser->appendData(data, strlen(data)); | 438 parser->appendData(data, strlen(data)); |
| 442 ASSERT_EQ(2u, client->m_responses.size()); | 439 ASSERT_EQ(2u, client->m_responses.size()); |
| 443 ASSERT_EQ(2u, client->m_data.size()); | 440 ASSERT_EQ(2u, client->m_data.size()); |
| 444 EXPECT_EQ("", toString(client->m_data[0])); | 441 EXPECT_EQ("", toString(client->m_data[0])); |
| 445 EXPECT_EQ("foofoo", toString(client->m_data[1])); | 442 EXPECT_EQ("foofoo", toString(client->m_data[1])); |
| 446 } | 443 } |
| 447 | 444 |
| 448 TEST(MultipartResponseTest, IsFirstPartSet) | |
| 449 { | |
| 450 ResourceResponse response; | |
| 451 response.setMimeType("multipart/x-mixed-replace"); | |
| 452 MockClient* client = new MockClient; | |
| 453 Vector<char> boundary; | |
| 454 boundary.append("bound", 5); | |
| 455 | |
| 456 MultipartImageResourceParser* parser = new MultipartImageResourceParser(resp
onse, boundary, client); | |
| 457 | |
| 458 // isFirstPart is checked at MockClient::didReceiveResponse. | |
| 459 const char data[] = | |
| 460 "--bound\n" | |
| 461 "Content-type: text/plain\n\n" | |
| 462 "response data\n" | |
| 463 "--bound\n"; | |
| 464 parser->appendData(data, strlen(data)); | |
| 465 ASSERT_EQ(1u, client->m_responses.size()); | |
| 466 ASSERT_EQ(1u, client->m_data.size()); | |
| 467 EXPECT_EQ("response data", toString(client->m_data[0])); | |
| 468 | |
| 469 const char data2[] = | |
| 470 "Content-type: text/plain\n\n" | |
| 471 "response data2\n" | |
| 472 "--bound\n"; | |
| 473 parser->appendData(data2, strlen(data2)); | |
| 474 ASSERT_EQ(2u, client->m_responses.size()); | |
| 475 ASSERT_EQ(2u, client->m_data.size()); | |
| 476 EXPECT_EQ("response data2", toString(client->m_data[1])); | |
| 477 } | |
| 478 | |
| 479 } // namespace | 445 } // namespace |
| 480 | 446 |
| 481 } // namespace blink | 447 } // namespace blink |
| OLD | NEW |