Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 6 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 7 | 7 |
| 8 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
| 9 #include "core/fetch/ResourceLoaderOptions.h" | 9 #include "core/fetch/ResourceLoaderOptions.h" |
| 10 #include "core/loader/ThreadableLoader.h" | 10 #include "core/loader/ThreadableLoader.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); | 334 handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &size); |
| 335 checkpoint.Call(1); | 335 checkpoint.Call(1); |
| 336 testing::runPendingTasks(); | 336 testing::runPendingTasks(); |
| 337 checkpoint.Call(2); | 337 checkpoint.Call(2); |
| 338 client->didReceiveResponse(0, ResourceResponse(), src.release()); | 338 client->didReceiveResponse(0, ResourceResponse(), src.release()); |
| 339 HandleReaderRunner<HandleReader> runner(handle.release()); | 339 HandleReaderRunner<HandleReader> runner(handle.release()); |
| 340 OwnPtr<HandleReadResult> r = runner.wait(); | 340 OwnPtr<HandleReadResult> r = runner.wait(); |
| 341 EXPECT_EQ(kUnexpectedError, r->result()); | 341 EXPECT_EQ(kUnexpectedError, r->result()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 TEST_F(FetchBlobDataConsumerHandleTest, drainAsBlobDataHandle) | |
| 345 { | |
| 346 auto factory = new StrictMock<MockLoaderFactory>; | |
| 347 | |
| 348 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); | |
| 349 OwnPtr<FetchDataConsumerHandle> handle | |
| 350 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); | |
| 351 | |
| 352 size_t size = 0; | |
| 353 EXPECT_EQ(blobDataHandle, handle->obtainReader(nullptr)->drainAsBlobDataHand le()); | |
| 354 EXPECT_FALSE(handle->obtainReader(nullptr)->drainAsFormData()); | |
| 355 | |
| 356 EXPECT_EQ(kDone, handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &siz e)); | |
| 357 } | |
| 358 | |
| 359 TEST_F(FetchBlobDataConsumerHandleTest, drainAsFormData) | |
| 360 { | |
| 361 auto factory = new StrictMock<MockLoaderFactory>; | |
| 362 | |
| 363 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti me"); | |
| 364 OwnPtr<FetchDataConsumerHandle> handle | |
| 365 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto ry); | |
| 366 | |
| 367 RefPtr<FormData> formData = handle->obtainReader(nullptr)->drainAsFormData() ; | |
| 368 ASSERT_TRUE(formData); | |
| 369 EXPECT_TRUE(formData->hasOneRef()); | |
|
hiroshige
2015/08/12 06:44:48
isSafeToSendToAnotherThread() would be better.
yhirano
2015/08/12 07:43:42
Done.
| |
| 370 ASSERT_EQ(1u, formData->elements().size()); | |
| 371 EXPECT_EQ(FormDataElement::encodedBlob, formData->elements()[0].m_type); | |
| 372 EXPECT_EQ(blobDataHandle->uuid(), formData->elements()[0].m_blobUUID); | |
| 373 EXPECT_EQ(blobDataHandle, formData->elements()[0].m_optionalBlobDataHandle); | |
| 374 | |
| 375 EXPECT_FALSE(handle->obtainReader(nullptr)->drainAsBlobDataHandle()); | |
| 376 size_t size; | |
| 377 EXPECT_EQ(kDone, handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &siz e)); | |
| 378 } | |
|
hiroshige
2015/08/12 06:44:48
Can we add tests for drainAs.*() called after 0-by
yhirano
2015/08/12 07:43:42
Done (only for AsBlobDataConsumerHandle with no ar
| |
| 379 | |
| 344 } // namespace | 380 } // namespace |
| 345 } // namespace blink | 381 } // namespace blink |
| OLD | NEW |