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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "content/child/resource_dispatcher.h" | 13 #include "content/child/resource_dispatcher.h" |
| 14 #include "content/child/resource_loader_bridge.h" |
14 #include "content/public/child/request_peer.h" | 15 #include "content/public/child/request_peer.h" |
15 #include "content/public/common/resource_response_info.h" | 16 #include "content/public/common/resource_response_info.h" |
16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "net/http/http_util.h" | 19 #include "net/http/http_util.h" |
19 #include "net/url_request/redirect_info.h" | 20 #include "net/url_request/redirect_info.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
22 #include "third_party/WebKit/public/platform/WebURLError.h" | 23 #include "third_party/WebKit/public/platform/WebURLError.h" |
23 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 24 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
24 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 25 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
26 #include "webkit/child/resource_loader_bridge.h" | |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 namespace { | 29 namespace { |
30 | 30 |
31 const char kTestURL[] = "http://foo"; | 31 const char kTestURL[] = "http://foo"; |
32 const char kTestData[] = "blah!"; | 32 const char kTestData[] = "blah!"; |
33 | 33 |
34 const char kFtpDirMimeType[] = "text/vnd.chromium.ftp-dir"; | 34 const char kFtpDirMimeType[] = "text/vnd.chromium.ftp-dir"; |
35 // Simple FTP directory listing. Tests are not concerned with correct parsing, | 35 // Simple FTP directory listing. Tests are not concerned with correct parsing, |
36 // but rather correct cleanup when deleted while parsing. Important details of | 36 // but rather correct cleanup when deleted while parsing. Important details of |
(...skipping 10 matching lines...) Expand all Loading... |
47 // contains multiple chunks, and that it doesn't end with a boundary, so will | 47 // contains multiple chunks, and that it doesn't end with a boundary, so will |
48 // send data in OnResponseComplete. Also, it will resolve to kTestData. | 48 // send data in OnResponseComplete. Also, it will resolve to kTestData. |
49 const char kMultipartResponse[] = | 49 const char kMultipartResponse[] = |
50 "--boundary\n" | 50 "--boundary\n" |
51 "Content-type: text/html\n\n" | 51 "Content-type: text/html\n\n" |
52 "bl" | 52 "bl" |
53 "--boundary\n" | 53 "--boundary\n" |
54 "Content-type: text/html\n\n" | 54 "Content-type: text/html\n\n" |
55 "ah!"; | 55 "ah!"; |
56 | 56 |
57 class TestBridge : public webkit_glue::ResourceLoaderBridge, | 57 class TestBridge : public ResourceLoaderBridge, |
58 public base::SupportsWeakPtr<TestBridge> { | 58 public base::SupportsWeakPtr<TestBridge> { |
59 public: | 59 public: |
60 TestBridge() : peer_(NULL), canceled_(false) {} | 60 TestBridge() : peer_(NULL), canceled_(false) {} |
61 virtual ~TestBridge() {} | 61 virtual ~TestBridge() {} |
62 | 62 |
63 // ResourceLoaderBridge implementation: | 63 // ResourceLoaderBridge implementation: |
64 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE {} | 64 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE {} |
65 | 65 |
66 virtual bool Start(RequestPeer* peer) OVERRIDE { | 66 virtual bool Start(RequestPeer* peer) OVERRIDE { |
67 EXPECT_FALSE(peer_); | 67 EXPECT_FALSE(peer_); |
(...skipping 29 matching lines...) Expand all Loading... |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(TestBridge); | 98 DISALLOW_COPY_AND_ASSIGN(TestBridge); |
99 }; | 99 }; |
100 | 100 |
101 class TestResourceDispatcher : public ResourceDispatcher { | 101 class TestResourceDispatcher : public ResourceDispatcher { |
102 public: | 102 public: |
103 TestResourceDispatcher() : ResourceDispatcher(NULL) {} | 103 TestResourceDispatcher() : ResourceDispatcher(NULL) {} |
104 virtual ~TestResourceDispatcher() {} | 104 virtual ~TestResourceDispatcher() {} |
105 | 105 |
106 // ResourceDispatcher implementation: | 106 // ResourceDispatcher implementation: |
107 virtual webkit_glue::ResourceLoaderBridge* CreateBridge( | 107 virtual ResourceLoaderBridge* CreateBridge( |
108 const RequestInfo& request_info) OVERRIDE { | 108 const RequestInfo& request_info) OVERRIDE { |
109 EXPECT_FALSE(bridge_.get()); | 109 EXPECT_FALSE(bridge_.get()); |
110 TestBridge* bridge = new TestBridge(); | 110 TestBridge* bridge = new TestBridge(); |
111 bridge_ = bridge->AsWeakPtr(); | 111 bridge_ = bridge->AsWeakPtr(); |
112 return bridge; | 112 return bridge; |
113 } | 113 } |
114 | 114 |
115 TestBridge* bridge() { return bridge_.get(); } | 115 TestBridge* bridge() { return bridge_.get(); } |
116 | 116 |
117 private: | 117 private: |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 client()->set_delete_on_fail(); | 641 client()->set_delete_on_fail(); |
642 DoStartAsyncRequest(); | 642 DoStartAsyncRequest(); |
643 DoReceiveResponseMultipart(); | 643 DoReceiveResponseMultipart(); |
644 DoReceiveDataMultipart(); | 644 DoReceiveDataMultipart(); |
645 DoFailRequest(); | 645 DoFailRequest(); |
646 EXPECT_FALSE(bridge()); | 646 EXPECT_FALSE(bridge()); |
647 } | 647 } |
648 | 648 |
649 } // namespace | 649 } // namespace |
650 } // namespace content | 650 } // namespace content |
OLD | NEW |