| 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/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/V8BindingMacros.h" | 8 #include "bindings/core/v8/V8BindingMacros.h" |
| 9 #include "bindings/core/v8/V8GCController.h" | 9 #include "bindings/core/v8/V8GCController.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| 11 #include "core/streams/ReadableStreamOperations.h" | 11 #include "core/streams/ReadableStreamOperations.h" |
| 12 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
| 13 #include "modules/fetch/DataConsumerHandleTestUtil.h" | 13 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
| 14 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
| 15 #include "platform/testing/UnitTestHelpers.h" | 15 #include "platform/testing/UnitTestHelpers.h" |
| 16 #include "public/platform/WebDataConsumerHandle.h" | 16 #include "public/platform/WebDataConsumerHandle.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include <memory> |
| 19 #include <v8.h> | 20 #include <v8.h> |
| 20 | 21 |
| 21 // TODO(yhirano): Add cross-thread tests once the handle gets thread-safe. | 22 // TODO(yhirano): Add cross-thread tests once the handle gets thread-safe. |
| 22 namespace blink { | 23 namespace blink { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 using ::testing::InSequence; | 27 using ::testing::InSequence; |
| 27 using ::testing::StrictMock; | 28 using ::testing::StrictMock; |
| 28 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; | 29 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 { | 75 { |
| 75 v8::TryCatch block(isolate()); | 76 v8::TryCatch block(isolate()); |
| 76 v8::MaybeLocal<v8::Value> r = eval(s); | 77 v8::MaybeLocal<v8::Value> r = eval(s); |
| 77 if (block.HasCaught()) { | 78 if (block.HasCaught()) { |
| 78 ADD_FAILURE() << toCoreString(block.Exception()->ToString(isolate())
).utf8().data(); | 79 ADD_FAILURE() << toCoreString(block.Exception()->ToString(isolate())
).utf8().data(); |
| 79 block.ReThrow(); | 80 block.ReThrow(); |
| 80 } | 81 } |
| 81 return r; | 82 return r; |
| 82 } | 83 } |
| 83 | 84 |
| 84 PassOwnPtr<ReadableStreamDataConsumerHandle> createHandle(ScriptValue stream
) | 85 std::unique_ptr<ReadableStreamDataConsumerHandle> createHandle(ScriptValue s
tream) |
| 85 { | 86 { |
| 86 NonThrowableExceptionState es; | 87 NonThrowableExceptionState es; |
| 87 ScriptValue reader = ReadableStreamOperations::getReader(getScriptState(
), stream, es); | 88 ScriptValue reader = ReadableStreamOperations::getReader(getScriptState(
), stream, es); |
| 88 ASSERT(!reader.isEmpty()); | 89 ASSERT(!reader.isEmpty()); |
| 89 ASSERT(reader.v8Value()->IsObject()); | 90 ASSERT(reader.v8Value()->IsObject()); |
| 90 return ReadableStreamDataConsumerHandle::create(getScriptState(), reader
); | 91 return ReadableStreamDataConsumerHandle::create(getScriptState(), reader
); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void gc() { V8GCController::collectAllGarbageForTesting(isolate()); } | 94 void gc() { V8GCController::collectAllGarbageForTesting(isolate()); } |
| 94 | 95 |
| 95 private: | 96 private: |
| 96 OwnPtr<DummyPageHolder> m_page; | 97 std::unique_ptr<DummyPageHolder> m_page; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 TEST_F(ReadableStreamDataConsumerHandleTest, Create) | 100 TEST_F(ReadableStreamDataConsumerHandleTest, Create) |
| 100 { | 101 { |
| 101 ScriptState::Scope scope(getScriptState()); | 102 ScriptState::Scope scope(getScriptState()); |
| 102 ScriptValue stream(getScriptState(), evalWithPrintingError("new ReadableStre
am")); | 103 ScriptValue stream(getScriptState(), evalWithPrintingError("new ReadableStre
am")); |
| 103 ASSERT_FALSE(stream.isEmpty()); | 104 ASSERT_FALSE(stream.isEmpty()); |
| 104 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 105 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 105 ASSERT_TRUE(handle); | 106 ASSERT_TRUE(handle); |
| 106 Persistent<MockClient> client = MockClient::create(); | 107 Persistent<MockClient> client = MockClient::create(); |
| 107 Checkpoint checkpoint; | 108 Checkpoint checkpoint; |
| 108 | 109 |
| 109 InSequence s; | 110 InSequence s; |
| 110 EXPECT_CALL(checkpoint, Call(1)); | 111 EXPECT_CALL(checkpoint, Call(1)); |
| 111 EXPECT_CALL(*client, didGetReadable()); | 112 EXPECT_CALL(*client, didGetReadable()); |
| 112 EXPECT_CALL(checkpoint, Call(2)); | 113 EXPECT_CALL(checkpoint, Call(2)); |
| 113 | 114 |
| 114 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 115 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 115 ASSERT_TRUE(reader); | 116 ASSERT_TRUE(reader); |
| 116 checkpoint.Call(1); | 117 checkpoint.Call(1); |
| 117 testing::runPendingTasks(); | 118 testing::runPendingTasks(); |
| 118 checkpoint.Call(2); | 119 checkpoint.Call(2); |
| 119 } | 120 } |
| 120 | 121 |
| 121 TEST_F(ReadableStreamDataConsumerHandleTest, EmptyStream) | 122 TEST_F(ReadableStreamDataConsumerHandleTest, EmptyStream) |
| 122 { | 123 { |
| 123 ScriptState::Scope scope(getScriptState()); | 124 ScriptState::Scope scope(getScriptState()); |
| 124 ScriptValue stream(getScriptState(), evalWithPrintingError( | 125 ScriptValue stream(getScriptState(), evalWithPrintingError( |
| 125 "new ReadableStream({start: c => c.close()})")); | 126 "new ReadableStream({start: c => c.close()})")); |
| 126 ASSERT_FALSE(stream.isEmpty()); | 127 ASSERT_FALSE(stream.isEmpty()); |
| 127 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 128 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 128 ASSERT_TRUE(handle); | 129 ASSERT_TRUE(handle); |
| 129 Persistent<MockClient> client = MockClient::create(); | 130 Persistent<MockClient> client = MockClient::create(); |
| 130 Checkpoint checkpoint; | 131 Checkpoint checkpoint; |
| 131 | 132 |
| 132 InSequence s; | 133 InSequence s; |
| 133 EXPECT_CALL(checkpoint, Call(1)); | 134 EXPECT_CALL(checkpoint, Call(1)); |
| 134 EXPECT_CALL(*client, didGetReadable()); | 135 EXPECT_CALL(*client, didGetReadable()); |
| 135 EXPECT_CALL(checkpoint, Call(2)); | 136 EXPECT_CALL(checkpoint, Call(2)); |
| 136 EXPECT_CALL(*client, didGetReadable()); | 137 EXPECT_CALL(*client, didGetReadable()); |
| 137 EXPECT_CALL(checkpoint, Call(3)); | 138 EXPECT_CALL(checkpoint, Call(3)); |
| 138 | 139 |
| 139 char c; | 140 char c; |
| 140 size_t readBytes; | 141 size_t readBytes; |
| 141 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 142 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 142 ASSERT_TRUE(reader); | 143 ASSERT_TRUE(reader); |
| 143 checkpoint.Call(1); | 144 checkpoint.Call(1); |
| 144 testing::runPendingTasks(); | 145 testing::runPendingTasks(); |
| 145 checkpoint.Call(2); | 146 checkpoint.Call(2); |
| 146 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes)); | 147 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes)); |
| 147 testing::runPendingTasks(); | 148 testing::runPendingTasks(); |
| 148 checkpoint.Call(3); | 149 checkpoint.Call(3); |
| 149 EXPECT_EQ(kDone, reader->read(&c, 1, kNone, &readBytes)); | 150 EXPECT_EQ(kDone, reader->read(&c, 1, kNone, &readBytes)); |
| 150 } | 151 } |
| 151 | 152 |
| 152 TEST_F(ReadableStreamDataConsumerHandleTest, ErroredStream) | 153 TEST_F(ReadableStreamDataConsumerHandleTest, ErroredStream) |
| 153 { | 154 { |
| 154 ScriptState::Scope scope(getScriptState()); | 155 ScriptState::Scope scope(getScriptState()); |
| 155 ScriptValue stream(getScriptState(), evalWithPrintingError( | 156 ScriptValue stream(getScriptState(), evalWithPrintingError( |
| 156 "new ReadableStream({start: c => c.error()})")); | 157 "new ReadableStream({start: c => c.error()})")); |
| 157 ASSERT_FALSE(stream.isEmpty()); | 158 ASSERT_FALSE(stream.isEmpty()); |
| 158 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 159 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 159 ASSERT_TRUE(handle); | 160 ASSERT_TRUE(handle); |
| 160 Persistent<MockClient> client = MockClient::create(); | 161 Persistent<MockClient> client = MockClient::create(); |
| 161 Checkpoint checkpoint; | 162 Checkpoint checkpoint; |
| 162 | 163 |
| 163 InSequence s; | 164 InSequence s; |
| 164 EXPECT_CALL(checkpoint, Call(1)); | 165 EXPECT_CALL(checkpoint, Call(1)); |
| 165 EXPECT_CALL(*client, didGetReadable()); | 166 EXPECT_CALL(*client, didGetReadable()); |
| 166 EXPECT_CALL(checkpoint, Call(2)); | 167 EXPECT_CALL(checkpoint, Call(2)); |
| 167 EXPECT_CALL(*client, didGetReadable()); | 168 EXPECT_CALL(*client, didGetReadable()); |
| 168 EXPECT_CALL(checkpoint, Call(3)); | 169 EXPECT_CALL(checkpoint, Call(3)); |
| 169 | 170 |
| 170 char c; | 171 char c; |
| 171 size_t readBytes; | 172 size_t readBytes; |
| 172 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 173 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 173 ASSERT_TRUE(reader); | 174 ASSERT_TRUE(reader); |
| 174 checkpoint.Call(1); | 175 checkpoint.Call(1); |
| 175 testing::runPendingTasks(); | 176 testing::runPendingTasks(); |
| 176 checkpoint.Call(2); | 177 checkpoint.Call(2); |
| 177 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes)); | 178 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes)); |
| 178 testing::runPendingTasks(); | 179 testing::runPendingTasks(); |
| 179 checkpoint.Call(3); | 180 checkpoint.Call(3); |
| 180 EXPECT_EQ(kUnexpectedError, reader->read(&c, 1, kNone, &readBytes)); | 181 EXPECT_EQ(kUnexpectedError, reader->read(&c, 1, kNone, &readBytes)); |
| 181 } | 182 } |
| 182 | 183 |
| 183 TEST_F(ReadableStreamDataConsumerHandleTest, Read) | 184 TEST_F(ReadableStreamDataConsumerHandleTest, Read) |
| 184 { | 185 { |
| 185 ScriptState::Scope scope(getScriptState()); | 186 ScriptState::Scope scope(getScriptState()); |
| 186 ScriptValue stream(getScriptState(), evalWithPrintingError( | 187 ScriptValue stream(getScriptState(), evalWithPrintingError( |
| 187 "var controller;" | 188 "var controller;" |
| 188 "var stream = new ReadableStream({start: c => controller = c});" | 189 "var stream = new ReadableStream({start: c => controller = c});" |
| 189 "controller.enqueue(new Uint8Array());" | 190 "controller.enqueue(new Uint8Array());" |
| 190 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" | 191 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" |
| 191 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" | 192 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" |
| 192 "controller.close();" | 193 "controller.close();" |
| 193 "stream")); | 194 "stream")); |
| 194 ASSERT_FALSE(stream.isEmpty()); | 195 ASSERT_FALSE(stream.isEmpty()); |
| 195 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 196 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 196 ASSERT_TRUE(handle); | 197 ASSERT_TRUE(handle); |
| 197 Persistent<MockClient> client = MockClient::create(); | 198 Persistent<MockClient> client = MockClient::create(); |
| 198 Checkpoint checkpoint; | 199 Checkpoint checkpoint; |
| 199 | 200 |
| 200 InSequence s; | 201 InSequence s; |
| 201 EXPECT_CALL(checkpoint, Call(1)); | 202 EXPECT_CALL(checkpoint, Call(1)); |
| 202 EXPECT_CALL(*client, didGetReadable()); | 203 EXPECT_CALL(*client, didGetReadable()); |
| 203 EXPECT_CALL(checkpoint, Call(2)); | 204 EXPECT_CALL(checkpoint, Call(2)); |
| 204 EXPECT_CALL(*client, didGetReadable()); | 205 EXPECT_CALL(*client, didGetReadable()); |
| 205 EXPECT_CALL(checkpoint, Call(3)); | 206 EXPECT_CALL(checkpoint, Call(3)); |
| 206 EXPECT_CALL(*client, didGetReadable()); | 207 EXPECT_CALL(*client, didGetReadable()); |
| 207 EXPECT_CALL(checkpoint, Call(4)); | 208 EXPECT_CALL(checkpoint, Call(4)); |
| 208 EXPECT_CALL(*client, didGetReadable()); | 209 EXPECT_CALL(*client, didGetReadable()); |
| 209 EXPECT_CALL(checkpoint, Call(5)); | 210 EXPECT_CALL(checkpoint, Call(5)); |
| 210 EXPECT_CALL(*client, didGetReadable()); | 211 EXPECT_CALL(*client, didGetReadable()); |
| 211 EXPECT_CALL(checkpoint, Call(6)); | 212 EXPECT_CALL(checkpoint, Call(6)); |
| 212 | 213 |
| 213 char buffer[3]; | 214 char buffer[3]; |
| 214 size_t readBytes; | 215 size_t readBytes; |
| 215 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 216 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 216 ASSERT_TRUE(reader); | 217 ASSERT_TRUE(reader); |
| 217 checkpoint.Call(1); | 218 checkpoint.Call(1); |
| 218 testing::runPendingTasks(); | 219 testing::runPendingTasks(); |
| 219 checkpoint.Call(2); | 220 checkpoint.Call(2); |
| 220 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes)); | 221 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes)); |
| 221 testing::runPendingTasks(); | 222 testing::runPendingTasks(); |
| 222 checkpoint.Call(3); | 223 checkpoint.Call(3); |
| 223 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes)); | 224 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes)); |
| 224 testing::runPendingTasks(); | 225 testing::runPendingTasks(); |
| 225 checkpoint.Call(4); | 226 checkpoint.Call(4); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 253 ScriptState::Scope scope(getScriptState()); | 254 ScriptState::Scope scope(getScriptState()); |
| 254 ScriptValue stream(getScriptState(), evalWithPrintingError( | 255 ScriptValue stream(getScriptState(), evalWithPrintingError( |
| 255 "var controller;" | 256 "var controller;" |
| 256 "var stream = new ReadableStream({start: c => controller = c});" | 257 "var stream = new ReadableStream({start: c => controller = c});" |
| 257 "controller.enqueue(new Uint8Array());" | 258 "controller.enqueue(new Uint8Array());" |
| 258 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" | 259 "controller.enqueue(new Uint8Array([0x43, 0x44, 0x45, 0x46]));" |
| 259 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" | 260 "controller.enqueue(new Uint8Array([0x47, 0x48, 0x49, 0x4a]));" |
| 260 "controller.close();" | 261 "controller.close();" |
| 261 "stream")); | 262 "stream")); |
| 262 ASSERT_FALSE(stream.isEmpty()); | 263 ASSERT_FALSE(stream.isEmpty()); |
| 263 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 264 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 264 ASSERT_TRUE(handle); | 265 ASSERT_TRUE(handle); |
| 265 Persistent<MockClient> client = MockClient::create(); | 266 Persistent<MockClient> client = MockClient::create(); |
| 266 Checkpoint checkpoint; | 267 Checkpoint checkpoint; |
| 267 | 268 |
| 268 InSequence s; | 269 InSequence s; |
| 269 EXPECT_CALL(checkpoint, Call(1)); | 270 EXPECT_CALL(checkpoint, Call(1)); |
| 270 EXPECT_CALL(*client, didGetReadable()); | 271 EXPECT_CALL(*client, didGetReadable()); |
| 271 EXPECT_CALL(checkpoint, Call(2)); | 272 EXPECT_CALL(checkpoint, Call(2)); |
| 272 EXPECT_CALL(*client, didGetReadable()); | 273 EXPECT_CALL(*client, didGetReadable()); |
| 273 EXPECT_CALL(checkpoint, Call(3)); | 274 EXPECT_CALL(checkpoint, Call(3)); |
| 274 EXPECT_CALL(*client, didGetReadable()); | 275 EXPECT_CALL(*client, didGetReadable()); |
| 275 EXPECT_CALL(checkpoint, Call(4)); | 276 EXPECT_CALL(checkpoint, Call(4)); |
| 276 EXPECT_CALL(*client, didGetReadable()); | 277 EXPECT_CALL(*client, didGetReadable()); |
| 277 EXPECT_CALL(checkpoint, Call(5)); | 278 EXPECT_CALL(checkpoint, Call(5)); |
| 278 EXPECT_CALL(*client, didGetReadable()); | 279 EXPECT_CALL(*client, didGetReadable()); |
| 279 EXPECT_CALL(checkpoint, Call(6)); | 280 EXPECT_CALL(checkpoint, Call(6)); |
| 280 | 281 |
| 281 const void* buffer; | 282 const void* buffer; |
| 282 size_t available; | 283 size_t available; |
| 283 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 284 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 284 ASSERT_TRUE(reader); | 285 ASSERT_TRUE(reader); |
| 285 checkpoint.Call(1); | 286 checkpoint.Call(1); |
| 286 testing::runPendingTasks(); | 287 testing::runPendingTasks(); |
| 287 checkpoint.Call(2); | 288 checkpoint.Call(2); |
| 288 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 289 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 289 testing::runPendingTasks(); | 290 testing::runPendingTasks(); |
| 290 checkpoint.Call(3); | 291 checkpoint.Call(3); |
| 291 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 292 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 292 testing::runPendingTasks(); | 293 testing::runPendingTasks(); |
| 293 checkpoint.Call(4); | 294 checkpoint.Call(4); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueUndefined) | 331 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueUndefined) |
| 331 { | 332 { |
| 332 ScriptState::Scope scope(getScriptState()); | 333 ScriptState::Scope scope(getScriptState()); |
| 333 ScriptValue stream(getScriptState(), evalWithPrintingError( | 334 ScriptValue stream(getScriptState(), evalWithPrintingError( |
| 334 "var controller;" | 335 "var controller;" |
| 335 "var stream = new ReadableStream({start: c => controller = c});" | 336 "var stream = new ReadableStream({start: c => controller = c});" |
| 336 "controller.enqueue(undefined);" | 337 "controller.enqueue(undefined);" |
| 337 "controller.close();" | 338 "controller.close();" |
| 338 "stream")); | 339 "stream")); |
| 339 ASSERT_FALSE(stream.isEmpty()); | 340 ASSERT_FALSE(stream.isEmpty()); |
| 340 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 341 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 341 ASSERT_TRUE(handle); | 342 ASSERT_TRUE(handle); |
| 342 Persistent<MockClient> client = MockClient::create(); | 343 Persistent<MockClient> client = MockClient::create(); |
| 343 Checkpoint checkpoint; | 344 Checkpoint checkpoint; |
| 344 | 345 |
| 345 InSequence s; | 346 InSequence s; |
| 346 EXPECT_CALL(checkpoint, Call(1)); | 347 EXPECT_CALL(checkpoint, Call(1)); |
| 347 EXPECT_CALL(*client, didGetReadable()); | 348 EXPECT_CALL(*client, didGetReadable()); |
| 348 EXPECT_CALL(checkpoint, Call(2)); | 349 EXPECT_CALL(checkpoint, Call(2)); |
| 349 EXPECT_CALL(*client, didGetReadable()); | 350 EXPECT_CALL(*client, didGetReadable()); |
| 350 EXPECT_CALL(checkpoint, Call(3)); | 351 EXPECT_CALL(checkpoint, Call(3)); |
| 351 | 352 |
| 352 const void* buffer; | 353 const void* buffer; |
| 353 size_t available; | 354 size_t available; |
| 354 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 355 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 355 ASSERT_TRUE(reader); | 356 ASSERT_TRUE(reader); |
| 356 checkpoint.Call(1); | 357 checkpoint.Call(1); |
| 357 testing::runPendingTasks(); | 358 testing::runPendingTasks(); |
| 358 checkpoint.Call(2); | 359 checkpoint.Call(2); |
| 359 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 360 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 360 testing::runPendingTasks(); | 361 testing::runPendingTasks(); |
| 361 checkpoint.Call(3); | 362 checkpoint.Call(3); |
| 362 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 363 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
| 363 } | 364 } |
| 364 | 365 |
| 365 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueNull) | 366 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueNull) |
| 366 { | 367 { |
| 367 ScriptState::Scope scope(getScriptState()); | 368 ScriptState::Scope scope(getScriptState()); |
| 368 ScriptValue stream(getScriptState(), evalWithPrintingError( | 369 ScriptValue stream(getScriptState(), evalWithPrintingError( |
| 369 "var controller;" | 370 "var controller;" |
| 370 "var stream = new ReadableStream({start: c => controller = c});" | 371 "var stream = new ReadableStream({start: c => controller = c});" |
| 371 "controller.enqueue(null);" | 372 "controller.enqueue(null);" |
| 372 "controller.close();" | 373 "controller.close();" |
| 373 "stream")); | 374 "stream")); |
| 374 ASSERT_FALSE(stream.isEmpty()); | 375 ASSERT_FALSE(stream.isEmpty()); |
| 375 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 376 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 376 ASSERT_TRUE(handle); | 377 ASSERT_TRUE(handle); |
| 377 Persistent<MockClient> client = MockClient::create(); | 378 Persistent<MockClient> client = MockClient::create(); |
| 378 Checkpoint checkpoint; | 379 Checkpoint checkpoint; |
| 379 | 380 |
| 380 InSequence s; | 381 InSequence s; |
| 381 EXPECT_CALL(checkpoint, Call(1)); | 382 EXPECT_CALL(checkpoint, Call(1)); |
| 382 EXPECT_CALL(*client, didGetReadable()); | 383 EXPECT_CALL(*client, didGetReadable()); |
| 383 EXPECT_CALL(checkpoint, Call(2)); | 384 EXPECT_CALL(checkpoint, Call(2)); |
| 384 EXPECT_CALL(*client, didGetReadable()); | 385 EXPECT_CALL(*client, didGetReadable()); |
| 385 EXPECT_CALL(checkpoint, Call(3)); | 386 EXPECT_CALL(checkpoint, Call(3)); |
| 386 | 387 |
| 387 const void* buffer; | 388 const void* buffer; |
| 388 size_t available; | 389 size_t available; |
| 389 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 390 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 390 ASSERT_TRUE(reader); | 391 ASSERT_TRUE(reader); |
| 391 checkpoint.Call(1); | 392 checkpoint.Call(1); |
| 392 testing::runPendingTasks(); | 393 testing::runPendingTasks(); |
| 393 checkpoint.Call(2); | 394 checkpoint.Call(2); |
| 394 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 395 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 395 testing::runPendingTasks(); | 396 testing::runPendingTasks(); |
| 396 checkpoint.Call(3); | 397 checkpoint.Call(3); |
| 397 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 398 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
| 398 } | 399 } |
| 399 | 400 |
| 400 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueString) | 401 TEST_F(ReadableStreamDataConsumerHandleTest, EnqueueString) |
| 401 { | 402 { |
| 402 ScriptState::Scope scope(getScriptState()); | 403 ScriptState::Scope scope(getScriptState()); |
| 403 ScriptValue stream(getScriptState(), evalWithPrintingError( | 404 ScriptValue stream(getScriptState(), evalWithPrintingError( |
| 404 "var controller;" | 405 "var controller;" |
| 405 "var stream = new ReadableStream({start: c => controller = c});" | 406 "var stream = new ReadableStream({start: c => controller = c});" |
| 406 "controller.enqueue('hello');" | 407 "controller.enqueue('hello');" |
| 407 "controller.close();" | 408 "controller.close();" |
| 408 "stream")); | 409 "stream")); |
| 409 ASSERT_FALSE(stream.isEmpty()); | 410 ASSERT_FALSE(stream.isEmpty()); |
| 410 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 411 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre
am); |
| 411 ASSERT_TRUE(handle); | 412 ASSERT_TRUE(handle); |
| 412 Persistent<MockClient> client = MockClient::create(); | 413 Persistent<MockClient> client = MockClient::create(); |
| 413 Checkpoint checkpoint; | 414 Checkpoint checkpoint; |
| 414 | 415 |
| 415 InSequence s; | 416 InSequence s; |
| 416 EXPECT_CALL(checkpoint, Call(1)); | 417 EXPECT_CALL(checkpoint, Call(1)); |
| 417 EXPECT_CALL(*client, didGetReadable()); | 418 EXPECT_CALL(*client, didGetReadable()); |
| 418 EXPECT_CALL(checkpoint, Call(2)); | 419 EXPECT_CALL(checkpoint, Call(2)); |
| 419 EXPECT_CALL(*client, didGetReadable()); | 420 EXPECT_CALL(*client, didGetReadable()); |
| 420 EXPECT_CALL(checkpoint, Call(3)); | 421 EXPECT_CALL(checkpoint, Call(3)); |
| 421 | 422 |
| 422 const void* buffer; | 423 const void* buffer; |
| 423 size_t available; | 424 size_t available; |
| 424 OwnPtr<FetchDataConsumerHandle::Reader> reader = handle->obtainReader(client
); | 425 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead
er(client); |
| 425 ASSERT_TRUE(reader); | 426 ASSERT_TRUE(reader); |
| 426 checkpoint.Call(1); | 427 checkpoint.Call(1); |
| 427 testing::runPendingTasks(); | 428 testing::runPendingTasks(); |
| 428 checkpoint.Call(2); | 429 checkpoint.Call(2); |
| 429 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 430 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 430 testing::runPendingTasks(); | 431 testing::runPendingTasks(); |
| 431 checkpoint.Call(3); | 432 checkpoint.Call(3); |
| 432 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 433 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
| 433 } | 434 } |
| 434 | 435 |
| 435 TEST_F(ReadableStreamDataConsumerHandleTest, StreamReaderShouldBeWeak) | 436 TEST_F(ReadableStreamDataConsumerHandleTest, StreamReaderShouldBeWeak) |
| 436 { | 437 { |
| 437 OwnPtr<FetchDataConsumerHandle::Reader> reader; | 438 std::unique_ptr<FetchDataConsumerHandle::Reader> reader; |
| 438 Checkpoint checkpoint; | 439 Checkpoint checkpoint; |
| 439 Persistent<MockClient> client = MockClient::create(); | 440 Persistent<MockClient> client = MockClient::create(); |
| 440 ScriptValue stream; | 441 ScriptValue stream; |
| 441 | 442 |
| 442 InSequence s; | 443 InSequence s; |
| 443 EXPECT_CALL(checkpoint, Call(1)); | 444 EXPECT_CALL(checkpoint, Call(1)); |
| 444 EXPECT_CALL(*client, didGetReadable()); | 445 EXPECT_CALL(*client, didGetReadable()); |
| 445 EXPECT_CALL(checkpoint, Call(2)); | 446 EXPECT_CALL(checkpoint, Call(2)); |
| 446 EXPECT_CALL(checkpoint, Call(3)); | 447 EXPECT_CALL(checkpoint, Call(3)); |
| 447 EXPECT_CALL(*client, didGetReadable()); | 448 EXPECT_CALL(*client, didGetReadable()); |
| 448 EXPECT_CALL(checkpoint, Call(4)); | 449 EXPECT_CALL(checkpoint, Call(4)); |
| 449 | 450 |
| 450 { | 451 { |
| 451 // We need this scope to collect local handles. | 452 // We need this scope to collect local handles. |
| 452 ScriptState::Scope scope(getScriptState()); | 453 ScriptState::Scope scope(getScriptState()); |
| 453 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab
leStream()")); | 454 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab
leStream()")); |
| 454 ASSERT_FALSE(stream.isEmpty()); | 455 ASSERT_FALSE(stream.isEmpty()); |
| 455 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 456 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(
stream); |
| 456 ASSERT_TRUE(handle); | 457 ASSERT_TRUE(handle); |
| 457 | 458 |
| 458 reader = handle->obtainReader(client); | 459 reader = handle->obtainReader(client); |
| 459 ASSERT_TRUE(reader); | 460 ASSERT_TRUE(reader); |
| 460 } | 461 } |
| 461 | 462 |
| 462 checkpoint.Call(1); | 463 checkpoint.Call(1); |
| 463 testing::runPendingTasks(); | 464 testing::runPendingTasks(); |
| 464 checkpoint.Call(2); | 465 checkpoint.Call(2); |
| 465 stream.clear(); | 466 stream.clear(); |
| 466 gc(); | 467 gc(); |
| 467 checkpoint.Call(3); | 468 checkpoint.Call(3); |
| 468 testing::runPendingTasks(); | 469 testing::runPendingTasks(); |
| 469 | 470 |
| 470 checkpoint.Call(4); | 471 checkpoint.Call(4); |
| 471 const void* buffer; | 472 const void* buffer; |
| 472 size_t available; | 473 size_t available; |
| 473 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 474 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
| 474 } | 475 } |
| 475 | 476 |
| 476 TEST_F(ReadableStreamDataConsumerHandleTest, StreamReaderShouldBeWeakWhenReading
) | 477 TEST_F(ReadableStreamDataConsumerHandleTest, StreamReaderShouldBeWeakWhenReading
) |
| 477 { | 478 { |
| 478 OwnPtr<FetchDataConsumerHandle::Reader> reader; | 479 std::unique_ptr<FetchDataConsumerHandle::Reader> reader; |
| 479 Checkpoint checkpoint; | 480 Checkpoint checkpoint; |
| 480 Persistent<MockClient> client = MockClient::create(); | 481 Persistent<MockClient> client = MockClient::create(); |
| 481 ScriptValue stream; | 482 ScriptValue stream; |
| 482 | 483 |
| 483 InSequence s; | 484 InSequence s; |
| 484 EXPECT_CALL(checkpoint, Call(1)); | 485 EXPECT_CALL(checkpoint, Call(1)); |
| 485 EXPECT_CALL(*client, didGetReadable()); | 486 EXPECT_CALL(*client, didGetReadable()); |
| 486 EXPECT_CALL(checkpoint, Call(2)); | 487 EXPECT_CALL(checkpoint, Call(2)); |
| 487 EXPECT_CALL(checkpoint, Call(3)); | 488 EXPECT_CALL(checkpoint, Call(3)); |
| 488 EXPECT_CALL(checkpoint, Call(4)); | 489 EXPECT_CALL(checkpoint, Call(4)); |
| 489 EXPECT_CALL(*client, didGetReadable()); | 490 EXPECT_CALL(*client, didGetReadable()); |
| 490 EXPECT_CALL(checkpoint, Call(5)); | 491 EXPECT_CALL(checkpoint, Call(5)); |
| 491 | 492 |
| 492 { | 493 { |
| 493 // We need this scope to collect local handles. | 494 // We need this scope to collect local handles. |
| 494 ScriptState::Scope scope(getScriptState()); | 495 ScriptState::Scope scope(getScriptState()); |
| 495 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab
leStream()")); | 496 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab
leStream()")); |
| 496 ASSERT_FALSE(stream.isEmpty()); | 497 ASSERT_FALSE(stream.isEmpty()); |
| 497 OwnPtr<ReadableStreamDataConsumerHandle> handle = createHandle(stream); | 498 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(
stream); |
| 498 ASSERT_TRUE(handle); | 499 ASSERT_TRUE(handle); |
| 499 | 500 |
| 500 reader = handle->obtainReader(client); | 501 reader = handle->obtainReader(client); |
| 501 ASSERT_TRUE(reader); | 502 ASSERT_TRUE(reader); |
| 502 } | 503 } |
| 503 | 504 |
| 504 const void* buffer; | 505 const void* buffer; |
| 505 size_t available; | 506 size_t available; |
| 506 checkpoint.Call(1); | 507 checkpoint.Call(1); |
| 507 testing::runPendingTasks(); | 508 testing::runPendingTasks(); |
| 508 checkpoint.Call(2); | 509 checkpoint.Call(2); |
| 509 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); | 510 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); |
| 510 | 511 |
| 511 testing::runPendingTasks(); | 512 testing::runPendingTasks(); |
| 512 checkpoint.Call(3); | 513 checkpoint.Call(3); |
| 513 stream.clear(); | 514 stream.clear(); |
| 514 gc(); | 515 gc(); |
| 515 checkpoint.Call(4); | 516 checkpoint.Call(4); |
| 516 testing::runPendingTasks(); | 517 testing::runPendingTasks(); |
| 517 | 518 |
| 518 checkpoint.Call(5); | 519 checkpoint.Call(5); |
| 519 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); | 520 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); |
| 520 } | 521 } |
| 521 | 522 |
| 522 } // namespace | 523 } // namespace |
| 523 | 524 |
| 524 } // namespace blink | 525 } // namespace blink |
| 525 | 526 |
| OLD | NEW |