| 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 "modules/fetch/BytesConsumerTestUtil.h" | 5 #include "modules/fetch/BytesConsumerTestUtil.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "platform/testing/UnitTestHelpers.h" | 9 #include "platform/testing/UnitTestHelpers.h" |
| 10 #include "public/platform/WebTaskRunner.h" | 10 #include "public/platform/WebTaskRunner.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 { | 154 { |
| 155 m_consumer->setClient(this); | 155 m_consumer->setClient(this); |
| 156 } | 156 } |
| 157 | 157 |
| 158 | 158 |
| 159 void BytesConsumerTestUtil::TwoPhaseReader::onStateChange() | 159 void BytesConsumerTestUtil::TwoPhaseReader::onStateChange() |
| 160 { | 160 { |
| 161 while (true) { | 161 while (true) { |
| 162 const char* buffer = nullptr; | 162 const char* buffer = nullptr; |
| 163 size_t available = 0; | 163 size_t available = 0; |
| 164 switch (m_consumer->beginRead(&buffer, &available)) { | 164 auto result = m_consumer->beginRead(&buffer, &available); |
| 165 case BytesConsumer::Result::Ok: { | 165 if (result == BytesConsumer::Result::ShouldWait) |
| 166 return; |
| 167 if (result == BytesConsumer::Result::Ok) { |
| 166 // We don't use |available| as-is to test cases where endRead | 168 // We don't use |available| as-is to test cases where endRead |
| 167 // is called with a number smaller than |available|. We choose 3 | 169 // is called with a number smaller than |available|. We choose 3 |
| 168 // because of the same reasons as Reader::onStateChange. | 170 // because of the same reasons as Reader::onStateChange. |
| 169 size_t read = std::min(static_cast<size_t>(3), available); | 171 size_t read = std::min(static_cast<size_t>(3), available); |
| 170 m_data.append(buffer, read); | 172 m_data.append(buffer, read); |
| 171 if (m_consumer->endRead(read) != BytesConsumer::Result::Ok) { | 173 result = m_consumer->endRead(read); |
| 172 m_result = BytesConsumer::Result::Error; | |
| 173 return; | |
| 174 } | |
| 175 break; | |
| 176 } | 174 } |
| 177 case BytesConsumer::Result::ShouldWait: | 175 DCHECK_NE(result, BytesConsumer::Result::ShouldWait); |
| 178 return; | 176 if (result != BytesConsumer::Result::Ok) { |
| 179 case BytesConsumer::Result::Done: | 177 m_result = result; |
| 180 m_result = BytesConsumer::Result::Done; | |
| 181 return; | |
| 182 case BytesConsumer::Result::Error: | |
| 183 m_result = BytesConsumer::Result::Error; | |
| 184 return; | 178 return; |
| 185 } | 179 } |
| 186 } | 180 } |
| 187 } | 181 } |
| 188 | 182 |
| 189 std::pair<BytesConsumer::Result, Vector<char>> BytesConsumerTestUtil::TwoPhaseRe
ader::run() | 183 std::pair<BytesConsumer::Result, Vector<char>> BytesConsumerTestUtil::TwoPhaseRe
ader::run() |
| 190 { | 184 { |
| 191 onStateChange(); | 185 onStateChange(); |
| 192 while (m_result != BytesConsumer::Result::Done && m_result != BytesConsumer:
:Result::Error) | 186 while (m_result != BytesConsumer::Result::Done && m_result != BytesConsumer:
:Result::Error) |
| 193 testing::runPendingTasks(); | 187 testing::runPendingTasks(); |
| 194 testing::runPendingTasks(); | 188 testing::runPendingTasks(); |
| 195 return std::make_pair(m_result, std::move(m_data)); | 189 return std::make_pair(m_result, std::move(m_data)); |
| 196 } | 190 } |
| 197 | 191 |
| 198 } // namespace blink | 192 } // namespace blink |
| OLD | NEW |