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