| 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/BodyStreamBuffer.h" | 5 #include "modules/fetch/BodyStreamBuffer.h" |
| 6 | 6 |
| 7 #include "core/html/FormData.h" | 7 #include "core/html/FormData.h" |
| 8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
| 9 #include "modules/fetch/DataConsumerHandleTestUtil.h" | 9 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
| 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| 11 #include "modules/fetch/FetchFormDataConsumerHandle.h" | 11 #include "modules/fetch/FetchFormDataConsumerHandle.h" |
| 12 #include "platform/blob/BlobData.h" | 12 #include "platform/blob/BlobData.h" |
| 13 #include "platform/blob/BlobURL.h" | 13 #include "platform/blob/BlobURL.h" |
| 14 #include "platform/network/EncodedFormData.h" | 14 #include "platform/network/EncodedFormData.h" |
| 15 #include "platform/testing/UnitTestHelpers.h" | 15 #include "platform/testing/UnitTestHelpers.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "wtf/OwnPtr.h" | 18 #include "wtf/PtrUtil.h" |
| 19 #include <memory> |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| 25 using ::testing::_; | 26 using ::testing::_; |
| 26 using ::testing::SaveArg; | 27 using ::testing::SaveArg; |
| 27 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; | 28 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; |
| 28 using Command = DataConsumerHandleTestUtil::Command; | 29 using Command = DataConsumerHandleTestUtil::Command; |
| 29 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; | 30 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; |
| 30 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade
rClient; | 31 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade
rClient; |
| 31 | 32 |
| 32 class FakeLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory { | 33 class FakeLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory { |
| 33 public: | 34 public: |
| 34 PassOwnPtr<ThreadableLoader> create(ExecutionContext&, ThreadableLoaderClien
t*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&) override | 35 std::unique_ptr<ThreadableLoader> create(ExecutionContext&, ThreadableLoader
Client*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&) override |
| 35 { | 36 { |
| 36 ASSERT_NOT_REACHED(); | 37 ASSERT_NOT_REACHED(); |
| 37 return nullptr; | 38 return nullptr; |
| 38 } | 39 } |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 class BodyStreamBufferTest : public ::testing::Test { | 42 class BodyStreamBufferTest : public ::testing::Test { |
| 42 public: | 43 public: |
| 43 BodyStreamBufferTest() | 44 BodyStreamBufferTest() |
| 44 { | 45 { |
| 45 m_page = DummyPageHolder::create(IntSize(1, 1)); | 46 m_page = DummyPageHolder::create(IntSize(1, 1)); |
| 46 } | 47 } |
| 47 ~BodyStreamBufferTest() override {} | 48 ~BodyStreamBufferTest() override {} |
| 48 | 49 |
| 49 protected: | 50 protected: |
| 50 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } | 51 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } |
| 51 ExecutionContext* getExecutionContext() { return &m_page->document(); } | 52 ExecutionContext* getExecutionContext() { return &m_page->document(); } |
| 52 | 53 |
| 53 OwnPtr<DummyPageHolder> m_page; | 54 std::unique_ptr<DummyPageHolder> m_page; |
| 54 | 55 |
| 55 ScriptValue eval(const char* s) | 56 ScriptValue eval(const char* s) |
| 56 { | 57 { |
| 57 v8::Local<v8::String> source; | 58 v8::Local<v8::String> source; |
| 58 v8::Local<v8::Script> script; | 59 v8::Local<v8::Script> script; |
| 59 v8::MicrotasksScope microtasks(getScriptState()->isolate(), v8::Microtas
ksScope::kDoNotRunMicrotasks); | 60 v8::MicrotasksScope microtasks(getScriptState()->isolate(), v8::Microtas
ksScope::kDoNotRunMicrotasks); |
| 60 if (!v8Call(v8::String::NewFromUtf8(getScriptState()->isolate(), s, v8::
NewStringType::kNormal), source)) { | 61 if (!v8Call(v8::String::NewFromUtf8(getScriptState()->isolate(), s, v8::
NewStringType::kNormal), source)) { |
| 61 ADD_FAILURE(); | 62 ADD_FAILURE(); |
| 62 return ScriptValue(); | 63 return ScriptValue(); |
| 63 } | 64 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 MockFetchDataLoaderClient* client2 = MockFetchDataLoaderClient::create(); | 87 MockFetchDataLoaderClient* client2 = MockFetchDataLoaderClient::create(); |
| 87 | 88 |
| 88 InSequence s; | 89 InSequence s; |
| 89 EXPECT_CALL(checkpoint, Call(1)); | 90 EXPECT_CALL(checkpoint, Call(1)); |
| 90 EXPECT_CALL(*client1, didFetchDataLoadedString(String("hello, world"))); | 91 EXPECT_CALL(*client1, didFetchDataLoadedString(String("hello, world"))); |
| 91 EXPECT_CALL(checkpoint, Call(2)); | 92 EXPECT_CALL(checkpoint, Call(2)); |
| 92 EXPECT_CALL(checkpoint, Call(3)); | 93 EXPECT_CALL(checkpoint, Call(3)); |
| 93 EXPECT_CALL(*client2, didFetchDataLoadedString(String("hello, world"))); | 94 EXPECT_CALL(*client2, didFetchDataLoadedString(String("hello, world"))); |
| 94 EXPECT_CALL(checkpoint, Call(4)); | 95 EXPECT_CALL(checkpoint, Call(4)); |
| 95 | 96 |
| 96 OwnPtr<DataConsumerHandleTestUtil::ReplayingHandle> handle = DataConsumerHan
dleTestUtil::ReplayingHandle::create(); | 97 std::unique_ptr<DataConsumerHandleTestUtil::ReplayingHandle> handle = DataCo
nsumerHandleTestUtil::ReplayingHandle::create(); |
| 97 handle->add(DataConsumerHandleTestUtil::Command(DataConsumerHandleTestUtil::
Command::Data, "hello, ")); | 98 handle->add(DataConsumerHandleTestUtil::Command(DataConsumerHandleTestUtil::
Command::Data, "hello, ")); |
| 98 handle->add(DataConsumerHandleTestUtil::Command(DataConsumerHandleTestUtil::
Command::Data, "world")); | 99 handle->add(DataConsumerHandleTestUtil::Command(DataConsumerHandleTestUtil::
Command::Data, "world")); |
| 99 handle->add(DataConsumerHandleTestUtil::Command(DataConsumerHandleTestUtil::
Command::Done)); | 100 handle->add(DataConsumerHandleTestUtil::Command(DataConsumerHandleTestUtil::
Command::Done)); |
| 100 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); | 101 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); |
| 101 | 102 |
| 102 BodyStreamBuffer* new1; | 103 BodyStreamBuffer* new1; |
| 103 BodyStreamBuffer* new2; | 104 BodyStreamBuffer* new2; |
| 104 buffer->tee(&new1, &new2); | 105 buffer->tee(&new1, &new2); |
| 105 | 106 |
| 106 EXPECT_TRUE(buffer->isStreamLocked()); | 107 EXPECT_TRUE(buffer->isStreamLocked()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 checkpoint.Call(2); | 167 checkpoint.Call(2); |
| 167 | 168 |
| 168 new2->startLoading(FetchDataLoader::createLoaderAsString(), client2); | 169 new2->startLoading(FetchDataLoader::createLoaderAsString(), client2); |
| 169 checkpoint.Call(3); | 170 checkpoint.Call(3); |
| 170 testing::runPendingTasks(); | 171 testing::runPendingTasks(); |
| 171 checkpoint.Call(4); | 172 checkpoint.Call(4); |
| 172 } | 173 } |
| 173 | 174 |
| 174 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandle) | 175 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandle) |
| 175 { | 176 { |
| 176 OwnPtr<BlobData> data = BlobData::create(); | 177 std::unique_ptr<BlobData> data = BlobData::create(); |
| 177 data->appendText("hello", false); | 178 data->appendText("hello", false); |
| 178 auto size = data->length(); | 179 auto size = data->length(); |
| 179 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(std::move(dat
a), size); | 180 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(std::move(dat
a), size); |
| 180 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), FetchBlobD
ataConsumerHandle::create(getExecutionContext(), blobDataHandle, new FakeLoaderF
actory)); | 181 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), FetchBlobD
ataConsumerHandle::create(getExecutionContext(), blobDataHandle, new FakeLoaderF
actory)); |
| 181 | 182 |
| 182 EXPECT_FALSE(buffer->isStreamLocked()); | 183 EXPECT_FALSE(buffer->isStreamLocked()); |
| 183 EXPECT_FALSE(buffer->isStreamDisturbed()); | 184 EXPECT_FALSE(buffer->isStreamDisturbed()); |
| 184 EXPECT_FALSE(buffer->hasPendingActivity()); | 185 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 185 RefPtr<BlobDataHandle> outputBlobDataHandle = buffer->drainAsBlobDataHandle(
FetchDataConsumerHandle::Reader::AllowBlobWithInvalidSize); | 186 RefPtr<BlobDataHandle> outputBlobDataHandle = buffer->drainAsBlobDataHandle(
FetchDataConsumerHandle::Reader::AllowBlobWithInvalidSize); |
| 186 | 187 |
| 187 EXPECT_TRUE(buffer->isStreamLocked()); | 188 EXPECT_TRUE(buffer->isStreamLocked()); |
| 188 EXPECT_TRUE(buffer->isStreamDisturbed()); | 189 EXPECT_TRUE(buffer->isStreamDisturbed()); |
| 189 EXPECT_FALSE(buffer->hasPendingActivity()); | 190 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 190 EXPECT_EQ(blobDataHandle, outputBlobDataHandle); | 191 EXPECT_EQ(blobDataHandle, outputBlobDataHandle); |
| 191 } | 192 } |
| 192 | 193 |
| 193 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandleReturnsNull) | 194 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandleReturnsNull) |
| 194 { | 195 { |
| 195 // This handle is not drainable. | 196 // This handle is not drainable. |
| 196 OwnPtr<FetchDataConsumerHandle> handle = createFetchDataConsumerHandleFromWe
bHandle(createWaitingDataConsumerHandle()); | 197 std::unique_ptr<FetchDataConsumerHandle> handle = createFetchDataConsumerHan
dleFromWebHandle(createWaitingDataConsumerHandle()); |
| 197 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), std::move(
handle)); | 198 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), std::move(
handle)); |
| 198 | 199 |
| 199 EXPECT_FALSE(buffer->isStreamLocked()); | 200 EXPECT_FALSE(buffer->isStreamLocked()); |
| 200 EXPECT_FALSE(buffer->isStreamDisturbed()); | 201 EXPECT_FALSE(buffer->isStreamDisturbed()); |
| 201 EXPECT_FALSE(buffer->hasPendingActivity()); | 202 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 202 | 203 |
| 203 EXPECT_FALSE(buffer->drainAsBlobDataHandle(FetchDataConsumerHandle::Reader::
AllowBlobWithInvalidSize)); | 204 EXPECT_FALSE(buffer->drainAsBlobDataHandle(FetchDataConsumerHandle::Reader::
AllowBlobWithInvalidSize)); |
| 204 | 205 |
| 205 EXPECT_FALSE(buffer->isStreamLocked()); | 206 EXPECT_FALSE(buffer->isStreamLocked()); |
| 206 EXPECT_FALSE(buffer->isStreamDisturbed()); | 207 EXPECT_FALSE(buffer->isStreamDisturbed()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 243 |
| 243 EXPECT_TRUE(buffer->isStreamLocked()); | 244 EXPECT_TRUE(buffer->isStreamLocked()); |
| 244 EXPECT_TRUE(buffer->isStreamDisturbed()); | 245 EXPECT_TRUE(buffer->isStreamDisturbed()); |
| 245 EXPECT_FALSE(buffer->hasPendingActivity()); | 246 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 246 EXPECT_EQ(outputFormData->flattenToString(), inputFormData->flattenToString(
)); | 247 EXPECT_EQ(outputFormData->flattenToString(), inputFormData->flattenToString(
)); |
| 247 } | 248 } |
| 248 | 249 |
| 249 TEST_F(BodyStreamBufferTest, DrainAsFormDataReturnsNull) | 250 TEST_F(BodyStreamBufferTest, DrainAsFormDataReturnsNull) |
| 250 { | 251 { |
| 251 // This handle is not drainable. | 252 // This handle is not drainable. |
| 252 OwnPtr<FetchDataConsumerHandle> handle = createFetchDataConsumerHandleFromWe
bHandle(createWaitingDataConsumerHandle()); | 253 std::unique_ptr<FetchDataConsumerHandle> handle = createFetchDataConsumerHan
dleFromWebHandle(createWaitingDataConsumerHandle()); |
| 253 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), std::move(
handle)); | 254 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), std::move(
handle)); |
| 254 | 255 |
| 255 EXPECT_FALSE(buffer->isStreamLocked()); | 256 EXPECT_FALSE(buffer->isStreamLocked()); |
| 256 EXPECT_FALSE(buffer->isStreamDisturbed()); | 257 EXPECT_FALSE(buffer->isStreamDisturbed()); |
| 257 EXPECT_FALSE(buffer->hasPendingActivity()); | 258 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 258 | 259 |
| 259 EXPECT_FALSE(buffer->drainAsFormData()); | 260 EXPECT_FALSE(buffer->drainAsFormData()); |
| 260 | 261 |
| 261 EXPECT_FALSE(buffer->isStreamLocked()); | 262 EXPECT_FALSE(buffer->isStreamLocked()); |
| 262 EXPECT_FALSE(buffer->isStreamDisturbed()); | 263 EXPECT_FALSE(buffer->isStreamDisturbed()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 286 { | 287 { |
| 287 Checkpoint checkpoint; | 288 Checkpoint checkpoint; |
| 288 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); | 289 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); |
| 289 DOMArrayBuffer* arrayBuffer = nullptr; | 290 DOMArrayBuffer* arrayBuffer = nullptr; |
| 290 | 291 |
| 291 InSequence s; | 292 InSequence s; |
| 292 EXPECT_CALL(checkpoint, Call(1)); | 293 EXPECT_CALL(checkpoint, Call(1)); |
| 293 EXPECT_CALL(*client, didFetchDataLoadedArrayBufferMock(_)).WillOnce(SaveArg<
0>(&arrayBuffer)); | 294 EXPECT_CALL(*client, didFetchDataLoadedArrayBufferMock(_)).WillOnce(SaveArg<
0>(&arrayBuffer)); |
| 294 EXPECT_CALL(checkpoint, Call(2)); | 295 EXPECT_CALL(checkpoint, Call(2)); |
| 295 | 296 |
| 296 OwnPtr<ReplayingHandle> handle = ReplayingHandle::create(); | 297 std::unique_ptr<ReplayingHandle> handle = ReplayingHandle::create(); |
| 297 handle->add(Command(Command::Data, "hello")); | 298 handle->add(Command(Command::Data, "hello")); |
| 298 handle->add(Command(Command::Done)); | 299 handle->add(Command(Command::Done)); |
| 299 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); | 300 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); |
| 300 buffer->startLoading(FetchDataLoader::createLoaderAsArrayBuffer(), client); | 301 buffer->startLoading(FetchDataLoader::createLoaderAsArrayBuffer(), client); |
| 301 | 302 |
| 302 EXPECT_TRUE(buffer->isStreamLocked()); | 303 EXPECT_TRUE(buffer->isStreamLocked()); |
| 303 EXPECT_TRUE(buffer->isStreamDisturbed()); | 304 EXPECT_TRUE(buffer->isStreamDisturbed()); |
| 304 EXPECT_TRUE(buffer->hasPendingActivity()); | 305 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 305 | 306 |
| 306 checkpoint.Call(1); | 307 checkpoint.Call(1); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 318 { | 319 { |
| 319 Checkpoint checkpoint; | 320 Checkpoint checkpoint; |
| 320 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); | 321 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); |
| 321 RefPtr<BlobDataHandle> blobDataHandle; | 322 RefPtr<BlobDataHandle> blobDataHandle; |
| 322 | 323 |
| 323 InSequence s; | 324 InSequence s; |
| 324 EXPECT_CALL(checkpoint, Call(1)); | 325 EXPECT_CALL(checkpoint, Call(1)); |
| 325 EXPECT_CALL(*client, didFetchDataLoadedBlobHandleMock(_)).WillOnce(SaveArg<0
>(&blobDataHandle)); | 326 EXPECT_CALL(*client, didFetchDataLoadedBlobHandleMock(_)).WillOnce(SaveArg<0
>(&blobDataHandle)); |
| 326 EXPECT_CALL(checkpoint, Call(2)); | 327 EXPECT_CALL(checkpoint, Call(2)); |
| 327 | 328 |
| 328 OwnPtr<ReplayingHandle> handle = ReplayingHandle::create(); | 329 std::unique_ptr<ReplayingHandle> handle = ReplayingHandle::create(); |
| 329 handle->add(Command(Command::Data, "hello")); | 330 handle->add(Command(Command::Data, "hello")); |
| 330 handle->add(Command(Command::Done)); | 331 handle->add(Command(Command::Done)); |
| 331 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); | 332 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); |
| 332 buffer->startLoading(FetchDataLoader::createLoaderAsBlobHandle("text/plain")
, client); | 333 buffer->startLoading(FetchDataLoader::createLoaderAsBlobHandle("text/plain")
, client); |
| 333 | 334 |
| 334 EXPECT_TRUE(buffer->isStreamLocked()); | 335 EXPECT_TRUE(buffer->isStreamLocked()); |
| 335 EXPECT_TRUE(buffer->isStreamDisturbed()); | 336 EXPECT_TRUE(buffer->isStreamDisturbed()); |
| 336 EXPECT_TRUE(buffer->hasPendingActivity()); | 337 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 337 | 338 |
| 338 checkpoint.Call(1); | 339 checkpoint.Call(1); |
| 339 testing::runPendingTasks(); | 340 testing::runPendingTasks(); |
| 340 checkpoint.Call(2); | 341 checkpoint.Call(2); |
| 341 | 342 |
| 342 EXPECT_TRUE(buffer->isStreamLocked()); | 343 EXPECT_TRUE(buffer->isStreamLocked()); |
| 343 EXPECT_TRUE(buffer->isStreamDisturbed()); | 344 EXPECT_TRUE(buffer->isStreamDisturbed()); |
| 344 EXPECT_FALSE(buffer->hasPendingActivity()); | 345 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 345 EXPECT_EQ(5u, blobDataHandle->size()); | 346 EXPECT_EQ(5u, blobDataHandle->size()); |
| 346 } | 347 } |
| 347 | 348 |
| 348 TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsString) | 349 TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsString) |
| 349 { | 350 { |
| 350 Checkpoint checkpoint; | 351 Checkpoint checkpoint; |
| 351 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); | 352 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); |
| 352 | 353 |
| 353 InSequence s; | 354 InSequence s; |
| 354 EXPECT_CALL(checkpoint, Call(1)); | 355 EXPECT_CALL(checkpoint, Call(1)); |
| 355 EXPECT_CALL(*client, didFetchDataLoadedString(String("hello"))); | 356 EXPECT_CALL(*client, didFetchDataLoadedString(String("hello"))); |
| 356 EXPECT_CALL(checkpoint, Call(2)); | 357 EXPECT_CALL(checkpoint, Call(2)); |
| 357 | 358 |
| 358 OwnPtr<ReplayingHandle> handle = ReplayingHandle::create(); | 359 std::unique_ptr<ReplayingHandle> handle = ReplayingHandle::create(); |
| 359 handle->add(Command(Command::Data, "hello")); | 360 handle->add(Command(Command::Data, "hello")); |
| 360 handle->add(Command(Command::Done)); | 361 handle->add(Command(Command::Done)); |
| 361 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); | 362 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), createFetc
hDataConsumerHandleFromWebHandle(std::move(handle))); |
| 362 buffer->startLoading(FetchDataLoader::createLoaderAsString(), client); | 363 buffer->startLoading(FetchDataLoader::createLoaderAsString(), client); |
| 363 | 364 |
| 364 EXPECT_TRUE(buffer->isStreamLocked()); | 365 EXPECT_TRUE(buffer->isStreamLocked()); |
| 365 EXPECT_TRUE(buffer->isStreamDisturbed()); | 366 EXPECT_TRUE(buffer->isStreamDisturbed()); |
| 366 EXPECT_TRUE(buffer->hasPendingActivity()); | 367 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 367 | 368 |
| 368 checkpoint.Call(1); | 369 checkpoint.Call(1); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 TEST_F(BodyStreamBufferTest, LoaderShouldBeKeptAliveByBodyStreamBuffer) | 445 TEST_F(BodyStreamBufferTest, LoaderShouldBeKeptAliveByBodyStreamBuffer) |
| 445 { | 446 { |
| 446 Checkpoint checkpoint; | 447 Checkpoint checkpoint; |
| 447 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); | 448 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); |
| 448 | 449 |
| 449 InSequence s; | 450 InSequence s; |
| 450 EXPECT_CALL(checkpoint, Call(1)); | 451 EXPECT_CALL(checkpoint, Call(1)); |
| 451 EXPECT_CALL(*client, didFetchDataLoadedString(String("hello"))); | 452 EXPECT_CALL(*client, didFetchDataLoadedString(String("hello"))); |
| 452 EXPECT_CALL(checkpoint, Call(2)); | 453 EXPECT_CALL(checkpoint, Call(2)); |
| 453 | 454 |
| 454 OwnPtr<ReplayingHandle> handle = ReplayingHandle::create(); | 455 std::unique_ptr<ReplayingHandle> handle = ReplayingHandle::create(); |
| 455 handle->add(Command(Command::Data, "hello")); | 456 handle->add(Command(Command::Data, "hello")); |
| 456 handle->add(Command(Command::Done)); | 457 handle->add(Command(Command::Done)); |
| 457 Persistent<BodyStreamBuffer> buffer = new BodyStreamBuffer(getScriptState(),
createFetchDataConsumerHandleFromWebHandle(std::move(handle))); | 458 Persistent<BodyStreamBuffer> buffer = new BodyStreamBuffer(getScriptState(),
createFetchDataConsumerHandleFromWebHandle(std::move(handle))); |
| 458 buffer->startLoading(FetchDataLoader::createLoaderAsString(), client); | 459 buffer->startLoading(FetchDataLoader::createLoaderAsString(), client); |
| 459 | 460 |
| 460 ThreadHeap::collectAllGarbage(); | 461 ThreadHeap::collectAllGarbage(); |
| 461 checkpoint.Call(1); | 462 checkpoint.Call(1); |
| 462 testing::runPendingTasks(); | 463 testing::runPendingTasks(); |
| 463 checkpoint.Call(2); | 464 checkpoint.Call(2); |
| 464 } | 465 } |
| 465 | 466 |
| 466 // TODO(hiroshige): Merge this class into MockFetchDataConsumerHandle. | 467 // TODO(hiroshige): Merge this class into MockFetchDataConsumerHandle. |
| 467 class MockFetchDataConsumerHandleWithMockDestructor : public DataConsumerHandleT
estUtil::MockFetchDataConsumerHandle { | 468 class MockFetchDataConsumerHandleWithMockDestructor : public DataConsumerHandleT
estUtil::MockFetchDataConsumerHandle { |
| 468 public: | 469 public: |
| 469 static PassOwnPtr<::testing::StrictMock<MockFetchDataConsumerHandleWithMockD
estructor>> create() { return adoptPtr(new ::testing::StrictMock<MockFetchDataCo
nsumerHandleWithMockDestructor>); } | 470 static std::unique_ptr<::testing::StrictMock<MockFetchDataConsumerHandleWith
MockDestructor>> create() { return wrapUnique(new ::testing::StrictMock<MockFetc
hDataConsumerHandleWithMockDestructor>); } |
| 470 | 471 |
| 471 ~MockFetchDataConsumerHandleWithMockDestructor() override | 472 ~MockFetchDataConsumerHandleWithMockDestructor() override |
| 472 { | 473 { |
| 473 destruct(); | 474 destruct(); |
| 474 } | 475 } |
| 475 | 476 |
| 476 MOCK_METHOD0(destruct, void()); | 477 MOCK_METHOD0(destruct, void()); |
| 477 }; | 478 }; |
| 478 | 479 |
| 479 TEST_F(BodyStreamBufferTest, SourceHandleAndReaderShouldBeDestructedWhenCanceled
) | 480 TEST_F(BodyStreamBufferTest, SourceHandleAndReaderShouldBeDestructedWhenCanceled
) |
| 480 { | 481 { |
| 481 ScriptState::Scope scope(getScriptState()); | 482 ScriptState::Scope scope(getScriptState()); |
| 482 using MockHandle = MockFetchDataConsumerHandleWithMockDestructor; | 483 using MockHandle = MockFetchDataConsumerHandleWithMockDestructor; |
| 483 using MockReader = DataConsumerHandleTestUtil::MockFetchDataConsumerReader; | 484 using MockReader = DataConsumerHandleTestUtil::MockFetchDataConsumerReader; |
| 484 OwnPtr<MockHandle> handle = MockHandle::create(); | 485 std::unique_ptr<MockHandle> handle = MockHandle::create(); |
| 485 OwnPtr<MockReader> reader = MockReader::create(); | 486 std::unique_ptr<MockReader> reader = MockReader::create(); |
| 486 | 487 |
| 487 Checkpoint checkpoint; | 488 Checkpoint checkpoint; |
| 488 InSequence s; | 489 InSequence s; |
| 489 | 490 |
| 490 EXPECT_CALL(*handle, obtainReaderInternal(_)).WillOnce(::testing::Return(rea
der.get())); | 491 EXPECT_CALL(*handle, obtainReaderInternal(_)).WillOnce(::testing::Return(rea
der.get())); |
| 491 EXPECT_CALL(checkpoint, Call(1)); | 492 EXPECT_CALL(checkpoint, Call(1)); |
| 492 EXPECT_CALL(*reader, destruct()); | 493 EXPECT_CALL(*reader, destruct()); |
| 493 EXPECT_CALL(*handle, destruct()); | 494 EXPECT_CALL(*handle, destruct()); |
| 494 EXPECT_CALL(checkpoint, Call(2)); | 495 EXPECT_CALL(checkpoint, Call(2)); |
| 495 | 496 |
| 496 // |reader| is adopted by |obtainReader|. | 497 // |reader| is adopted by |obtainReader|. |
| 497 ASSERT_TRUE(reader.leakPtr()); | 498 ASSERT_TRUE(reader.release()); |
| 498 | 499 |
| 499 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), std::move(
handle)); | 500 BodyStreamBuffer* buffer = new BodyStreamBuffer(getScriptState(), std::move(
handle)); |
| 500 checkpoint.Call(1); | 501 checkpoint.Call(1); |
| 501 ScriptValue reason(getScriptState(), v8String(getScriptState()->isolate(), "
reason")); | 502 ScriptValue reason(getScriptState(), v8String(getScriptState()->isolate(), "
reason")); |
| 502 buffer->cancelSource(getScriptState(), reason); | 503 buffer->cancelSource(getScriptState(), reason); |
| 503 checkpoint.Call(2); | 504 checkpoint.Call(2); |
| 504 } | 505 } |
| 505 | 506 |
| 506 } // namespace | 507 } // namespace |
| 507 | 508 |
| 508 } // namespace blink | 509 } // namespace blink |
| OLD | NEW |