| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(), 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); | 64 m_client->didFail(m_loader, m_error, m_totalEncodedDataLength); |
| 65 } else { | 65 } else { |
| 66 // TODO(esprehn): Is claiming a request time of 0 okay for tests? | 66 // TODO(esprehn): Is claiming a request time of 0 okay for tests? |
| 67 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength); | 67 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength); |
| 68 } | 68 } |
| 69 reset(); | 69 reset(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void SimRequest::complete(const String& data) { | 72 void SimRequest::complete(const String& data) { |
| 73 start(); | 73 start(); |
| 74 if (!data.isEmpty()) | 74 if (!data.isEmpty()) |
| 75 write(data); | 75 write(data); |
| 76 finish(); | 76 finish(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SimRequest::reset() { | 79 void SimRequest::reset() { |
| 80 m_isReady = false; | 80 m_isReady = false; |
| 81 m_client = nullptr; | 81 m_client = nullptr; |
| 82 m_loader = nullptr; | 82 m_loader = nullptr; |
| 83 SimNetwork::current().removeRequest(*this); | 83 SimNetwork::current().removeRequest(*this); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace blink | 86 } // namespace blink |
| OLD | NEW |