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 "core/streams/ReadableStream.h" | 6 #include "core/streams/ReadableStream.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
12 #include "core/dom/DOMArrayBuffer.h" | 12 #include "core/dom/DOMArrayBuffer.h" |
13 #include "core/dom/DOMException.h" | 13 #include "core/dom/DOMException.h" |
14 #include "core/dom/Document.h" | 14 #include "core/dom/Document.h" |
15 #include "core/dom/ExceptionCode.h" | 15 #include "core/dom/ExceptionCode.h" |
16 #include "core/streams/ReadableStreamImpl.h" | 16 #include "core/streams/ReadableStreamImpl.h" |
17 #include "core/streams/ReadableStreamReader.h" | 17 #include "core/streams/ReadableStreamReader.h" |
18 #include "core/streams/UnderlyingSource.h" | 18 #include "core/streams/UnderlyingSource.h" |
19 #include "core/testing/DummyPageHolder.h" | 19 #include "core/testing/DummyPageHolder.h" |
| 20 #include <gmock/gmock-more-actions.h> |
20 #include <gmock/gmock.h> | 21 #include <gmock/gmock.h> |
21 #include <gtest/gtest.h> | 22 #include <gtest/gtest.h> |
22 | 23 |
23 namespace blink { | 24 namespace blink { |
24 | 25 |
25 using ::testing::_; | 26 using ::testing::_; |
26 using ::testing::InSequence; | 27 using ::testing::InSequence; |
27 using ::testing::Invoke; | 28 using ::testing::Invoke; |
28 using ::testing::Return; | 29 using ::testing::Return; |
| 30 using ::testing::ReturnPointee; |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; | 34 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; |
33 using StringStream = ReadableStreamImpl<ReadableStreamChunkTypeTraits<String>>; | 35 using StringStream = ReadableStreamImpl<ReadableStreamChunkTypeTraits<String>>; |
34 | 36 |
35 class StringCapturingFunction : public ScriptFunction { | 37 class StringCapturingFunction : public ScriptFunction { |
36 public: | 38 public: |
37 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Stri
ng* value) | 39 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Stri
ng* value) |
38 { | 40 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }; | 100 }; |
99 | 101 |
100 } // unnamed namespace | 102 } // unnamed namespace |
101 | 103 |
102 // ReadableStream::read and some related functionalities are tested in | 104 // ReadableStream::read and some related functionalities are tested in |
103 // ReadableStreamReaderTest. | 105 // ReadableStreamReaderTest. |
104 class ReadableStreamTest : public ::testing::Test { | 106 class ReadableStreamTest : public ::testing::Test { |
105 public: | 107 public: |
106 ReadableStreamTest() | 108 ReadableStreamTest() |
107 : m_page(DummyPageHolder::create(IntSize(1, 1))) | 109 : m_page(DummyPageHolder::create(IntSize(1, 1))) |
108 , m_scope(scriptState()) | |
109 , m_underlyingSource(new ::testing::StrictMock<MockUnderlyingSource>) | 110 , m_underlyingSource(new ::testing::StrictMock<MockUnderlyingSource>) |
110 , m_exceptionState(ExceptionState::ConstructionContext, "property", "int
erface", scriptState()->context()->Global(), isolate()) | |
111 { | 111 { |
112 } | 112 } |
113 | 113 |
114 ~ReadableStreamTest() override | 114 ~ReadableStreamTest() override |
115 { | 115 { |
116 } | 116 } |
117 | 117 |
118 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } | 118 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } |
119 v8::Isolate* isolate() { return scriptState()->isolate(); } | 119 v8::Isolate* isolate() { return scriptState()->isolate(); } |
120 | 120 |
(...skipping 27 matching lines...) Expand all Loading... |
148 EXPECT_CALL(checkpoint, Call(1)); | 148 EXPECT_CALL(checkpoint, Call(1)); |
149 } | 149 } |
150 StringStream* stream = new StringStream(m_underlyingSource, new Permissi
veStrategy); | 150 StringStream* stream = new StringStream(m_underlyingSource, new Permissi
veStrategy); |
151 checkpoint.Call(0); | 151 checkpoint.Call(0); |
152 stream->didSourceStart(); | 152 stream->didSourceStart(); |
153 checkpoint.Call(1); | 153 checkpoint.Call(1); |
154 return stream; | 154 return stream; |
155 } | 155 } |
156 | 156 |
157 OwnPtr<DummyPageHolder> m_page; | 157 OwnPtr<DummyPageHolder> m_page; |
158 ScriptState::Scope m_scope; | |
159 Persistent<MockUnderlyingSource> m_underlyingSource; | 158 Persistent<MockUnderlyingSource> m_underlyingSource; |
160 ExceptionState m_exceptionState; | |
161 }; | 159 }; |
162 | 160 |
163 TEST_F(ReadableStreamTest, Start) | 161 TEST_F(ReadableStreamTest, Start) |
164 { | 162 { |
| 163 ScriptState::Scope scope(scriptState()); |
| 164 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
165 Checkpoint checkpoint; | 165 Checkpoint checkpoint; |
166 { | 166 { |
167 InSequence s; | 167 InSequence s; |
168 EXPECT_CALL(checkpoint, Call(0)); | 168 EXPECT_CALL(checkpoint, Call(0)); |
169 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | 169 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); |
170 EXPECT_CALL(checkpoint, Call(1)); | 170 EXPECT_CALL(checkpoint, Call(1)); |
171 } | 171 } |
172 | 172 |
173 StringStream* stream = new StringStream(m_underlyingSource); | 173 StringStream* stream = new StringStream(m_underlyingSource); |
174 EXPECT_FALSE(m_exceptionState.hadException()); | 174 EXPECT_FALSE(exceptionState.hadException()); |
175 EXPECT_FALSE(stream->isStarted()); | 175 EXPECT_FALSE(stream->isStarted()); |
176 EXPECT_FALSE(stream->isDraining()); | 176 EXPECT_FALSE(stream->isDraining()); |
177 EXPECT_FALSE(stream->isPulling()); | 177 EXPECT_FALSE(stream->isPulling()); |
178 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); | 178 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); |
179 | 179 |
180 checkpoint.Call(0); | 180 checkpoint.Call(0); |
181 stream->didSourceStart(); | 181 stream->didSourceStart(); |
182 checkpoint.Call(1); | 182 checkpoint.Call(1); |
183 | 183 |
184 EXPECT_TRUE(stream->isStarted()); | 184 EXPECT_TRUE(stream->isStarted()); |
185 EXPECT_FALSE(stream->isDraining()); | 185 EXPECT_FALSE(stream->isDraining()); |
186 EXPECT_TRUE(stream->isPulling()); | 186 EXPECT_TRUE(stream->isPulling()); |
187 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); | 187 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); |
188 | 188 |
189 // We need to call |error| in order to make | 189 // We need to call |error| in order to make |
190 // ActiveDOMObject::hasPendingActivity return false. | 190 // ActiveDOMObject::hasPendingActivity return false. |
191 stream->error(DOMException::create(AbortError, "done")); | 191 stream->error(DOMException::create(AbortError, "done")); |
192 } | 192 } |
193 | 193 |
194 TEST_F(ReadableStreamTest, StartFail) | 194 TEST_F(ReadableStreamTest, StartFail) |
195 { | 195 { |
| 196 ScriptState::Scope scope(scriptState()); |
| 197 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
196 StringStream* stream = new StringStream(m_underlyingSource); | 198 StringStream* stream = new StringStream(m_underlyingSource); |
197 EXPECT_FALSE(m_exceptionState.hadException()); | 199 EXPECT_FALSE(exceptionState.hadException()); |
198 EXPECT_FALSE(stream->isStarted()); | 200 EXPECT_FALSE(stream->isStarted()); |
199 EXPECT_FALSE(stream->isDraining()); | 201 EXPECT_FALSE(stream->isDraining()); |
200 EXPECT_FALSE(stream->isPulling()); | 202 EXPECT_FALSE(stream->isPulling()); |
201 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); | 203 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); |
202 | 204 |
203 stream->error(DOMException::create(NotFoundError)); | 205 stream->error(DOMException::create(NotFoundError)); |
204 | 206 |
205 EXPECT_FALSE(stream->isStarted()); | 207 EXPECT_FALSE(stream->isStarted()); |
206 EXPECT_FALSE(stream->isDraining()); | 208 EXPECT_FALSE(stream->isDraining()); |
207 EXPECT_FALSE(stream->isPulling()); | 209 EXPECT_FALSE(stream->isPulling()); |
208 EXPECT_EQ(stream->stateInternal(), ReadableStream::Errored); | 210 EXPECT_EQ(stream->stateInternal(), ReadableStream::Errored); |
209 } | 211 } |
210 | 212 |
211 TEST_F(ReadableStreamTest, ErrorAndEnqueue) | 213 TEST_F(ReadableStreamTest, ErrorAndEnqueue) |
212 { | 214 { |
| 215 ScriptState::Scope scope(scriptState()); |
| 216 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
213 StringStream* stream = construct(); | 217 StringStream* stream = construct(); |
214 | 218 |
215 stream->error(DOMException::create(NotFoundError, "error")); | 219 stream->error(DOMException::create(NotFoundError, "error")); |
216 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 220 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
217 | 221 |
218 bool result = stream->enqueue("hello"); | 222 bool result = stream->enqueue("hello"); |
219 EXPECT_FALSE(result); | 223 EXPECT_FALSE(result); |
220 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 224 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
221 } | 225 } |
222 | 226 |
223 TEST_F(ReadableStreamTest, CloseAndEnqueue) | 227 TEST_F(ReadableStreamTest, CloseAndEnqueue) |
224 { | 228 { |
| 229 ScriptState::Scope scope(scriptState()); |
| 230 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
225 StringStream* stream = construct(); | 231 StringStream* stream = construct(); |
226 | 232 |
227 stream->close(); | 233 stream->close(); |
228 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 234 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
229 | 235 |
230 bool result = stream->enqueue("hello"); | 236 bool result = stream->enqueue("hello"); |
231 EXPECT_FALSE(result); | 237 EXPECT_FALSE(result); |
232 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 238 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
233 } | 239 } |
234 | 240 |
235 TEST_F(ReadableStreamTest, CloseWhenErrored) | 241 TEST_F(ReadableStreamTest, CloseWhenErrored) |
236 { | 242 { |
| 243 ScriptState::Scope scope(scriptState()); |
| 244 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
237 StringStream* stream = construct(); | 245 StringStream* stream = construct(); |
238 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 246 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
239 | 247 |
240 stream->error(DOMException::create(NotFoundError, "error")); | 248 stream->error(DOMException::create(NotFoundError, "error")); |
241 stream->close(); | 249 stream->close(); |
242 | 250 |
243 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 251 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
244 } | 252 } |
245 | 253 |
246 TEST_F(ReadableStreamTest, ReadQueue) | 254 TEST_F(ReadableStreamTest, ReadQueue) |
247 { | 255 { |
| 256 ScriptState::Scope scope(scriptState()); |
| 257 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
248 StringStream* stream = construct(); | 258 StringStream* stream = construct(); |
249 Checkpoint checkpoint; | 259 Checkpoint checkpoint; |
250 | 260 |
251 { | 261 { |
252 InSequence s; | 262 InSequence s; |
253 EXPECT_CALL(checkpoint, Call(0)); | 263 EXPECT_CALL(checkpoint, Call(0)); |
254 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | 264 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); |
255 EXPECT_CALL(checkpoint, Call(1)); | 265 EXPECT_CALL(checkpoint, Call(1)); |
256 } | 266 } |
257 | 267 |
(...skipping 12 matching lines...) Expand all Loading... |
270 EXPECT_EQ(std::make_pair(String("hello"), static_cast<size_t>(5)), queue[0])
; | 280 EXPECT_EQ(std::make_pair(String("hello"), static_cast<size_t>(5)), queue[0])
; |
271 EXPECT_EQ(std::make_pair(String("bye"), static_cast<size_t>(3)), queue[1]); | 281 EXPECT_EQ(std::make_pair(String("bye"), static_cast<size_t>(3)), queue[1]); |
272 | 282 |
273 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 283 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
274 EXPECT_TRUE(stream->isPulling()); | 284 EXPECT_TRUE(stream->isPulling()); |
275 EXPECT_FALSE(stream->isDraining()); | 285 EXPECT_FALSE(stream->isDraining()); |
276 } | 286 } |
277 | 287 |
278 TEST_F(ReadableStreamTest, CloseWhenReadable) | 288 TEST_F(ReadableStreamTest, CloseWhenReadable) |
279 { | 289 { |
| 290 ScriptState::Scope scope(scriptState()); |
| 291 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
280 StringStream* stream = construct(); | 292 StringStream* stream = construct(); |
281 | 293 |
282 EXPECT_TRUE(stream->enqueue("hello")); | 294 EXPECT_TRUE(stream->enqueue("hello")); |
283 EXPECT_TRUE(stream->enqueue("bye")); | 295 EXPECT_TRUE(stream->enqueue("bye")); |
284 stream->close(); | 296 stream->close(); |
285 EXPECT_FALSE(stream->enqueue("should be ignored")); | 297 EXPECT_FALSE(stream->enqueue("should be ignored")); |
286 | 298 |
287 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 299 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
288 EXPECT_FALSE(stream->isPulling()); | 300 EXPECT_FALSE(stream->isPulling()); |
289 EXPECT_TRUE(stream->isDraining()); | 301 EXPECT_TRUE(stream->isDraining()); |
290 | 302 |
291 stream->read(scriptState()); | 303 stream->read(scriptState()); |
292 | 304 |
293 isolate()->RunMicrotasks(); | 305 isolate()->RunMicrotasks(); |
294 | 306 |
295 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 307 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
296 EXPECT_FALSE(stream->isPulling()); | 308 EXPECT_FALSE(stream->isPulling()); |
297 EXPECT_TRUE(stream->isDraining()); | 309 EXPECT_TRUE(stream->isDraining()); |
298 | 310 |
299 stream->read(scriptState()); | 311 stream->read(scriptState()); |
300 | 312 |
301 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 313 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
302 EXPECT_FALSE(stream->isPulling()); | 314 EXPECT_FALSE(stream->isPulling()); |
303 EXPECT_TRUE(stream->isDraining()); | 315 EXPECT_TRUE(stream->isDraining()); |
304 } | 316 } |
305 | 317 |
306 TEST_F(ReadableStreamTest, CancelWhenClosed) | 318 TEST_F(ReadableStreamTest, CancelWhenClosed) |
307 { | 319 { |
| 320 ScriptState::Scope scope(scriptState()); |
| 321 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
308 StringStream* stream = construct(); | 322 StringStream* stream = construct(); |
309 String onFulfilled, onRejected; | 323 String onFulfilled, onRejected; |
310 stream->close(); | 324 stream->close(); |
311 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 325 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
312 | 326 |
313 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); | 327 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); |
314 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 328 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
315 | 329 |
316 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | 330 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); |
317 EXPECT_TRUE(onFulfilled.isNull()); | 331 EXPECT_TRUE(onFulfilled.isNull()); |
318 EXPECT_TRUE(onRejected.isNull()); | 332 EXPECT_TRUE(onRejected.isNull()); |
319 | 333 |
320 isolate()->RunMicrotasks(); | 334 isolate()->RunMicrotasks(); |
321 EXPECT_EQ("undefined", onFulfilled); | 335 EXPECT_EQ("undefined", onFulfilled); |
322 EXPECT_TRUE(onRejected.isNull()); | 336 EXPECT_TRUE(onRejected.isNull()); |
323 } | 337 } |
324 | 338 |
325 TEST_F(ReadableStreamTest, CancelWhenErrored) | 339 TEST_F(ReadableStreamTest, CancelWhenErrored) |
326 { | 340 { |
| 341 ScriptState::Scope scope(scriptState()); |
| 342 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
327 StringStream* stream = construct(); | 343 StringStream* stream = construct(); |
328 String onFulfilled, onRejected; | 344 String onFulfilled, onRejected; |
329 stream->error(DOMException::create(NotFoundError, "error")); | 345 stream->error(DOMException::create(NotFoundError, "error")); |
330 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 346 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
331 | 347 |
332 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); | 348 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); |
333 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 349 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
334 | 350 |
335 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | 351 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); |
336 EXPECT_TRUE(onFulfilled.isNull()); | 352 EXPECT_TRUE(onFulfilled.isNull()); |
337 EXPECT_TRUE(onRejected.isNull()); | 353 EXPECT_TRUE(onRejected.isNull()); |
338 | 354 |
339 isolate()->RunMicrotasks(); | 355 isolate()->RunMicrotasks(); |
340 EXPECT_TRUE(onFulfilled.isNull()); | 356 EXPECT_TRUE(onFulfilled.isNull()); |
341 EXPECT_EQ("NotFoundError: error", onRejected); | 357 EXPECT_EQ("NotFoundError: error", onRejected); |
342 } | 358 } |
343 | 359 |
344 TEST_F(ReadableStreamTest, CancelWhenReadable) | 360 TEST_F(ReadableStreamTest, CancelWhenReadable) |
345 { | 361 { |
| 362 ScriptState::Scope scope(scriptState()); |
| 363 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
346 StringStream* stream = construct(); | 364 StringStream* stream = construct(); |
347 String onFulfilled, onRejected; | 365 String onFulfilled, onRejected; |
348 String onCancelFulfilled, onCancelRejected; | 366 String onCancelFulfilled, onCancelRejected; |
349 ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason
")); | 367 ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason
")); |
350 ScriptPromise promise = ScriptPromise::cast(scriptState(), v8String(scriptSt
ate()->isolate(), "hello")); | 368 ScriptPromise promise = ScriptPromise::cast(scriptState(), v8String(scriptSt
ate()->isolate(), "hello")); |
351 | 369 |
352 { | 370 { |
353 InSequence s; | 371 InSequence s; |
354 EXPECT_CALL(*m_underlyingSource, cancelSource(scriptState(), reason)).Wi
llOnce(Return(promise)); | 372 EXPECT_CALL(*m_underlyingSource, cancelSource(scriptState(), reason)).Wi
llOnce(ReturnPointee(&promise)); |
355 } | 373 } |
356 | 374 |
357 stream->enqueue("hello"); | 375 stream->enqueue("hello"); |
358 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 376 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
359 | 377 |
360 ScriptPromise cancelResult = stream->cancel(scriptState(), reason); | 378 ScriptPromise cancelResult = stream->cancel(scriptState(), reason); |
361 cancelResult.then(createCaptor(&onCancelFulfilled), createCaptor(&onCancelRe
jected)); | 379 cancelResult.then(createCaptor(&onCancelFulfilled), createCaptor(&onCancelRe
jected)); |
362 | 380 |
363 EXPECT_NE(promise, cancelResult); | 381 EXPECT_NE(promise, cancelResult); |
364 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 382 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
365 | 383 |
366 EXPECT_TRUE(onCancelFulfilled.isNull()); | 384 EXPECT_TRUE(onCancelFulfilled.isNull()); |
367 EXPECT_TRUE(onCancelRejected.isNull()); | 385 EXPECT_TRUE(onCancelRejected.isNull()); |
368 | 386 |
369 isolate()->RunMicrotasks(); | 387 isolate()->RunMicrotasks(); |
370 EXPECT_EQ("undefined", onCancelFulfilled); | 388 EXPECT_EQ("undefined", onCancelFulfilled); |
371 EXPECT_TRUE(onCancelRejected.isNull()); | 389 EXPECT_TRUE(onCancelRejected.isNull()); |
372 } | 390 } |
373 | 391 |
374 TEST_F(ReadableStreamTest, CancelWhenLocked) | 392 TEST_F(ReadableStreamTest, CancelWhenLocked) |
375 { | 393 { |
| 394 ScriptState::Scope scope(scriptState()); |
| 395 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
376 String onFulfilled, onRejected; | 396 String onFulfilled, onRejected; |
377 StringStream* stream = construct(); | 397 StringStream* stream = construct(); |
378 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), m_exceptionState); | 398 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), exceptionState); |
379 | 399 |
380 EXPECT_TRUE(reader->isActive()); | 400 EXPECT_TRUE(reader->isActive()); |
381 EXPECT_FALSE(m_exceptionState.hadException()); | 401 EXPECT_FALSE(exceptionState.hadException()); |
382 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 402 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
383 | 403 |
384 stream->cancel(scriptState(), ScriptValue(scriptState(), v8::Undefined(isola
te()))).then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | 404 stream->cancel(scriptState(), ScriptValue(scriptState(), v8::Undefined(isola
te()))).then(createCaptor(&onFulfilled), createCaptor(&onRejected)); |
385 | 405 |
386 EXPECT_TRUE(onFulfilled.isNull()); | 406 EXPECT_TRUE(onFulfilled.isNull()); |
387 EXPECT_TRUE(onRejected.isNull()); | 407 EXPECT_TRUE(onRejected.isNull()); |
388 | 408 |
389 isolate()->RunMicrotasks(); | 409 isolate()->RunMicrotasks(); |
390 | 410 |
391 EXPECT_TRUE(onFulfilled.isNull()); | 411 EXPECT_TRUE(onFulfilled.isNull()); |
392 EXPECT_EQ("TypeError: this stream is locked to a ReadableStreamReader", onRe
jected); | 412 EXPECT_EQ("TypeError: this stream is locked to a ReadableStreamReader", onRe
jected); |
393 EXPECT_TRUE(reader->isActive()); | 413 EXPECT_TRUE(reader->isActive()); |
394 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 414 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
395 } | 415 } |
396 | 416 |
397 TEST_F(ReadableStreamTest, ReadableArrayBufferStreamCompileTest) | 417 TEST_F(ReadableStreamTest, ReadableArrayBufferStreamCompileTest) |
398 { | 418 { |
| 419 ScriptState::Scope scope(scriptState()); |
| 420 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
399 // This test tests if ReadableStreamImpl<DOMArrayBuffer> can be | 421 // This test tests if ReadableStreamImpl<DOMArrayBuffer> can be |
400 // instantiated. | 422 // instantiated. |
401 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>(m_unde
rlyingSource); | 423 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>(m_unde
rlyingSource); |
402 } | 424 } |
403 | 425 |
404 TEST_F(ReadableStreamTest, ReadableArrayBufferViewStreamCompileTest) | 426 TEST_F(ReadableStreamTest, ReadableArrayBufferViewStreamCompileTest) |
405 { | 427 { |
| 428 ScriptState::Scope scope(scriptState()); |
| 429 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
406 // This test tests if ReadableStreamImpl<DOMArrayBufferVIew> can be | 430 // This test tests if ReadableStreamImpl<DOMArrayBufferVIew> can be |
407 // instantiated. | 431 // instantiated. |
408 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBufferView>>(m_
underlyingSource); | 432 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBufferView>>(m_
underlyingSource); |
409 } | 433 } |
410 | 434 |
411 TEST_F(ReadableStreamTest, BackpressureOnEnqueueing) | 435 TEST_F(ReadableStreamTest, BackpressureOnEnqueueing) |
412 { | 436 { |
| 437 ScriptState::Scope scope(scriptState()); |
| 438 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
413 auto strategy = MockStrategy::create(); | 439 auto strategy = MockStrategy::create(); |
414 Checkpoint checkpoint; | 440 Checkpoint checkpoint; |
415 | 441 |
416 StringStream* stream = construct(strategy); | 442 StringStream* stream = construct(strategy); |
417 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 443 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
418 | 444 |
419 { | 445 { |
420 InSequence s; | 446 InSequence s; |
421 EXPECT_CALL(checkpoint, Call(0)); | 447 EXPECT_CALL(checkpoint, Call(0)); |
422 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(1)
); | 448 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(1)
); |
(...skipping 12 matching lines...) Expand all Loading... |
435 checkpoint.Call(2); | 461 checkpoint.Call(2); |
436 result = stream->enqueue("world"); | 462 result = stream->enqueue("world"); |
437 checkpoint.Call(3); | 463 checkpoint.Call(3); |
438 EXPECT_FALSE(result); | 464 EXPECT_FALSE(result); |
439 | 465 |
440 stream->error(DOMException::create(AbortError, "done")); | 466 stream->error(DOMException::create(AbortError, "done")); |
441 } | 467 } |
442 | 468 |
443 TEST_F(ReadableStreamTest, BackpressureOnReading) | 469 TEST_F(ReadableStreamTest, BackpressureOnReading) |
444 { | 470 { |
| 471 ScriptState::Scope scope(scriptState()); |
| 472 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
445 auto strategy = MockStrategy::create(); | 473 auto strategy = MockStrategy::create(); |
446 Checkpoint checkpoint; | 474 Checkpoint checkpoint; |
447 | 475 |
448 StringStream* stream = construct(strategy); | 476 StringStream* stream = construct(strategy); |
449 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 477 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
450 | 478 |
451 { | 479 { |
452 InSequence s; | 480 InSequence s; |
453 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(2)
); | 481 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(2)
); |
454 EXPECT_CALL(*strategy, shouldApplyBackpressure(2, stream)).WillOnce(Retu
rn(false)); | 482 EXPECT_CALL(*strategy, shouldApplyBackpressure(2, stream)).WillOnce(Retu
rn(false)); |
(...skipping 28 matching lines...) Expand all Loading... |
483 checkpoint.Call(3); | 511 checkpoint.Call(3); |
484 stream->read(scriptState()); | 512 stream->read(scriptState()); |
485 checkpoint.Call(4); | 513 checkpoint.Call(4); |
486 | 514 |
487 stream->error(DOMException::create(AbortError, "done")); | 515 stream->error(DOMException::create(AbortError, "done")); |
488 } | 516 } |
489 | 517 |
490 // Note: Detailed tests are on ReadableStreamReaderTest. | 518 // Note: Detailed tests are on ReadableStreamReaderTest. |
491 TEST_F(ReadableStreamTest, ReadableStreamReader) | 519 TEST_F(ReadableStreamTest, ReadableStreamReader) |
492 { | 520 { |
| 521 ScriptState::Scope scope(scriptState()); |
| 522 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
493 StringStream* stream = construct(); | 523 StringStream* stream = construct(); |
494 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), m_exceptionState); | 524 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), exceptionState); |
495 | 525 |
496 ASSERT_TRUE(reader); | 526 ASSERT_TRUE(reader); |
497 EXPECT_FALSE(m_exceptionState.hadException()); | 527 EXPECT_FALSE(exceptionState.hadException()); |
498 EXPECT_TRUE(reader->isActive()); | 528 EXPECT_TRUE(reader->isActive()); |
499 EXPECT_TRUE(stream->isLockedTo(reader)); | 529 EXPECT_TRUE(stream->isLockedTo(reader)); |
500 | 530 |
501 ReadableStreamReader* another = stream->getReader(scriptState()->executionCo
ntext(), m_exceptionState); | 531 ReadableStreamReader* another = stream->getReader(scriptState()->executionCo
ntext(), exceptionState); |
502 ASSERT_EQ(nullptr, another); | 532 ASSERT_EQ(nullptr, another); |
503 EXPECT_TRUE(m_exceptionState.hadException()); | 533 EXPECT_TRUE(exceptionState.hadException()); |
504 EXPECT_TRUE(reader->isActive()); | 534 EXPECT_TRUE(reader->isActive()); |
505 EXPECT_TRUE(stream->isLockedTo(reader)); | 535 EXPECT_TRUE(stream->isLockedTo(reader)); |
506 } | 536 } |
507 | 537 |
508 TEST_F(ReadableStreamTest, GetClosedReader) | 538 TEST_F(ReadableStreamTest, GetClosedReader) |
509 { | 539 { |
| 540 ScriptState::Scope scope(scriptState()); |
| 541 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
510 StringStream* stream = construct(); | 542 StringStream* stream = construct(); |
511 stream->close(); | 543 stream->close(); |
512 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), m_exceptionState); | 544 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), exceptionState); |
513 | 545 |
514 ASSERT_TRUE(reader); | 546 ASSERT_TRUE(reader); |
515 EXPECT_FALSE(m_exceptionState.hadException()); | 547 EXPECT_FALSE(exceptionState.hadException()); |
516 | 548 |
517 String onFulfilled, onRejected; | 549 String onFulfilled, onRejected; |
518 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor(
&onRejected)); | 550 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor(
&onRejected)); |
519 | 551 |
520 EXPECT_FALSE(reader->isActive()); | 552 EXPECT_FALSE(reader->isActive()); |
521 EXPECT_TRUE(onFulfilled.isNull()); | 553 EXPECT_TRUE(onFulfilled.isNull()); |
522 EXPECT_TRUE(onRejected.isNull()); | 554 EXPECT_TRUE(onRejected.isNull()); |
523 | 555 |
524 isolate()->RunMicrotasks(); | 556 isolate()->RunMicrotasks(); |
525 EXPECT_EQ("undefined", onFulfilled); | 557 EXPECT_EQ("undefined", onFulfilled); |
526 EXPECT_TRUE(onRejected.isNull()); | 558 EXPECT_TRUE(onRejected.isNull()); |
527 } | 559 } |
528 | 560 |
529 TEST_F(ReadableStreamTest, GetErroredReader) | 561 TEST_F(ReadableStreamTest, GetErroredReader) |
530 { | 562 { |
| 563 ScriptState::Scope scope(scriptState()); |
| 564 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
531 StringStream* stream = construct(); | 565 StringStream* stream = construct(); |
532 stream->error(DOMException::create(SyntaxError, "some error")); | 566 stream->error(DOMException::create(SyntaxError, "some error")); |
533 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), m_exceptionState); | 567 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), exceptionState); |
534 | 568 |
535 ASSERT_TRUE(reader); | 569 ASSERT_TRUE(reader); |
536 EXPECT_FALSE(m_exceptionState.hadException()); | 570 EXPECT_FALSE(exceptionState.hadException()); |
537 | 571 |
538 String onFulfilled, onRejected; | 572 String onFulfilled, onRejected; |
539 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor(
&onRejected)); | 573 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor(
&onRejected)); |
540 | 574 |
541 EXPECT_FALSE(reader->isActive()); | 575 EXPECT_FALSE(reader->isActive()); |
542 EXPECT_TRUE(onFulfilled.isNull()); | 576 EXPECT_TRUE(onFulfilled.isNull()); |
543 EXPECT_TRUE(onRejected.isNull()); | 577 EXPECT_TRUE(onRejected.isNull()); |
544 | 578 |
545 isolate()->RunMicrotasks(); | 579 isolate()->RunMicrotasks(); |
546 EXPECT_TRUE(onFulfilled.isNull()); | 580 EXPECT_TRUE(onFulfilled.isNull()); |
547 EXPECT_EQ("SyntaxError: some error", onRejected); | 581 EXPECT_EQ("SyntaxError: some error", onRejected); |
548 } | 582 } |
549 | 583 |
550 TEST_F(ReadableStreamTest, StrictStrategy) | 584 TEST_F(ReadableStreamTest, StrictStrategy) |
551 { | 585 { |
| 586 ScriptState::Scope scope(scriptState()); |
| 587 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", scriptState()->context()->Global(), isolate()); |
552 Checkpoint checkpoint; | 588 Checkpoint checkpoint; |
553 { | 589 { |
554 InSequence s; | 590 InSequence s; |
555 EXPECT_CALL(checkpoint, Call(0)); | 591 EXPECT_CALL(checkpoint, Call(0)); |
556 EXPECT_CALL(checkpoint, Call(1)); | 592 EXPECT_CALL(checkpoint, Call(1)); |
557 EXPECT_CALL(*m_underlyingSource, pullSource()); | 593 EXPECT_CALL(*m_underlyingSource, pullSource()); |
558 EXPECT_CALL(checkpoint, Call(2)); | 594 EXPECT_CALL(checkpoint, Call(2)); |
559 EXPECT_CALL(checkpoint, Call(3)); | 595 EXPECT_CALL(checkpoint, Call(3)); |
560 EXPECT_CALL(*m_underlyingSource, pullSource()); | 596 EXPECT_CALL(*m_underlyingSource, pullSource()); |
561 EXPECT_CALL(checkpoint, Call(4)); | 597 EXPECT_CALL(checkpoint, Call(4)); |
562 EXPECT_CALL(checkpoint, Call(5)); | 598 EXPECT_CALL(checkpoint, Call(5)); |
563 EXPECT_CALL(checkpoint, Call(6)); | 599 EXPECT_CALL(checkpoint, Call(6)); |
564 EXPECT_CALL(checkpoint, Call(7)); | 600 EXPECT_CALL(checkpoint, Call(7)); |
565 EXPECT_CALL(checkpoint, Call(8)); | 601 EXPECT_CALL(checkpoint, Call(8)); |
566 EXPECT_CALL(checkpoint, Call(9)); | 602 EXPECT_CALL(checkpoint, Call(9)); |
567 EXPECT_CALL(*m_underlyingSource, pullSource()); | 603 EXPECT_CALL(*m_underlyingSource, pullSource()); |
568 } | 604 } |
569 StringStream* stream = new StringStream(m_underlyingSource, new StringStream
::StrictStrategy); | 605 StringStream* stream = new StringStream(m_underlyingSource, new StringStream
::StrictStrategy); |
570 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), m_exceptionState); | 606 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon
text(), exceptionState); |
571 | 607 |
572 checkpoint.Call(0); | 608 checkpoint.Call(0); |
573 stream->didSourceStart(); | 609 stream->didSourceStart(); |
574 | 610 |
575 checkpoint.Call(1); | 611 checkpoint.Call(1); |
576 EXPECT_FALSE(stream->isPulling()); | 612 EXPECT_FALSE(stream->isPulling()); |
577 reader->read(scriptState()); | 613 reader->read(scriptState()); |
578 EXPECT_TRUE(stream->isPulling()); | 614 EXPECT_TRUE(stream->isPulling()); |
579 checkpoint.Call(2); | 615 checkpoint.Call(2); |
580 stream->enqueue("hello"); | 616 stream->enqueue("hello"); |
(...skipping 17 matching lines...) Expand all Loading... |
598 reader->read(scriptState()); | 634 reader->read(scriptState()); |
599 EXPECT_FALSE(stream->isPulling()); | 635 EXPECT_FALSE(stream->isPulling()); |
600 checkpoint.Call(9); | 636 checkpoint.Call(9); |
601 reader->read(scriptState()); | 637 reader->read(scriptState()); |
602 EXPECT_TRUE(stream->isPulling()); | 638 EXPECT_TRUE(stream->isPulling()); |
603 | 639 |
604 stream->error(DOMException::create(AbortError, "done")); | 640 stream->error(DOMException::create(AbortError, "done")); |
605 } | 641 } |
606 | 642 |
607 } // namespace blink | 643 } // namespace blink |
OLD | NEW |