Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: third_party/WebKit/Source/modules/fetch/ReadableStreamDataConsumerHandleTest.cpp

Issue 2172183003: Return unique_ptr<WebDataConsumerHandle::Reader> directly from obtainReader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gmock_cxx11
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre am); 105 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre am);
106 ASSERT_TRUE(handle); 106 ASSERT_TRUE(handle);
107 Persistent<MockClient> client = MockClient::create(); 107 Persistent<MockClient> client = MockClient::create();
108 Checkpoint checkpoint; 108 Checkpoint checkpoint;
109 109
110 InSequence s; 110 InSequence s;
111 EXPECT_CALL(checkpoint, Call(1)); 111 EXPECT_CALL(checkpoint, Call(1));
112 EXPECT_CALL(*client, didGetReadable()); 112 EXPECT_CALL(*client, didGetReadable());
113 EXPECT_CALL(checkpoint, Call(2)); 113 EXPECT_CALL(checkpoint, Call(2));
114 114
115 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 115 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
116 ASSERT_TRUE(reader); 116 ASSERT_TRUE(reader);
117 checkpoint.Call(1); 117 checkpoint.Call(1);
118 testing::runPendingTasks(); 118 testing::runPendingTasks();
119 checkpoint.Call(2); 119 checkpoint.Call(2);
120 } 120 }
121 121
122 TEST_F(ReadableStreamDataConsumerHandleTest, EmptyStream) 122 TEST_F(ReadableStreamDataConsumerHandleTest, EmptyStream)
123 { 123 {
124 ScriptState::Scope scope(getScriptState()); 124 ScriptState::Scope scope(getScriptState());
125 ScriptValue stream(getScriptState(), evalWithPrintingError( 125 ScriptValue stream(getScriptState(), evalWithPrintingError(
126 "new ReadableStream({start: c => c.close()})")); 126 "new ReadableStream({start: c => c.close()})"));
127 ASSERT_FALSE(stream.isEmpty()); 127 ASSERT_FALSE(stream.isEmpty());
128 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre am); 128 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle(stre am);
129 ASSERT_TRUE(handle); 129 ASSERT_TRUE(handle);
130 Persistent<MockClient> client = MockClient::create(); 130 Persistent<MockClient> client = MockClient::create();
131 Checkpoint checkpoint; 131 Checkpoint checkpoint;
132 132
133 InSequence s; 133 InSequence s;
134 EXPECT_CALL(checkpoint, Call(1)); 134 EXPECT_CALL(checkpoint, Call(1));
135 EXPECT_CALL(*client, didGetReadable()); 135 EXPECT_CALL(*client, didGetReadable());
136 EXPECT_CALL(checkpoint, Call(2)); 136 EXPECT_CALL(checkpoint, Call(2));
137 EXPECT_CALL(*client, didGetReadable()); 137 EXPECT_CALL(*client, didGetReadable());
138 EXPECT_CALL(checkpoint, Call(3)); 138 EXPECT_CALL(checkpoint, Call(3));
139 139
140 char c; 140 char c;
141 size_t readBytes; 141 size_t readBytes;
142 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 142 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
143 ASSERT_TRUE(reader); 143 ASSERT_TRUE(reader);
144 checkpoint.Call(1); 144 checkpoint.Call(1);
145 testing::runPendingTasks(); 145 testing::runPendingTasks();
146 checkpoint.Call(2); 146 checkpoint.Call(2);
147 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes)); 147 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes));
148 testing::runPendingTasks(); 148 testing::runPendingTasks();
149 checkpoint.Call(3); 149 checkpoint.Call(3);
150 EXPECT_EQ(kDone, reader->read(&c, 1, kNone, &readBytes)); 150 EXPECT_EQ(kDone, reader->read(&c, 1, kNone, &readBytes));
151 } 151 }
152 152
(...skipping 10 matching lines...) Expand all
163 163
164 InSequence s; 164 InSequence s;
165 EXPECT_CALL(checkpoint, Call(1)); 165 EXPECT_CALL(checkpoint, Call(1));
166 EXPECT_CALL(*client, didGetReadable()); 166 EXPECT_CALL(*client, didGetReadable());
167 EXPECT_CALL(checkpoint, Call(2)); 167 EXPECT_CALL(checkpoint, Call(2));
168 EXPECT_CALL(*client, didGetReadable()); 168 EXPECT_CALL(*client, didGetReadable());
169 EXPECT_CALL(checkpoint, Call(3)); 169 EXPECT_CALL(checkpoint, Call(3));
170 170
171 char c; 171 char c;
172 size_t readBytes; 172 size_t readBytes;
173 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 173 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
174 ASSERT_TRUE(reader); 174 ASSERT_TRUE(reader);
175 checkpoint.Call(1); 175 checkpoint.Call(1);
176 testing::runPendingTasks(); 176 testing::runPendingTasks();
177 checkpoint.Call(2); 177 checkpoint.Call(2);
178 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes)); 178 EXPECT_EQ(kShouldWait, reader->read(&c, 1, kNone, &readBytes));
179 testing::runPendingTasks(); 179 testing::runPendingTasks();
180 checkpoint.Call(3); 180 checkpoint.Call(3);
181 EXPECT_EQ(kUnexpectedError, reader->read(&c, 1, kNone, &readBytes)); 181 EXPECT_EQ(kUnexpectedError, reader->read(&c, 1, kNone, &readBytes));
182 } 182 }
183 183
(...skipping 22 matching lines...) Expand all
206 EXPECT_CALL(checkpoint, Call(3)); 206 EXPECT_CALL(checkpoint, Call(3));
207 EXPECT_CALL(*client, didGetReadable()); 207 EXPECT_CALL(*client, didGetReadable());
208 EXPECT_CALL(checkpoint, Call(4)); 208 EXPECT_CALL(checkpoint, Call(4));
209 EXPECT_CALL(*client, didGetReadable()); 209 EXPECT_CALL(*client, didGetReadable());
210 EXPECT_CALL(checkpoint, Call(5)); 210 EXPECT_CALL(checkpoint, Call(5));
211 EXPECT_CALL(*client, didGetReadable()); 211 EXPECT_CALL(*client, didGetReadable());
212 EXPECT_CALL(checkpoint, Call(6)); 212 EXPECT_CALL(checkpoint, Call(6));
213 213
214 char buffer[3]; 214 char buffer[3];
215 size_t readBytes; 215 size_t readBytes;
216 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 216 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
217 ASSERT_TRUE(reader); 217 ASSERT_TRUE(reader);
218 checkpoint.Call(1); 218 checkpoint.Call(1);
219 testing::runPendingTasks(); 219 testing::runPendingTasks();
220 checkpoint.Call(2); 220 checkpoint.Call(2);
221 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes)); 221 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes));
222 testing::runPendingTasks(); 222 testing::runPendingTasks();
223 checkpoint.Call(3); 223 checkpoint.Call(3);
224 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes)); 224 EXPECT_EQ(kShouldWait, reader->read(buffer, 3, kNone, &readBytes));
225 testing::runPendingTasks(); 225 testing::runPendingTasks();
226 checkpoint.Call(4); 226 checkpoint.Call(4);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EXPECT_CALL(checkpoint, Call(3)); 274 EXPECT_CALL(checkpoint, Call(3));
275 EXPECT_CALL(*client, didGetReadable()); 275 EXPECT_CALL(*client, didGetReadable());
276 EXPECT_CALL(checkpoint, Call(4)); 276 EXPECT_CALL(checkpoint, Call(4));
277 EXPECT_CALL(*client, didGetReadable()); 277 EXPECT_CALL(*client, didGetReadable());
278 EXPECT_CALL(checkpoint, Call(5)); 278 EXPECT_CALL(checkpoint, Call(5));
279 EXPECT_CALL(*client, didGetReadable()); 279 EXPECT_CALL(*client, didGetReadable());
280 EXPECT_CALL(checkpoint, Call(6)); 280 EXPECT_CALL(checkpoint, Call(6));
281 281
282 const void* buffer; 282 const void* buffer;
283 size_t available; 283 size_t available;
284 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 284 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
285 ASSERT_TRUE(reader); 285 ASSERT_TRUE(reader);
286 checkpoint.Call(1); 286 checkpoint.Call(1);
287 testing::runPendingTasks(); 287 testing::runPendingTasks();
288 checkpoint.Call(2); 288 checkpoint.Call(2);
289 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); 289 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available));
290 testing::runPendingTasks(); 290 testing::runPendingTasks();
291 checkpoint.Call(3); 291 checkpoint.Call(3);
292 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); 292 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available));
293 testing::runPendingTasks(); 293 testing::runPendingTasks();
294 checkpoint.Call(4); 294 checkpoint.Call(4);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 345
346 InSequence s; 346 InSequence s;
347 EXPECT_CALL(checkpoint, Call(1)); 347 EXPECT_CALL(checkpoint, Call(1));
348 EXPECT_CALL(*client, didGetReadable()); 348 EXPECT_CALL(*client, didGetReadable());
349 EXPECT_CALL(checkpoint, Call(2)); 349 EXPECT_CALL(checkpoint, Call(2));
350 EXPECT_CALL(*client, didGetReadable()); 350 EXPECT_CALL(*client, didGetReadable());
351 EXPECT_CALL(checkpoint, Call(3)); 351 EXPECT_CALL(checkpoint, Call(3));
352 352
353 const void* buffer; 353 const void* buffer;
354 size_t available; 354 size_t available;
355 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 355 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
356 ASSERT_TRUE(reader); 356 ASSERT_TRUE(reader);
357 checkpoint.Call(1); 357 checkpoint.Call(1);
358 testing::runPendingTasks(); 358 testing::runPendingTasks();
359 checkpoint.Call(2); 359 checkpoint.Call(2);
360 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); 360 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available));
361 testing::runPendingTasks(); 361 testing::runPendingTasks();
362 checkpoint.Call(3); 362 checkpoint.Call(3);
363 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); 363 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available));
364 } 364 }
365 365
(...skipping 14 matching lines...) Expand all
380 380
381 InSequence s; 381 InSequence s;
382 EXPECT_CALL(checkpoint, Call(1)); 382 EXPECT_CALL(checkpoint, Call(1));
383 EXPECT_CALL(*client, didGetReadable()); 383 EXPECT_CALL(*client, didGetReadable());
384 EXPECT_CALL(checkpoint, Call(2)); 384 EXPECT_CALL(checkpoint, Call(2));
385 EXPECT_CALL(*client, didGetReadable()); 385 EXPECT_CALL(*client, didGetReadable());
386 EXPECT_CALL(checkpoint, Call(3)); 386 EXPECT_CALL(checkpoint, Call(3));
387 387
388 const void* buffer; 388 const void* buffer;
389 size_t available; 389 size_t available;
390 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 390 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
391 ASSERT_TRUE(reader); 391 ASSERT_TRUE(reader);
392 checkpoint.Call(1); 392 checkpoint.Call(1);
393 testing::runPendingTasks(); 393 testing::runPendingTasks();
394 checkpoint.Call(2); 394 checkpoint.Call(2);
395 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); 395 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available));
396 testing::runPendingTasks(); 396 testing::runPendingTasks();
397 checkpoint.Call(3); 397 checkpoint.Call(3);
398 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); 398 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available));
399 } 399 }
400 400
(...skipping 14 matching lines...) Expand all
415 415
416 InSequence s; 416 InSequence s;
417 EXPECT_CALL(checkpoint, Call(1)); 417 EXPECT_CALL(checkpoint, Call(1));
418 EXPECT_CALL(*client, didGetReadable()); 418 EXPECT_CALL(*client, didGetReadable());
419 EXPECT_CALL(checkpoint, Call(2)); 419 EXPECT_CALL(checkpoint, Call(2));
420 EXPECT_CALL(*client, didGetReadable()); 420 EXPECT_CALL(*client, didGetReadable());
421 EXPECT_CALL(checkpoint, Call(3)); 421 EXPECT_CALL(checkpoint, Call(3));
422 422
423 const void* buffer; 423 const void* buffer;
424 size_t available; 424 size_t available;
425 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainRead er(client); 425 std::unique_ptr<FetchDataConsumerHandle::Reader> reader = handle->obtainFetc hDataReader(client);
426 ASSERT_TRUE(reader); 426 ASSERT_TRUE(reader);
427 checkpoint.Call(1); 427 checkpoint.Call(1);
428 testing::runPendingTasks(); 428 testing::runPendingTasks();
429 checkpoint.Call(2); 429 checkpoint.Call(2);
430 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); 430 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available));
431 testing::runPendingTasks(); 431 testing::runPendingTasks();
432 checkpoint.Call(3); 432 checkpoint.Call(3);
433 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); 433 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available));
434 } 434 }
435 435
(...skipping 13 matching lines...) Expand all
449 EXPECT_CALL(checkpoint, Call(4)); 449 EXPECT_CALL(checkpoint, Call(4));
450 450
451 { 451 {
452 // We need this scope to collect local handles. 452 // We need this scope to collect local handles.
453 ScriptState::Scope scope(getScriptState()); 453 ScriptState::Scope scope(getScriptState());
454 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab leStream()")); 454 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab leStream()"));
455 ASSERT_FALSE(stream.isEmpty()); 455 ASSERT_FALSE(stream.isEmpty());
456 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle( stream); 456 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle( stream);
457 ASSERT_TRUE(handle); 457 ASSERT_TRUE(handle);
458 458
459 reader = handle->obtainReader(client); 459 reader = handle->obtainFetchDataReader(client);
460 ASSERT_TRUE(reader); 460 ASSERT_TRUE(reader);
461 } 461 }
462 462
463 checkpoint.Call(1); 463 checkpoint.Call(1);
464 testing::runPendingTasks(); 464 testing::runPendingTasks();
465 checkpoint.Call(2); 465 checkpoint.Call(2);
466 stream.clear(); 466 stream.clear();
467 gc(); 467 gc();
468 checkpoint.Call(3); 468 checkpoint.Call(3);
469 testing::runPendingTasks(); 469 testing::runPendingTasks();
(...skipping 21 matching lines...) Expand all
491 EXPECT_CALL(checkpoint, Call(5)); 491 EXPECT_CALL(checkpoint, Call(5));
492 492
493 { 493 {
494 // We need this scope to collect local handles. 494 // We need this scope to collect local handles.
495 ScriptState::Scope scope(getScriptState()); 495 ScriptState::Scope scope(getScriptState());
496 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab leStream()")); 496 stream = ScriptValue(getScriptState(), evalWithPrintingError("new Readab leStream()"));
497 ASSERT_FALSE(stream.isEmpty()); 497 ASSERT_FALSE(stream.isEmpty());
498 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle( stream); 498 std::unique_ptr<ReadableStreamDataConsumerHandle> handle = createHandle( stream);
499 ASSERT_TRUE(handle); 499 ASSERT_TRUE(handle);
500 500
501 reader = handle->obtainReader(client); 501 reader = handle->obtainFetchDataReader(client);
502 ASSERT_TRUE(reader); 502 ASSERT_TRUE(reader);
503 } 503 }
504 504
505 const void* buffer; 505 const void* buffer;
506 size_t available; 506 size_t available;
507 checkpoint.Call(1); 507 checkpoint.Call(1);
508 testing::runPendingTasks(); 508 testing::runPendingTasks();
509 checkpoint.Call(2); 509 checkpoint.Call(2);
510 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available)); 510 EXPECT_EQ(kShouldWait, reader->beginRead(&buffer, kNone, &available));
511 511
512 testing::runPendingTasks(); 512 testing::runPendingTasks();
513 checkpoint.Call(3); 513 checkpoint.Call(3);
514 stream.clear(); 514 stream.clear();
515 gc(); 515 gc();
516 checkpoint.Call(4); 516 checkpoint.Call(4);
517 testing::runPendingTasks(); 517 testing::runPendingTasks();
518 518
519 checkpoint.Call(5); 519 checkpoint.Call(5);
520 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available)); 520 EXPECT_EQ(kUnexpectedError, reader->beginRead(&buffer, kNone, &available));
521 } 521 }
522 522
523 } // namespace 523 } // namespace
524 524
525 } // namespace blink 525 } // namespace blink
526
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698