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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 DCHECK(is_ready_); | 51 DCHECK(is_ready_); |
52 DCHECK(!error_.reason); | 52 DCHECK(!error_.reason); |
53 total_encoded_data_length_ += data.length(); | 53 total_encoded_data_length_ += data.length(); |
54 client_->DidReceiveData(data.Utf8().data(), data.length()); | 54 client_->DidReceiveData(data.Utf8().data(), data.length()); |
55 } | 55 } |
56 | 56 |
57 void SimRequest::Finish() { | 57 void SimRequest::Finish() { |
58 DCHECK(is_ready_); | 58 DCHECK(is_ready_); |
59 if (error_.reason) { | 59 if (error_.reason) { |
60 client_->DidFail(error_, total_encoded_data_length_, | 60 client_->DidFail(error_, total_encoded_data_length_, |
61 total_encoded_data_length_); | 61 total_encoded_data_length_, total_encoded_data_length_); |
62 } else { | 62 } else { |
63 // TODO(esprehn): Is claiming a request time of 0 okay for tests? | 63 // TODO(esprehn): Is claiming a request time of 0 okay for tests? |
64 client_->DidFinishLoading(0, total_encoded_data_length_, | 64 client_->DidFinishLoading(0, total_encoded_data_length_, |
| 65 total_encoded_data_length_, |
65 total_encoded_data_length_); | 66 total_encoded_data_length_); |
66 } | 67 } |
67 Reset(); | 68 Reset(); |
68 } | 69 } |
69 | 70 |
70 void SimRequest::Complete(const String& data) { | 71 void SimRequest::Complete(const String& data) { |
71 Start(); | 72 Start(); |
72 if (!data.IsEmpty()) | 73 if (!data.IsEmpty()) |
73 Write(data); | 74 Write(data); |
74 Finish(); | 75 Finish(); |
75 } | 76 } |
76 | 77 |
77 void SimRequest::Reset() { | 78 void SimRequest::Reset() { |
78 is_ready_ = false; | 79 is_ready_ = false; |
79 client_ = nullptr; | 80 client_ = nullptr; |
80 SimNetwork::Current().RemoveRequest(*this); | 81 SimNetwork::Current().RemoveRequest(*this); |
81 } | 82 } |
82 | 83 |
83 } // namespace blink | 84 } // namespace blink |
OLD | NEW |