Пример #1
0
TEST_F(ReadableStreamTest, CancelWhenLocked)
{
    ScriptState::Scope scope(scriptState());
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "property", "interface", scriptState()->context()->Global(), isolate());
    String onFulfilled, onRejected;
    StringStream* stream = construct();
    ReadableStreamReader* reader = stream->getReader(scriptState()->executionContext(), exceptionState);

    EXPECT_TRUE(reader->isActive());
    EXPECT_FALSE(exceptionState.hadException());
    EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());

    EXPECT_FALSE(stream->isDisturbed());
    stream->cancel(scriptState(), ScriptValue(scriptState(), v8::Undefined(isolate()))).then(createCaptor(&onFulfilled), createCaptor(&onRejected));
    EXPECT_FALSE(stream->isDisturbed());

    EXPECT_TRUE(onFulfilled.isNull());
    EXPECT_TRUE(onRejected.isNull());

    isolate()->RunMicrotasks();

    EXPECT_TRUE(onFulfilled.isNull());
    EXPECT_EQ("TypeError: this stream is locked to a ReadableStreamReader", onRejected);
    EXPECT_TRUE(reader->isActive());
    EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
}
Пример #2
0
TEST_F(ReadableStreamTest, StrictStrategy)
{
    ScriptState::Scope scope(scriptState());
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "property", "interface", scriptState()->context()->Global(), isolate());
    Checkpoint checkpoint;
    {
        InSequence s;
        EXPECT_CALL(checkpoint, Call(0));
        EXPECT_CALL(checkpoint, Call(1));
        EXPECT_CALL(*m_underlyingSource, pullSource());
        EXPECT_CALL(checkpoint, Call(2));
        EXPECT_CALL(checkpoint, Call(3));
        EXPECT_CALL(*m_underlyingSource, pullSource());
        EXPECT_CALL(checkpoint, Call(4));
        EXPECT_CALL(checkpoint, Call(5));
        EXPECT_CALL(checkpoint, Call(6));
        EXPECT_CALL(checkpoint, Call(7));
        EXPECT_CALL(checkpoint, Call(8));
        EXPECT_CALL(checkpoint, Call(9));
        EXPECT_CALL(*m_underlyingSource, pullSource());
    }
    StringStream* stream = new StringStream(m_underlyingSource, new StringStream::StrictStrategy);
    ReadableStreamReader* reader = stream->getReader(scriptState()->executionContext(), exceptionState);

    checkpoint.Call(0);
    stream->didSourceStart();

    checkpoint.Call(1);
    EXPECT_FALSE(stream->isPulling());
    reader->read(scriptState());
    EXPECT_TRUE(stream->isPulling());
    checkpoint.Call(2);
    stream->enqueue("hello");
    EXPECT_FALSE(stream->isPulling());
    checkpoint.Call(3);
    reader->read(scriptState());
    EXPECT_TRUE(stream->isPulling());
    checkpoint.Call(4);
    reader->read(scriptState());
    EXPECT_TRUE(stream->isPulling());
    checkpoint.Call(5);
    stream->enqueue("hello");
    EXPECT_FALSE(stream->isPulling());
    checkpoint.Call(6);
    stream->enqueue("hello");
    EXPECT_FALSE(stream->isPulling());
    checkpoint.Call(7);
    stream->enqueue("hello");
    EXPECT_FALSE(stream->isPulling());
    checkpoint.Call(8);
    reader->read(scriptState());
    EXPECT_FALSE(stream->isPulling());
    checkpoint.Call(9);
    reader->read(scriptState());
    EXPECT_TRUE(stream->isPulling());

    stream->error(DOMException::create(AbortError, "done"));
}
Пример #3
0
// Note: Detailed tests are on ReadableStreamReaderTest.
TEST_F(ReadableStreamTest, ReadableStreamReader)
{
    ScriptState::Scope scope(scriptState());
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "property", "interface", scriptState()->context()->Global(), isolate());
    StringStream* stream = construct();
    ReadableStreamReader* reader = stream->getReader(scriptState()->executionContext(), exceptionState);

    ASSERT_TRUE(reader);
    EXPECT_FALSE(exceptionState.hadException());
    EXPECT_TRUE(reader->isActive());
    EXPECT_TRUE(stream->isLockedTo(reader));

    ReadableStreamReader* another = stream->getReader(scriptState()->executionContext(), exceptionState);
    ASSERT_EQ(nullptr, another);
    EXPECT_TRUE(exceptionState.hadException());
    EXPECT_TRUE(reader->isActive());
    EXPECT_TRUE(stream->isLockedTo(reader));
}
Пример #4
0
TEST_F(ReadableStreamTest, GetErroredReader)
{
    ScriptState::Scope scope(scriptState());
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "property", "interface", scriptState()->context()->Global(), isolate());
    StringStream* stream = construct();
    stream->error(DOMException::create(SyntaxError, "some error"));
    ReadableStreamReader* reader = stream->getReader(scriptState()->executionContext(), exceptionState);

    ASSERT_TRUE(reader);
    EXPECT_FALSE(exceptionState.hadException());

    String onFulfilled, onRejected;
    reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor(&onRejected));

    EXPECT_FALSE(reader->isActive());
    EXPECT_TRUE(onFulfilled.isNull());
    EXPECT_TRUE(onRejected.isNull());

    isolate()->RunMicrotasks();
    EXPECT_TRUE(onFulfilled.isNull());
    EXPECT_EQ("SyntaxError: some error", onRejected);
}