Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 | 64 |
| 65 // TestDispatcher implementation: | 65 // TestDispatcher implementation: |
| 66 | 66 |
| 67 int StartAsync(const RequestInfo& request_info, | 67 int StartAsync(const RequestInfo& request_info, |
| 68 ResourceRequestBody* request_body, | 68 ResourceRequestBody* request_body, |
| 69 scoped_ptr<RequestPeer> peer) override { | 69 scoped_ptr<RequestPeer> peer) override { |
| 70 EXPECT_FALSE(peer_); | 70 EXPECT_FALSE(peer_); |
| 71 peer_ = std::move(peer); | 71 peer_ = std::move(peer); |
| 72 url_ = request_info.url; | 72 url_ = request_info.url; |
| 73 stream_url_ = request_info.resource_body_stream_url; | 73 stream_url_ = request_info.resource_body_stream_url; |
| 74 empty_body_in_service_worker_ = request_info.empty_body_in_service_worker; | |
| 74 return 1; | 75 return 1; |
| 75 } | 76 } |
| 76 | 77 |
| 77 void Cancel(int request_id) override { | 78 void Cancel(int request_id) override { |
| 78 EXPECT_FALSE(canceled_); | 79 EXPECT_FALSE(canceled_); |
| 79 canceled_ = true; | 80 canceled_ = true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 RequestPeer* peer() { return peer_.get(); } | 83 RequestPeer* peer() { return peer_.get(); } |
| 83 | 84 |
| 84 bool canceled() { return canceled_; } | 85 bool canceled() { return canceled_; } |
| 85 | 86 |
| 86 const GURL& url() { return url_; } | 87 const GURL& url() { return url_; } |
| 87 const GURL& stream_url() { return stream_url_; } | 88 const GURL& stream_url() { return stream_url_; } |
| 89 bool empty_body_in_service_worker() const { | |
| 90 return empty_body_in_service_worker_; | |
| 91 } | |
| 88 | 92 |
| 89 private: | 93 private: |
| 90 scoped_ptr<RequestPeer> peer_; | 94 scoped_ptr<RequestPeer> peer_; |
| 91 bool canceled_; | 95 bool canceled_; |
| 92 GURL url_; | 96 GURL url_; |
| 93 GURL stream_url_; | 97 GURL stream_url_; |
| 98 bool empty_body_in_service_worker_; | |
| 94 | 99 |
| 95 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher); | 100 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher); |
| 96 }; | 101 }; |
| 97 | 102 |
| 98 class TestWebURLLoaderClient : public blink::WebURLLoaderClient { | 103 class TestWebURLLoaderClient : public blink::WebURLLoaderClient { |
| 99 public: | 104 public: |
| 100 TestWebURLLoaderClient(ResourceDispatcher* dispatcher, | 105 TestWebURLLoaderClient(ResourceDispatcher* dispatcher, |
| 101 scoped_refptr<scheduler::TaskQueue> task_runner) | 106 scoped_refptr<scheduler::TaskQueue> task_runner) |
| 102 : loader_(new WebURLLoaderImpl( | 107 : loader_(new WebURLLoaderImpl( |
| 103 dispatcher, | 108 dispatcher, |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 // The response info should have been overriden. | 596 // The response info should have been overriden. |
| 592 ASSERT_FALSE(client()->response().isNull()); | 597 ASSERT_FALSE(client()->response().isNull()); |
| 593 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); | 598 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); |
| 594 | 599 |
| 595 DoReceiveData(); | 600 DoReceiveData(); |
| 596 DoCompleteRequest(); | 601 DoCompleteRequest(); |
| 597 EXPECT_FALSE(dispatcher()->canceled()); | 602 EXPECT_FALSE(dispatcher()->canceled()); |
| 598 EXPECT_EQ(kTestData, client()->received_data()); | 603 EXPECT_EQ(kTestData, client()->received_data()); |
| 599 } | 604 } |
| 600 | 605 |
| 606 TEST_F(WebURLLoaderImplTest, EmptyBodyInServiceWorkerNoCredential) { | |
| 607 // Initialize the request and kick off the load | |
| 608 blink::WebURLRequest request; | |
| 609 request.initialize(); | |
| 610 request.setURL(GURL(kTestURL)); | |
| 611 request.setHTTPMethod("POST"); | |
| 612 client()->loader()->loadAsynchronously(request, client()); | |
| 613 | |
| 614 // No credential body, so the body can be given to the service worker. | |
| 615 EXPECT_FALSE(dispatcher()->empty_body_in_service_worker()); | |
| 616 } | |
| 617 | |
| 618 TEST_F(WebURLLoaderImplTest, EmptyBodyInServiceWorkerWithCredential) { | |
| 619 // Initialize the request and kick off the load | |
| 620 blink::WebURLRequest request; | |
| 621 request.initialize(); | |
| 622 request.setHTTPMethod("POST"); | |
| 623 request.setURL(GURL(kTestURL)); | |
|
tyoshino (SeeGerritForStatus)
2016/04/12 16:30:25
order these two lines the same as EmptyBodyInServi
| |
| 624 | |
| 625 blink::WebHTTPBody body; | |
| 626 body.initialize(); | |
| 627 request.setAttachedCredentialBody(body); | |
| 628 client()->loader()->loadAsynchronously(request, client()); | |
| 629 | |
| 630 // No credential body, so the body can be given to the service worker. | |
| 631 EXPECT_TRUE(dispatcher()->empty_body_in_service_worker()); | |
| 632 } | |
| 633 | |
| 601 TEST_F(WebURLLoaderImplTest, ResponseIPAddress) { | 634 TEST_F(WebURLLoaderImplTest, ResponseIPAddress) { |
| 602 GURL url("http://example.test/"); | 635 GURL url("http://example.test/"); |
| 603 | 636 |
| 604 struct TestCase { | 637 struct TestCase { |
| 605 const char* ip; | 638 const char* ip; |
| 606 const char* expected; | 639 const char* expected; |
| 607 } cases[] = { | 640 } cases[] = { |
| 608 {"127.0.0.1", "127.0.0.1"}, | 641 {"127.0.0.1", "127.0.0.1"}, |
| 609 {"123.123.123.123", "123.123.123.123"}, | 642 {"123.123.123.123", "123.123.123.123"}, |
| 610 {"::1", "[::1]"}, | 643 {"::1", "[::1]"}, |
| 611 {"2001:0db8:85a3:0000:0000:8a2e:0370:7334", | 644 {"2001:0db8:85a3:0000:0000:8a2e:0370:7334", |
| 612 "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"}, | 645 "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"}, |
| 613 {"2001:db8:85a3:0:0:8a2e:370:7334", "[2001:db8:85a3:0:0:8a2e:370:7334]"}, | 646 {"2001:db8:85a3:0:0:8a2e:370:7334", "[2001:db8:85a3:0:0:8a2e:370:7334]"}, |
| 614 {"2001:db8:85a3::8a2e:370:7334", "[2001:db8:85a3::8a2e:370:7334]"}, | 647 {"2001:db8:85a3::8a2e:370:7334", "[2001:db8:85a3::8a2e:370:7334]"}, |
| 615 {"::ffff:192.0.2.128", "[::ffff:192.0.2.128]"}}; | 648 {"::ffff:192.0.2.128", "[::ffff:192.0.2.128]"}}; |
| 616 | 649 |
| 617 for (const auto& test : cases) { | 650 for (const auto& test : cases) { |
| 618 SCOPED_TRACE(test.ip); | 651 SCOPED_TRACE(test.ip); |
| 619 content::ResourceResponseInfo info; | 652 content::ResourceResponseInfo info; |
| 620 info.socket_address = net::HostPortPair(test.ip, 443); | 653 info.socket_address = net::HostPortPair(test.ip, 443); |
| 621 blink::WebURLResponse response; | 654 blink::WebURLResponse response; |
| 622 response.initialize(); | 655 response.initialize(); |
| 623 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); | 656 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); |
| 624 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); | 657 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); |
| 625 }; | 658 }; |
| 626 } | 659 } |
| 627 | 660 |
| 628 } // namespace | 661 } // namespace |
| 629 } // namespace content | 662 } // namespace content |
| OLD | NEW |