| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "web/tests/sim/SimRequest.h" | 5 #include "web/tests/sim/SimRequest.h" |
| 6 | 6 |
| 7 #include "platform/weborigin/KURL.h" | 7 #include "platform/weborigin/KURL.h" |
| 8 #include "public/platform/Platform.h" | 8 #include "public/platform/Platform.h" |
| 9 #include "public/platform/WebURLLoaderClient.h" | 9 #include "public/platform/WebURLLoaderClient.h" |
| 10 #include "public/platform/WebURLLoaderMockFactory.h" | 10 #include "public/platform/WebURLLoaderMockFactory.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 SimNetwork::current().servePendingRequests(); | 48 SimNetwork::current().servePendingRequests(); |
| 49 DCHECK(m_isReady); | 49 DCHECK(m_isReady); |
| 50 m_client->didReceiveResponse(m_loader, m_response); | 50 m_client->didReceiveResponse(m_loader, m_response); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void SimRequest::write(const String& data) { | 53 void SimRequest::write(const String& data) { |
| 54 DCHECK(m_isReady); | 54 DCHECK(m_isReady); |
| 55 DCHECK(!m_error.reason); | 55 DCHECK(!m_error.reason); |
| 56 m_totalEncodedDataLength += data.length(); | 56 m_totalEncodedDataLength += data.length(); |
| 57 m_client->didReceiveData(m_loader, data.utf8().data(), data.length(), | 57 m_client->didReceiveData(m_loader, data.utf8().data(), data.length(), |
| 58 data.length(), data.length()); | 58 data.length()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SimRequest::finish() { | 61 void SimRequest::finish() { |
| 62 DCHECK(m_isReady); | 62 DCHECK(m_isReady); |
| 63 if (m_error.reason) { | 63 if (m_error.reason) { |
| 64 m_client->didFail(m_loader, m_error, m_totalEncodedDataLength); | 64 m_client->didFail(m_loader, m_error, m_totalEncodedDataLength, |
| 65 m_totalEncodedDataLength); |
| 65 } else { | 66 } else { |
| 66 // TODO(esprehn): Is claiming a request time of 0 okay for tests? | 67 // TODO(esprehn): Is claiming a request time of 0 okay for tests? |
| 67 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength); | 68 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength, |
| 69 m_totalEncodedDataLength); |
| 68 } | 70 } |
| 69 reset(); | 71 reset(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void SimRequest::complete(const String& data) { | 74 void SimRequest::complete(const String& data) { |
| 73 start(); | 75 start(); |
| 74 if (!data.isEmpty()) | 76 if (!data.isEmpty()) |
| 75 write(data); | 77 write(data); |
| 76 finish(); | 78 finish(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void SimRequest::reset() { | 81 void SimRequest::reset() { |
| 80 m_isReady = false; | 82 m_isReady = false; |
| 81 m_client = nullptr; | 83 m_client = nullptr; |
| 82 m_loader = nullptr; | 84 m_loader = nullptr; |
| 83 SimNetwork::current().removeRequest(*this); | 85 SimNetwork::current().removeRequest(*this); |
| 84 } | 86 } |
| 85 | 87 |
| 86 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |