Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/ReadableStreamOperationsTest.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/ReadableStreamOperationsTest.cpp b/third_party/WebKit/Source/bindings/core/v8/ReadableStreamOperationsTest.cpp |
| index 97151473f77fa4024ab66ff8d688efa883df1554..224f9160c245257c2531e53a943ca8bb019e0073 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/ReadableStreamOperationsTest.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/ReadableStreamOperationsTest.cpp |
| @@ -5,15 +5,18 @@ |
| #include "bindings/core/v8/ReadableStreamOperations.h" |
| #include "bindings/core/v8/ExceptionState.h" |
| +#include "bindings/core/v8/ReadableStreamController.h" |
| #include "bindings/core/v8/ScriptFunction.h" |
| #include "bindings/core/v8/ScriptState.h" |
| #include "bindings/core/v8/ScriptValue.h" |
| +#include "bindings/core/v8/ScriptWrappable.h" |
| #include "bindings/core/v8/V8Binding.h" |
| #include "bindings/core/v8/V8BindingForTesting.h" |
| #include "bindings/core/v8/V8BindingMacros.h" |
| #include "bindings/core/v8/V8IteratorResultValue.h" |
| #include "bindings/core/v8/V8ThrowException.h" |
| #include "core/dom/Document.h" |
| +#include "core/streams/UnderlyingSourceBase.h" |
| #include "platform/heap/Handle.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include <v8.h> |
| @@ -110,6 +113,20 @@ private: |
| Member<Iteration> m_iteration; |
| }; |
| +class UnderlyingSourceTest final : public UnderlyingSourceBase { |
|
yhirano
2016/01/25 11:10:32
Can you rename this class to something like FakeUn
domenic
2016/02/02 22:59:55
done
|
| +public: |
| + UnderlyingSourceTest(ScriptState* scriptState) |
|
yhirano
2016/01/25 11:10:33
+explicit
domenic
2016/02/02 22:59:55
done
|
| + : UnderlyingSourceBase(scriptState) |
| + { |
| + } |
| + |
| + // Just expose the controller methods for easy testing |
| + void enqueue(ScriptValue v) { controller()->enqueue(v); } |
| + void close() { controller()->close(); } |
| + void error(ScriptValue e) { controller()->error(e); } |
| + double desiredSize() { return controller()->desiredSize(); } |
| +}; |
| + |
| class ReadableStreamOperationsTest : public ::testing::Test { |
| public: |
| ReadableStreamOperationsTest() |
| @@ -260,6 +277,63 @@ TEST_F(ReadableStreamOperationsTest, Read) |
| EXPECT_TRUE(it2->isDone()); |
| } |
| +TEST_F(ReadableStreamOperationsTest, CreateReadableStreamWithCustomUnderlyingSourceAndStrategy) |
| +{ |
| + auto underlyingSource = new UnderlyingSourceTest(scriptState()); |
| + |
| + ScriptValue strategy = ReadableStreamOperations::createCountQueuingStrategy(scriptState(), 10); |
| + ASSERT_FALSE(strategy.isEmpty()); |
| + |
| + ScriptValue stream = ReadableStreamOperations::createReadableStream(scriptState(), underlyingSource, strategy); |
| + ASSERT_FALSE(stream.isEmpty()); |
| + |
| + EXPECT_EQ(10, underlyingSource->desiredSize()); |
| + |
| + underlyingSource->enqueue(ScriptValue::from(scriptState(), "a")); |
| + EXPECT_EQ(9, underlyingSource->desiredSize()); |
| + |
| + underlyingSource->enqueue(ScriptValue::from(scriptState(), "b")); |
| + EXPECT_EQ(8, underlyingSource->desiredSize()); |
| + |
| + ScriptValue reader; |
| + { |
| + TrackExceptionState es; |
| + reader = ReadableStreamOperations::getReader(scriptState(), stream, es); |
| + ASSERT_FALSE(es.hadException()); |
| + } |
| + ASSERT_FALSE(reader.isEmpty()); |
| + |
| + Iteration* it1 = new Iteration(); |
| + Iteration* it2 = new Iteration(); |
| + Iteration* it3 = new Iteration(); |
| + ReadableStreamOperations::read(scriptState(), reader).then(Function::createFunction(scriptState(), it1), NotReached::createFunction(scriptState())); |
| + ReadableStreamOperations::read(scriptState(), reader).then(Function::createFunction(scriptState(), it2), NotReached::createFunction(scriptState())); |
| + ReadableStreamOperations::read(scriptState(), reader).then(Function::createFunction(scriptState(), it3), NotReached::createFunction(scriptState())); |
| + |
| + isolate()->RunMicrotasks(); |
| + |
| + EXPECT_EQ(10, underlyingSource->desiredSize()); |
| + |
| + EXPECT_TRUE(it1->isSet()); |
| + EXPECT_TRUE(it1->isValid()); |
| + EXPECT_FALSE(it1->isDone()); |
| + EXPECT_EQ("a", it1->value()); |
| + |
| + EXPECT_TRUE(it2->isSet()); |
| + EXPECT_TRUE(it2->isValid()); |
| + EXPECT_FALSE(it2->isDone()); |
| + EXPECT_EQ("b", it2->value()); |
| + |
| + EXPECT_FALSE(it3->isSet()); |
| + |
| + underlyingSource->close(); |
| + isolate()->RunMicrotasks(); |
| + |
| + EXPECT_TRUE(it3->isSet()); |
| + EXPECT_TRUE(it3->isValid()); |
| + EXPECT_TRUE(it3->isDone()); |
| +} |
| + |
| } // namespace |
| } // namespace blink |