| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/Response.h" | 5 #include "modules/fetch/Response.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 208 } |
| 209 | 209 |
| 210 BodyStreamBuffer* createHelloWorldBuffer(ScriptState* scriptState) { | 210 BodyStreamBuffer* createHelloWorldBuffer(ScriptState* scriptState) { |
| 211 using Command = BytesConsumerTestUtil::Command; | 211 using Command = BytesConsumerTestUtil::Command; |
| 212 BytesConsumerTestUtil::ReplayingBytesConsumer* src = | 212 BytesConsumerTestUtil::ReplayingBytesConsumer* src = |
| 213 new BytesConsumerTestUtil::ReplayingBytesConsumer( | 213 new BytesConsumerTestUtil::ReplayingBytesConsumer( |
| 214 scriptState->getExecutionContext()); | 214 scriptState->getExecutionContext()); |
| 215 src->add(Command(Command::Data, "Hello, ")); | 215 src->add(Command(Command::Data, "Hello, ")); |
| 216 src->add(Command(Command::Data, "world")); | 216 src->add(Command(Command::Data, "world")); |
| 217 src->add(Command(Command::Done)); | 217 src->add(Command(Command::Done)); |
| 218 return new BodyStreamBuffer(scriptState, src); | 218 return BodyStreamBuffer::create(scriptState, src); |
| 219 } | 219 } |
| 220 | 220 |
| 221 TEST(ServiceWorkerResponseTest, BodyStreamBufferCloneDefault) { | 221 TEST(ServiceWorkerResponseTest, BodyStreamBufferCloneDefault) { |
| 222 V8TestingScope scope; | 222 V8TestingScope scope; |
| 223 BodyStreamBuffer* buffer = createHelloWorldBuffer(scope.getScriptState()); | 223 BodyStreamBuffer* buffer = createHelloWorldBuffer(scope.getScriptState()); |
| 224 FetchResponseData* fetchResponseData = | 224 FetchResponseData* fetchResponseData = |
| 225 FetchResponseData::createWithBuffer(buffer); | 225 FetchResponseData::createWithBuffer(buffer); |
| 226 fetchResponseData->setURL(KURL(ParsedURLString, "http://www.response.com")); | 226 fetchResponseData->setURL(KURL(ParsedURLString, "http://www.response.com")); |
| 227 Response* response = | 227 Response* response = |
| 228 Response::create(scope.getExecutionContext(), fetchResponseData); | 228 Response::create(scope.getExecutionContext(), fetchResponseData); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 fetchResponseData->setURL(KURL(ParsedURLString, "http://www.response.com")); | 264 fetchResponseData->setURL(KURL(ParsedURLString, "http://www.response.com")); |
| 265 fetchResponseData = fetchResponseData->createOpaqueFilteredResponse(); | 265 fetchResponseData = fetchResponseData->createOpaqueFilteredResponse(); |
| 266 Response* response = | 266 Response* response = |
| 267 Response::create(scope.getExecutionContext(), fetchResponseData); | 267 Response::create(scope.getExecutionContext(), fetchResponseData); |
| 268 EXPECT_EQ(response->internalBodyBuffer(), buffer); | 268 EXPECT_EQ(response->internalBodyBuffer(), buffer); |
| 269 checkResponseStream(scope.getScriptState(), response, false); | 269 checkResponseStream(scope.getScriptState(), response, false); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST(ServiceWorkerResponseTest, BodyStreamBufferCloneError) { | 272 TEST(ServiceWorkerResponseTest, BodyStreamBufferCloneError) { |
| 273 V8TestingScope scope; | 273 V8TestingScope scope; |
| 274 BodyStreamBuffer* buffer = new BodyStreamBuffer( | 274 BodyStreamBuffer* buffer = BodyStreamBuffer::create( |
| 275 scope.getScriptState(), | 275 scope.getScriptState(), |
| 276 BytesConsumer::createErrored(BytesConsumer::Error())); | 276 BytesConsumer::createErrored(BytesConsumer::Error())); |
| 277 FetchResponseData* fetchResponseData = | 277 FetchResponseData* fetchResponseData = |
| 278 FetchResponseData::createWithBuffer(buffer); | 278 FetchResponseData::createWithBuffer(buffer); |
| 279 fetchResponseData->setURL(KURL(ParsedURLString, "http://www.response.com")); | 279 fetchResponseData->setURL(KURL(ParsedURLString, "http://www.response.com")); |
| 280 Response* response = | 280 Response* response = |
| 281 Response::create(scope.getExecutionContext(), fetchResponseData); | 281 Response::create(scope.getExecutionContext(), fetchResponseData); |
| 282 TrackExceptionState exceptionState; | 282 TrackExceptionState exceptionState; |
| 283 Response* clonedResponse = | 283 Response* clonedResponse = |
| 284 response->clone(scope.getScriptState(), exceptionState); | 284 response->clone(scope.getScriptState(), exceptionState); |
| 285 EXPECT_FALSE(exceptionState.hadException()); | 285 EXPECT_FALSE(exceptionState.hadException()); |
| 286 | 286 |
| 287 BytesConsumerTestUtil::MockFetchDataLoaderClient* client1 = | 287 BytesConsumerTestUtil::MockFetchDataLoaderClient* client1 = |
| 288 new BytesConsumerTestUtil::MockFetchDataLoaderClient(); | 288 new BytesConsumerTestUtil::MockFetchDataLoaderClient(); |
| 289 BytesConsumerTestUtil::MockFetchDataLoaderClient* client2 = | 289 BytesConsumerTestUtil::MockFetchDataLoaderClient* client2 = |
| 290 new BytesConsumerTestUtil::MockFetchDataLoaderClient(); | 290 new BytesConsumerTestUtil::MockFetchDataLoaderClient(); |
| 291 EXPECT_CALL(*client1, didFetchDataLoadFailed()); | 291 EXPECT_CALL(*client1, didFetchDataLoadFailed()); |
| 292 EXPECT_CALL(*client2, didFetchDataLoadFailed()); | 292 EXPECT_CALL(*client2, didFetchDataLoadFailed()); |
| 293 | 293 |
| 294 response->internalBodyBuffer()->startLoading( | 294 response->internalBodyBuffer()->startLoading( |
| 295 FetchDataLoader::createLoaderAsString(), client1); | 295 FetchDataLoader::createLoaderAsString(), client1); |
| 296 clonedResponse->internalBodyBuffer()->startLoading( | 296 clonedResponse->internalBodyBuffer()->startLoading( |
| 297 FetchDataLoader::createLoaderAsString(), client2); | 297 FetchDataLoader::createLoaderAsString(), client2); |
| 298 blink::testing::runPendingTasks(); | 298 blink::testing::runPendingTasks(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 } // namespace | 301 } // namespace |
| 302 } // namespace blink | 302 } // namespace blink |
| OLD | NEW |