OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ReadableStreamDataConsumerHandle.h" | 5 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
6 | 6 |
| 7 #include "bindings/core/v8/ReadableStreamOperations.h" |
7 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
8 #include "bindings/core/v8/V8BindingMacros.h" | 9 #include "bindings/core/v8/V8BindingMacros.h" |
| 10 #include "bindings/core/v8/V8GCController.h" |
9 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
10 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
11 #include "modules/fetch/DataConsumerHandleTestUtil.h" | 13 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
12 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
13 #include "platform/testing/UnitTestHelpers.h" | 15 #include "platform/testing/UnitTestHelpers.h" |
14 #include "public/platform/WebDataConsumerHandle.h" | 16 #include "public/platform/WebDataConsumerHandle.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 #include <v8.h> | 19 #include <v8.h> |
18 | 20 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 { | 73 { |
72 v8::TryCatch block(isolate()); | 74 v8::TryCatch block(isolate()); |
73 v8::MaybeLocal<v8::Value> r = eval(s); | 75 v8::MaybeLocal<v8::Value> r = eval(s); |
74 if (block.HasCaught()) { | 76 if (block.HasCaught()) { |
75 ADD_FAILURE() << toCoreString(block.Exception()->ToString(isolate())
).utf8().data(); | 77 ADD_FAILURE() << toCoreString(block.Exception()->ToString(isolate())
).utf8().data(); |
76 block.ReThrow(); | 78 block.ReThrow(); |
77 } | 79 } |
78 return r; | 80 return r; |
79 } | 81 } |
80 | 82 |
| 83 PassOwnPtr<ReadableStreamDataConsumerHandle> createHandle(ScriptValue stream
) |
| 84 { |
| 85 NonThrowableExceptionState es; |
| 86 ScriptValue reader = ReadableStreamOperations::getReader(scriptState(),
stream, es); |
| 87 ASSERT(!reader.isEmpty()); |
| 88 ASSERT(reader.v8Value()->IsObject()); |
| 89 return ReadableStreamDataConsumerHandle::create(scriptState(), reader); |
| 90 } |
| 91 |
| 92 void gc() { V8GCController::collectAllGarbageForTesting(isolate()); } |
| 93 |
81 private: | 94 private: |
82 OwnPtr<DummyPageHolder> m_page; | 95 OwnPtr<DummyPageHolder> m_page; |
83 }; | 96 }; |
84 | 97 |
85 TEST_F(ReadableStreamDataConsumerHandleTest, Create) | 98 TEST_F(ReadableStreamDataConsumerHandleTest, Create) |
86 { | 99 { |
87 ScriptState::Scope scope(scriptState()); | 100 ScriptState::Scope scope(scriptState()); |
88 ScriptValue stream(scriptState(), evalWithPrintingError("new ReadableStream"
)); | 101 ScriptValue stream(scriptState(), evalWithPrintingError("new ReadableStream"
)); |
89 ASSERT_FALSE(stream.isEmpty()); | 102 ASSERT_FALSE(stream.isEmpty()); |
90 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 103 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
91 ASSERT_TRUE(handle); | 104 ASSERT_TRUE(handle); |
92 MockClient* client = MockClient::create(); | 105 MockClient* client = MockClient::create(); |
93 Checkpoint checkpoint; | 106 Checkpoint checkpoint; |
94 | 107 |
95 InSequence s; | 108 InSequence s; |
96 EXPECT_CALL(checkpoint, Call(1)); | 109 EXPECT_CALL(checkpoint, Call(1)); |
97 EXPECT_CALL(*client, didGetReadable()); | 110 EXPECT_CALL(*client, didGetReadable()); |
98 EXPECT_CALL(checkpoint, Call(2)); | 111 EXPECT_CALL(checkpoint, Call(2)); |
99 | 112 |
100 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 113 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); |
101 ASSERT_TRUE(reader); | 114 ASSERT_TRUE(reader); |
102 checkpoint.Call(1); | 115 checkpoint.Call(1); |
103 testing::runPendingTasks(); | 116 testing::runPendingTasks(); |
104 checkpoint.Call(2); | 117 checkpoint.Call(2); |
105 } | 118 } |
106 | 119 |
107 TEST_F(ReadableStreamDataConsumerHandleTest, EmptyStream) | 120 TEST_F(ReadableStreamDataConsumerHandleTest, EmptyStream) |
108 { | 121 { |
109 ScriptState::Scope scope(scriptState()); | 122 ScriptState::Scope scope(scriptState()); |
110 ScriptValue stream(scriptState(), evalWithPrintingError( | 123 ScriptValue stream(scriptState(), evalWithPrintingError( |
111 "new ReadableStream({start: c => c.close()})")); | 124 "new ReadableStream({start: c => c.close()})")); |
112 ASSERT_FALSE(stream.isEmpty()); | 125 ASSERT_FALSE(stream.isEmpty()); |
113 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 126 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
114 ASSERT_TRUE(handle); | 127 ASSERT_TRUE(handle); |
115 MockClient* client = MockClient::create(); | 128 MockClient* client = MockClient::create(); |
116 Checkpoint checkpoint; | 129 Checkpoint checkpoint; |
117 | 130 |
118 InSequence s; | 131 InSequence s; |
119 EXPECT_CALL(checkpoint, Call(1)); | 132 EXPECT_CALL(checkpoint, Call(1)); |
120 EXPECT_CALL(*client, didGetReadable()); | 133 EXPECT_CALL(*client, didGetReadable()); |
121 EXPECT_CALL(checkpoint, Call(2)); | 134 EXPECT_CALL(checkpoint, Call(2)); |
122 EXPECT_CALL(*client, didGetReadable()); | 135 EXPECT_CALL(*client, didGetReadable()); |
123 EXPECT_CALL(checkpoint, Call(3)); | 136 EXPECT_CALL(checkpoint, Call(3)); |
(...skipping 10 matching lines...) Expand all Loading... |
134 checkpoint.Call(3); | 147 checkpoint.Call(3); |
135 EXPECT_EQ(kDone, reader->read(&c, 1, kNone, &readBytes)); | 148 EXPECT_EQ(kDone, reader->read(&c, 1, kNone, &readBytes)); |
136 } | 149 } |
137 | 150 |
138 TEST_F(ReadableStreamDataConsumerHandleTest, ErroredStream) | 151 TEST_F(ReadableStreamDataConsumerHandleTest, ErroredStream) |
139 { | 152 { |
140 ScriptState::Scope scope(scriptState()); | 153 ScriptState::Scope scope(scriptState()); |
141 ScriptValue stream(scriptState(), evalWithPrintingError( | 154 ScriptValue stream(scriptState(), evalWithPrintingError( |
142 "new ReadableStream({start: c => c.error()})")); | 155 "new ReadableStream({start: c => c.error()})")); |
143 ASSERT_FALSE(stream.isEmpty()); | 156 ASSERT_FALSE(stream.isEmpty()); |
144 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 157 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
145 ASSERT_TRUE(handle); | 158 ASSERT_TRUE(handle); |
146 MockClient* client = MockClient::create(); | 159 MockClient* client = MockClient::create(); |
147 Checkpoint checkpoint; | 160 Checkpoint checkpoint; |
148 | 161 |
149 InSequence s; | 162 InSequence s; |
150 EXPECT_CALL(checkpoint, Call(1)); | 163 EXPECT_CALL(checkpoint, Call(1)); |
151 EXPECT_CALL(*client, didGetReadable()); | 164 EXPECT_CALL(*client, didGetReadable()); |
152 EXPECT_CALL(checkpoint, Call(2)); | 165 EXPECT_CALL(checkpoint, Call(2)); |
153 EXPECT_CALL(*client, didGetReadable()); | 166 EXPECT_CALL(*client, didGetReadable()); |
154 EXPECT_CALL(checkpoint, Call(3)); | 167 EXPECT_CALL(checkpoint, Call(3)); |
(...skipping 15 matching lines...) Expand all Loading... |
170 { | 183 { |
171 ScriptState::Scope scope(scriptState()); | 184 ScriptState::Scope scope(scriptState()); |
172 ScriptValue stream(scriptState(), evalWithPrintingError( | 185 ScriptValue stream(scriptState(), evalWithPrintingError( |
173 "var controller;" | 186 "var controller;" |
174 "var stream = new ReadableStream({start: c => controller = c});" | 187 "var stream = new ReadableStream({start: c => controller = c});" |
175 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" | 188 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" |
176 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" | 189 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" |
177 "controller.close();" | 190 "controller.close();" |
178 "stream")); | 191 "stream")); |
179 ASSERT_FALSE(stream.isEmpty()); | 192 ASSERT_FALSE(stream.isEmpty()); |
180 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 193 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
181 ASSERT_TRUE(handle); | 194 ASSERT_TRUE(handle); |
182 MockClient* client = MockClient::create(); | 195 MockClient* client = MockClient::create(); |
183 Checkpoint checkpoint; | 196 Checkpoint checkpoint; |
184 | 197 |
185 InSequence s; | 198 InSequence s; |
186 EXPECT_CALL(checkpoint, Call(1)); | 199 EXPECT_CALL(checkpoint, Call(1)); |
187 EXPECT_CALL(*client, didGetReadable()); | 200 EXPECT_CALL(*client, didGetReadable()); |
188 EXPECT_CALL(checkpoint, Call(2)); | 201 EXPECT_CALL(checkpoint, Call(2)); |
189 EXPECT_CALL(*client, didGetReadable()); | 202 EXPECT_CALL(*client, didGetReadable()); |
190 EXPECT_CALL(checkpoint, Call(3)); | 203 EXPECT_CALL(checkpoint, Call(3)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 { | 245 { |
233 ScriptState::Scope scope(scriptState()); | 246 ScriptState::Scope scope(scriptState()); |
234 ScriptValue stream(scriptState(), evalWithPrintingError( | 247 ScriptValue stream(scriptState(), evalWithPrintingError( |
235 "var controller;" | 248 "var controller;" |
236 "var stream = new ReadableStream({start: c => controller = c});" | 249 "var stream = new ReadableStream({start: c => controller = c});" |
237 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" | 250 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" |
238 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" | 251 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" |
239 "controller.close();" | 252 "controller.close();" |
240 "stream")); | 253 "stream")); |
241 ASSERT_FALSE(stream.isEmpty()); | 254 ASSERT_FALSE(stream.isEmpty()); |
242 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 255 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
243 ASSERT_TRUE(handle); | 256 ASSERT_TRUE(handle); |
244 MockClient* client = MockClient::create(); | 257 MockClient* client = MockClient::create(); |
245 Checkpoint checkpoint; | 258 Checkpoint checkpoint; |
246 | 259 |
247 InSequence s; | 260 InSequence s; |
248 EXPECT_CALL(checkpoint, Call(1)); | 261 EXPECT_CALL(checkpoint, Call(1)); |
249 EXPECT_CALL(*client, didGetReadable()); | 262 EXPECT_CALL(*client, didGetReadable()); |
250 EXPECT_CALL(checkpoint, Call(2)); | 263 EXPECT_CALL(checkpoint, Call(2)); |
251 EXPECT_CALL(*client, didGetReadable()); | 264 EXPECT_CALL(*client, didGetReadable()); |
252 EXPECT_CALL(checkpoint, Call(3)); | 265 EXPECT_CALL(checkpoint, Call(3)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 EXPECT_EQ(0x48, static_cast<const char*>(buffer)[1]); | 307 EXPECT_EQ(0x48, static_cast<const char*>(buffer)[1]); |
295 EXPECT_EQ(0x49, static_cast<const char*>(buffer)[2]); | 308 EXPECT_EQ(0x49, static_cast<const char*>(buffer)[2]); |
296 EXPECT_EQ(0x4a, static_cast<const char*>(buffer)[3]); | 309 EXPECT_EQ(0x4a, static_cast<const char*>(buffer)[3]); |
297 EXPECT_EQ(kOk, reader->endRead(4)); | 310 EXPECT_EQ(kOk, reader->endRead(4)); |
298 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 311 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
299 testing::runPendingTasks(); | 312 testing::runPendingTasks(); |
300 checkpoint.Call(5); | 313 checkpoint.Call(5); |
301 EXPECT_EQ(kDone, reader->beginRead(&buffer, kNone, &available)); | 314 EXPECT_EQ(kDone, reader->beginRead(&buffer, kNone, &available)); |
302 } | 315 } |
303 | 316 |
304 TEST_F(ReadableStreamDataConsumerHandleTest, LockedStream) | 317 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueUndefined) |
305 { | 318 { |
306 ScriptState::Scope scope(scriptState()); | 319 ScriptState::Scope scope(scriptState()); |
307 ScriptValue stream(scriptState(), evalWithPrintingError( | 320 ScriptValue stream(scriptState(), evalWithPrintingError( |
308 "var stream = new ReadableStream;" | 321 "var controller;" |
309 "stream.getReader();" | 322 "var stream = new ReadableStream({start: c => controller = c});" |
| 323 "controller.enqueue(undefined);" |
| 324 "controller.close();" |
310 "stream")); | 325 "stream")); |
311 ASSERT_FALSE(stream.isEmpty()); | 326 ASSERT_FALSE(stream.isEmpty()); |
312 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 327 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
313 ASSERT_TRUE(handle); | 328 ASSERT_TRUE(handle); |
314 MockClient* client = MockClient::create(); | 329 MockClient* client = MockClient::create(); |
315 Checkpoint checkpoint; | 330 Checkpoint checkpoint; |
316 | 331 |
317 InSequence s; | 332 InSequence s; |
318 EXPECT_CALL(checkpoint, Call(1)); | 333 EXPECT_CALL(checkpoint, Call(1)); |
319 EXPECT_CALL(*client, didGetReadable()); | 334 EXPECT_CALL(*client, didGetReadable()); |
320 EXPECT_CALL(checkpoint, Call(2)); | 335 EXPECT_CALL(checkpoint, Call(2)); |
| 336 EXPECT_CALL(*client, didGetReadable()); |
| 337 EXPECT_CALL(checkpoint, Call(3)); |
321 | 338 |
322 char c; | 339 const void* buffer; |
323 size_t readBytes; | 340 size_t available; |
324 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 341 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); |
325 ASSERT_TRUE(reader); | 342 ASSERT_TRUE(reader); |
326 checkpoint.Call(1); | 343 checkpoint.Call(1); |
327 testing::runPendingTasks(); | 344 testing::runPendingTasks(); |
328 checkpoint.Call(2); | 345 checkpoint.Call(2); |
329 EXPECT_EQ(kUnexpectedError, reader->read(&c, 1, kNone, &readBytes)); | 346 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 347 testing::runPendingTasks(); |
| 348 checkpoint.Call(3); |
| 349 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
330 } | 350 } |
331 | 351 |
332 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueUndefined) | 352 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueNull) |
333 { | 353 { |
334 ScriptState::Scope scope(scriptState()); | 354 ScriptState::Scope scope(scriptState()); |
335 ScriptValue stream(scriptState(), evalWithPrintingError( | 355 ScriptValue stream(scriptState(), evalWithPrintingError( |
336 "var controller;" | 356 "var controller;" |
337 "var stream = new ReadableStream({start: c => controller = c});" | 357 "var stream = new ReadableStream({start: c => controller = c});" |
338 "controller.enqueue(undefined);" | 358 "controller.enqueue(null);" |
339 "controller.close();" | 359 "controller.close();" |
340 "stream")); | 360 "stream")); |
341 ASSERT_FALSE(stream.isEmpty()); | 361 ASSERT_FALSE(stream.isEmpty()); |
342 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 362 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
343 ASSERT_TRUE(handle); | 363 ASSERT_TRUE(handle); |
344 MockClient* client = MockClient::create(); | 364 MockClient* client = MockClient::create(); |
345 Checkpoint checkpoint; | 365 Checkpoint checkpoint; |
346 | 366 |
347 InSequence s; | 367 InSequence s; |
348 EXPECT_CALL(checkpoint, Call(1)); | 368 EXPECT_CALL(checkpoint, Call(1)); |
349 EXPECT_CALL(*client, didGetReadable()); | 369 EXPECT_CALL(*client, didGetReadable()); |
350 EXPECT_CALL(checkpoint, Call(2)); | 370 EXPECT_CALL(checkpoint, Call(2)); |
351 EXPECT_CALL(*client, didGetReadable()); | 371 EXPECT_CALL(*client, didGetReadable()); |
352 EXPECT_CALL(checkpoint, Call(3)); | 372 EXPECT_CALL(checkpoint, Call(3)); |
353 | 373 |
354 const void* buffer; | 374 const void* buffer; |
355 size_t available; | 375 size_t available; |
356 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 376 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); |
357 ASSERT_TRUE(reader); | 377 ASSERT_TRUE(reader); |
358 checkpoint.Call(1); | 378 checkpoint.Call(1); |
359 testing::runPendingTasks(); | 379 testing::runPendingTasks(); |
360 checkpoint.Call(2); | 380 checkpoint.Call(2); |
361 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 381 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
362 testing::runPendingTasks(); | 382 testing::runPendingTasks(); |
363 checkpoint.Call(3); | 383 checkpoint.Call(3); |
364 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 384 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
365 } | 385 } |
366 | 386 |
367 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueNull) | 387 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueString) |
368 { | 388 { |
369 ScriptState::Scope scope(scriptState()); | 389 ScriptState::Scope scope(scriptState()); |
370 ScriptValue stream(scriptState(), evalWithPrintingError( | 390 ScriptValue stream(scriptState(), evalWithPrintingError( |
371 "var controller;" | 391 "var controller;" |
372 "var stream = new ReadableStream({start: c => controller = c});" | 392 "var stream = new ReadableStream({start: c => controller = c});" |
373 "controller.enqueue(null);" | 393 "controller.enqueue('hello');" |
374 "controller.close();" | 394 "controller.close();" |
375 "stream")); | 395 "stream")); |
376 ASSERT_FALSE(stream.isEmpty()); | 396 ASSERT_FALSE(stream.isEmpty()); |
377 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | 397 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
378 ASSERT_TRUE(handle); | 398 ASSERT_TRUE(handle); |
379 MockClient* client = MockClient::create(); | 399 MockClient* client = MockClient::create(); |
380 Checkpoint checkpoint; | 400 Checkpoint checkpoint; |
381 | 401 |
382 InSequence s; | 402 InSequence s; |
383 EXPECT_CALL(checkpoint, Call(1)); | 403 EXPECT_CALL(checkpoint, Call(1)); |
384 EXPECT_CALL(*client, didGetReadable()); | 404 EXPECT_CALL(*client, didGetReadable()); |
385 EXPECT_CALL(checkpoint, Call(2)); | 405 EXPECT_CALL(checkpoint, Call(2)); |
386 EXPECT_CALL(*client, didGetReadable()); | 406 EXPECT_CALL(*client, didGetReadable()); |
387 EXPECT_CALL(checkpoint, Call(3)); | 407 EXPECT_CALL(checkpoint, Call(3)); |
388 | 408 |
389 const void* buffer; | 409 const void* buffer; |
390 size_t available; | 410 size_t available; |
391 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 411 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); |
392 ASSERT_TRUE(reader); | 412 ASSERT_TRUE(reader); |
393 checkpoint.Call(1); | 413 checkpoint.Call(1); |
394 testing::runPendingTasks(); | 414 testing::runPendingTasks(); |
395 checkpoint.Call(2); | 415 checkpoint.Call(2); |
396 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 416 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
397 testing::runPendingTasks(); | 417 testing::runPendingTasks(); |
398 checkpoint.Call(3); | 418 checkpoint.Call(3); |
399 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 419 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
400 } | 420 } |
401 | 421 |
402 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueString) | 422 TEST_F(ReadableStreamDataConsumerHandleTest, StreamReaderShouldBeWeak) |
403 { | 423 { |
404 ScriptState::Scope scope(scriptState()); | 424 OwnPtr<FetchDataConsumerHandle::Reader> reader; |
405 ScriptValue stream(scriptState(), evalWithPrintingError( | |
406 "var controller;" | |
407 "var stream = new ReadableStream({start: c => controller = c});" | |
408 "controller.enqueue('hello');" | |
409 "controller.close();" | |
410 "stream")); | |
411 ASSERT_FALSE(stream.isEmpty()); | |
412 OwnPtr<ReadableStreamDataConsumerHandle> handle = ReadableStreamDataConsumer
Handle::create(scriptState(), stream); | |
413 ASSERT_TRUE(handle); | |
414 MockClient* client = MockClient::create(); | |
415 Checkpoint checkpoint; | 425 Checkpoint checkpoint; |
| 426 Persistent<MockClient> client = MockClient::create(); |
| 427 ScriptValue stream; |
416 | 428 |
417 InSequence s; | 429 InSequence s; |
418 EXPECT_CALL(checkpoint, Call(1)); | 430 EXPECT_CALL(checkpoint, Call(1)); |
419 EXPECT_CALL(*client, didGetReadable()); | 431 EXPECT_CALL(*client, didGetReadable()); |
420 EXPECT_CALL(checkpoint, Call(2)); | 432 EXPECT_CALL(checkpoint, Call(2)); |
| 433 EXPECT_CALL(checkpoint, Call(3)); |
421 EXPECT_CALL(*client, didGetReadable()); | 434 EXPECT_CALL(*client, didGetReadable()); |
| 435 EXPECT_CALL(checkpoint, Call(4)); |
| 436 |
| 437 { |
| 438 // We need this scope to collect local handles. |
| 439 ScriptState::Scope scope(scriptState()); |
| 440 stream = ScriptValue(scriptState(), evalWithPrintingError("new ReadableS
tream()")); |
| 441 ASSERT_FALSE(stream.isEmpty()); |
| 442 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
| 443 ASSERT_TRUE(handle); |
| 444 |
| 445 reader = handle->obtainReader(client); |
| 446 ASSERT_TRUE(reader); |
| 447 } |
| 448 |
| 449 checkpoint.Call(1); |
| 450 testing::runPendingTasks(); |
| 451 checkpoint.Call(2); |
| 452 stream.clear(); |
| 453 gc(); |
| 454 checkpoint.Call(3); |
| 455 testing::runPendingTasks(); |
| 456 |
| 457 checkpoint.Call(4); |
| 458 const void* buffer; |
| 459 size_t available; |
| 460 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
| 461 } |
| 462 |
| 463 TEST_F(ReadableStreamDataConsumerHandleTest, StreamReaderShouldBeWeakWhenReading
) |
| 464 { |
| 465 OwnPtr<FetchDataConsumerHandle::Reader> reader; |
| 466 Checkpoint checkpoint; |
| 467 Persistent<MockClient> client = MockClient::create(); |
| 468 ScriptValue stream; |
| 469 |
| 470 InSequence s; |
| 471 EXPECT_CALL(checkpoint, Call(1)); |
| 472 EXPECT_CALL(*client, didGetReadable()); |
| 473 EXPECT_CALL(checkpoint, Call(2)); |
422 EXPECT_CALL(checkpoint, Call(3)); | 474 EXPECT_CALL(checkpoint, Call(3)); |
| 475 EXPECT_CALL(checkpoint, Call(4)); |
| 476 EXPECT_CALL(*client, didGetReadable()); |
| 477 EXPECT_CALL(checkpoint, Call(5)); |
| 478 |
| 479 { |
| 480 // We need this scope to collect local handles. |
| 481 ScriptState::Scope scope(scriptState()); |
| 482 stream = ScriptValue(scriptState(), evalWithPrintingError("new ReadableS
tream()")); |
| 483 ASSERT_FALSE(stream.isEmpty()); |
| 484 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); |
| 485 ASSERT_TRUE(handle); |
| 486 |
| 487 reader = handle->obtainReader(client); |
| 488 ASSERT_TRUE(reader); |
| 489 } |
423 | 490 |
424 const void* buffer; | 491 const void* buffer; |
425 size_t available; | 492 size_t available; |
426 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | |
427 ASSERT_TRUE(reader); | |
428 checkpoint.Call(1); | 493 checkpoint.Call(1); |
429 testing::runPendingTasks(); | 494 testing::runPendingTasks(); |
430 checkpoint.Call(2); | 495 checkpoint.Call(2); |
431 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 496 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 497 |
432 testing::runPendingTasks(); | 498 testing::runPendingTasks(); |
433 checkpoint.Call(3); | 499 checkpoint.Call(3); |
| 500 stream.clear(); |
| 501 gc(); |
| 502 checkpoint.Call(4); |
| 503 testing::runPendingTasks(); |
| 504 |
| 505 checkpoint.Call(5); |
434 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 506 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
435 } | 507 } |
436 | 508 |
437 } // namespace | 509 } // namespace |
438 | 510 |
439 } // namespace blink | 511 } // namespace blink |
440 | 512 |
OLD | NEW |