| 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/testing/UnitTestHelpers.h" |
| 7 #include "platform/weborigin/KURL.h" | 8 #include "platform/weborigin/KURL.h" |
| 8 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
| 9 #include "public/platform/WebURLLoaderClient.h" | 10 #include "public/platform/WebURLLoaderClient.h" |
| 10 #include "public/platform/WebUnitTestSupport.h" | 11 #include "public/platform/WebUnitTestSupport.h" |
| 11 #include "web/tests/sim/SimNetwork.h" | 12 #include "web/tests/sim/SimNetwork.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 SimRequest::SimRequest(String url, String mimeType) | 16 SimRequest::SimRequest(String url, String mimeType) |
| 16 : m_url(url) | 17 : m_url(url) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 void SimRequest::finish() | 63 void SimRequest::finish() |
| 63 { | 64 { |
| 64 ASSERT(m_isReady); | 65 ASSERT(m_isReady); |
| 65 if (m_error.reason) { | 66 if (m_error.reason) { |
| 66 m_client->didFail(m_loader, m_error); | 67 m_client->didFail(m_loader, m_error); |
| 67 } else { | 68 } else { |
| 68 // TODO(esprehn): Is claiming a request time of 0 okay for tests? | 69 // TODO(esprehn): Is claiming a request time of 0 okay for tests? |
| 69 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength); | 70 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength); |
| 70 } | 71 } |
| 71 reset(); | 72 reset(); |
| 73 |
| 74 // Pump the message loop to process the load event. |
| 75 testing::runPendingTasks(); |
| 72 } | 76 } |
| 73 | 77 |
| 74 void SimRequest::complete(const String& data) | 78 void SimRequest::complete(const String& data) |
| 75 { | 79 { |
| 76 start(); | 80 start(); |
| 77 if (!data.isEmpty()) | 81 if (!data.isEmpty()) |
| 78 write(data); | 82 write(data); |
| 79 finish(); | 83 finish(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 void SimRequest::reset() | 86 void SimRequest::reset() |
| 83 { | 87 { |
| 84 m_isReady = false; | 88 m_isReady = false; |
| 85 m_client = nullptr; | 89 m_client = nullptr; |
| 86 m_loader = nullptr; | 90 m_loader = nullptr; |
| 87 SimNetwork::current().removeRequest(*this); | 91 SimNetwork::current().removeRequest(*this); |
| 88 } | 92 } |
| 89 | 93 |
| 90 } // namespace blink | 94 } // namespace blink |
| OLD | NEW |