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