| 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> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/time/default_tick_clock.h" | 17 #include "base/time/default_tick_clock.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "components/scheduler/child/scheduler_tqm_delegate_impl.h" | 19 #include "components/scheduler/child/scheduler_tqm_delegate_impl.h" |
| 20 #include "components/scheduler/child/web_task_runner_impl.h" | 20 #include "components/scheduler/child/web_task_runner_impl.h" |
| 21 #include "components/scheduler/child/worker_scheduler.h" | 21 #include "components/scheduler/child/worker_scheduler.h" |
| 22 #include "content/child/request_extra_data.h" | 22 #include "content/child/request_extra_data.h" |
| 23 #include "content/child/request_info.h" | 23 #include "content/child/request_info.h" |
| 24 #include "content/child/resource_dispatcher.h" | 24 #include "content/child/resource_dispatcher.h" |
| 25 #include "content/public/child/fixed_received_data.h" | 25 #include "content/public/child/fixed_received_data.h" |
| 26 #include "content/public/child/request_peer.h" | 26 #include "content/public/child/request_peer.h" |
| 27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 28 #include "content/public/common/resource_response_info.h" | 28 #include "content/public/common/resource_response_info.h" |
| 29 #include "net/base/host_port_pair.h" |
| 29 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 30 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 31 #include "net/http/http_util.h" | 32 #include "net/http/http_util.h" |
| 32 #include "net/url_request/redirect_info.h" | 33 #include "net/url_request/redirect_info.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/WebKit/public/platform/WebString.h" | 35 #include "third_party/WebKit/public/platform/WebString.h" |
| 35 #include "third_party/WebKit/public/platform/WebURLError.h" | 36 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 36 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 37 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 38 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 38 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 39 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 // The response info should have been overriden. | 704 // The response info should have been overriden. |
| 704 ASSERT_FALSE(client()->response().isNull()); | 705 ASSERT_FALSE(client()->response().isNull()); |
| 705 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); | 706 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); |
| 706 | 707 |
| 707 DoReceiveData(); | 708 DoReceiveData(); |
| 708 DoCompleteRequest(); | 709 DoCompleteRequest(); |
| 709 EXPECT_FALSE(dispatcher()->canceled()); | 710 EXPECT_FALSE(dispatcher()->canceled()); |
| 710 EXPECT_EQ(kTestData, client()->received_data()); | 711 EXPECT_EQ(kTestData, client()->received_data()); |
| 711 } | 712 } |
| 712 | 713 |
| 714 TEST_F(WebURLLoaderImplTest, ResponseIPAddress) { |
| 715 GURL url("http://example.test/"); |
| 716 |
| 717 struct TestCase { |
| 718 const char* ip; |
| 719 const char* expected; |
| 720 } cases[] = { |
| 721 {"127.0.0.1", "127.0.0.1"}, |
| 722 {"123.123.123.123", "123.123.123.123"}, |
| 723 {"::1", "[::1]"}, |
| 724 {"2001:0db8:85a3:0000:0000:8a2e:0370:7334", |
| 725 "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"}, |
| 726 {"2001:db8:85a3:0:0:8a2e:370:7334", "[2001:db8:85a3:0:0:8a2e:370:7334]"}, |
| 727 {"2001:db8:85a3::8a2e:370:7334", "[2001:db8:85a3::8a2e:370:7334]"}, |
| 728 {"::ffff:192.0.2.128", "[::ffff:192.0.2.128]"}}; |
| 729 |
| 730 for (const auto& test : cases) { |
| 731 SCOPED_TRACE(test.ip); |
| 732 content::ResourceResponseInfo info; |
| 733 info.socket_address = net::HostPortPair(test.ip, 443); |
| 734 blink::WebURLResponse response; |
| 735 response.initialize(); |
| 736 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); |
| 737 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); |
| 738 }; |
| 739 } |
| 740 |
| 713 } // namespace | 741 } // namespace |
| 714 } // namespace content | 742 } // namespace content |
| OLD | NEW |