OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "modules/fetch/BlobBytesConsumer.h" | |
6 | |
7 #include "core/dom/Document.h" | |
8 #include "core/loader/ThreadableLoader.h" | |
9 #include "core/testing/DummyPageHolder.h" | |
10 #include "modules/fetch/BytesConsumerTestUtil.h" | |
11 #include "modules/fetch/DataConsumerHandleTestUtil.h" | |
12 #include "platform/blob/BlobData.h" | |
13 #include "platform/network/EncodedFormData.h" | |
14 #include "platform/network/ResourceError.h" | |
15 #include "platform/network/ResourceResponse.h" | |
16 #include "platform/testing/UnitTestHelpers.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 #include "wtf/Vector.h" | |
19 #include "wtf/text/WTFString.h" | |
20 | |
21 namespace blink { | |
22 | |
23 namespace { | |
24 | |
25 using Command = DataConsumerHandleTestUtil::Command; | |
26 using PublicState = BytesConsumer::PublicState; | |
27 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; | |
28 using Result = BytesConsumer::Result; | |
29 | |
30 String toString(const Vector<char>& v) | |
31 { | |
32 return String(v.data(), v.size()); | |
33 } | |
34 | |
35 class TestThreadableLoader : public ThreadableLoader { | |
36 public: | |
37 ~TestThreadableLoader() override | |
38 { | |
39 EXPECT_FALSE(m_shouldBeCancelled && !m_isCancelled) << "The loader shoul d be cancelled but is not cancelled."; | |
40 } | |
41 | |
42 void start(const ResourceRequest& request) override | |
43 { | |
44 m_isStarted = true; | |
45 } | |
46 | |
47 void overrideTimeout(unsigned long timeoutMilliseconds) override | |
48 { | |
49 ADD_FAILURE() << "overrideTimeout should not be called."; | |
50 } | |
51 | |
52 void cancel() override | |
53 { | |
54 m_isCancelled = true; | |
55 } | |
56 | |
57 bool isStarted() const { return m_isStarted; } | |
58 bool isCancelled() const { return m_isCancelled; } | |
59 void setShouldBeCancelled() { m_shouldBeCancelled = true; } | |
60 | |
61 private: | |
62 bool m_isStarted = false; | |
63 bool m_isCancelled = false; | |
64 bool m_shouldBeCancelled = false; | |
65 }; | |
66 | |
67 class TestClient final : public GarbageCollectedFinalized<TestClient>, public By tesConsumer::Client { | |
68 USING_GARBAGE_COLLECTED_MIXIN(TestClient); | |
69 public: | |
70 void onStateChange() override { ++m_numOnStateChangeCalled; } | |
71 int numOnStateChangeCalled() const { return m_numOnStateChangeCalled; } | |
72 | |
73 private: | |
74 int m_numOnStateChangeCalled = 0; | |
75 }; | |
76 | |
77 class BlobBytesConsumerTest : public ::testing::Test { | |
78 public: | |
79 BlobBytesConsumerTest() | |
80 : m_dummyPageHolder(DummyPageHolder::create(IntSize(1, 1))) {} | |
81 | |
82 Document& document() { return m_dummyPageHolder->document(); } | |
83 | |
84 private: | |
85 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | |
86 }; | |
87 | |
88 TEST_F(BlobBytesConsumerTest, Read) | |
89 { | |
90 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
91 TestThreadableLoader* loader = new TestThreadableLoader(); | |
92 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
93 std::unique_ptr<ReplayingHandle> src = ReplayingHandle::create(); | |
94 src->add(Command(Command::Data, "hello, ")); | |
95 src->add(Command(Command::Wait)); | |
96 src->add(Command(Command::Data, "world")); | |
97 src->add(Command(Command::Done)); | |
98 | |
99 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
100 EXPECT_FALSE(loader->isStarted()); | |
101 | |
102 char buffer[3]; | |
103 size_t read = 0; | |
104 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
105 EXPECT_TRUE(loader->isStarted()); | |
106 EXPECT_FALSE(consumer->drainAsBlobDataHandle(BytesConsumer::BlobSizePolicy:: AllowBlobWithInvalidSize)); | |
107 EXPECT_FALSE(consumer->drainAsFormData()); | |
108 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
109 | |
110 consumer->didReceiveResponse(0, ResourceResponse(), std::move(src)); | |
111 consumer->didFinishLoading(0, 0); | |
112 | |
113 auto result = (new BytesConsumerTestUtil::Reader(consumer))->run(); | |
114 EXPECT_EQ(Result::Done, result.first); | |
115 EXPECT_EQ("hello, world", toString(result.second)); | |
116 } | |
117 | |
118 TEST_F(BlobBytesConsumerTest, TwoPhaseRead) | |
119 { | |
120 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
121 TestThreadableLoader* loader = new TestThreadableLoader(); | |
122 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
123 std::unique_ptr<ReplayingHandle> src = ReplayingHandle::create(); | |
124 src->add(Command(Command::Data, "hello, ")); | |
125 src->add(Command(Command::Wait)); | |
126 src->add(Command(Command::Data, "world")); | |
127 src->add(Command(Command::Done)); | |
128 | |
129 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
130 EXPECT_FALSE(loader->isStarted()); | |
131 | |
132 char buffer[3]; | |
133 size_t read = 0; | |
134 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
135 EXPECT_TRUE(loader->isStarted()); | |
136 EXPECT_FALSE(consumer->drainAsBlobDataHandle(BytesConsumer::BlobSizePolicy:: AllowBlobWithInvalidSize)); | |
137 EXPECT_FALSE(consumer->drainAsFormData()); | |
138 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
139 | |
140 consumer->didReceiveResponse(0, ResourceResponse(), std::move(src)); | |
141 consumer->didFinishLoading(0, 0); | |
142 | |
143 auto result = (new BytesConsumerTestUtil::TwoPhaseReader(consumer))->run(); | |
144 EXPECT_EQ(Result::Done, result.first); | |
145 EXPECT_EQ("hello, world", toString(result.second)); | |
146 } | |
147 | |
148 TEST_F(BlobBytesConsumerTest, FailLoading) | |
149 { | |
150 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
151 TestThreadableLoader* loader = new TestThreadableLoader(); | |
152 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
153 TestClient* client = new TestClient(); | |
154 consumer->setClient(client); | |
155 | |
156 char buffer[3]; | |
157 size_t read = 0; | |
158 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
159 EXPECT_TRUE(loader->isStarted()); | |
160 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
161 | |
162 int numOnStateChangeCalled = client->numOnStateChangeCalled(); | |
163 consumer->didFail(ResourceError()); | |
164 | |
165 EXPECT_EQ(numOnStateChangeCalled + 1, client->numOnStateChangeCalled()); | |
166 EXPECT_EQ(PublicState::Errored, consumer->getPublicState()); | |
167 EXPECT_EQ(Result::Error, consumer->read(buffer, sizeof(buffer), &read)); | |
168 } | |
169 | |
170 TEST_F(BlobBytesConsumerTest, FailLoadingAfterResponseReceived) | |
171 { | |
172 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
173 TestThreadableLoader* loader = new TestThreadableLoader(); | |
174 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
175 TestClient* client = new TestClient(); | |
176 consumer->setClient(client); | |
177 | |
178 char buffer[3]; | |
179 size_t read = 0; | |
180 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
181 EXPECT_TRUE(loader->isStarted()); | |
182 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
183 | |
184 int numOnStateChangeCalled = client->numOnStateChangeCalled(); | |
185 consumer->didReceiveResponse(0, ResourceResponse(), createWaitingDataConsume rHandle()); | |
186 EXPECT_EQ(numOnStateChangeCalled + 1, client->numOnStateChangeCalled()); | |
187 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
188 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
189 | |
190 consumer->didFail(ResourceError()); | |
191 EXPECT_EQ(numOnStateChangeCalled + 2, client->numOnStateChangeCalled()); | |
192 EXPECT_EQ(PublicState::Errored, consumer->getPublicState()); | |
193 EXPECT_EQ(Result::Error, consumer->read(buffer, sizeof(buffer), &read)); | |
194 } | |
195 | |
196 TEST_F(BlobBytesConsumerTest, FailAccessControlCheck) | |
197 { | |
198 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
199 TestThreadableLoader* loader = new TestThreadableLoader(); | |
200 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
201 TestClient* client = new TestClient(); | |
202 consumer->setClient(client); | |
203 | |
204 char buffer[3]; | |
205 size_t read = 0; | |
206 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
207 EXPECT_TRUE(loader->isStarted()); | |
208 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
209 | |
210 int numOnStateChangeCalled = client->numOnStateChangeCalled(); | |
211 consumer->didFailAccessControlCheck(ResourceError()); | |
212 EXPECT_EQ(numOnStateChangeCalled + 1, client->numOnStateChangeCalled()); | |
213 | |
214 EXPECT_EQ(PublicState::Errored, consumer->getPublicState()); | |
215 EXPECT_EQ(Result::Error, consumer->read(buffer, sizeof(buffer), &read)); | |
216 } | |
217 | |
218 TEST_F(BlobBytesConsumerTest, FailRedirectCheck) | |
219 { | |
220 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
221 TestThreadableLoader* loader = new TestThreadableLoader(); | |
222 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
223 TestClient* client = new TestClient(); | |
224 consumer->setClient(client); | |
225 | |
226 char buffer[3]; | |
227 size_t read = 0; | |
228 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
229 EXPECT_TRUE(loader->isStarted()); | |
230 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
231 | |
232 int numOnStateChangeCalled = client->numOnStateChangeCalled(); | |
233 consumer->didFailRedirectCheck(); | |
234 EXPECT_EQ(numOnStateChangeCalled + 1, client->numOnStateChangeCalled()); | |
235 | |
236 EXPECT_EQ(Result::Error, consumer->read(buffer, sizeof(buffer), &read)); | |
237 } | |
238 | |
239 TEST_F(BlobBytesConsumerTest, CancelBeforeStarting) | |
240 { | |
241 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
242 TestThreadableLoader* loader = new TestThreadableLoader(); | |
243 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
244 TestClient* client = new TestClient(); | |
245 consumer->setClient(client); | |
246 | |
247 consumer->cancel(); | |
248 // This should be FALSE in production, but TRUE here because we set the | |
249 // loader before starting loading in tests. | |
250 EXPECT_TRUE(loader->isCancelled()); | |
251 | |
252 char buffer[3]; | |
253 size_t read = 0; | |
254 EXPECT_EQ(PublicState::Closed, consumer->getPublicState()); | |
255 EXPECT_EQ(Result::Done, consumer->read(buffer, sizeof(buffer), &read)); | |
256 EXPECT_FALSE(loader->isStarted()); | |
257 EXPECT_EQ(0, client->numOnStateChangeCalled()); | |
258 } | |
259 | |
260 TEST_F(BlobBytesConsumerTest, CancelAfterStarting) | |
261 { | |
262 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
263 TestThreadableLoader* loader = new TestThreadableLoader(); | |
264 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
265 TestClient* client = new TestClient(); | |
266 consumer->setClient(client); | |
267 | |
268 char buffer[3]; | |
269 size_t read = 0; | |
270 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
271 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
272 EXPECT_TRUE(loader->isStarted()); | |
273 EXPECT_EQ(0, client->numOnStateChangeCalled()); | |
274 | |
275 consumer->cancel(); | |
276 EXPECT_TRUE(loader->isCancelled()); | |
277 EXPECT_EQ(PublicState::Closed, consumer->getPublicState()); | |
278 EXPECT_EQ(Result::Done, consumer->read(buffer, sizeof(buffer), &read)); | |
279 EXPECT_EQ(0, client->numOnStateChangeCalled()); | |
280 } | |
281 | |
282 TEST_F(BlobBytesConsumerTest, ReadLastChunkBeforeDidFinishLoadingArrives) | |
283 { | |
284 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
285 TestThreadableLoader* loader = new TestThreadableLoader(); | |
286 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
287 TestClient* client = new TestClient(); | |
288 consumer->setClient(client); | |
289 std::unique_ptr<ReplayingHandle> src = ReplayingHandle::create(); | |
290 src->add(Command(Command::Data, "hello")); | |
291 src->add(Command(Command::Done)); | |
292 | |
293 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
294 EXPECT_FALSE(loader->isStarted()); | |
295 | |
296 char buffer[128]; | |
297 size_t read = 0; | |
298 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
299 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
300 EXPECT_TRUE(loader->isStarted()); | |
301 EXPECT_EQ(0, client->numOnStateChangeCalled()); | |
302 | |
303 consumer->didReceiveResponse(0, ResourceResponse(), std::move(src)); | |
304 EXPECT_EQ(1, client->numOnStateChangeCalled()); | |
305 testing::runPendingTasks(); | |
306 EXPECT_EQ(2, client->numOnStateChangeCalled()); | |
307 | |
308 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
309 EXPECT_EQ(Result::Ok, consumer->read(buffer, sizeof(buffer), &read)); | |
hiroshige
2016/09/13 08:35:44
How about testing |read| and the contents of |buff
yhirano
2016/09/14 07:33:25
Done.
| |
310 | |
311 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
312 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
313 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
314 | |
315 consumer->didFinishLoading(0, 0); | |
316 EXPECT_EQ(3, client->numOnStateChangeCalled()); | |
317 EXPECT_EQ(PublicState::Closed, consumer->getPublicState()); | |
318 EXPECT_EQ(Result::Done, consumer->read(buffer, sizeof(buffer), &read)); | |
319 } | |
320 | |
321 TEST_F(BlobBytesConsumerTest, ReadLastChunkAfterDidFinishLoadingArrives) | |
322 { | |
323 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
324 TestThreadableLoader* loader = new TestThreadableLoader(); | |
325 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
326 TestClient* client = new TestClient(); | |
327 consumer->setClient(client); | |
328 std::unique_ptr<ReplayingHandle> src = ReplayingHandle::create(); | |
329 src->add(Command(Command::Data, "hello")); | |
330 src->add(Command(Command::Done)); | |
331 | |
332 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
333 EXPECT_FALSE(loader->isStarted()); | |
334 | |
335 char buffer[128]; | |
336 size_t read = 0; | |
337 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
338 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &read)) ; | |
339 EXPECT_TRUE(loader->isStarted()); | |
340 EXPECT_EQ(0, client->numOnStateChangeCalled()); | |
341 | |
342 consumer->didReceiveResponse(0, ResourceResponse(), std::move(src)); | |
343 EXPECT_EQ(1, client->numOnStateChangeCalled()); | |
344 testing::runPendingTasks(); | |
345 EXPECT_EQ(2, client->numOnStateChangeCalled()); | |
346 | |
347 consumer->didFinishLoading(0, 0); | |
348 testing::runPendingTasks(); | |
349 EXPECT_EQ(2, client->numOnStateChangeCalled()); | |
350 | |
351 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
352 EXPECT_EQ(Result::Ok, consumer->read(buffer, sizeof(buffer), &read)); | |
hiroshige
2016/09/13 08:35:44
How about testing |read| and the contents of |buff
yhirano
2016/09/14 07:33:25
Done.
| |
353 | |
354 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
355 EXPECT_EQ(Result::Done, consumer->read(buffer, sizeof(buffer), &read)); | |
356 EXPECT_EQ(2, client->numOnStateChangeCalled()); | |
357 } | |
358 | |
359 TEST_F(BlobBytesConsumerTest, DrainAsBlobDataHandle) | |
360 { | |
361 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
362 TestThreadableLoader* loader = new TestThreadableLoader(); | |
363 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
364 | |
365 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
366 EXPECT_FALSE(loader->isStarted()); | |
367 | |
368 RefPtr<BlobDataHandle> result = consumer->drainAsBlobDataHandle(BytesConsume r::BlobSizePolicy::DisallowBlobWithInvalidSize); | |
369 ASSERT_TRUE(result); | |
370 EXPECT_FALSE(consumer->drainAsBlobDataHandle(BytesConsumer::BlobSizePolicy:: DisallowBlobWithInvalidSize)); | |
371 EXPECT_EQ(12345u, result->size()); | |
372 } | |
373 | |
374 | |
375 TEST_F(BlobBytesConsumerTest, DrainAsBlobDataHandle_2) | |
376 { | |
377 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), -1); | |
378 TestThreadableLoader* loader = new TestThreadableLoader(); | |
379 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
380 | |
381 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
382 EXPECT_FALSE(loader->isStarted()); | |
383 | |
384 RefPtr<BlobDataHandle> result = consumer->drainAsBlobDataHandle(BytesConsume r::BlobSizePolicy::AllowBlobWithInvalidSize); | |
385 ASSERT_TRUE(result); | |
386 EXPECT_FALSE(consumer->drainAsBlobDataHandle(BytesConsumer::BlobSizePolicy:: AllowBlobWithInvalidSize)); | |
387 EXPECT_EQ(UINT64_MAX, result->size()); | |
388 } | |
389 | |
390 TEST_F(BlobBytesConsumerTest, DrainAsBlobDataHandle_3) | |
391 { | |
392 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), -1); | |
393 TestThreadableLoader* loader = new TestThreadableLoader(); | |
394 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
395 | |
396 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
397 EXPECT_FALSE(loader->isStarted()); | |
398 | |
399 EXPECT_FALSE(consumer->drainAsBlobDataHandle(BytesConsumer::BlobSizePolicy:: DisallowBlobWithInvalidSize)); | |
400 } | |
401 | |
402 TEST_F(BlobBytesConsumerTest, DrainAsFormData) | |
403 { | |
404 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData::cre ate(), 12345); | |
405 TestThreadableLoader* loader = new TestThreadableLoader(); | |
406 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&document( ), blobDataHandle, loader); | |
407 | |
408 EXPECT_EQ(PublicState::ReadableOrWaiting, consumer->getPublicState()); | |
409 EXPECT_FALSE(loader->isStarted()); | |
410 | |
411 RefPtr<EncodedFormData> result = consumer->drainAsFormData(); | |
412 ASSERT_TRUE(result); | |
413 ASSERT_EQ(1u, result->elements().size()); | |
414 ASSERT_EQ(FormDataElement::encodedBlob, result->elements()[0].m_type); | |
415 ASSERT_TRUE(result->elements()[0].m_optionalBlobDataHandle); | |
416 EXPECT_EQ(12345u, result->elements()[0].m_optionalBlobDataHandle->size()); | |
417 EXPECT_EQ(blobDataHandle->uuid(), result->elements()[0].m_blobUUID); | |
418 } | |
419 | |
420 TEST_F(BlobBytesConsumerTest, LoaderShouldBeCancelled) | |
421 { | |
422 { | |
423 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(BlobData: :create(), 12345); | |
424 TestThreadableLoader* loader = new TestThreadableLoader(); | |
425 BlobBytesConsumer* consumer = BlobBytesConsumer::createForTesting(&docum ent(), blobDataHandle, loader); | |
426 | |
427 char buffer[3]; | |
428 size_t read = 0; | |
429 EXPECT_EQ(Result::ShouldWait, consumer->read(buffer, sizeof(buffer), &re ad)); | |
430 EXPECT_TRUE(loader->isStarted()); | |
431 loader->setShouldBeCancelled(); | |
432 } | |
433 ThreadState::current()->collectAllGarbage(); | |
434 } | |
435 | |
436 } // namespace | |
437 | |
438 } // namespace blink | |
OLD | NEW |