| 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/FetchBlobDataConsumerHandle.h" | 5 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/fetch/ResourceLoaderOptions.h" | 8 #include "core/fetch/ResourceLoaderOptions.h" |
| 9 #include "core/loader/MockThreadableLoader.h" | 9 #include "core/loader/MockThreadableLoader.h" |
| 10 #include "core/loader/ThreadableLoaderClient.h" | 10 #include "core/loader/ThreadableLoaderClient.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 351 |
| 352 TEST_F(FetchBlobDataConsumerHandleTest, DrainAsBlobDataHandle) | 352 TEST_F(FetchBlobDataConsumerHandleTest, DrainAsBlobDataHandle) |
| 353 { | 353 { |
| 354 auto factory = new StrictMock<MockLoaderFactory>; | 354 auto factory = new StrictMock<MockLoaderFactory>; |
| 355 | 355 |
| 356 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 356 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 357 std::unique_ptr<FetchDataConsumerHandle> handle | 357 std::unique_ptr<FetchDataConsumerHandle> handle |
| 358 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 358 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 359 | 359 |
| 360 size_t size = 0; | 360 size_t size = 0; |
| 361 EXPECT_EQ(blobDataHandle, handle->obtainReader(nullptr)->drainAsBlobDataHand
le()); | 361 EXPECT_EQ(blobDataHandle, handle->obtainFetchDataReader(nullptr)->drainAsBlo
bDataHandle()); |
| 362 EXPECT_FALSE(handle->obtainReader(nullptr)->drainAsFormData()); | 362 EXPECT_FALSE(handle->obtainFetchDataReader(nullptr)->drainAsFormData()); |
| 363 | 363 |
| 364 EXPECT_EQ(kDone, handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &siz
e)); | 364 EXPECT_EQ(kDone, handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &siz
e)); |
| 365 } | 365 } |
| 366 | 366 |
| 367 TEST_F(FetchBlobDataConsumerHandleTest, DrainAsFormData) | 367 TEST_F(FetchBlobDataConsumerHandleTest, DrainAsFormData) |
| 368 { | 368 { |
| 369 auto factory = new StrictMock<MockLoaderFactory>; | 369 auto factory = new StrictMock<MockLoaderFactory>; |
| 370 | 370 |
| 371 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 371 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 372 std::unique_ptr<FetchDataConsumerHandle> handle | 372 std::unique_ptr<FetchDataConsumerHandle> handle |
| 373 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 373 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 374 | 374 |
| 375 RefPtr<EncodedFormData> formData = handle->obtainReader(nullptr)->drainAsFor
mData(); | 375 RefPtr<EncodedFormData> formData = handle->obtainFetchDataReader(nullptr)->d
rainAsFormData(); |
| 376 ASSERT_TRUE(formData); | 376 ASSERT_TRUE(formData); |
| 377 EXPECT_TRUE(formData->isSafeToSendToAnotherThread()); | 377 EXPECT_TRUE(formData->isSafeToSendToAnotherThread()); |
| 378 ASSERT_EQ(1u, formData->elements().size()); | 378 ASSERT_EQ(1u, formData->elements().size()); |
| 379 EXPECT_EQ(FormDataElement::encodedBlob, formData->elements()[0].m_type); | 379 EXPECT_EQ(FormDataElement::encodedBlob, formData->elements()[0].m_type); |
| 380 EXPECT_EQ(blobDataHandle->uuid(), formData->elements()[0].m_blobUUID); | 380 EXPECT_EQ(blobDataHandle->uuid(), formData->elements()[0].m_blobUUID); |
| 381 EXPECT_EQ(blobDataHandle, formData->elements()[0].m_optionalBlobDataHandle); | 381 EXPECT_EQ(blobDataHandle, formData->elements()[0].m_optionalBlobDataHandle); |
| 382 | 382 |
| 383 EXPECT_FALSE(handle->obtainReader(nullptr)->drainAsBlobDataHandle()); | 383 EXPECT_FALSE(handle->obtainFetchDataReader(nullptr)->drainAsBlobDataHandle()
); |
| 384 size_t size; | 384 size_t size; |
| 385 EXPECT_EQ(kDone, handle->obtainReader(nullptr)->read(nullptr, 0, kNone, &siz
e)); | 385 EXPECT_EQ(kDone, handle->obtainFetchDataReader(nullptr)->read(nullptr, 0, kN
one, &size)); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(FetchBlobDataConsumerHandleTest, ZeroByteReadDoesNotAffectDraining) | 388 TEST_F(FetchBlobDataConsumerHandleTest, ZeroByteReadDoesNotAffectDraining) |
| 389 { | 389 { |
| 390 auto factory = new StrictMock<MockLoaderFactory>; | 390 auto factory = new StrictMock<MockLoaderFactory>; |
| 391 | 391 |
| 392 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 392 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 393 std::unique_ptr<FetchDataConsumerHandle> handle | 393 std::unique_ptr<FetchDataConsumerHandle> handle |
| 394 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 394 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 395 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(nullptr); | 395 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc
hDataReader(nullptr); |
| 396 | 396 |
| 397 size_t readSize; | 397 size_t readSize; |
| 398 EXPECT_EQ(kShouldWait, reader->read(nullptr, 0, kNone, &readSize)); | 398 EXPECT_EQ(kShouldWait, reader->read(nullptr, 0, kNone, &readSize)); |
| 399 EXPECT_EQ(blobDataHandle, reader->drainAsBlobDataHandle()); | 399 EXPECT_EQ(blobDataHandle, reader->drainAsBlobDataHandle()); |
| 400 } | 400 } |
| 401 | 401 |
| 402 TEST_F(FetchBlobDataConsumerHandleTest, OneByteReadAffectsDraining) | 402 TEST_F(FetchBlobDataConsumerHandleTest, OneByteReadAffectsDraining) |
| 403 { | 403 { |
| 404 auto factory = new StrictMock<MockLoaderFactory>; | 404 auto factory = new StrictMock<MockLoaderFactory>; |
| 405 | 405 |
| 406 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 406 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 407 std::unique_ptr<FetchDataConsumerHandle> handle | 407 std::unique_ptr<FetchDataConsumerHandle> handle |
| 408 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 408 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 409 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(nullptr); | 409 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc
hDataReader(nullptr); |
| 410 | 410 |
| 411 size_t readSize; | 411 size_t readSize; |
| 412 char c; | 412 char c; |
| 413 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readSize)); | 413 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readSize)); |
| 414 EXPECT_FALSE(reader->drainAsFormData()); | 414 EXPECT_FALSE(reader->drainAsFormData()); |
| 415 } | 415 } |
| 416 | 416 |
| 417 TEST_F(FetchBlobDataConsumerHandleTest, BeginReadAffectsDraining) | 417 TEST_F(FetchBlobDataConsumerHandleTest, BeginReadAffectsDraining) |
| 418 { | 418 { |
| 419 auto factory = new StrictMock<MockLoaderFactory>; | 419 auto factory = new StrictMock<MockLoaderFactory>; |
| 420 | 420 |
| 421 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); | 421 RefPtr<BlobDataHandle> blobDataHandle = createBlobDataHandle("Once upon a ti
me"); |
| 422 std::unique_ptr<FetchDataConsumerHandle> handle | 422 std::unique_ptr<FetchDataConsumerHandle> handle |
| 423 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); | 423 = FetchBlobDataConsumerHandle::create(&document(), blobDataHandle, facto
ry); |
| 424 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(nullptr); | 424 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc
hDataReader(nullptr); |
| 425 | 425 |
| 426 const void* buffer; | 426 const void* buffer; |
| 427 size_t available; | 427 size_t available; |
| 428 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 428 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 429 EXPECT_FALSE(reader->drainAsBlobDataHandle()); | 429 EXPECT_FALSE(reader->drainAsBlobDataHandle()); |
| 430 } | 430 } |
| 431 | 431 |
| 432 } // namespace | 432 } // namespace |
| 433 } // namespace blink | 433 } // namespace blink |
| OLD | NEW |