| Index: third_party/WebKit/Source/modules/fetch/FetchDataLoaderTest.cpp
|
| diff --git a/third_party/WebKit/Source/modules/fetch/FetchDataLoaderTest.cpp b/third_party/WebKit/Source/modules/fetch/FetchDataLoaderTest.cpp
|
| index 3002f6555f62dd5a58bc588b2c242a69020a2a47..e09f0edc6b40f2beafd6e20b6edec4ca5ee54c4e 100644
|
| --- a/third_party/WebKit/Source/modules/fetch/FetchDataLoaderTest.cpp
|
| +++ b/third_party/WebKit/Source/modules/fetch/FetchDataLoaderTest.cpp
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "modules/fetch/FetchDataLoader.h"
|
|
|
| +#include "core/html/FormData.h"
|
| #include "modules/fetch/BytesConsumerForDataConsumerHandle.h"
|
| #include "modules/fetch/DataConsumerHandleTestUtil.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -37,6 +38,13 @@ constexpr FetchDataConsumerHandle::Reader::BlobSizePolicy kDisallowBlobWithInval
|
| constexpr char kQuickBrownFox[] = "Quick brown fox";
|
| constexpr size_t kQuickBrownFoxLength = 15;
|
| constexpr size_t kQuickBrownFoxLengthWithTerminatingNull = 16;
|
| +constexpr char kQuickBrownFoxFormData[] =
|
| + "--boundary\r\n"
|
| + "Content-Disposition: form-data; name=\"string\"\r\n"
|
| + "\r\n"
|
| + "Quick brown fox\r\n"
|
| + "--boundary--\r\n";
|
| +constexpr size_t kQuickBrownFoxFormDataLength = WTF_ARRAY_LENGTH(kQuickBrownFoxFormData) - 1u;
|
|
|
| TEST(FetchDataLoaderTest, LoadAsBlob)
|
| {
|
| @@ -330,6 +338,150 @@ TEST(FetchDataLoaderTest, LoadAsArrayBufferCancel)
|
| checkpoint.Call(3);
|
| }
|
|
|
| +TEST(FetchDataLoaderTest, LoadAsFormData)
|
| +{
|
| + WebDataConsumerHandle::Client *client = nullptr;
|
| + Checkpoint checkpoint;
|
| +
|
| + std::unique_ptr<MockHandle> handle = MockHandle::create();
|
| +
|
| + // |reader| will be adopted by |obtainFetchDataReader|.
|
| + MockReader* reader = MockReader::create().release();
|
| +
|
| + FetchDataLoader* fetchDataLoader = FetchDataLoader::createLoaderAsFormData("boundary");
|
| + MockFetchDataLoaderClient* fetchDataLoaderClient = MockFetchDataLoaderClient::create();
|
| + FormData* formData = nullptr;
|
| +
|
| + InSequence s;
|
| + EXPECT_CALL(checkpoint, Call(1));
|
| + EXPECT_CALL(*handle, obtainFetchDataReader(_)).WillOnce(DoAll(SaveArg<0>(&client), Return(ByMove(WTF::wrapUnique(reader)))));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(DoAll(SetArgPointee<0>(nullptr), SetArgPointee<2>(0), Return(kShouldWait)));
|
| + EXPECT_CALL(checkpoint, Call(2));
|
| + EXPECT_CALL(*reader, read(nullptr, kNone, 0, _)).WillOnce(DoAll(SetArgPointee<3>(0), Return(kShouldWait)));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(DoAll(SetArgPointee<0>(static_cast<const void*>(kQuickBrownFoxFormData)), SetArgPointee<2>(kQuickBrownFoxFormDataLength), Return(kOk)));
|
| + EXPECT_CALL(*reader, endRead(kQuickBrownFoxFormDataLength)).WillOnce(Return(kOk));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(Return(kDone));
|
| + EXPECT_CALL(*reader, destruct());
|
| + EXPECT_CALL(*fetchDataLoaderClient, didFetchDataLoadedFormDataMock(_)).WillOnce(SaveArg<0>(&formData));
|
| + EXPECT_CALL(checkpoint, Call(3));
|
| + EXPECT_CALL(checkpoint, Call(4));
|
| +
|
| + checkpoint.Call(1);
|
| + fetchDataLoader->start(new BytesConsumerForDataConsumerHandle(nullptr, std::move(handle)), fetchDataLoaderClient);
|
| + checkpoint.Call(2);
|
| + ASSERT_TRUE(client);
|
| + client->didGetReadable();
|
| + checkpoint.Call(3);
|
| + fetchDataLoader->cancel();
|
| + checkpoint.Call(4);
|
| +
|
| + ASSERT_TRUE(formData);
|
| + ASSERT_EQ(1u, formData->entries().size());
|
| + ASSERT_TRUE(formData->entries()[0]->isString());
|
| + EXPECT_EQ(kQuickBrownFox, formData->entries()[0]->value());
|
| +}
|
| +
|
| +TEST(FetchDataLoaderTest, LoadAsFormDataPartialInput)
|
| +{
|
| + WebDataConsumerHandle::Client *client = nullptr;
|
| + Checkpoint checkpoint;
|
| +
|
| + std::unique_ptr<MockHandle> handle = MockHandle::create();
|
| +
|
| + // |reader| will be adopted by |obtainFetchDataReader|.
|
| + MockReader* reader = MockReader::create().release();
|
| +
|
| + FetchDataLoader* fetchDataLoader = FetchDataLoader::createLoaderAsFormData("boundary");
|
| + MockFetchDataLoaderClient* fetchDataLoaderClient = MockFetchDataLoaderClient::create();
|
| +
|
| + InSequence s;
|
| + EXPECT_CALL(checkpoint, Call(1));
|
| + EXPECT_CALL(*handle, obtainFetchDataReader(_)).WillOnce(DoAll(SaveArg<0>(&client), Return(ByMove(WTF::wrapUnique(reader)))));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(DoAll(SetArgPointee<0>(nullptr), SetArgPointee<2>(0), Return(kShouldWait)));
|
| + EXPECT_CALL(checkpoint, Call(2));
|
| + EXPECT_CALL(*reader, read(nullptr, kNone, 0, _)).WillOnce(DoAll(SetArgPointee<3>(0), Return(kShouldWait)));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(DoAll(SetArgPointee<0>(static_cast<const void*>(kQuickBrownFoxFormData)), SetArgPointee<2>(kQuickBrownFoxFormDataLength - 3u), Return(kOk)));
|
| + EXPECT_CALL(*reader, endRead(kQuickBrownFoxFormDataLength - 3u)).WillOnce(Return(kOk));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(Return(kDone));
|
| + EXPECT_CALL(*reader, destruct());
|
| + EXPECT_CALL(*fetchDataLoaderClient, didFetchDataLoadFailed());
|
| + EXPECT_CALL(checkpoint, Call(3));
|
| + EXPECT_CALL(checkpoint, Call(4));
|
| +
|
| + checkpoint.Call(1);
|
| + fetchDataLoader->start(new BytesConsumerForDataConsumerHandle(nullptr, std::move(handle)), fetchDataLoaderClient);
|
| + checkpoint.Call(2);
|
| + ASSERT_TRUE(client);
|
| + client->didGetReadable();
|
| + checkpoint.Call(3);
|
| + fetchDataLoader->cancel();
|
| + checkpoint.Call(4);
|
| +}
|
| +
|
| +TEST(FetchDataLoaderTest, LoadAsFormDataError)
|
| +{
|
| + WebDataConsumerHandle::Client *client = nullptr;
|
| + Checkpoint checkpoint;
|
| +
|
| + std::unique_ptr<MockHandle> handle = MockHandle::create();
|
| +
|
| + // |reader| will be adopted by |obtainFetchDataReader|.
|
| + MockReader* reader = MockReader::create().release();
|
| +
|
| + FetchDataLoader* fetchDataLoader = FetchDataLoader::createLoaderAsFormData("boundary");
|
| + MockFetchDataLoaderClient* fetchDataLoaderClient = MockFetchDataLoaderClient::create();
|
| +
|
| + InSequence s;
|
| + EXPECT_CALL(checkpoint, Call(1));
|
| + EXPECT_CALL(*handle, obtainFetchDataReader(_)).WillOnce(DoAll(SaveArg<0>(&client), Return(ByMove(WTF::wrapUnique(reader)))));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(DoAll(SetArgPointee<0>(nullptr), SetArgPointee<2>(0), Return(kShouldWait)));
|
| + EXPECT_CALL(checkpoint, Call(2));
|
| + EXPECT_CALL(*reader, read(nullptr, kNone, 0, _)).WillOnce(DoAll(SetArgPointee<3>(0), Return(kShouldWait)));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(DoAll(SetArgPointee<0>(static_cast<const void*>(kQuickBrownFoxFormData)), SetArgPointee<2>(kQuickBrownFoxFormDataLength), Return(kOk)));
|
| + EXPECT_CALL(*reader, endRead(kQuickBrownFoxFormDataLength)).WillOnce(Return(kOk));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(Return(kUnexpectedError));
|
| + EXPECT_CALL(*reader, destruct());
|
| + EXPECT_CALL(*fetchDataLoaderClient, didFetchDataLoadFailed());
|
| + EXPECT_CALL(checkpoint, Call(3));
|
| + EXPECT_CALL(checkpoint, Call(4));
|
| +
|
| + checkpoint.Call(1);
|
| + fetchDataLoader->start(new BytesConsumerForDataConsumerHandle(nullptr, std::move(handle)), fetchDataLoaderClient);
|
| + checkpoint.Call(2);
|
| + ASSERT_TRUE(client);
|
| + client->didGetReadable();
|
| + checkpoint.Call(3);
|
| + fetchDataLoader->cancel();
|
| + checkpoint.Call(4);
|
| +}
|
| +
|
| +TEST(FetchDataLoaderTest, LoadAsFormDataCancel)
|
| +{
|
| + Checkpoint checkpoint;
|
| +
|
| + std::unique_ptr<MockHandle> handle = MockHandle::create();
|
| +
|
| + // |reader| will be adopted by |obtainFetchDataReader|.
|
| + MockReader* reader = MockReader::create().release();
|
| +
|
| + FetchDataLoader* fetchDataLoader = FetchDataLoader::createLoaderAsFormData("boundary");
|
| + MockFetchDataLoaderClient* fetchDataLoaderClient = MockFetchDataLoaderClient::create();
|
| +
|
| + InSequence s;
|
| + EXPECT_CALL(checkpoint, Call(1));
|
| + EXPECT_CALL(*handle, obtainFetchDataReader(_)).WillOnce(Return(ByMove(WTF::wrapUnique(reader))));
|
| + EXPECT_CALL(*reader, beginRead(_, kNone, _)).WillOnce(DoAll(SetArgPointee<0>(nullptr), SetArgPointee<2>(0), Return(kShouldWait)));
|
| + EXPECT_CALL(checkpoint, Call(2));
|
| + EXPECT_CALL(*reader, destruct());
|
| + EXPECT_CALL(checkpoint, Call(3));
|
| +
|
| + checkpoint.Call(1);
|
| + fetchDataLoader->start(new BytesConsumerForDataConsumerHandle(nullptr, std::move(handle)), fetchDataLoaderClient);
|
| + checkpoint.Call(2);
|
| + fetchDataLoader->cancel();
|
| + checkpoint.Call(3);
|
| +}
|
| +
|
| TEST(FetchDataLoaderTest, LoadAsString)
|
| {
|
| WebDataConsumerHandle::Client *client = nullptr;
|
|
|