| 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 "platform/testing/weburl_loader_mock.h" | 5 #include "platform/testing/weburl_loader_mock.h" |
| 6 | 6 |
| 7 #include "platform/testing/weburl_loader_mock_factory_impl.h" | 7 #include "platform/testing/weburl_loader_mock_factory_impl.h" |
| 8 #include "public/platform/URLConversion.h" | 8 #include "public/platform/URLConversion.h" |
| 9 #include "public/platform/WebData.h" | 9 #include "public/platform/WebData.h" |
| 10 #include "public/platform/WebURLError.h" | 10 #include "public/platform/WebURLError.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 // didReceiveResponse() and didReceiveData() might end up getting ::cancel() | 43 // didReceiveResponse() and didReceiveData() might end up getting ::cancel() |
| 44 // to be called which will make the ResourceLoader to delete |this|. | 44 // to be called which will make the ResourceLoader to delete |this|. |
| 45 WeakPtr<WebURLLoaderMock> self = weak_factory_.createWeakPtr(); | 45 WeakPtr<WebURLLoaderMock> self = weak_factory_.createWeakPtr(); |
| 46 | 46 |
| 47 delegate->didReceiveResponse(client_, this, response); | 47 delegate->didReceiveResponse(client_, this, response); |
| 48 if (!self) | 48 if (!self) |
| 49 return; | 49 return; |
| 50 | 50 |
| 51 if (error.reason) { | 51 if (error.reason) { |
| 52 delegate->didFail(client_, this, error, data.size()); | 52 delegate->didFail(client_, this, error, data.size(), 0); |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 delegate->didReceiveData(client_, this, data.data(), data.size(), | 55 delegate->didReceiveData(client_, this, data.data(), data.size(), |
| 56 data.size()); | 56 data.size()); |
| 57 if (!self) | 57 if (!self) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 delegate->didFinishLoading(client_, this, 0, data.size()); | 60 delegate->didFinishLoading(client_, this, 0, data.size(), data.size()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 WebURLRequest WebURLLoaderMock::ServeRedirect( | 63 WebURLRequest WebURLLoaderMock::ServeRedirect( |
| 64 const WebURLRequest& request, | 64 const WebURLRequest& request, |
| 65 const WebURLResponse& redirectResponse) { | 65 const WebURLResponse& redirectResponse) { |
| 66 KURL redirectURL( | 66 KURL redirectURL( |
| 67 ParsedURLString, redirectResponse.httpHeaderField("Location")); | 67 ParsedURLString, redirectResponse.httpHeaderField("Location")); |
| 68 | 68 |
| 69 WebURLRequest newRequest(redirectURL); | 69 WebURLRequest newRequest(redirectURL); |
| 70 newRequest.setFirstPartyForCookies(redirectURL); | 70 newRequest.setFirstPartyForCookies(redirectURL); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 if (!follow) | 92 if (!follow) |
| 93 cancel(); | 93 cancel(); |
| 94 | 94 |
| 95 return newRequest; | 95 return newRequest; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void WebURLLoaderMock::loadSynchronously(const WebURLRequest& request, | 98 void WebURLLoaderMock::loadSynchronously(const WebURLRequest& request, |
| 99 WebURLResponse& response, | 99 WebURLResponse& response, |
| 100 WebURLError& error, | 100 WebURLError& error, |
| 101 WebData& data, | 101 WebData& data, |
| 102 int64_t& encoded_data_length) { | 102 int64_t& encoded_data_length, |
| 103 int64_t& encoded_body_length) { |
| 103 if (factory_->IsMockedURL(request.url())) { | 104 if (factory_->IsMockedURL(request.url())) { |
| 104 factory_->LoadSynchronously(request, &response, &error, &data, | 105 factory_->LoadSynchronously(request, &response, &error, &data, |
| 105 &encoded_data_length); | 106 &encoded_data_length); |
| 106 return; | 107 return; |
| 107 } | 108 } |
| 108 DCHECK(KURL(request.url()).protocolIsData()) | 109 DCHECK(KURL(request.url()).protocolIsData()) |
| 109 << "loadSynchronously shouldn't be falling back: " | 110 << "loadSynchronously shouldn't be falling back: " |
| 110 << request.url().string().utf8(); | 111 << request.url().string().utf8(); |
| 111 using_default_loader_ = true; | 112 using_default_loader_ = true; |
| 112 default_loader_->loadSynchronously(request, response, error, data, | 113 default_loader_->loadSynchronously(request, response, error, data, |
| 113 encoded_data_length); | 114 encoded_data_length, encoded_body_length); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void WebURLLoaderMock::loadAsynchronously(const WebURLRequest& request, | 117 void WebURLLoaderMock::loadAsynchronously(const WebURLRequest& request, |
| 117 WebURLLoaderClient* client) { | 118 WebURLLoaderClient* client) { |
| 118 DCHECK(client); | 119 DCHECK(client); |
| 119 if (factory_->IsMockedURL(request.url())) { | 120 if (factory_->IsMockedURL(request.url())) { |
| 120 client_ = client; | 121 client_ = client; |
| 121 factory_->LoadAsynchronouly(request, this); | 122 factory_->LoadAsynchronouly(request, this); |
| 122 return; | 123 return; |
| 123 } | 124 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods | 158 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods |
| 158 // the console during webkit unit tests, so we leave the function empty. | 159 // the console during webkit unit tests, so we leave the function empty. |
| 159 DCHECK(runner); | 160 DCHECK(runner); |
| 160 } | 161 } |
| 161 | 162 |
| 162 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { | 163 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { |
| 163 return weak_factory_.createWeakPtr(); | 164 return weak_factory_.createWeakPtr(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |