Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/fetch/BodyStreamBuffer.h" | 6 #include "modules/fetch/BodyStreamBuffer.h" |
| 7 | 7 |
| 8 #include "core/testing/DummyPageHolder.h" | |
| 8 #include "modules/fetch/DataConsumerHandleTestUtil.h" | 9 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
| 9 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
| 11 #include "wtf/OwnPtr.h" | |
| 10 | 12 |
| 11 #include <gmock/gmock.h> | 13 #include <gmock/gmock.h> |
| 12 #include <gtest/gtest.h> | 14 #include <gtest/gtest.h> |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 using ::testing::InSequence; | 20 using ::testing::InSequence; |
| 19 using ::testing::_; | 21 using ::testing::_; |
| 20 using ::testing::Return; | 22 using ::testing::SaveArg; |
| 21 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; | 23 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; |
| 22 using Command = DataConsumerHandleTestUtil::Command; | 24 using Command = DataConsumerHandleTestUtil::Command; |
| 23 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; | 25 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; |
| 24 using MockFetchDataConsumerHandle = DataConsumerHandleTestUtil::MockFetchDataCon sumerHandle; | |
| 25 using MockFetchDataConsumerReader = DataConsumerHandleTestUtil::MockFetchDataCon sumerReader; | |
| 26 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient; | 26 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient; |
| 27 | 27 |
| 28 const FetchDataConsumerHandle::Reader::BlobSizePolicy kAllowBlobWithInvalidSize = FetchDataConsumerHandle::Reader::AllowBlobWithInvalidSize; | 28 using Result = WebDataConsumerHandle::Result; |
| 29 | 29 const WebDataConsumerHandle::Flags kNone = WebDataConsumerHandle::FlagNone; |
| 30 class MockDrainingStreamNotificationClient : public GarbageCollectedFinalized<Mo ckDrainingStreamNotificationClient>, public BodyStreamBuffer::DrainingStreamNoti ficationClient { | 30 const Result kDone = WebDataConsumerHandle::Done; |
| 31 USING_GARBAGE_COLLECTED_MIXIN(MockDrainingStreamNotificationClient); | 31 |
| 32 class BodyStreamBufferTest : public ::testing::Test { | |
| 32 public: | 33 public: |
| 33 static ::testing::StrictMock<MockDrainingStreamNotificationClient>* create() { return new ::testing::StrictMock<MockDrainingStreamNotificationClient>; } | 34 BodyStreamBufferTest() |
| 34 | |
| 35 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 36 { | 35 { |
| 37 DrainingStreamNotificationClient::trace(visitor); | 36 m_page = DummyPageHolder::create(IntSize(1, 1)); |
| 38 } | 37 } |
| 39 | 38 ~BodyStreamBufferTest() override {} |
| 40 MOCK_METHOD0(didFetchDataLoadFinishedFromDrainingStream, void()); | 39 |
| 40 protected: | |
| 41 ExecutionContext* executionContext() { return &m_page->document(); } | |
| 42 | |
| 43 OwnPtr<DummyPageHolder> m_page; | |
| 41 }; | 44 }; |
| 42 | 45 |
| 43 TEST(DrainingBodyStreamBufferTest, NotifyOnDestruction) | 46 TEST_F(BodyStreamBufferTest, CreateNullBodyStreamBuffer) |
| 44 { | 47 { |
| 45 Checkpoint checkpoint; | 48 BodyStreamBuffer* buffer = new BodyStreamBuffer(); |
| 46 InSequence s; | 49 EXPECT_FALSE(buffer->hasBody()); |
| 47 | 50 EXPECT_FALSE(buffer->isLocked()); |
| 48 MockDrainingStreamNotificationClient* client = MockDrainingStreamNotificatio nClient::create(); | 51 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 49 | 52 EXPECT_TRUE(buffer->stream()); |
| 50 EXPECT_CALL(checkpoint, Call(1)); | 53 } |
| 51 EXPECT_CALL(*client, didFetchDataLoadFinishedFromDrainingStream()); | 54 |
| 52 EXPECT_CALL(checkpoint, Call(2)); | 55 TEST_F(BodyStreamBufferTest, LockNullBodyStreamBuffer) |
| 53 | 56 { |
| 54 BodyStreamBuffer* buffer = BodyStreamBuffer::createEmpty(); | 57 BodyStreamBuffer* buffer = new BodyStreamBuffer(); |
| 55 OwnPtr<DrainingBodyStreamBuffer> drainingBuffer = DrainingBodyStreamBuffer:: create(buffer, client); | 58 size_t size; |
| 56 checkpoint.Call(1); | 59 |
| 57 drainingBuffer.clear(); | 60 OwnPtr<FetchDataConsumerHandle> handle = buffer->lock(executionContext()); |
| 58 checkpoint.Call(2); | 61 |
| 59 } | 62 EXPECT_FALSE(buffer->hasBody()); |
| 60 | 63 EXPECT_FALSE(buffer->isLocked()); |
| 61 TEST(DrainingBodyStreamBufferTest, NotifyWhenBlobDataHandleIsDrained) | 64 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 62 { | 65 ASSERT_TRUE(handle); |
| 63 Checkpoint checkpoint; | 66 |
| 64 InSequence s; | 67 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(nullpt r); |
| 65 | 68 ASSERT_TRUE(reader); |
| 66 OwnPtr<MockFetchDataConsumerHandle> src(MockFetchDataConsumerHandle::create( )); | 69 Result r =reader->read(nullptr, 0, kNone, &size); |
| 67 OwnPtr<MockFetchDataConsumerReader> reader(MockFetchDataConsumerReader::crea te()); | 70 EXPECT_EQ(kDone, r); |
| 68 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(); | 71 reader = nullptr; |
| 69 | 72 } |
| 70 MockDrainingStreamNotificationClient* client = MockDrainingStreamNotificatio nClient::create(); | 73 |
| 71 | 74 TEST_F(BodyStreamBufferTest, LoadNullBodyStreamBuffer) |
| 72 EXPECT_CALL(checkpoint, Call(1)); | 75 { |
| 73 EXPECT_CALL(checkpoint, Call(2)); | 76 Checkpoint checkpoint; |
| 74 EXPECT_CALL(*src, obtainReaderInternal(_)).WillOnce(Return(reader.get())); | 77 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); |
| 75 EXPECT_CALL(*reader, drainAsBlobDataHandle(kAllowBlobWithInvalidSize)).WillO nce(Return(blobDataHandle)); | 78 |
| 76 EXPECT_CALL(*client, didFetchDataLoadFinishedFromDrainingStream()); | 79 InSequence s; |
| 77 EXPECT_CALL(checkpoint, Call(3)); | 80 EXPECT_CALL(checkpoint, Call(1)); |
| 78 EXPECT_CALL(checkpoint, Call(4)); | 81 EXPECT_CALL(*client, didFetchDataLoadedString(String(""))); |
| 79 | 82 EXPECT_CALL(checkpoint, Call(2)); |
| 80 // |reader| is adopted by |obtainReader|. | 83 |
| 81 ASSERT_TRUE(reader.leakPtr()); | 84 BodyStreamBuffer* buffer = new BodyStreamBuffer(); |
| 82 | 85 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client); |
| 83 BodyStreamBuffer* buffer = BodyStreamBuffer::create(src.release()); | 86 |
| 84 checkpoint.Call(1); | 87 EXPECT_FALSE(buffer->hasBody()); |
| 85 OwnPtr<DrainingBodyStreamBuffer> drainingBuffer = DrainingBodyStreamBuffer:: create(buffer, client); | 88 EXPECT_FALSE(buffer->isLocked()); |
| 86 checkpoint.Call(2); | 89 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 87 EXPECT_EQ(blobDataHandle, drainingBuffer->drainAsBlobDataHandle(kAllowBlobWi thInvalidSize)); | 90 |
| 88 checkpoint.Call(3); | 91 checkpoint.Call(1); |
| 89 drainingBuffer.clear(); | 92 testing::runPendingTasks(); |
| 90 checkpoint.Call(4); | 93 checkpoint.Call(2); |
| 91 } | 94 |
| 92 | 95 EXPECT_FALSE(buffer->hasBody()); |
| 93 TEST(DrainingBodyStreamBufferTest, DoNotNotifyWhenNullBlobDataHandleIsDrained) | 96 EXPECT_FALSE(buffer->isLocked()); |
| 94 { | 97 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 95 Checkpoint checkpoint; | 98 } |
| 96 InSequence s; | 99 |
| 97 | 100 TEST_F(BodyStreamBufferTest, LockBodyStreamBuffer) |
| 98 MockDrainingStreamNotificationClient* client = MockDrainingStreamNotificatio nClient::create(); | 101 { |
| 99 | 102 OwnPtr<FetchDataConsumerHandle> handle = createFetchDataConsumerHandleFromWe bHandle(createWaitingDataConsumerHandle()); |
| 100 EXPECT_CALL(checkpoint, Call(1)); | 103 FetchDataConsumerHandle* rawHandle = handle.get(); |
| 101 EXPECT_CALL(checkpoint, Call(2)); | 104 BodyStreamBuffer* buffer = new BodyStreamBuffer(handle.release()); |
| 102 EXPECT_CALL(*client, didFetchDataLoadFinishedFromDrainingStream()); | 105 |
| 103 EXPECT_CALL(checkpoint, Call(3)); | 106 EXPECT_TRUE(buffer->hasBody()); |
| 104 | 107 EXPECT_FALSE(buffer->isLocked()); |
| 105 BodyStreamBuffer* buffer = BodyStreamBuffer::createEmpty(); | 108 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 106 OwnPtr<DrainingBodyStreamBuffer> drainingBuffer = DrainingBodyStreamBuffer:: create(buffer, client); | 109 |
| 107 checkpoint.Call(1); | 110 handle = buffer->lock(executionContext()); |
|
hiroshige
2015/07/25 05:27:35
nit: Reusing |handle| here is somehow confusing.
yhirano
2015/07/29 08:45:02
Done.
| |
| 108 EXPECT_FALSE(drainingBuffer->drainAsBlobDataHandle(kAllowBlobWithInvalidSize )); | 111 |
| 109 checkpoint.Call(2); | 112 ASSERT_EQ(rawHandle, handle.get()); |
| 110 drainingBuffer.clear(); | 113 EXPECT_TRUE(buffer->hasBody()); |
| 111 checkpoint.Call(3); | 114 EXPECT_TRUE(buffer->isLocked()); |
| 112 } | 115 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 113 | 116 } |
| 114 TEST(DrainingBodyStreamBufferTest, DoNotNotifyWhenBufferIsLeaked) | 117 |
| 115 { | 118 TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsArrayBuffer) |
|
hiroshige
2015/07/25 05:27:35
optional: do we need LoadBodyStreamBufferAsArrayBu
yhirano
2015/07/29 08:45:02
I don't have a strong opinion, but what I wanted t
| |
| 116 Checkpoint checkpoint; | 119 { |
| 117 InSequence s; | 120 Checkpoint checkpoint; |
| 118 | 121 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); |
| 119 MockDrainingStreamNotificationClient* client = MockDrainingStreamNotificatio nClient::create(); | 122 RefPtr<DOMArrayBuffer> arrayBuffer; |
| 120 | 123 |
| 121 EXPECT_CALL(checkpoint, Call(1)); | 124 InSequence s; |
| 122 EXPECT_CALL(checkpoint, Call(2)); | 125 EXPECT_CALL(checkpoint, Call(1)); |
| 123 EXPECT_CALL(checkpoint, Call(3)); | 126 EXPECT_CALL(*client, didFetchDataLoadedArrayBufferMock(_)).WillOnce(SaveArg< 0>(&arrayBuffer)); |
| 124 | 127 EXPECT_CALL(checkpoint, Call(2)); |
| 125 BodyStreamBuffer* buffer = BodyStreamBuffer::createEmpty(); | 128 |
| 126 | 129 OwnPtr<ReplayingHandle> handle = ReplayingHandle::create(); |
| 127 OwnPtr<DrainingBodyStreamBuffer> drainingBuffer = DrainingBodyStreamBuffer:: create(buffer, client); | 130 handle->add(Command(Command::Data, "hello")); |
| 128 checkpoint.Call(1); | 131 handle->add(Command(Command::Done)); |
| 129 EXPECT_EQ(buffer, drainingBuffer->leakBuffer()); | 132 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(handle.release())); |
| 130 checkpoint.Call(2); | 133 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsArra yBuffer(), client); |
| 131 drainingBuffer.clear(); | 134 |
| 132 checkpoint.Call(3); | 135 EXPECT_TRUE(buffer->hasBody()); |
| 133 } | 136 EXPECT_TRUE(buffer->isLocked()); |
| 134 | 137 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 135 TEST(DrainingBodyStreamBufferTest, NotifyOnStartLoading) | 138 |
| 136 { | 139 checkpoint.Call(1); |
| 137 Checkpoint checkpoint; | 140 testing::runPendingTasks(); |
| 138 InSequence s; | 141 checkpoint.Call(2); |
| 139 | 142 |
| 140 OwnPtr<ReplayingHandle> src(ReplayingHandle::create()); | 143 EXPECT_TRUE(buffer->hasBody()); |
| 141 src->add(Command(Command::Data, "hello, world.")); | 144 EXPECT_FALSE(buffer->isLocked()); |
| 142 src->add(Command(Command::Done)); | 145 EXPECT_FALSE(buffer->hasPendingActivity()); |
| 143 | 146 EXPECT_EQ("hello", String(static_cast<const char*>(arrayBuffer->data()), arr ayBuffer->byteLength())); |
| 144 MockDrainingStreamNotificationClient* client = MockDrainingStreamNotificatio nClient::create(); | 147 } |
| 145 MockFetchDataLoaderClient* fetchDataLoaderClient = MockFetchDataLoaderClient ::create(); | 148 |
| 146 FetchDataLoader* fetchDataLoader = FetchDataLoader::createLoaderAsString(); | 149 TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsBlob) |
| 147 | 150 { |
| 148 EXPECT_CALL(checkpoint, Call(1)); | 151 Checkpoint checkpoint; |
| 149 EXPECT_CALL(checkpoint, Call(2)); | 152 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); |
| 150 EXPECT_CALL(checkpoint, Call(3)); | 153 RefPtr<BlobDataHandle> blobDataHandle; |
| 151 EXPECT_CALL(checkpoint, Call(4)); | 154 |
| 152 EXPECT_CALL(*fetchDataLoaderClient, didFetchDataLoadedString(String("hello, world."))); | 155 InSequence s; |
| 153 EXPECT_CALL(*client, didFetchDataLoadFinishedFromDrainingStream()); | 156 EXPECT_CALL(checkpoint, Call(1)); |
| 154 EXPECT_CALL(checkpoint, Call(5)); | 157 EXPECT_CALL(*client, didFetchDataLoadedBlobHandleMock(_)).WillOnce(SaveArg<0 >(&blobDataHandle)); |
| 155 | 158 EXPECT_CALL(checkpoint, Call(2)); |
| 156 Persistent<BodyStreamBuffer> buffer = BodyStreamBuffer::create(createFetchDa taConsumerHandleFromWebHandle(src.release())); | 159 |
| 157 OwnPtr<DrainingBodyStreamBuffer> drainingBuffer = DrainingBodyStreamBuffer:: create(buffer, client); | 160 OwnPtr<ReplayingHandle> handle = ReplayingHandle::create(); |
| 158 checkpoint.Call(1); | 161 handle->add(Command(Command::Data, "hello")); |
| 159 drainingBuffer->startLoading(fetchDataLoader, fetchDataLoaderClient); | 162 handle->add(Command(Command::Done)); |
| 160 checkpoint.Call(2); | 163 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(handle.release())); |
| 161 drainingBuffer.clear(); | 164 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsBlob Handle("text/plain"), client); |
| 162 checkpoint.Call(3); | 165 |
| 163 // Loading continues as long as |buffer| is alive. | 166 EXPECT_TRUE(buffer->hasBody()); |
| 164 Heap::collectAllGarbage(); | 167 EXPECT_TRUE(buffer->isLocked()); |
| 165 checkpoint.Call(4); | 168 EXPECT_TRUE(buffer->hasPendingActivity()); |
| 166 testing::runPendingTasks(); | 169 |
| 167 checkpoint.Call(5); | 170 checkpoint.Call(1); |
| 171 testing::runPendingTasks(); | |
| 172 checkpoint.Call(2); | |
| 173 | |
| 174 EXPECT_TRUE(buffer->hasBody()); | |
| 175 EXPECT_FALSE(buffer->isLocked()); | |
| 176 EXPECT_FALSE(buffer->hasPendingActivity()); | |
| 177 EXPECT_EQ(5u, blobDataHandle->size()); | |
| 178 } | |
| 179 | |
| 180 TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsString) | |
| 181 { | |
| 182 Checkpoint checkpoint; | |
| 183 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); | |
| 184 | |
| 185 InSequence s; | |
| 186 EXPECT_CALL(checkpoint, Call(1)); | |
| 187 EXPECT_CALL(*client, didFetchDataLoadedString(String("hello"))); | |
| 188 EXPECT_CALL(checkpoint, Call(2)); | |
| 189 | |
| 190 OwnPtr<ReplayingHandle> handle = ReplayingHandle::create(); | |
| 191 handle->add(Command(Command::Data, "hello")); | |
| 192 handle->add(Command(Command::Done)); | |
| 193 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(handle.release())); | |
| 194 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client); | |
| 195 | |
| 196 EXPECT_TRUE(buffer->hasBody()); | |
| 197 EXPECT_TRUE(buffer->isLocked()); | |
| 198 EXPECT_TRUE(buffer->hasPendingActivity()); | |
| 199 | |
| 200 checkpoint.Call(1); | |
| 201 testing::runPendingTasks(); | |
| 202 checkpoint.Call(2); | |
| 203 | |
| 204 EXPECT_TRUE(buffer->hasBody()); | |
| 205 EXPECT_FALSE(buffer->isLocked()); | |
| 206 EXPECT_FALSE(buffer->hasPendingActivity()); | |
| 207 } | |
| 208 | |
| 209 TEST_F(BodyStreamBufferTest, LockClosedHandle) | |
| 210 { | |
| 211 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(createDoneDataConsumerHandle())); | |
| 212 | |
| 213 EXPECT_EQ(ReadableStream::Readable, buffer->stream()->stateInternal()); | |
| 214 testing::runPendingTasks(); | |
| 215 EXPECT_EQ(ReadableStream::Closed, buffer->stream()->stateInternal()); | |
| 216 | |
| 217 EXPECT_FALSE(buffer->isLocked()); | |
| 218 OwnPtr<FetchDataConsumerHandle> handle = buffer->lock(executionContext()); | |
| 219 EXPECT_FALSE(buffer->isLocked()); | |
| 220 OwnPtr<FetchDataConsumerHandle> handle2 = buffer->lock(executionContext()); | |
| 221 | |
| 222 EXPECT_TRUE(handle); | |
|
hiroshige
2015/07/25 05:27:35
nit optional: looks a little nicer if this is move
yhirano
2015/07/29 08:45:02
Done.
| |
| 223 EXPECT_TRUE(handle2); | |
| 224 EXPECT_FALSE(buffer->isLocked()); | |
| 225 EXPECT_TRUE(buffer->hasPendingActivity()); | |
| 226 EXPECT_TRUE(buffer->hasBody()); | |
| 227 } | |
| 228 | |
| 229 TEST_F(BodyStreamBufferTest, LoadClosedHandle) | |
| 230 { | |
| 231 Checkpoint checkpoint; | |
| 232 MockFetchDataLoaderClient* client1 = MockFetchDataLoaderClient::create(); | |
| 233 MockFetchDataLoaderClient* client2 = MockFetchDataLoaderClient::create(); | |
| 234 | |
| 235 InSequence s; | |
| 236 EXPECT_CALL(checkpoint, Call(1)); | |
| 237 EXPECT_CALL(*client1, didFetchDataLoadedString(String(""))); | |
| 238 EXPECT_CALL(*client2, didFetchDataLoadedString(String(""))); | |
| 239 EXPECT_CALL(checkpoint, Call(2)); | |
| 240 | |
| 241 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(createDoneDataConsumerHandle())); | |
| 242 | |
| 243 EXPECT_EQ(ReadableStream::Readable, buffer->stream()->stateInternal()); | |
| 244 testing::runPendingTasks(); | |
| 245 EXPECT_EQ(ReadableStream::Closed, buffer->stream()->stateInternal()); | |
| 246 | |
| 247 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client1); | |
| 248 EXPECT_FALSE(buffer->isLocked()); | |
| 249 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client2); | |
| 250 EXPECT_FALSE(buffer->isLocked()); | |
| 251 EXPECT_TRUE(buffer->hasPendingActivity()); | |
| 252 | |
| 253 checkpoint.Call(1); | |
| 254 testing::runPendingTasks(); | |
| 255 checkpoint.Call(2); | |
| 256 | |
| 257 EXPECT_FALSE(buffer->isLocked()); | |
| 258 EXPECT_FALSE(buffer->hasPendingActivity()); | |
| 259 } | |
| 260 | |
| 261 TEST_F(BodyStreamBufferTest, LockErroredHandle) | |
| 262 { | |
| 263 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(createUnexpectedErrorDataConsumerHandle())); | |
| 264 | |
| 265 EXPECT_EQ(ReadableStream::Readable, buffer->stream()->stateInternal()); | |
| 266 testing::runPendingTasks(); | |
| 267 EXPECT_EQ(ReadableStream::Errored, buffer->stream()->stateInternal()); | |
| 268 | |
| 269 EXPECT_FALSE(buffer->isLocked()); | |
| 270 OwnPtr<FetchDataConsumerHandle> handle = buffer->lock(executionContext()); | |
| 271 EXPECT_FALSE(buffer->isLocked()); | |
| 272 OwnPtr<FetchDataConsumerHandle> handle2 = buffer->lock(executionContext()); | |
| 273 | |
| 274 EXPECT_TRUE(handle); | |
|
hiroshige
2015/07/25 05:27:35
ditto.
yhirano
2015/07/29 08:45:02
Done.
| |
| 275 EXPECT_TRUE(handle2); | |
| 276 EXPECT_FALSE(buffer->isLocked()); | |
| 277 EXPECT_TRUE(buffer->hasPendingActivity()); | |
| 278 EXPECT_TRUE(buffer->hasBody()); | |
| 279 } | |
| 280 | |
| 281 TEST_F(BodyStreamBufferTest, LoadErroredHandle) | |
| 282 { | |
| 283 Checkpoint checkpoint; | |
| 284 MockFetchDataLoaderClient* client1 = MockFetchDataLoaderClient::create(); | |
| 285 MockFetchDataLoaderClient* client2 = MockFetchDataLoaderClient::create(); | |
| 286 | |
| 287 InSequence s; | |
| 288 EXPECT_CALL(checkpoint, Call(1)); | |
| 289 EXPECT_CALL(*client1, didFetchDataLoadFailed()); | |
| 290 EXPECT_CALL(*client2, didFetchDataLoadFailed()); | |
| 291 EXPECT_CALL(checkpoint, Call(2)); | |
| 292 | |
| 293 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(createUnexpectedErrorDataConsumerHandle())); | |
| 294 | |
| 295 EXPECT_EQ(ReadableStream::Readable, buffer->stream()->stateInternal()); | |
| 296 testing::runPendingTasks(); | |
| 297 EXPECT_EQ(ReadableStream::Errored, buffer->stream()->stateInternal()); | |
| 298 | |
| 299 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client1); | |
| 300 EXPECT_FALSE(buffer->isLocked()); | |
| 301 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client2); | |
| 302 EXPECT_FALSE(buffer->isLocked()); | |
| 303 EXPECT_TRUE(buffer->hasPendingActivity()); | |
| 304 | |
|
hiroshige
2015/07/25 05:27:35
If we call collectGarbase() here, can we test that
yhirano
2015/07/29 08:45:02
Yes, but I'm not sure if it should be tested. Gene
| |
| 305 checkpoint.Call(1); | |
| 306 testing::runPendingTasks(); | |
| 307 checkpoint.Call(2); | |
| 308 | |
| 309 EXPECT_FALSE(buffer->isLocked()); | |
| 310 EXPECT_FALSE(buffer->hasPendingActivity()); | |
| 168 } | 311 } |
| 169 | 312 |
| 170 } // namespace | 313 } // namespace |
| 171 | 314 |
| 172 } // namespace blink | 315 } // namespace blink |
| OLD | NEW |