OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader
Client.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader
Client.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
12 #include "webkit/glue/multipart_response_delegate.h" | 12 #include "webkit/glue/multipart_response_delegate.h" |
| 13 #include "webkit/glue/weburlresponse_extradata_impl.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using std::string; | 16 using std::string; |
16 using WebKit::WebString; | 17 using WebKit::WebString; |
17 using WebKit::WebURL; | 18 using WebKit::WebURL; |
18 using WebKit::WebURLError; | 19 using WebKit::WebURLError; |
19 using WebKit::WebURLLoader; | 20 using WebKit::WebURLLoader; |
20 using WebKit::WebURLLoaderClient; | 21 using WebKit::WebURLLoaderClient; |
21 using WebKit::WebURLRequest; | 22 using WebKit::WebURLRequest; |
22 using WebKit::WebURLResponse; | 23 using WebKit::WebURLResponse; |
23 using webkit_glue::MultipartResponseDelegate; | 24 using webkit_glue::MultipartResponseDelegate; |
24 using webkit_glue::MultipartResponseDelegateTester; | 25 using webkit_glue::MultipartResponseDelegateTester; |
| 26 using webkit_glue::WebURLResponseExtraDataImpl; |
25 | 27 |
26 namespace webkit_glue { | 28 namespace webkit_glue { |
27 | 29 |
28 class MultipartResponseDelegateTester { | 30 class MultipartResponseDelegateTester { |
29 public: | 31 public: |
30 MultipartResponseDelegateTester(MultipartResponseDelegate* delegate) | 32 MultipartResponseDelegateTester(MultipartResponseDelegate* delegate) |
31 : delegate_(delegate) { | 33 : delegate_(delegate) { |
32 } | 34 } |
33 | 35 |
34 int PushOverLine(const std::string& data, size_t pos) { | 36 int PushOverLine(const std::string& data, size_t pos) { |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 &content_range_upper_bound, | 637 &content_range_upper_bound, |
636 &content_range_instance_size); | 638 &content_range_instance_size); |
637 | 639 |
638 EXPECT_EQ(result, false); | 640 EXPECT_EQ(result, false); |
639 } | 641 } |
640 | 642 |
641 TEST(MultipartResponseTest, MultipartPayloadSet) { | 643 TEST(MultipartResponseTest, MultipartPayloadSet) { |
642 WebURLResponse response; | 644 WebURLResponse response; |
643 response.initialize(); | 645 response.initialize(); |
644 response.setMIMEType("multipart/x-mixed-replace"); | 646 response.setMIMEType("multipart/x-mixed-replace"); |
| 647 response.setExtraData(new WebURLResponseExtraDataImpl("")); |
645 MockWebURLLoaderClient client; | 648 MockWebURLLoaderClient client; |
646 MultipartResponseDelegate delegate(&client, NULL, response, "bound"); | 649 MultipartResponseDelegate delegate(&client, NULL, response, "bound"); |
647 | 650 |
648 string data( | 651 string data( |
649 "--bound\n" | 652 "--bound\n" |
650 "Content-type: text/plain\n\n" | 653 "Content-type: text/plain\n\n" |
651 "response data\n" | 654 "response data\n" |
652 "--bound\n"); | 655 "--bound\n"); |
653 delegate.OnReceivedData(data.c_str(), | 656 delegate.OnReceivedData(data.c_str(), |
654 static_cast<int>(data.length()), | 657 static_cast<int>(data.length()), |
655 static_cast<int>(data.length())); | 658 static_cast<int>(data.length())); |
656 EXPECT_EQ(1, client.received_response_); | 659 EXPECT_EQ(1, client.received_response_); |
657 EXPECT_EQ(string("response data"), client.data_); | 660 EXPECT_EQ(string("response data"), client.data_); |
658 EXPECT_EQ(static_cast<int>(data.length()), client.total_encoded_data_length_); | 661 EXPECT_EQ(static_cast<int>(data.length()), client.total_encoded_data_length_); |
659 EXPECT_FALSE(client.response_.isMultipartPayload()); | 662 WebURLResponseExtraDataImpl* extra_data = |
| 663 static_cast<WebURLResponseExtraDataImpl*>(client.response_.extraData()); |
| 664 EXPECT_FALSE(extra_data->is_multipart_payload()); |
660 | 665 |
661 string data2( | 666 string data2( |
662 "Content-type: text/plain\n\n" | 667 "Content-type: text/plain\n\n" |
663 "response data2\n" | 668 "response data2\n" |
664 "--bound\n"); | 669 "--bound\n"); |
665 delegate.OnReceivedData(data2.c_str(), | 670 delegate.OnReceivedData(data2.c_str(), |
666 static_cast<int>(data2.length()), | 671 static_cast<int>(data2.length()), |
667 static_cast<int>(data2.length())); | 672 static_cast<int>(data2.length())); |
668 EXPECT_EQ(2, client.received_response_); | 673 EXPECT_EQ(2, client.received_response_); |
669 EXPECT_EQ(string("response data2"), client.data_); | 674 EXPECT_EQ(string("response data2"), client.data_); |
670 EXPECT_EQ(static_cast<int>(data.length()) + static_cast<int>(data2.length()), | 675 EXPECT_EQ(static_cast<int>(data.length()) + static_cast<int>(data2.length()), |
671 client.total_encoded_data_length_); | 676 client.total_encoded_data_length_); |
672 EXPECT_TRUE(client.response_.isMultipartPayload()); | 677 extra_data = static_cast<WebURLResponseExtraDataImpl*>( |
| 678 client.response_.extraData()); |
| 679 EXPECT_TRUE(extra_data->is_multipart_payload()); |
673 } | 680 } |
674 | 681 |
675 } // namespace | 682 } // namespace |
OLD | NEW |